felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1777468 - in /felix/trunk/scr: ./ src/main/java/org/apache/felix/scr/impl/manager/ src/main/java/org/apache/felix/scr/impl/metadata/ src/main/java/org/apache/felix/scr/impl/xml/
Date Thu, 05 Jan 2017 14:53:09 GMT
Author: cziegeler
Date: Thu Jan  5 14:53:09 2017
New Revision: 1777468

URL: http://svn.apache.org/viewvc?rev=1777468&view=rev
Log:
FELIX-5454 : [R7] Service properties for ComponentFactory

Modified:
    felix/trunk/scr/changelog.txt
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java

Modified: felix/trunk/scr/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scr/changelog.txt?rev=1777468&r1=1777467&r2=1777468&view=diff
==============================================================================
--- felix/trunk/scr/changelog.txt (original)
+++ felix/trunk/scr/changelog.txt Thu Jan  5 14:53:09 2017
@@ -2,6 +2,7 @@ Changes from 2.0.8 to 2.1.0
 ---------------------------
 ** Improvement
     * [FELIX-5458] Improved ConfigurationPlugin Support (OSGi R7)
+    * [FELIX-5454] Service properties for ComponentFactory (OSGi R7)
 
 
 Changes from 2.0.6 to 2.0.8

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java?rev=1777468&r1=1777467&r2=1777468&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
Thu Jan  5 14:53:09 2017
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.felix.scr.component.ExtFactoryComponentInstance;
+import org.apache.felix.scr.impl.BundleComponentActivator;
 import org.apache.felix.scr.impl.helper.ComponentMethods;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
 import org.apache.felix.scr.impl.metadata.ReferenceMetadata;
