public static <T extends Resource> T loadProvider(AnyObject ao, Class<T> type) throws ResourceInitializationException { ResourceHandle handle = buildHandleFromObject(ao); try { return buildResource(handle, type); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { type.getCanonicalName(), ao }, e); } }
public static <T extends Resource> T buildResource(ResourceHandle handle, Class<T> type) throws ResourceInitializationException { Map<String, Object> tuples = Maps.newLinkedHashMap(); try { Class<? extends Resource> resourceClass = loadFromClassOrInherit(handle, Resource.class, tuples); return buildResource(resourceClass, tuples, type); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { type.getCanonicalName(), handle }, e); } }
private static <T extends Resource> T getProvider(Map<String, String> providerConfMap, Class<T> type) throws ResourceInitializationException { Resource resource = GLOBAL_CONF_TO_RESOURCE.get(providerConfMap); if (resource == null) { resource = BaseExperimentBuilder .buildResource(BaseExperimentBuilder.buildHandleFromMap(providerConfMap), type); } if (resource == null) { throw new ResourceInitializationException(); } GLOBAL_CONF_TO_RESOURCE.put(providerConfMap, resource); return type.cast(resource); }
public static <T extends Resource> List<T> createResourceList(List<Map<String, String>> names, Class<T> type) { List<T> resources = Lists.newArrayList(); for (Map<String, String> name : names) { try { ResourceHandle handle = buildHandleFromMap(name); resources.add(buildResource(handle, type)); } catch (Exception e) { System.err.printf("[ERROR] %s Caused by:\n", e); Throwables.getRootCause(e).printStackTrace(); } } return resources; }
public static <T extends Resource> T loadProvider(String provider, Class<T> type) throws ResourceInitializationException { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) yaml.load(provider); ResourceHandle handle = buildHandleFromMap(map); try { return buildResource(handle, type); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { type.getCanonicalName(), provider }, e); } }
@Override public <T extends Resource> T initializeResource(AnyObject config, String node, Class<T> type) throws Exception { AnyObject descriptor = config.getAnyObject(node); if (descriptor == null) { return null; } Map<String, Object> tuples = Maps.newLinkedHashMap(); Class<? extends Resource> cseClass = getFromClassOrInherit(descriptor, Resource.class, tuples); return buildResource(cseClass, tuples, type); }