Search in sources :

Example 46 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class SubArrayVisitor method visitAnnotation.

/**
 * Visit an annotation element of the visited array.
 *
 * @param name : null
 * @param desc : annotation to visit
 * @return the visitor which will visit the annotation
 * @see org.objectweb.asm.AnnotationVisitor#visitAnnotation(String, String)
 */
public AnnotationVisitor visitAnnotation(String name, String desc) {
    // Sub annotations are map to sub-elements
    Element elem = Elements.buildElement(Type.getType(desc));
    m_elem.addElement(elem);
    return new GenericVisitor(elem);
}
Also used : Element(org.apache.felix.ipojo.metadata.Element)

Example 47 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class MetadataRenderer method renderElement.

private void renderElement(Element element, StringBuilder builder) {
    // If the element is already here, do not re-add the element.
    if (!isFiltered(element)) {
        // Print the beginning of the element
        startElement(element, builder);
        // Render all attributes
        for (Attribute attribute : element.getAttributes()) {
            renderAttribute(attribute, builder);
        }
        // Render child elements
        for (Element child : element.getElements()) {
            renderElement(child, builder);
        }
        // Print the end of the element
        endElement(builder);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 48 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class InnerClassAdapterTest method testThatManipulationMetadataContainsTheInnerClasses.

@Test
public void testThatManipulationMetadataContainsTheInnerClasses() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    Manipulator manipulator = new Manipulator(this.getClass().getClassLoader());
    String className = "test.inner.ComponentWithInnerClasses";
    manipulate(className, manipulator);
    assertThat(manipulator.getInnerClasses().size()).isEqualTo(3);
    Element manipulation = manipulator.getManipulationMetadata();
    System.out.println(manipulation);
    Element[] inners = manipulation.getElements("inner");
    assertThat(inners.length).isEqualTo(3);
    Element inner = getInnerClassMetadataByName(inners, "MyInnerWithANativeMethod");
    assertThat(inner).isNotNull();
    assertThat(getMethodByName(inner.getElements("method"), "foo")).isNotNull();
    inner = getInnerClassMetadataByName(inners, "MyInnerClass");
    assertThat(inner).isNotNull();
    assertThat(getMethodByName(inner.getElements("method"), "foo")).isNotNull();
    inner = getInnerClassMetadataByName(inners, "1");
    assertThat(inner).isNotNull();
    assertThat(getMethodByName(inner.getElements("method"), "compute")).isNotNull();
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) Test(org.junit.Test)

Example 49 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class RemanipulationTest method testDoubleManipulationWithAnnotations.

/**
 * Tests checking that the consecutive manipulation does still returns valid metadata (from annotations),
 * and valid manipulation metadata.
 *
 * @throws IOException
 * @throws ClassNotFoundException
 */
public void testDoubleManipulationWithAnnotations() throws IOException, ClassNotFoundException {
    Reporter reporter = mock(Reporter.class);
    // Step 1 - First collection and manipulation
    // 1.1 Metadata collection
    byte[] origin = ManipulatorTest.getBytesFromFile(new File("target/test-classes/test/PlentyOfAnnotations.class"));
    MiniStore store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", origin);
    AnnotationMetadataProvider provider = new AnnotationMetadataProvider(store, reporter);
    List<Element> originalMetadata = provider.getMetadatas();
    // 1.2 Manipulation
    Manipulator manipulator = new Manipulator(this.getClass().getClassLoader());
    manipulator.prepare(origin);
    byte[] clazz = manipulator.manipulate(origin);
    Element originalManipulationMetadata = manipulator.getManipulationMetadata();
    // 1.3 Check that the class is valid
    ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
    Class cl = classloader.findClass("test.PlentyOfAnnotations");
    Assert.assertNotNull(cl);
    // ---------------
    // Step 2 - Second collection and manipulation
    // We use the output class as entry.
    // 2.1 Metadata collection
    store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", clazz);
    provider = new AnnotationMetadataProvider(store, reporter);
    List<Element> metadataAfterOneManipulation = provider.getMetadatas();
    // 2.2 Manipulation
    manipulator = new Manipulator(this.getClass().getClassLoader());
    manipulator.prepare(clazz);
    byte[] clazz2 = manipulator.manipulate(clazz);
    Element manipulationMetadataAfterSecondManipulation = manipulator.getManipulationMetadata();
    // 2.3 Check that the class is valid
    classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
    cl = classloader.findClass("test.PlentyOfAnnotations");
    Assert.assertNotNull(cl);
    // ---------------
    // Step 3 - Third collection and manipulation
    // We use the output class of 2 as entry.
    // 3.1 Metadata collection
    store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", clazz2);
    provider = new AnnotationMetadataProvider(store, reporter);
    List<Element> metadataAfterTwoManipulation = provider.getMetadatas();
    // 3.2 Manipulation
    manipulator = new Manipulator(this.getClass().getClassLoader());
    manipulator.prepare(clazz2);
    byte[] clazz3 = manipulator.manipulate(clazz2);
    Element manipulationMetadataAfterThirdManipulation = manipulator.getManipulationMetadata();
    // 3.3 Check that the class is valid
    classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
    cl = classloader.findClass("test.PlentyOfAnnotations");
    Assert.assertNotNull(cl);
    // ---------------
    // Verification
    // Unchanged metadata
    Assert.assertEquals(originalMetadata.toString(), metadataAfterOneManipulation.toString());
    Assert.assertEquals(originalMetadata.toString(), metadataAfterTwoManipulation.toString());
    // Unchanged manipulation metadata
    Assert.assertEquals(originalManipulationMetadata.toString(), manipulationMetadataAfterSecondManipulation.toString());
    Assert.assertEquals(originalManipulationMetadata.toString(), manipulationMetadataAfterThirdManipulation.toString());
}
Also used : Reporter(org.apache.felix.ipojo.manipulator.Reporter) Element(org.apache.felix.ipojo.metadata.Element) AnnotationMetadataProvider(org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider) File(java.io.File)

Example 50 with Element

use of org.apache.felix.ipojo.metadata.Element in project felix by apache.

the class ManipulationEngineTestCase method testManipulationOfSimpleClass.

public void testManipulationOfSimpleClass() throws Exception {
    when(store.read(anyString())).thenReturn(from(ClusterDaemon.class));
    when(visitor.visitManipulationResult(any(Element.class))).thenReturn(result);
    String path = Strings.asResourcePath(ClusterDaemon.class.getName());
    Element metadata = new Element("", "");
    ManipulationUnit info = new ManipulationUnit(path, metadata);
    engine.addManipulationUnit(info);
    engine.generate();
    verify(visitor).visitManipulationResult(eq(metadata));
    verify(result).visitClassStructure(any(Element.class));
    verify(result).visitManipulatedResource(eq(path), any(byte[].class));
    verify(result).visitEnd();
}
Also used : ClusterDaemon(test.ClusterDaemon) Element(org.apache.felix.ipojo.metadata.Element) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

Element (org.apache.felix.ipojo.metadata.Element)400 Test (org.junit.Test)126 Attribute (org.apache.felix.ipojo.metadata.Attribute)109 ConfigurationException (org.apache.felix.ipojo.ConfigurationException)22 ParseException (org.apache.felix.ipojo.parser.ParseException)14 PojoMetadata (org.apache.felix.ipojo.parser.PojoMetadata)14 ArrayList (java.util.ArrayList)13 Reporter (org.apache.felix.ipojo.manipulator.Reporter)12 FieldMetadata (org.apache.felix.ipojo.parser.FieldMetadata)12 Dictionary (java.util.Dictionary)10 Properties (java.util.Properties)10 MethodMetadata (org.apache.felix.ipojo.parser.MethodMetadata)10 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)10 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)9 IOException (java.io.IOException)8 List (java.util.List)8 Before (org.junit.Before)7 Enumeration (java.util.Enumeration)6 ComponentWorkbench (org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench)6 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)6