You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2010/05/08 10:24:46 UTC
svn commit: r942341 - in
/felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge: pom.xml
src/main/java/org/apache/felix/ipojo/metatype/bridge/MetatypeFactoryWrapper.java
Author: clement
Date: Sat May 8 08:24:46 2010
New Revision: 942341
URL: http://svn.apache.org/viewvc?rev=942341&view=rev
Log:
Add javadoc, update dependencies
Modified:
felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/pom.xml
felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/src/main/java/org/apache/felix/ipojo/metatype/bridge/MetatypeFactoryWrapper.java
Modified: felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/pom.xml?rev=942341&r1=942340&r2=942341&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/pom.xml (original)
+++ felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/pom.xml Sat May 8 08:24:46 2010
@@ -24,14 +24,28 @@
<dependencies>
<dependency>
- <groupId>org.apache.felix</groupId>
+ <groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
- <version>1.2.0</version>
+ <version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo</artifactId>
- <version>1.2.0</version>
+ <version>1.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.4</version>
+ <type>jar</type>
+ <scope>compile</scope>
</dependency>
</dependencies>
Modified: felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/src/main/java/org/apache/felix/ipojo/metatype/bridge/MetatypeFactoryWrapper.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/src/main/java/org/apache/felix/ipojo/metatype/bridge/MetatypeFactoryWrapper.java?rev=942341&r1=942340&r2=942341&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/src/main/java/org/apache/felix/ipojo/metatype/bridge/MetatypeFactoryWrapper.java (original)
+++ felix/sandbox/clement/ipojo-utils/iPOJO-Metatype-Bridge/src/main/java/org/apache/felix/ipojo/metatype/bridge/MetatypeFactoryWrapper.java Sat May 8 08:24:46 2010
@@ -27,12 +27,26 @@ public class MetatypeFactoryWrapper impl
*/
private IPojoFactory m_factory; //Injected
+ /**
+ * Provides an implementation of {@link ObjectClassDefinition}
+ * based on the injected factory.
+ */
private class ObjectClassDefinitionImpl implements ObjectClassDefinition {
+ /**
+ * The description.
+ */
private ComponentTypeDescription m_description;
+ /**
+ * List of attributes.
+ */
List m_attributes = new ArrayList();
+ /**
+ * Creates a ObjectClassDefinitionImpl.
+ * @param desc the component type description
+ */
public ObjectClassDefinitionImpl(ComponentTypeDescription desc) {
m_description = desc;
PropertyDescription[] props = desc.getProperties();
@@ -41,6 +55,12 @@ public class MetatypeFactoryWrapper impl
}
}
+ /**
+ * Gets the list of attributes matching the filter
+ * @param filter the filter
+ * @return the list of attributes or <code>null</code> if no attributes match.
+ * @see org.osgi.service.metatype.ObjectClassDefinition#getAttributeDefinitions(int)
+ */
public AttributeDefinition[] getAttributeDefinitions(int filter) {
List list = new ArrayList();
switch(filter) {
@@ -68,37 +88,93 @@ public class MetatypeFactoryWrapper impl
}
}
}
- return (AttributeDefinition[]) list.toArray(new AttributeDefinition[list.size()]);
+ if (list.size() > 0) {
+ return (AttributeDefinition[]) list.toArray(new AttributeDefinition[list.size()]);
+ } else {
+ return null;
+ }
}
+ /**
+ * Gets the description (mapped to the name)
+ * @return the name
+ * @see org.osgi.service.metatype.ObjectClassDefinition#getDescription()
+ */
public String getDescription() {
return m_description.getName();
}
+ /**
+ * Gets the ID (mapped to the name)
+ * @return the name
+ * @return
+ * @see org.osgi.service.metatype.ObjectClassDefinition#getID()
+ */
public String getID() {
return m_description.getName();
}
+ /**
+ * Not supported method.
+ * @param arg0 an integer.
+ * @return <code>null</code>
+ * @throws IOException cannot happen
+ * @see org.osgi.service.metatype.ObjectClassDefinition#getIcon(int)
+ */
public InputStream getIcon(int arg0) throws IOException {
return null;
}
+ /**
+ * Gets the name.
+ * @return the name
+ * @see org.osgi.service.metatype.ObjectClassDefinition#getName()
+ */
public String getName() {
return m_description.getName();
}
}
+ /**
+ * Provides an {@link AttributeDefinition} implementation
+ * based on iPOJO properties.
+ */
private class AttributeDefinitionImpl implements AttributeDefinition {
+ /**
+ * The property description.
+ */
private PropertyDescription m_desc;
+ /**
+ * The type name.
+ */
private String m_typeName;
+ /**
+ * the type (Metatype).
+ */
private int m_type;
+ /**
+ * The cardinality.
+ */
private int m_cardinality;
+ /**
+ * Is the attribute mandatory or not.
+ */
private boolean m_isMandatory;
+
+ /**
+ * Is the attribute immutable.
+ * The immutable properties are hidden.
+ */
private boolean m_isImmutable;
+ /**
+ * Creates a AttributeDefinitionImpl.
+ * @param desc the property description
+ * @param typeName the type name.
+ */
public AttributeDefinitionImpl(PropertyDescription desc, String typeName) {
m_desc = desc;
m_typeName = typeName;
@@ -121,6 +197,11 @@ public class MetatypeFactoryWrapper impl
m_type = getTypeByInternType(internType);
}
+ /**
+ * Computes the metatype type matching the given type.
+ * @param internType the type
+ * @return the adequate metatype type
+ */
private int getTypeByInternType(String internType) {
//STRING,LONG,INTEGER, CHAR,BYTE,DOUBLE,FLOAT, BOOLEAN
@@ -152,75 +233,154 @@ public class MetatypeFactoryWrapper impl
return -1;
}
+ /**
+ * Gets the cardinality.
+ * @return the cardinality
+ * @see org.osgi.service.metatype.AttributeDefinition#getCardinality()
+ */
public int getCardinality() {
return m_cardinality;
}
+ /**
+ * Gets the default value.
+ * @return the default value or <code>null</code> if not set
+ * @see org.osgi.service.metatype.AttributeDefinition#getDefaultValue()
+ */
public String[] getDefaultValue() {
if (m_desc.getValue() != null) {
if (getCardinality() == 0) {
return new String[] { m_desc.getValue() };
- } else if (m_cardinality > 0) {
+ } else {
return org.apache.felix.ipojo.parser.ParseUtils.parseArrays(m_desc.getValue());
- } else if (m_cardinality < 0) {
- //TODO handle vector case
- return new String[] { m_desc.getValue() };
}
}
return null;
}
+ /**
+ * Gets the description (i.e. the name).
+ * @return the name
+ * @see org.osgi.service.metatype.AttributeDefinition#getDescription()
+ */
public String getDescription() {
return m_desc.getName();
}
+ /**
+ * Gets the ID
+ * @return the id.
+ * @see org.osgi.service.metatype.AttributeDefinition#getID()
+ */
public String getID() {
return m_typeName + "-" + m_desc.getName();
}
+ /**
+ * Gets the name.
+ * @return the name
+ * @see org.osgi.service.metatype.AttributeDefinition#getName()
+ */
public String getName() {
return m_desc.getName();
}
+ /**
+ * Not supported method.
+ * @return <code>null</code>
+ * @see org.osgi.service.metatype.AttributeDefinition#getOptionLabels()
+ */
public String[] getOptionLabels() {
return null;
}
+ /**
+ * Not supported method
+ * @return <code>null</code>
+ * @see org.osgi.service.metatype.AttributeDefinition#getOptionValues()
+ */
public String[] getOptionValues() {
return null;
}
+ /**
+ * Gets the type.
+ * @return the type.
+ * @see org.osgi.service.metatype.AttributeDefinition#getType()
+ */
public int getType() {
return m_type;
}
+ /**
+ * Not supported method (No validation).
+ * @param arg0 a value
+ * @return <code>null</code>
+ * @see org.osgi.service.metatype.AttributeDefinition#validate(java.lang.String)
+ */
public String validate(String arg0) {
return null; // No validation
}
-
-
}
+ /**
+ * Creates a MetatypeFactoryWrapper.
+ * For testing purpose only
+ * @param factory the factory
+ */
+ protected MetatypeFactoryWrapper(IPojoFactory factory) {
+ m_factory = factory;
+ }
+
+ /**
+ * Delete the given configuration.
+ * @param arg0 the configuration PID
+ * @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
+ */
public void deleted(String arg0) {
m_factory.deleted(arg0);
}
+ /**
+ * Gets the factory PID.
+ * @return the name
+ * @see org.osgi.service.cm.ManagedServiceFactory#getName()
+ */
public String getName() {
return m_factory.getName();
}
+ /**
+ * Add or update a configuration.
+ * @param arg0 the configuration id
+ * @param arg1 the configuration
+ * @throws ConfigurationException
+ * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
+ */
public void updated(String arg0, Dictionary arg1)
throws ConfigurationException {
m_factory.updated(arg0, arg1);
}
+ /**
+ * Not supported.
+ * @return <code>null</code>
+ * @see org.osgi.service.metatype.MetaTypeProvider#getLocales()
+ */
public String[] getLocales() {
return null;
}
+ /**
+ * Gets the {@link ObjectClassDefinition} representing this factory.
+ * @param id the id (ignored)
+ * @param loc the locale (ignored)
+ * @return the {@link ObjectClassDefinition} matching this factory
+ * @see org.osgi.service.metatype.MetaTypeProvider#getObjectClassDefinition(java.lang.String, java.lang.String)
+ */
public ObjectClassDefinition getObjectClassDefinition(String id,
String loc) {
return new ObjectClassDefinitionImpl(m_factory.getComponentDescription());