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();
     }
   }
 }
 @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);
 }