org.apache.felix.scrplugin
Class SCRDescriptorGenerator

java.lang.Object
  extended by org.apache.felix.scrplugin.SCRDescriptorGenerator

public class SCRDescriptorGenerator
extends Object

The SCRDescriptorGenerator class does the hard work of generating the SCR descriptors. This class is being instantiated and configured by clients and the execute() method called to generate the descriptor files.

When using this class carefully consider calling all setter methods to properly configure the generator. All setter method document, which default value is assumed for the respective property if the setter is not called.

Instances of this class are not thread save and should not be reused.


Field Summary
protected  boolean strictMode
           
 
Constructor Summary
SCRDescriptorGenerator(Log logger)
          Create an instance of this generator using the given Log instance of logging.
 
Method Summary
protected  void addInterfaces(Service service, JavaTag serviceTag, JavaClassDescription description)
          Recursively add interfaces to the service.
protected  Component createComponent(JavaClassDescription description, JavaTag componentTag, MetaData metaData, IssueLog iLog)
          Create a component for the java class description.
protected  OCD doComponent(JavaTag tag, Component component, MetaData metaData, IssueLog iLog)
          Fill the component object with the information from the tag.
protected  void doReference(JavaTag reference, String name, Component component, String type)
           
protected  void doServices(JavaTag[] services, Component component, JavaClassDescription description)
          Process the service annotations
 boolean execute()
          Actually generates the Declarative Services and Metatype descriptors scanning the java sources provided by the descriptor manager.
static boolean getBoolean(JavaTag tag, String name, boolean defaultValue)
           
protected  JavaField getReferencedField(JavaTag tag, String ref)
           
protected  String getReferenceName(JavaTag reference, String defaultName)
           
 void setDescriptorManager(JavaClassDescriptorManager descriptorManager)
          Sets the JavaClassDescriptorManager instance used to access existing descriptors and to parse JavaDoc tags as well as interpret the SCR annotations.
 void setFinalName(String finalName)
          Sets the name of the SCR declaration descriptor file.
 void setGenerateAccessors(boolean generateAccessors)
          Defines whether bind and unbind methods are automatically created by the SCR descriptor generator.
 void setMetaTypeName(String metaTypeName)
          Sets the name of the file taking the Metatype Service descriptors.
 void setOutputDirectory(File outputDirectory)
          Sets the directory where the descriptor files will be created.
 void setProperties(Map<String,String> properties)
          Sets global properties to be set for each descriptor.
 void setSpecVersion(String specVersion)
          Sets the Declarative Services specification version number to be forced on the declarations.
 void setStrictMode(boolean strictMode)
          Defines whether warnings should be considered as errors and thus cause the generation process to fail.
protected  void testReference(Map<String,Object[]> references, JavaTag reference, String defaultName, boolean isInspectedClass)
          Test a newly found reference
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

strictMode

protected boolean strictMode
Constructor Detail

SCRDescriptorGenerator

public SCRDescriptorGenerator(Log logger)
Create an instance of this generator using the given Log instance of logging.

Method Detail

setOutputDirectory

public void setOutputDirectory(File outputDirectory)
Sets the directory where the descriptor files will be created.

This field has no default value and this setter must called prior to calling execute().


setDescriptorManager

public void setDescriptorManager(JavaClassDescriptorManager descriptorManager)
Sets the JavaClassDescriptorManager instance used to access existing descriptors and to parse JavaDoc tags as well as interpret the SCR annotations.

This field has no default value and this setter must called prior to calling execute().


setFinalName

public void setFinalName(String finalName)
Sets the name of the SCR declaration descriptor file. This file will be created in the OSGI-INF directory below the output directory.

This file will be overwritten if already existing. If no descriptors are created the file is actually removed.

The default value of this property is serviceComponents.xml.


setMetaTypeName

public void setMetaTypeName(String metaTypeName)
Sets the name of the file taking the Metatype Service descriptors. This file will be created in the OSGI-INF/metatype directory below the output directory.

This file will be overwritten if already existing. If no descriptors are created the file is actually removed.

The default value of this property is metatype.xml.


setGenerateAccessors

public void setGenerateAccessors(boolean generateAccessors)
Defines whether bind and unbind methods are automatically created by the SCR descriptor generator.

The generator uses the ASM library to create the method byte codes directly inside the class files. If bind and unbind methods are not to be created, the generator fails if such methods are missing.

The default value of this property is true.


setStrictMode

public void setStrictMode(boolean strictMode)
Defines whether warnings should be considered as errors and thus cause the generation process to fail.

The default value of this property is false.


setProperties

public void setProperties(Map<String,String> properties)
Sets global properties to be set for each descriptor. If a descriptor provides properties of the same name, the descriptor properties are preferred over the properties provided here.

The are no default global properties.


setSpecVersion

public void setSpecVersion(String specVersion)
Sets the Declarative Services specification version number to be forced on the declarations.

Supported values for this property are null to autodetect the specification version, 1.0 to force 1.0 descriptors and 1.1 to force 1.1 descriptors. If 1.0 descriptors are forced the generation fails if a descriptor requires 1.1 functionality.

The default is to generate the descriptor version according to the capabilities used by the descriptors. If no 1.1 capabilities, such as configuration-policy, are used, version 1.0 is used, otherwise a 1.1 descriptor is generated.


execute

public boolean execute()
                throws SCRDescriptorException,
                       SCRDescriptorFailureException
Actually generates the Declarative Services and Metatype descriptors scanning the java sources provided by the descriptor manager.

Returns:
true if descriptors have been generated.
Throws:
SCRDescriptorException
SCRDescriptorFailureException

createComponent

protected Component createComponent(JavaClassDescription description,
                                    JavaTag componentTag,
                                    MetaData metaData,
                                    IssueLog iLog)
                             throws SCRDescriptorException
Create a component for the java class description.

Parameters:
description -
Returns:
The generated component descriptor or null if any error occurs.
Throws:
SCRDescriptorException

doComponent

protected OCD doComponent(JavaTag tag,
                          Component component,
                          MetaData metaData,
                          IssueLog iLog)
                   throws SCRDescriptorException
Fill the component object with the information from the tag.

Parameters:
tag -
component -
Throws:
SCRDescriptorException

doServices

protected void doServices(JavaTag[] services,
                          Component component,
                          JavaClassDescription description)
                   throws SCRDescriptorException
Process the service annotations

Parameters:
services -
component -
description -
Throws:
SCRDescriptorException

addInterfaces

protected void addInterfaces(Service service,
                             JavaTag serviceTag,
                             JavaClassDescription description)
                      throws SCRDescriptorException
Recursively add interfaces to the service.

Throws:
SCRDescriptorException

testReference

protected void testReference(Map<String,Object[]> references,
                             JavaTag reference,
                             String defaultName,
                             boolean isInspectedClass)
                      throws SCRDescriptorException
Test a newly found reference

Parameters:
references -
reference -
defaultName -
isInspectedClass -
Throws:
SCRDescriptorException

getReferenceName

protected String getReferenceName(JavaTag reference,
                                  String defaultName)
                           throws SCRDescriptorException
Throws:
SCRDescriptorException

getReferencedField

protected JavaField getReferencedField(JavaTag tag,
                                       String ref)
                                throws SCRDescriptorException
Throws:
SCRDescriptorException

doReference

protected void doReference(JavaTag reference,
                           String name,
                           Component component,
                           String type)
                    throws SCRDescriptorException
Parameters:
reference -
defaultName -
component -
Throws:
SCRDescriptorException

getBoolean

public static boolean getBoolean(JavaTag tag,
                                 String name,
                                 boolean defaultValue)


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.