private void validateUnique( Resource resource, ResourceElement<QNameSymbol, Composite> element, XMLStreamReader reader, IntrospectionContext context) { Contribution contribution = resource.getContribution(); for (Resource entry : contribution.getResources()) { if (resource == entry) { // skip self since the resource is added to the contribution and will be iterated continue; } if (resource.getContentType().equals(entry.getContentType())) { for (ResourceElement<?, ?> elementEntry : entry.getResourceElements()) { if (element.getSymbol().equals(elementEntry.getSymbol())) { QName name = element.getSymbol().getKey(); Location location = reader.getLocation(); Composite composite = element.getValue(); DuplicateComposite error = new DuplicateComposite( "Duplicate composite found with name: " + name, location, composite); context.addError(error); break; } } } } }
@SuppressWarnings({"unchecked"}) public void process(Resource resource, IntrospectionContext context) { Source source = resource.getSource(); ClassLoader classLoader = context.getClassLoader(); URI contributionUri = context.getContributionUri(); URL location = source.getBaseLocation(); IntrospectionContext childContext = new DefaultIntrospectionContext(contributionUri, classLoader, location); Composite composite; try { // check to see if the resource has already been evaluated composite = loader.load(source, Composite.class, childContext); } catch (LoaderException e) { throw new Fabric3Exception(e); } if (composite == null) { // composite could not be parsed InvalidXmlArtifact error = new InvalidXmlArtifact("Invalid composite: " + location, null); context.addError(error); return; } boolean found = false; for (ResourceElement element : resource.getResourceElements()) { if (element.getSymbol().getKey().equals(composite.getName())) { element.setValue(composite); found = true; break; } } if (!found) { // should not happen String identifier = composite.getName().toString(); throw new AssertionError("Resource element not found: " + identifier); } if (childContext.hasErrors()) { context.addErrors(childContext.getErrors()); } if (childContext.hasWarnings()) { context.addWarnings(childContext.getWarnings()); } resource.setState(ResourceState.PROCESSED); }