public static ResourceBasedJobTemplate forResourcePath(String path, JobCatalogWithTemplates catalog) throws SpecNotFoundException, TemplateException, IOException, URISyntaxException { return forURI(new URI(path), catalog); }
@Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { // resources are accessed by relative uris, make the uri relative (get path, strip initial /) URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); }
@Test public void testRequiredAttrList() throws Exception { Properties jobProps = this.userProp; Collection<String> requiredConfigList = ResourceBasedJobTemplate.forURI(new URI( jobProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH)), new PackagedTemplatesJobCatalogDecorator()) .getRequiredConfigList(); Assert.assertEquals(requiredConfigList.size(), 3); Assert.assertTrue( requiredConfigList.contains("required0")); Assert.assertTrue( requiredConfigList.contains("required1")); Assert.assertTrue( requiredConfigList.contains("required2")); }
public static ResourceBasedJobTemplate forResourcePath(String path, JobCatalogWithTemplates catalog) throws SpecNotFoundException, TemplateException, IOException, URISyntaxException { return forURI(new URI(path), catalog); }
@Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { // resources are accessed by relative uris, make the uri relative (get path, strip initial /) URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); }