@@ -286,7 +287,7 @@ public class ComponentFactoryImpl<S> ext
 
     public Dictionary<String, Object> getServiceProperties()
     {
-        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        Dictionary<String, Object> props = new Hashtable<String, Object>(getComponentMetadata().getFactoryProperties());
 
         // 112.5.5 The Component Factory service must register with the following properties
         props.put( ComponentConstants.COMPONENT_NAME, getComponentMetadata().getName() );

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java?rev=1777468&r1=1777467&r2=1777468&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
Thu Jan  5 14:53:09 2017
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.scr.impl.metadata;
 
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -33,9 +32,9 @@ import org.apache.felix.scr.impl.helper.
 import org.apache.felix.scr.impl.metadata.ServiceMetadata.Scope;
 import org.osgi.service.component.ComponentException;
 
-
 /**
- * This class holds the information associated to a component in the descriptor *  */
+ * This class holds the information associated to a component in the descriptor
+ */
 public class ComponentMetadata
 {
     // Configuration required for component activation (since DS 1.1)
@@ -56,8 +55,7 @@ public class ComponentMetadata
     // marker value indicating duplicate service setting
     private static final ServiceMetadata SERVICE_DUPLICATE = new ServiceMetadata();
 
-    // the namespace code of the namespace declaring this component, this is
-    // one of the XmlHandler.DS_VERSION_* constants
+    // the namespace code of the namespace declaring this component
     private final DSVersion m_dsVersion;
 
     // 112.4.3: A Globally unique component name (required)
@@ -67,51 +65,60 @@ public class ComponentMetadata
     private boolean m_enabled = true;
 
     // 112.4.3: Factory identified. If set to a non empty string, it indicates that the component
is a factory component (optional).
-    private String m_factory = null;
+    private String m_factory;
 
     // 112.4.3: Controls whether component configurations must be immediately activated after
becoming
     // satisfied or whether activation should be delayed. (optional, default value depends
     // on whether the component has a service element or not).
-    private Boolean m_immediate = null;
+    private Boolean m_immediate;
 
     // 112.4.4 Implementation Element (required)
-    private String m_implementationClassName = null;
+    private String m_implementationClassName;
 
     // 112.5.8 activate can be specified (since DS 1.1)
-    private String m_activate = null;
+    private String m_activate;
 
     // 112.5.8 whether activate has been specified
     private boolean m_activateDeclared = false;
 
     // 112.5.12 deactivate can be specified (since DS 1.1)
-    private String m_deactivate = null;
+    private String m_deactivate;
 
     // 112.5.12 whether deactivate has been specified
     private boolean m_deactivateDeclared = false;
 
     // 112.??.?? modified method (configuration update, since DS 1.1)
-    private String m_modified = null;
+    private String m_modified;
 
     // 112.4.3 configuration-policy (since DS 1.1)
-    private String m_configurationPolicy = null;
+    private String m_configurationPolicy;
 
     // 112.4.4 configuration-pid (since DS 1.2)
     private List<String> m_configurationPid;
 
     // Associated properties (0..*)
-    private Map<String, Object> m_properties = new HashMap<String, Object>();
+    private final Map<String, Object> m_properties = new HashMap<String, Object>();
+
+    // Associated factory properties (0..*)
+    private final Map<String, Object> m_factoryProperties = new HashMap<String,
Object>();
 
     // List of Property metadata - used while building the meta data
     // while validating the properties contained in the PropertyMetadata
     // instances are copied to the m_properties Dictionary while this
     // list will be cleared
-    private List<PropertyMetadata> m_propertyMetaData = new ArrayList<PropertyMetadata>();
+    private final List<PropertyMetadata> m_propertyMetaData = new ArrayList<PropertyMetadata>();
+
+    // List of Property metadata - used while building the meta data
+    // while validating the properties contained in the PropertyMetadata
+    // instances are copied to the m_factoryProperties Dictionary while this
+    // list will be cleared
+    private final List<PropertyMetadata> m_factoryPropertyMetaData = new ArrayList<PropertyMetadata>();
 
     // Provided services (0..1)
-    private ServiceMetadata m_service = null;
+    private ServiceMetadata m_service;
 
     // List of service references, (required services 0..*)
-    private List<ReferenceMetadata> m_references = new ArrayList<ReferenceMetadata>();
+    private final List<ReferenceMetadata> m_references = new ArrayList<ReferenceMetadata>();
 
     private boolean m_configurableServiceProperties;
     private boolean m_persistentFactoryComponent;
@@ -132,7 +139,7 @@ public class ComponentMetadata
     }
 
 
-    public ComponentMetadata( DSVersion dsVersion )
+    public ComponentMetadata( final DSVersion dsVersion )
     {
         this.m_dsVersion = dsVersion;
     }
@@ -321,6 +328,24 @@ public class ComponentMetadata
 
 
     /**
+     * Used to add a factory property to the instance
+     *
+     * @param newProperty a property metadata object
+     */
+	public void addFactoryProperty( PropertyMetadata newProperty ) 
+	{
+        if ( m_validated )
+        {
+            return;
+        }
+        if ( newProperty == null )
+        {
+            throw new IllegalArgumentException( "Cannot add a null property" );
+        }
+        m_factoryPropertyMetaData.add( newProperty );
+	}
+
+    /**
      * Used to set a ServiceMetadata object.
      *
      * @param service a ServiceMetadata
@@ -649,6 +674,17 @@ public class ComponentMetadata
 
 
     /**
+     * Returns the factory properties.
+     *
+     * @return the factory properties as a Dictionary
+     */
+    public Map<String, Object> getFactoryProperties()
+    {
+        return m_factoryProperties;
+    }
+
+    
+    /**
      * Returns the list of property meta data.
      * <b>Note: This method is intended for unit testing only</b>
      *
@@ -661,6 +697,18 @@ public class ComponentMetadata
 
 
     /**
+     * Returns the list of factory property meta data.
+     * <b>Note: This method is intended for unit testing only</b>
+     *
+     * @return the list of property meta data.
+     */
+    List<PropertyMetadata> getFactoryPropertyMetaData()
+    {
+        return m_factoryPropertyMetaData;
+    }
+
+    
+    /**
      * Returns the dependency descriptors
      *
      * @return a Collection of dependency descriptors
@@ -855,6 +903,22 @@ public class ComponentMetadata
         }
         m_propertyMetaData.clear();
 
+        // Next check if the factory properties are valid (and extract property values)
+        if ( !m_dsVersion.isDS14() && !m_factoryPropertyMetaData.isEmpty() ) 
+        {
+            throw validationFailure( "Use of factory properties requires DS 1.4 or later
namespace " );        	
+        }
+        if ( m_dsVersion.isDS14() && isFactory() )
+        {
+        	for ( PropertyMetadata propMeta: m_factoryPropertyMetaData )
+        	{
+        		propMeta.validate( this );
+        		m_factoryProperties.put( propMeta.getName(), propMeta.getValue() );
+        	}
+        }
+        // if this is not a factory, these props are ignored, so nothing else to do
+        m_factoryPropertyMetaData.clear();
+
         // Check that the provided services are valid too
         if ( m_service == SERVICE_DUPLICATE )
         {
@@ -936,13 +1000,12 @@ public class ComponentMetadata
         	throw validationFailure("Only a factory component can be a persistent factory component");
         }
 
-
         m_validated = true;
     }
 
 
     /**
-     * Returns a <code>ComponentException</code> for this compeonent with the
+     * Returns a <code>ComponentException</code> for this component with the
      * given explanation for failure.
      *
      * @param reason The explanation for failing to validate this component.

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java?rev=1777468&r1=1777467&r2=1777468&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java Thu Jan  5
14:53:09 2017
@@ -88,27 +88,6 @@ public class XmlHandler implements KXml2
 
     public static final String DELAYED_KEEP_INSTANCES = "delayedKeepInstances";
 
-    // namespace code for non-DS namespace
-    public static final int DS_VERSION_NONE = -1;
-
-    // namespace code for the DS 1.0 specification
-    public static final int DS_VERSION_1_0 = 0;
-
-    // namespace code for the DS 1.1 specification
-    public static final int DS_VERSION_1_1 = 1;
-
-    // namespace code for the DS 1.1-felix specification
-    public static final int DS_VERSION_1_1_FELIX = 2;
-
-    // namespace code for the DS 1.2 specification
-    public static final int DS_VERSION_1_2 = 3;
-
-    // namespace code for the DS 1.2-felix specification
-    public static final int DS_VERSION_1_2_FELIX = 4;
-
-    // namespace code for the DS 1.3 specification
-    public static final int DS_VERSION_1_3 = 5;
-
     // mapping of namespace URI to namespace code
     private static final Map<String, DSVersion> NAMESPACE_CODE_MAP;
 
@@ -134,6 +113,9 @@ public class XmlHandler implements KXml2
     // PropertyMetaData whose value attribute is missing, hence has element data
     private PropertyMetadata m_pendingProperty;
 
+    // PropertyMetaData whose value attribute is missing, hence has element data
+    private PropertyMetadata m_pendingFactoryProperty;
+
     /** Flag for detecting the first element. */
     protected boolean firstElement = true;
 
@@ -347,7 +329,55 @@ public class XmlHandler implements KXml2
                 // 112.4.5 Properties [...] Elements
                 else if ( localName.equals( "properties" ) )
                 {
-                    readPropertiesEntry( attributes.getAttribute( "entry" ) );
+                    final Properties props = readPropertiesEntry( attributes.getAttribute(
"entry" ) );
+                    // create PropertyMetadata for the properties from the file
+                    for ( Map.Entry<Object, Object> pEntry: props.entrySet() )
+                    {
+                        PropertyMetadata prop = new PropertyMetadata();
+                        prop.setName( String.valueOf( pEntry.getKey() ) );
+                        prop.setValue( String.valueOf( pEntry.getValue() ) );
+                        m_currentComponent.addProperty( prop );
+                    }
+
+                }
+                // TODO Section [...] Factory Property Elements
+                else if ( localName.equals( "factoryProperty" ) )
+                {
+                    PropertyMetadata prop = new PropertyMetadata();
+
+                    // name attribute is mandatory
+                    prop.setName( attributes.getAttribute( "name" ) );
+
+                    // type attribute is optional
+                    if ( attributes.getAttribute( "type" ) != null )
+                    {
+                        prop.setType( attributes.getAttribute( "type" ) );
+                    }
+
+                    // 112.4.5: If the value attribute is specified, the body of the element
is ignored.
+                    if ( attributes.getAttribute( "value" ) != null )
+                    {
+                        prop.setValue( attributes.getAttribute( "value" ) );
+                        m_currentComponent.addFactoryProperty( prop );
+                    }
+                    else
+                    {
+                        // hold the metadata pending
+                    	m_pendingFactoryProperty = prop;
+                    }
+                }
+                // TODO Section [...] Factory Properties [...] Elements
+                else if ( localName.equals( "factoryProperties" ) )
+                {
+                    final Properties props = readPropertiesEntry( attributes.getAttribute(
"entry" ) );
+                    // create PropertyMetadata for the properties from the file
+                    for ( Map.Entry<Object, Object> pEntry: props.entrySet() )
+                    {
+                        PropertyMetadata prop = new PropertyMetadata();
+                        prop.setName( String.valueOf( pEntry.getKey() ) );
+                        prop.setValue( String.valueOf( pEntry.getValue() ) );
+                        m_currentComponent.addFactoryProperty( prop );
+                    }
                 }
                 // 112.4.6 Service Element
                 else if ( localName.equals( "service" ) )
@@ -485,6 +515,13 @@ public class XmlHandler implements KXml2
                 // currently, we just ignore this situation
                 m_pendingProperty = null;
             }
