コード例 #1
0
  public void testName() throws Exception {
    Field field = TestClass.class.getDeclaredField("producer2");
    Producer annotation = field.getAnnotation(Producer.class);
    IntrospectionContext context = new DefaultIntrospectionContext();
    TypeMapping mapping = new TypeMapping();
    context.addTypeMapping(TestClass.class, mapping);

    processor.visitField(annotation, field, TestClass.class, componentType, context);
    assertEquals(0, context.getErrors().size());
    assertTrue(componentType.getProducers().containsKey("foo"));
  }
コード例 #2
0
  public void testMethod() throws Exception {
    Method method = TestClass.class.getDeclaredMethod("setProducer", TestProducer.class);
    Producer annotation = method.getAnnotation(Producer.class);
    IntrospectionContext context = new DefaultIntrospectionContext();
    TypeMapping mapping = new TypeMapping();
    context.addTypeMapping(TestClass.class, mapping);

    processor.visitMethod(annotation, method, TestClass.class, componentType, context);
    assertEquals(0, context.getErrors().size());
    assertTrue(componentType.getProducers().containsKey("producer"));
  }
コード例 #3
0
 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;
         }
       }
     }
   }
 }
コード例 #4
0
 @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);
 }
コード例 #5
0
 public ExtendsDeclaration load(XMLStreamReader reader, IntrospectionContext context)
     throws XMLStreamException {
   Location startLocation = reader.getLocation();
   validateAttributes(reader, context);
   String name = reader.getAttributeValue(null, "name");
   if (name == null) {
     MissingPackage failure =
         new MissingPackage("No name specified for extends declaration", startLocation);
     context.addError(failure);
     return null;
   }
   return new ExtendsDeclaration(name);
 }
コード例 #6
0
 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();
     }
   }
 }