felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1348918 - in /felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin: SCRDescriptorGenerator.java xml/ComponentDescriptorIO.java
Date Mon, 11 Jun 2012 15:51:17 GMT
Author: cziegeler
Date: Mon Jun 11 15:51:16 2012
New Revision: 1348918

URL: http://svn.apache.org/viewvc?rev=1348918&view=rev
Log:
New SCR Plugin (WiP)

Modified:
    felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
    felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java

Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1348918&r1=1348917&r2=1348918&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
Mon Jun 11 15:51:16 2012
@@ -37,6 +37,7 @@ import java.util.jar.Manifest;
 import org.apache.felix.scrplugin.description.ClassDescription;
 import org.apache.felix.scrplugin.description.ComponentDescription;
 import org.apache.felix.scrplugin.description.PropertyDescription;
+import org.apache.felix.scrplugin.description.PropertyType;
 import org.apache.felix.scrplugin.description.ReferenceDescription;
 import org.apache.felix.scrplugin.description.ServiceDescription;
 import org.apache.felix.scrplugin.description.SpecVersion;
@@ -439,6 +440,16 @@ public class SCRDescriptorGenerator {
         }
     }
 
+    private boolean hasProperty(final Component component, final String name) {
+        boolean found = false;
+        final Iterator<Property> iter = component.getProperties().iterator();
+        while ( !found && iter.hasNext() ) {
+            final Property prop = iter.next();
+            found = name.equals( prop.getName() );
+        }
+        return found;
+    }
+
     /**
      * Process property directives
      */
@@ -459,19 +470,36 @@ public class SCRDescriptorGenerator {
             }
         }
         // PID handling
-        if ( componentDesc.isCreatePid() ) {
-            // check for an existing pid first
-            boolean found = false;
-            final Iterator<Property> iter = component.getProperties().iterator();
-            while ( !found && iter.hasNext() ) {
-                final Property prop = iter.next();
-                found = org.osgi.framework.Constants.SERVICE_PID.equals( prop.getName() );
-            }
-            if ( !found ) {
-                final Property pid = new Property();
-                component.addProperty( pid );
-                pid.setName( org.osgi.framework.Constants.SERVICE_PID );
-                pid.setValue( component.getName() );
+        if ( componentDesc.isCreatePid() && !hasProperty(component, org.osgi.framework.Constants.SERVICE_PID))
{
+            final Property pid = new Property();
+            component.addProperty( pid );
+            pid.setName( org.osgi.framework.Constants.SERVICE_PID );
+            pid.setValue( component.getName() );
+        }
+        this.processGlobalProperties(desc, component);
+    }
+
+    /**
+     * Process all found properties for the component.
+     * @param globalProperties Global properties are set on all components.
+     * @param iLog The issue log.
+     * @throws SCRDescriptorException
+     */
+    private void processGlobalProperties(final ClassDescription desc, final Component component)
{
+        // apply pre configured global properties
+        if ( this.options.getProperties() != null ) {
+            for(final Map.Entry<String, String> entry : this.options.getProperties().entrySet())
{
+                final String propName = entry.getKey();
+                final String value = entry.getValue();
+                // check if the service already provides this property
+                if ( value != null && !hasProperty(component, propName) ) {
+
+                    final Property p = new Property();
+                    p.setName(propName);
+                    p.setValue(value);
+                    p.setType(PropertyType.String);
+                    component.addProperty(p);
+                }
             }
         }
     }

Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1348918&r1=1348917&r2=1348918&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
Mon Jun 11 15:51:16 2012
@@ -215,7 +215,9 @@ public class ComponentDescriptorIO {
 
         // attributes new in 1.1
         if (NAMESPACE_URI_1_1.equals(namespace) || NAMESPACE_URI_1_1_FELIX.equals(namespace))
{
-            IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name());
+            if ( component.getConfigurationPolicy() != ComponentConfigurationPolicy.OPTIONAL
) {
+                IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name());
+            }
             IOUtils.addAttribute(ai, COMPONENT_ATTR_ACTIVATE, component.getActivate());
             IOUtils.addAttribute(ai, COMPONENT_ATTR_DEACTIVATE, component.getDeactivate());
             IOUtils.addAttribute(ai, COMPONENT_ATTR_MODIFIED, component.getModified());
@@ -463,6 +465,7 @@ public class ComponentDescriptorIO {
 
                     desc.setFactory(attributes.getValue(COMPONENT_ATTR_FACTORY));
 
+                    desc.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL);
                     // check for version 1.1 attributes
                     if (specVersion == SpecVersion.VERSION_1_1
                                     || specVersion == SpecVersion.VERSION_1_1_FELIX) {



Mime
View raw message