Package org.apache.felix.ipojo.manipulator.metadata.annotation

Examples of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench


        bind(ServiceProperty.class)
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
                        String name = context.getFieldNode().name;
                        ComponentWorkbench workbench = context.getWorkbench();

                        if (!workbench.getIds().containsKey("provides")) {
                            // The provides annotation is already computed.
                            context.getReporter().warn("The component does not provide services, skip ServiceProperty for {}", name);
                            return null;
                        } else {
                            // Get the provides element
                            Element provides = workbench.getIds().get("provides");
                            return new FieldPropertyVisitor(name, provides);
                        }

                    }
                });

        bind(ServiceController.class)
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
                        String name = context.getFieldNode().name;
                        ComponentWorkbench workbench = context.getWorkbench();

                        if (!workbench.getIds().containsKey("provides")) { // The provides annotation is already computed.
                            context.getReporter().warn("The component does not provide services, skip @ServiceController for {}", name);
                            return null;
                        } else {
                            // Get the provides element
                            Element provides = workbench.getIds().get("provides");
                            return new ServiceControllerVisitor(name, provides);
                        }

                    }
                });

        bind(Property.class)
                .when(on(ElementType.FIELD))
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {

                        ComponentWorkbench workbench = context.getWorkbench();
                        Element properties = Elements.getPropertiesElement(workbench);
                        String name = context.getFieldNode().name;
                        return new FieldPropertyVisitor(name, properties);
                    }

                })
                .when(on(ElementType.METHOD))
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {

                        ComponentWorkbench workbench = context.getWorkbench();
                        // @Property on method parameter
                        Element properties = Elements.getPropertiesElement(workbench);
                        String name = context.getMethodNode().name;
                        return new MethodPropertyVisitor(properties, name);
                    }
                })
                .when(on(ElementType.PARAMETER))
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {

                        ComponentWorkbench workbench = context.getWorkbench();
                        // @Property on method parameter
                        Element properties = Elements.getPropertiesElement(workbench);
                        MethodNode method = context.getMethodNode();
                        return new ParameterPropertyVisitor(properties, method, context.getParameterIndex());
                    }
View Full Code Here


*/
public class ComponentVisitorTestCase extends TestCase {

    public void testDefaultNameIsClassname() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, clazz());
        ComponentVisitor visitor = new ComponentVisitor(workbench, reporter);
        visitor.visitEnd();

        Element root = workbench.getRoot();
        assertNotNull(root);
        assertEquals("my.Component", root.getAttribute("name"));
    }
View Full Code Here

        assertEquals("my.Component", root.getAttribute("name"));
    }

    public void testNameAttribute() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, clazz());
        ComponentVisitor visitor = new ComponentVisitor(workbench, reporter);
        visitor.visit("name", "changed");
        visitor.visitEnd();

        Element root = workbench.getRoot();
        assertNotNull(root);
        assertEquals("changed", root.getAttribute("name"));
    }
View Full Code Here

        assertEquals("changed", root.getAttribute("name"));
    }

    public void testPublicFactoryDeprecationSupport() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, clazz());
        ComponentVisitor visitor = new ComponentVisitor(workbench, reporter);
        visitor.visit("public_factory", "false");
        visitor.visitEnd();

        Element root = workbench.getRoot();
        assertNotNull(root);
        assertEquals("false", root.getAttribute("public"));
    }
View Full Code Here

        assertEquals("false", root.getAttribute("public"));
    }

    public void testFactoryMethodDeprecationSupport() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, clazz());
        ComponentVisitor visitor = new ComponentVisitor(workbench, reporter);
        visitor.visit("factory_method", "create");
        visitor.visitEnd();

        Element root = workbench.getRoot();
        assertNotNull(root);
        assertEquals("create", root.getAttribute("factory-method"));
    }
View Full Code Here

    private HandlerDeclarationVisitor visitor;

    @Override
    public void setUp() throws Exception {
        reporter = mock(Reporter.class);
        workbench = new ComponentWorkbench(null, node());
        workbench.setRoot(new Element("container", null));
        visitor = new HandlerDeclarationVisitor(workbench, builder(), reporter);
    }
View Full Code Here

*/
public class MethodBindVisitorTestCase extends TestCase {

    public void testIdentifierProvided() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, type());
        MethodNode node = new MethodNode();
        node.name = "myMethod";

        MethodBindVisitor visitor = new MethodBindVisitor(workbench, Action.BIND, node, reporter);
        visitor.visit("id", "my-identifier");
        visitor.visitEnd();

        assertNotNull(workbench.getIds().get("my-identifier"));
    }
View Full Code Here

        assertNotNull(workbench.getIds().get("my-identifier"));
    }

    public void testNoIdentifierButSpecificationAsAttributeProvided() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, type());
        MethodNode node = new MethodNode();
        node.name = "notify";
        node.desc = "()V";

        MethodBindVisitor visitor = new MethodBindVisitor(workbench, Action.BIND, node, reporter);
        visitor.visit("specification", "my.Service");
        visitor.visitEnd();

        assertNotNull(workbench.getIds().get("my.Service"));
    }
View Full Code Here

        assertNotNull(workbench.getIds().get("my.Service"));
    }

    public void testNoIdentifierAndNoSpecificationProvided() throws Exception {
        Reporter reporter = mock(Reporter.class);
        ComponentWorkbench workbench = new ComponentWorkbench(null, type());
        MethodNode node = new MethodNode();
        node.name = "notify";
        node.desc = "()V";

        MethodBindVisitor visitor = new MethodBindVisitor(workbench, Action.BIND, node, reporter);
View Full Code Here

        bind(ServiceProperty.class)
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
                        String name = context.getFieldNode().name;
                        ComponentWorkbench workbench = context.getWorkbench();

                        if (!workbench.getIds().containsKey("provides")) {
                            // The provides annotation is already computed.
                            context.getReporter().warn("The component does not provide services, skip ServiceProperty for {}", name);
                            return null;
                        } else {
                            // Get the provides element
                            Element provides = workbench.getIds().get("provides");
                            return new FieldPropertyVisitor(name, provides);
                        }

                    }
                });

        bind(ServiceController.class)
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
                        String name = context.getFieldNode().name;
                        ComponentWorkbench workbench = context.getWorkbench();

                        if (!workbench.getIds().containsKey("provides")) { // The provides annotation is already computed.
                            context.getReporter().warn("The component does not provide services, skip @ServiceController for {}", name);
                            return null;
                        } else {
                            // Get the provides element
                            Element provides = workbench.getIds().get("provides");
                            return new ServiceControllerVisitor(name, provides);
                        }

                    }
                });

        bind(Property.class)
                .when(on(ElementType.FIELD))
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {

                        ComponentWorkbench workbench = context.getWorkbench();
                        Element properties = Elements.getPropertiesElement(workbench);
                        String name = context.getFieldNode().name;
                        return new FieldPropertyVisitor(name, properties);
                    }

                })
                .when(on(ElementType.METHOD))
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {

                        ComponentWorkbench workbench = context.getWorkbench();
                        // @Property on method parameter
                        Element properties = Elements.getPropertiesElement(workbench);
                        String name = context.getMethodNode().name;
                        return new MethodPropertyVisitor(properties, name);
                    }
                })
                .when(on(ElementType.PARAMETER))
                .to(new AnnotationVisitorFactory() {
                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {

                        ComponentWorkbench workbench = context.getWorkbench();
                        // @Property on method parameter
                        Element properties = Elements.getPropertiesElement(workbench);
                        MethodNode method = context.getMethodNode();
                        return new ParameterPropertyVisitor(properties, method, context.getParameterIndex());
                    }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.