public void process(Contribution contribution, IntrospectionContext context) { try { Source source = contribution.getSource(); Composite composite = loaderRegistry.load(source, Composite.class, context); QName name = composite.getName(); Resource resource = new Resource(contribution, source, "application/xml"); QNameSymbol symbol = new QNameSymbol(name); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol); element.setValue(composite); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); contribution.addResource(resource); ContributionManifest manifest = contribution.getManifest(); Deployable deployable = new Deployable(name); manifest.addDeployable(deployable); QNameExport export = new QNameExport(name.getNamespaceURI()); manifest.addExport(export); } catch (LoaderException e) { throw new Fabric3Exception(e); } }
public void index(Resource resource, IntrospectionContext context) { XMLStreamReader reader = null; InputStream stream = null; try { Source source = resource.getSource(); stream = source.openStream(); reader = xmlFactory.createXMLStreamReader(stream); reader.nextTag(); Location startLocation = reader.getLocation(); if (!"composite".equals(reader.getName().getLocalPart())) { // not a composite root element return; } String name = reader.getAttributeValue(null, "name"); if (name == null) { context.addError(new MissingAttribute("Composite name not specified", startLocation)); return; } String targetNamespace = reader.getAttributeValue(null, "targetNamespace"); QName compositeName = new QName(targetNamespace, name); QNameSymbol symbol = new QNameSymbol(compositeName); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol); resource.addResourceElement(element); validateUnique(resource, element, reader, context); } catch (XMLStreamException e) { throw new Fabric3Exception(e); } finally { try { if (stream != null) { stream.close(); } } catch (IOException e) { e.printStackTrace(); } try { if (reader != null) { reader.close(); } } catch (XMLStreamException e) { e.printStackTrace(); } } }