You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2015/01/06 11:54:11 UTC

svn commit: r1649773 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl: helper/FieldHandler.java metadata/ReferenceMetadata.java metadata/XmlHandler.java

Author: cziegeler
Date: Tue Jan  6 10:54:11 2015
New Revision: 1649773

URL: http://svn.apache.org/r1649773
Log:
FELIX-4631 : [DS][R6/RFC212] Implement field injection. Update to latest draft: only a single reference element in XML, different names for the attributes

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java?rev=1649773&r1=1649772&r2=1649773&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java Tue Jan  6 10:54:11 2015
@@ -364,23 +364,23 @@ public class FieldHandler
                 }
             }
 
-            if ( ReferenceMetadata.FIELD_VALUE_TYPE_SERVICE.equals(metadata.getFieldValueType()) )
+            if ( ReferenceMetadata.FIELD_VALUE_TYPE_SERVICE.equals(metadata.getFieldCollectionType()) )
             {
                 valueType = ParamType.serviceType;
             }
-            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_REFERENCE.equals(metadata.getFieldValueType()) )
+            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_REFERENCE.equals(metadata.getFieldCollectionType()) )
             {
                 valueType = ParamType.serviceReference;
             }
-            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_SERVICEOBJECTS.equals(metadata.getFieldValueType()) )
+            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_SERVICEOBJECTS.equals(metadata.getFieldCollectionType()) )
             {
                 valueType = ParamType.serviceObjects;
             }
-            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_PROPERTIES.equals(metadata.getFieldValueType()) )
+            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_PROPERTIES.equals(metadata.getFieldCollectionType()) )
             {
                 valueType = ParamType.map;
             }
-            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_TUPLE.equals(metadata.getFieldValueType()) )
+            else if ( ReferenceMetadata.FIELD_VALUE_TYPE_TUPLE.equals(metadata.getFieldCollectionType()) )
             {
                 valueType = ParamType.tuple;
             }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java?rev=1649773&r1=1649772&r2=1649773&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java Tue Jan  6 10:54:11 2015
@@ -116,10 +116,10 @@ public class ReferenceMetadata
     private String m_field;
 
     // Name of the strategy for the field (optional, since DS 1.3)
-    private String m_field_strategy;
+    private String m_field_option;
 
     // Name of the value type for the field (optional, since DS 1.3)
-    private String m_field_value_type;
+    private String m_field_collection_type;
 
     // Policy attribute (optional, default = static)
     private String m_policy = null;
@@ -140,9 +140,6 @@ public class ReferenceMetadata
     // Flag that is set once the component is verified (its properties cannot be changed)
     private boolean m_validated = false;
 
-    // flag indicating this is a field reference
-    private final boolean m_fieldReference;
-
     static
     {
         CARDINALITY_VALID = new TreeSet<String>();
@@ -171,14 +168,6 @@ public class ReferenceMetadata
         FIELD_VALUE_TYPE_VALID.add ( FIELD_VALUE_TYPE_TUPLE );
     }
 
-    public ReferenceMetadata() {
-        this(false);
-    }
-
-    public ReferenceMetadata(final boolean flag) {
-        this.m_fieldReference = flag;
-    }
-
     /////////////////////////////////////////////// setters ///////////////////////////////////
 
     /**
@@ -356,14 +345,14 @@ public class ReferenceMetadata
      *
      * @param strategy the field strategy
      */
-    public void setFieldStrategy( final String strategy )
+    public void setFieldOption( final String strategy )
     {
         if ( m_validated )
         {
             return;
         }
 
-        m_field_strategy = strategy;
+        m_field_option = strategy;
 
         m_isReplace = FIELD_STRATEGY_REPLACE.equals(strategy);
     }
@@ -373,14 +362,14 @@ public class ReferenceMetadata
      *
      * @param valuetype the field value type
      */