+            else if ( localName.equals( "factoryProperty" ) && m_pendingFactoryProperty
!= null )
+            {
+                // 112.4.5 body expected to contain property value
+                // if so, the m_pendingFactoryProperty field would be null
+                // currently, we just ignore this situation
+            	m_pendingFactoryProperty = null;
+            }
         }
     }
 
@@ -501,6 +538,12 @@ public class XmlHandler implements KXml2
             m_currentComponent.addProperty( m_pendingProperty );
             m_pendingProperty = null;
         }
+        if ( m_pendingFactoryProperty != null )
+        {
+        	m_pendingFactoryProperty.setValues( text );
+            m_currentComponent.addFactoryProperty( m_pendingFactoryProperty );
+            m_pendingFactoryProperty = null;
+        }
     }
 
 
@@ -543,7 +586,7 @@ public class XmlHandler implements KXml2
      *      entry with the given name exists in the bundle or an error occurrs
      *      reading the properties file.
      */
-    private void readPropertiesEntry( String entryName ) throws ParseException
+    private Properties readPropertiesEntry( String entryName ) throws ParseException
     {
         if ( entryName == null )
         {
@@ -582,13 +625,6 @@ public class XmlHandler implements KXml2
             }
         }
 
-        // create PropertyMetadata for the properties from the file
-        for ( Map.Entry<Object, Object> pEntry: props.entrySet() )
-        {
-            PropertyMetadata prop = new PropertyMetadata();
-            prop.setName( String.valueOf( pEntry.getKey() ) );
-            prop.setValue( String.valueOf( pEntry.getValue() ) );
-            m_currentComponent.addProperty( prop );
-        }
+        return props;
     }
 }



Mime
View raw message