FELIX-3550 : Reimplement the SCR Generator

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1356177 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
index f3a7a2b..9283327 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
@@ -370,7 +370,7 @@
                 index += 2;
             }
 
-            final boolean hasName = ad.getStringValue("name", null) != null;
+            String name = ad.getStringValue("name", null);
 
             if (values != null) {
                 prop.setType(PropertyType.valueOf(type));
@@ -379,9 +379,16 @@
                 } else {
                     prop.setMultiValue(values);
                 }
+                if ( name == null ) {
+                    final Object value = fieldAnnotation.getAnnotatedFieldValue();
+                    if (value != null) {
+                        name = value.toString();
+                    }
+                }
+
             } else if (fieldAnnotation != null) {
                 // Detect values from field
-                if ( hasName ) {
+                if ( name != null ) {
                     final Object value = fieldAnnotation.getAnnotatedFieldValue();
                     if (value != null) {
                         if (value.getClass().isArray()) {
@@ -398,26 +405,11 @@
                     }
                 } else {
                     prop.setType(PropertyType.String);
-                    prop.setValue(fieldAnnotation.getAnnotatedField().getName());
-                }
-            }
-
-            final String name;
-            if ( hasName ) {
-                name = ad.getStringValue("name", null);
-            } else if (fieldAnnotation != null) {
-                if (values == null) {
                     final Object value = fieldAnnotation.getAnnotatedFieldValue();
                     if (value != null) {
                         name = value.toString();
-                    } else {
-                        name = null;
                     }
-                } else {
-                    name = fieldAnnotation.getAnnotatedField().getName();
                 }
-            } else {
-                name = null;
             }
 
             prop.setName(name);
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
index 3a14ffd..5f72254 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
@@ -433,6 +433,9 @@
             }
         } while ( current != null);
 
+        // global properties
+        this.processGlobalProperties(desc, container.getProperties());
+
         // PID handling
         if ( componentDesc.isCreatePid() && !container.getProperties().containsKey(org.osgi.framework.Constants.SERVICE_PID)) {
             final PropertyDescription pid = new PropertyDescription(null);
@@ -442,7 +445,6 @@
 
             container.getProperties().put(org.osgi.framework.Constants.SERVICE_PID, pid);
         }
-        this.processGlobalProperties(desc, container.getProperties());
 
         return container;
     }
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index 1b1b1ad..75894e4 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -310,7 +310,9 @@
     protected static void generatePropertyXML(PropertyDescription property, ContentHandler contentHandler) throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, "name", property.getName());
-        IOUtils.addAttribute(ai, "type", property.getType());
+        if ( property.getType() != PropertyType.String ) {
+            IOUtils.addAttribute(ai, "type", property.getType());
+        }
         IOUtils.addAttribute(ai, "value", property.getValue());
 
         IOUtils.indent(contentHandler, 2);