-    public void setFieldValueType( final String valuetype )
+    public void setFieldCollectionType( final String valuetype )
     {
         if ( m_validated )
         {
             return;
         }
 
-        m_field_value_type = valuetype;
+        m_field_collection_type = valuetype;
     }
 
     public void setScope(String scopeName) {
@@ -514,9 +503,9 @@ public class ReferenceMetadata
      *
      * @return a String with the strategy name for the field
      */
-    public String getFieldStrategy()
+    public String getFieldOption()
     {
-        return m_field_strategy;
+        return m_field_option;
     }
 
     /**
@@ -525,9 +514,9 @@ public class ReferenceMetadata
      *
      * @return a String with the value type for the field
      */
-    public String getFieldValueType()
+    public String getFieldCollectionType()
     {
-        return m_field_value_type;
+        return m_field_collection_type;
     }
 
     // Getters for boolean values that determine both policy and cardinality
@@ -678,7 +667,7 @@ public class ReferenceMetadata
         }
 
         // checks for event based injection
-        if ( !m_fieldReference )
+        if ( m_field == null )
         {
             // updated method is only supported in namespace xxx and later
             if ( m_updated != null && !(dsVersion.isDS12() || dsVersion == DSVersion.DS11Felix) )
@@ -689,7 +678,7 @@ public class ReferenceMetadata
         }
 
         // checks for field injection
-        if ( m_fieldReference )
+        if ( m_field != null )
         {
             // field reference requires DS 1.3
             if ( !dsVersion.isDS13() )
@@ -697,19 +686,25 @@ public class ReferenceMetadata
                 throw componentMetadata.validationFailure( "Field reference requires DS >= 1.3" );
             }
 
+            // check for bind/unbind/updated
+            if ( m_bind != null || m_unbind != null || m_updated != null )
+            {
+                throw componentMetadata.validationFailure( "Bind/unbind/updated should not be specified with a field reference" );
+            }
+
             // field strategy
-            if ( m_field_strategy == null )
+            if ( m_field_option == null )
             {
-                setFieldStrategy( FIELD_STRATEGY_REPLACE );
+                setFieldOption( FIELD_STRATEGY_REPLACE );
             }
-            else if ( !FIELD_STRATEGY_VALID.contains( m_field_strategy ) )
+            else if ( !FIELD_STRATEGY_VALID.contains( m_field_option ) )
             {
                 throw componentMetadata.validationFailure( "Field strategy must be one of " + FIELD_STRATEGY_VALID );
             }
             if ( !m_isMultiple )
             {
                 // update is not allowed for unary references
-                if ( m_field_strategy.equals(FIELD_STRATEGY_UPDATE) )
+                if ( m_field_option.equals(FIELD_STRATEGY_UPDATE) )
                 {
                     throw componentMetadata.validationFailure( "Field strategy update not allowed for unary field references." );
                 }
@@ -719,18 +714,18 @@ public class ReferenceMetadata
             if ( !m_isMultiple )
             {
                 // value type must not be specified for unary references
-                if ( m_field_value_type != null )
+                if ( m_field_collection_type != null )
                 {
                     throw componentMetadata.validationFailure( "Field value type must not be set for unary field references." );
                 }
             }
             else
             {
-                if ( m_field_value_type == null )
+                if ( m_field_collection_type == null )
                 {
-                    setFieldValueType( FIELD_VALUE_TYPE_SERVICE );
+                    setFieldCollectionType( FIELD_VALUE_TYPE_SERVICE );
                 }
-                else if ( !FIELD_VALUE_TYPE_VALID.contains( m_field_value_type ) )
+                else if ( !FIELD_VALUE_TYPE_VALID.contains( m_field_collection_type ) )
                 {
                     throw componentMetadata.validationFailure( "Field value type must be one of " + FIELD_VALUE_TYPE_VALID );
                 }
@@ -739,34 +734,28 @@ public class ReferenceMetadata
             // static references only allow replace strateg
             if ( m_isStatic )
             {
-                if ( ! m_field_strategy.equals(FIELD_STRATEGY_REPLACE) )
+                if ( ! m_field_option.equals(FIELD_STRATEGY_REPLACE) )
                 {
                     throw componentMetadata.validationFailure( "Field strategy update not allowed for static field references." );
                 }
             }
         }
 
-
         m_validated = true;
     }
 
     public String getDebugInfo()
     {
-        if ( this.m_fieldReference )
-        {
-            return getField() +
-                    "interface=" + this.getInterface() +
-                    ", filter=" + this.getTarget() +
-                    ", strategy=" + this.getFieldStrategy() +
-                    ", policy=" + this.getPolicy() +
-                    ", cardinality=" + this.getCardinality();
-        }
         return getName() +
                 "interface=" + this.getInterface() +
                 ", filter=" + this.getTarget() +
                 ", policy=" + this.getPolicy() +
                 ", cardinality=" + this.getCardinality() +
                 ", bind=" + this.getBind() +
-                ", unbind=" + this.getUnbind();
+                ", unbind=" + this.getUnbind() +
+                ", updated=" + this.getUpdated() +
+                ", field=" + this.getField() +
+                ", field-option=" + this.getFieldOption() +
+                ", field-collection-type=" + this.getFieldCollectionType();
     }
 }
