public <O> O load(URL url, Class<O> type, IntrospectionContext ctx) throws LoaderException { InputStream stream; try { stream = url.openStream(); } catch (IOException e) { throw new LoaderException("Invalid URL: " + url.toString(), e); } try { try { return load(url, stream, type, ctx); } catch (XMLStreamException e) { throw new LoaderException("Invalid URL: " + url.toString(), e); } } finally { try { stream.close(); } catch (IOException e) { // ignore } } }
public String toString() { StringBuilder builder = new StringBuilder(); builder.append(getClass().getName()); builder.append(" in "); builder.append(resourceURI == null ? "unknown" : resourceURI); if (line != -1) { builder.append(" at ").append(line).append(',').append(column); } builder.append(": "); builder.append(getLocalizedMessage()); return builder.toString(); } }
public WebImplementation load(XMLStreamReader reader, IntrospectionContext context) throws XMLStreamException { Location startLocation = reader.getLocation(); URI uri = parseUri(reader, startLocation, context); WebImplementation impl = new WebImplementation(uri); validateAttributes(reader, context, impl); for (WebImplementationIntrospector introspector : introspectors) { introspector.introspect(impl, context); } try { ComponentType type = impl.getComponentType(); // FIXME we should allow implementation to specify the component type; ComponentType componentType = loadComponentType(context); for (Map.Entry<String, ReferenceDefinition> entry : componentType.getReferences().entrySet()) { type.add(entry.getValue()); } for (Map.Entry<String, Property> entry : componentType.getProperties().entrySet()) { type.add(entry.getValue()); } } catch (LoaderException e) { if (e.getCause() instanceof FileNotFoundException) { // ignore since we allow component types not to be specified in the web app } else { ElementLoadFailure failure = new ElementLoadFailure("Error loading web.componentType", e, startLocation); context.addError(failure); return null; } } LoaderUtil.skipToEndElement(reader); return impl; }
public void processManifest(Contribution contribution, IntrospectionContext context) throws InstallException { ContributionManifest manifest; try { URL sourceUrl = contribution.getLocation(); URL manifestUrl = new URL("jar:" + sourceUrl.toExternalForm() + "!/WEB-INF/sca-contribution.xml"); ClassLoader cl = getClass().getClassLoader(); URI uri = contribution.getUri(); IntrospectionContext childContext = new DefaultIntrospectionContext(uri, cl); Source source = new UrlSource(manifestUrl); manifest = loader.load(source, ContributionManifest.class, childContext); if (childContext.hasErrors()) { context.addErrors(childContext.getErrors()); } if (childContext.hasWarnings()) { context.addWarnings(childContext.getWarnings()); } contribution.setManifest(manifest); } catch (LoaderException e) { if (e.getCause() instanceof FileNotFoundException) { // ignore no manifest found } else { throw new InstallException(e); } } catch (MalformedURLException e) { // ignore no manifest found } }
if (e.getCause() instanceof FileNotFoundException) {
private ComponentType loadComponentType(IntrospectionContext context) throws LoaderException { URL url; try { url = new URL(context.getSourceBase(), "web.componentType"); } catch (MalformedURLException e) { // this should not happen throw new LoaderException(e.getMessage(), e); } Source source = new UrlSource(url); IntrospectionContext childContext = new DefaultIntrospectionContext(null, context.getClassLoader(), url); ComponentType componentType = registry.load(source, ComponentType.class, childContext); if (childContext.hasErrors()) { context.addErrors(childContext.getErrors()); } if (childContext.hasWarnings()) { context.addWarnings(childContext.getWarnings()); } return componentType; } }