use of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench in project felix by apache.
the class DefaultBindingModule method configure.
/**
* Configure all the iPOJO's default annotation's bindings.
*/
public void configure() {
// Class level annotations
// --------------------------------
bind(Component.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new ComponentVisitor(context.getWorkbench(), context.getReporter());
}
});
bind(Handler.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new HandlerVisitor(context.getWorkbench(), context.getReporter());
}
});
bind(Provides.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new ProvidesVisitor(context.getWorkbench());
}
});
bind(HandlerDeclaration.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
Reporter reporter = context.getReporter();
return new HandlerDeclarationVisitor(context.getWorkbench(), getFreshDocumentBuilder(reporter), reporter);
}
});
bind(Instantiate.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new InstantiateVisitor(context.getWorkbench());
}
});
// Field level annotations
// --------------------------------
bind(Requires.class).when(on(ElementType.FIELD)).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new RequiresVisitor(context.getWorkbench(), context.getFieldNode().name);
}
}).when(on(ElementType.PARAMETER)).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new ParameterBindVisitor(context.getWorkbench(), Action.BIND, context.getParameterIndex());
}
});
bind(Controller.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
return new ControllerVisitor(context.getWorkbench(), context.getFieldNode().name);
}
});
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());
}
});
bind(Validate.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new LifecycleVisitor(context.getWorkbench(), Names.computeEffectiveMethodName(node.name), LifecycleVisitor.Transition.VALIDATE);
}
});
bind(Invalidate.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new LifecycleVisitor(context.getWorkbench(), Names.computeEffectiveMethodName(node.name), LifecycleVisitor.Transition.INVALIDATE);
}
});
bind(Updated.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new UpdatedVisitor(context.getWorkbench(), Names.computeEffectiveMethodName(node.name));
}
});
bind(Bind.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new MethodBindVisitor(context.getWorkbench(), Action.BIND, node, context.getReporter());
}
});
bind(Unbind.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new MethodBindVisitor(context.getWorkbench(), Action.UNBIND, node, context.getReporter());
}
});
bind(Modified.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new MethodBindVisitor(context.getWorkbench(), Action.MODIFIED, node, context.getReporter());
}
});
bind(PostRegistration.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new PostRegistrationVisitor(context.getWorkbench(), node.name);
}
});
bind(PostUnregistration.class).to(new AnnotationVisitorFactory() {
public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
MethodNode node = context.getMethodNode();
return new PostUnregistrationVisitor(context.getWorkbench(), node.name);
}
});
bind(Context.class).to(new GenericVisitorFactory("context", ""));
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench in project felix by apache.
the class ComponentVisitorTestCase method testFactoryMethodDeprecationSupport.
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"));
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench in project felix by apache.
the class ComponentVisitorTestCase method testNameAttribute.
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"));
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench in project felix by apache.
the class ComponentVisitorTestCase method testDefaultNameIsClassname.
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"));
}
use of org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench in project felix by apache.
the class MethodBindVisitorTestCase method testIdentifierProvided.
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"));
}
Aggregations