You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Clement Escoffier (JIRA)" <ji...@apache.org> on 2013/04/10 14:10:16 UTC

[jira] [Comment Edited] (FELIX-3699) Allow annotations to handle custom component definitions.

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

Clement Escoffier edited comment on FELIX-3699 at 4/10/13 12:09 PM:
--------------------------------------------------------------------

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:

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()));
            return;
        }
    }

    /**
     * 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
        workbench.setRoot(processor);
    }
}

                
      was (Author: clement.escoffier):
    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,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 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()));
            return;
        }
    }

    /**
     * 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
        workbench.setRoot(processor);
    }
}

                  
> 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