\ No newline at end of file

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java?rev=1649773&r1=1649772&r2=1649773&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java Tue Jan  6 10:54:11 2015
@@ -407,59 +407,16 @@ public class XmlHandler implements KXml2
                         m_currentComponent.addProperty( prop );
 
                     }
+
+                    // method reference
                     ref.setBind( attributes.getAttribute( "bind" ) );
                     ref.setUpdated( attributes.getAttribute( "updated" ) );
                     ref.setUnbind( attributes.getAttribute( "unbind" ) );
 
-                    m_currentComponent.addDependency( ref );
-                }
-                // 112.x.x Field Reference element
-                else if ( localName.equals( "field-reference" ) )
-                {
-                    ReferenceMetadata ref = new ReferenceMetadata(true);
-
-                    // name attribute is optional 
-                    if ( attributes.getAttribute( "name" ) != null )
-                    {
-                        ref.setName( attributes.getAttribute( "name" ) );
-                    }
-
-                    ref.setInterface( attributes.getAttribute( "interface" ) );
-
-                    // Cardinality
-                    if ( attributes.getAttribute( "cardinality" ) != null )
-                    {
-                        ref.setCardinality( attributes.getAttribute( "cardinality" ) );
-                    }
-
-                    if ( attributes.getAttribute( "policy" ) != null )
-                    {
-                        ref.setPolicy( attributes.getAttribute( "policy" ) );
-                    }
-
-                    if ( attributes.getAttribute( "policy-option" ) != null )
-                    {
-                        ref.setPolicyOption( attributes.getAttribute( "policy-option" ) );
-                    }
-
-                    if ( attributes.getAttribute( "scope" ) != null )
-                    {
-                        ref.setScope( attributes.getAttribute( "scope" ) );
-                    }
-
-                    if ( attributes.getAttribute( "target" ) != null)
-                    {
-                        ref.setTarget( attributes.getAttribute( "target" ) );
-                        PropertyMetadata prop = new PropertyMetadata();
-                        prop.setName( (ref.getName() == null? ref.getInterface(): ref.getName()) + ".target");
-                        prop.setValue( attributes.getAttribute( "target" ) );
-                        m_currentComponent.addProperty( prop );
-
-                    }
-
+                    // field reference
                     ref.setField( attributes.getAttribute( "field" ) );
-                    ref.setFieldStrategy( attributes.getAttribute( "strategy" ) );
-                    ref.setFieldValueType( attributes.getAttribute( "valuetype" ) );
+                    ref.setFieldOption( attributes.getAttribute( "field-option" ) );
+                    ref.setFieldCollectionType( attributes.getAttribute( "field-collection-type" ) );
 
                     m_currentComponent.addDependency( ref );
                 }