felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clement Escoffier (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FELIX-3699) Allow annotations to handle custom component definitions.
Date Wed, 10 Apr 2013 12:02:15 GMT

    [ https://issues.apache.org/jira/browse/FELIX-3699?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13627705#comment-13627705

Clement Escoffier commented on FELIX-3699:

It's already supported.

The visitor must declare itself as 'root'.
If the annotation requires the iPOJO manipulation, it must also add an attribute 'classname'
in the created metadata:

 * Copyright Adele Team LIG
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *   http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package fr.liglab.adele.cilia.annotations.visitors;

import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.commons.EmptyVisitor;

public class ProcessorVisitor extends EmptyVisitor implements ClassVisitor {

    private String NAMESPACE = "fr.liglab.adele.cilia";
    private Element processor = new Element("processor", NAMESPACE);
    private ComponentWorkbench workbench;

    public ProcessorVisitor(ComponentWorkbench workbench) {
        System.out.println("********** Creating visitor");
        this.workbench = workbench;

     * Visit @Processor annotation attributes.
    public void visit(String name, Object value) {
        System.out.println("Name: " + name + " Value: " + value);
        if (name.equals("name")) {
            processor.addAttribute(new Attribute("name", value.toString()));

     * Append to the "component" element computed attribute.
    public void visitEnd() {
        System.out.println("********** END visitor");

        // Advise: we recommend to be more defensive on the following instructions (check
if there is not a root already, check if classname is not already defined).

        // Add the classname attribute
        processor.addAttribute(new Attribute("classname", workbench.getClassNode().name.replace("/",

        // Declare ourself as root

> Allow annotations to handle custom component definitions.
> ---------------------------------------------------------
>                 Key: FELIX-3699
>                 URL: https://issues.apache.org/jira/browse/FELIX-3699
>             Project: Felix
>          Issue Type: New Feature
>          Components: iPOJO
>            Reporter: Issac Garcia
> Custom components are well handled in iPOJO using the metadata.xml, for example:
> <CustomComponent classname="MyClass" name="myCustomComponent">
>     <requires field="service"/>
> </CustomComponent>
> The custom component definition will, for example, add handlers and so on. It works very
well and is nice that iPOJO allows that kind of extensions. 
> But we can't declare a custom component by using annotations, for example doing:
> @CustomComponent
> public class MyClass {...}
> It will be a nice if iPOJO allows to do it using annotations, since the same functionality
must be possible with the metadata.mxl and with annotations.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

View raw message