FELIX-478
- Move property handling into helper class to make the mojo class smaller
- Use compiled class to get the initial value of a field
- Add new valueRef attribute to the property tag which can reference a field in the same class.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@617500 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
index 50a3ec5..1777396 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
@@ -59,6 +59,12 @@
 
     public static final String PROPERTY_VALUE = "value";
 
+    public static final String PROPERTY_MULTIVALUE_PREFIX = "values";
+
+    public static final String PROPERTY_VALUE_REF = "valueRef";
+
+    public static final String PROPERTY_MULTIVALUE_REF_PREFIX = "refValues";
+
     public static final String PROPERTY_TYPE = "type";
 
     public static final String PROPERTY_CARDINALITY = "cardinality";
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
new file mode 100644
index 0000000..80d11fe
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin;
+
+import java.util.*;
+
+import org.apache.felix.scrplugin.om.Component;
+import org.apache.felix.scrplugin.om.Property;
+import org.apache.felix.scrplugin.om.metatype.AttributeDefinition;
+import org.apache.felix.scrplugin.om.metatype.OCD;
+import org.apache.felix.scrplugin.tags.*;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.StringUtils;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Utility class for handling the properties.
+ */
+public class PropertyHandler {
+
+    /**
+     * @param property
+     * @param name
+     * @param component
+     * @param ocd
+     */
+    public void doProperty(JavaTag property, String name, Component component, OCD ocd)
+    throws MojoExecutionException {
+        final Property prop = new Property(property);
+        prop.setName(name);
+        prop.setType(property.getNamedParameter(Constants.PROPERTY_TYPE));
+        // let's first check for a value attribute
+        final String value = property.getNamedParameter(Constants.PROPERTY_VALUE);
+        if ( value != null ) {
+            prop.setValue(value);
+        } else {
+            // now we check for a value ref attribute
+            final String valueRef = property.getNamedParameter(Constants.PROPERTY_VALUE_REF);
+            if ( valueRef != null ) {
+                prop.setValue(this.getPropertyValueRef(property.getJavaClassDescription(), prop, valueRef));
+            } else {
+                // check for multivalue - these can either be values or value refs
+                final List values = new ArrayList();
+                final Map valueMap = property.getNamedParameterMap();
+                for (Iterator vi = valueMap.entrySet().iterator(); vi.hasNext();) {
+                    final Map.Entry entry = (Map.Entry) vi.next();
+                    final String key = (String) entry.getKey();
+                    if (key.startsWith(Constants.PROPERTY_MULTIVALUE_PREFIX) ) {
+                        values.add(entry.getValue());
+                    } else if ( key.startsWith(Constants.PROPERTY_MULTIVALUE_REF_PREFIX) ) {
+                        values.add(this.getPropertyValueRef(property.getJavaClassDescription(), prop, (String)entry.getValue()));
+                    }
+                }
+                if ( values.size() > 0 ) {
+                    prop.setMultiValue((String[])values.toArray(new String[values.size()]));
+                }
+            }
+        }
+
+        // property is private if explicitly marked or a well known
+        // service property such as service.pid
+        final boolean isPrivate = SCRDescriptorMojo.getBoolean(property,
+            Constants.PROPERTY_PRIVATE, false)
+            || name.equals(org.osgi.framework.Constants.SERVICE_PID)
+            || name.equals(org.osgi.framework.Constants.SERVICE_DESCRIPTION)
+            || name.equals(org.osgi.framework.Constants.SERVICE_ID)
+            || name.equals(org.osgi.framework.Constants.SERVICE_RANKING)
+            || name.equals(org.osgi.framework.Constants.SERVICE_VENDOR)
+            || name.equals(ConfigurationAdmin.SERVICE_BUNDLELOCATION)
+            || name.equals(ConfigurationAdmin.SERVICE_FACTORYPID);
+
+        // if this is a public property and the component is generating metatype info
+        // store the information!
+        if ( !isPrivate && ocd != null ) {
+            final AttributeDefinition ad = new AttributeDefinition();
+            ocd.getProperties().add(ad);
+            ad.setId(prop.getName());
+            ad.setType(prop.getType());
+
+            String adName = property.getNamedParameter(Constants.PROPERTY_LABEL);
+            if ( adName == null ) {
+                adName = "%" + prop.getName() + ".name";
+            }
+            ad.setName(adName);
+            String adDesc = property.getNamedParameter(Constants.PROPERTY_DESCRIPTION);
+            if ( adDesc == null ) {
+                adDesc = "%" + prop.getName() + ".description";
+            }
+            ad.setDescription(adDesc);
+            // set optional multivalues, cardinality might be overwritten by setValues !!
+            final String cValue = property.getNamedParameter(Constants.PROPERTY_CARDINALITY);
+            if (cValue != null) {
+                if ("-".equals(cValue)) {
+                    // unlimited vector
+                    ad.setCardinality(new Integer(Integer.MIN_VALUE));
+                } else if ("+".equals(cValue)) {
+                   // unlimited array
+                    ad.setCardinality(new Integer(Integer.MAX_VALUE));
+                } else {
+                    try {
+                        ad.setCardinality(Integer.valueOf(cValue));
+                    } catch (NumberFormatException nfe) {
+                        // default to scalar in case of conversion problem
+                    }
+                }
+            }
+            ad.setDefaultValue(prop.getValue());
+            ad.setDefaultMultiValue(prop.getMultiValue());
+
+            // check options
+            String[] parameters = property.getParameters();
+            Map options = null;
+            for (int j=0; j < parameters.length; j++) {
+                if (Constants.PROPERTY_OPTIONS.equals(parameters[j])) {
+                    options = new LinkedHashMap();
+                } else if (options != null) {
+                    String optionLabel = parameters[j];
+                    String optionValue = (j < parameters.length-2) ? parameters[j+2] : null;
+                    if (optionValue != null) {
+                        options.put(optionLabel, optionValue);
+                    }
+                    j += 2;
+                }
+            }
+            ad.setOptions(options);
+        }
+
+        component.addProperty(prop);
+    }
+
+    /**
+     * Return the name of the property.
+     * @param property
+     * @param defaultName
+     * @return The name of the property or the defaultName
+     */
+    public String getPropertyName(JavaTag property, String defaultName) {
+        final String name = property.getNamedParameter(Constants.PROPERTY_NAME);
+        if (!StringUtils.isEmpty(name)) {
+            return name;
+        }
+
+        return defaultName;
+    }
+
+    public String getPropertyValueRef(JavaClassDescription desc, Property prop, String valueRef)
+    throws MojoExecutionException {
+        int classSep = valueRef.lastIndexOf('.');
+        if ( classSep == -1 ) {
+            // local variable
+            final JavaField field = desc.getFieldByName(valueRef);
+            if ( field == null ) {
+                throw new MojoExecutionException("Property references unknown field " + valueRef + " in class " + desc.getName());
+            }
+            // determine type (if not set explicitly)
+            if ( prop.getType() == null ) {
+                final String type = field.getType();
+                if ( "java.lang.String".equals(type) ) {
+                    prop.setType("String");
+                } else if ("java.lang.Long".equals(type) || "long".equals(type) ) {
+                    prop.setType("Long");
+                } else if ("java.lang.Double".equals(type) || "double".equals(type) ) {
+                    prop.setType("Double");
+                } else if ("java.lang.Float".equals(type) || "float".equals(type) ) {
+                    prop.setType("Float");
+                } else if ("java.lang.Integer".equals(type) || "int".equals(type) ) {
+                    prop.setType("Integer");
+                } else if ("java.lang.Byte".equals(type) || "byte".equals(type) ) {
+                    prop.setType("Byte");
+                } else if ("java.lang.Character".equals(type) || "char".equals(type) ) {
+                    prop.setType("Char");
+                } else if ("java.lang.Boolean".equals(type) || "boolean".equals(type) ) {
+                    prop.setType("Boolean");
+                } else if ("java.lang.Short".equals(type) || "short".equals(type) ) {
+                    prop.setType("Short");
+                }
+
+            }
+            return field.getInitializationExpression();
+        }
+        throw new MojoExecutionException("Referencing values from foreign classes not supported yet.");
+    }
+
+    public void testProperty(Map properties, JavaTag property, String defaultName, boolean isInspectedClass)
+    throws MojoExecutionException {
+        final String propName = this.getPropertyName(property, defaultName);
+
+        if ( propName != null ) {
+            if ( properties.containsKey(propName) ) {
+                // if the current class is the class we are currently inspecting, we
+                // have found a duplicate definition
+                if ( isInspectedClass ) {
+                    throw new MojoExecutionException("Duplicate definition for property " + propName + " in class " + property.getJavaClassDescription().getName());
+                }
+            } else {
+                properties.put(propName, property);
+            }
+        }
+    }
+
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index 041e32d..0f1022c 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -30,7 +30,6 @@
 import org.apache.maven.plugin.*;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
-import org.osgi.service.cm.ConfigurationAdmin;
 
 /**
  * The <code>SCRDescriptorMojo</code>
@@ -79,6 +78,9 @@
      */
     private boolean generateAccessors;
 
+    /** Utility handler for propertie. */
+    private final PropertyHandler propertyHandler = new PropertyHandler();
+
     /**
      * @see org.apache.maven.plugin.AbstractMojo#execute()
      */
@@ -219,7 +221,7 @@
 
         final OCD ocd = this.doComponent(componentTag, component, metaData);
 
-        boolean inherited = this.getBoolean(componentTag, Constants.COMPONENT_INHERIT, true);
+        boolean inherited = getBoolean(componentTag, Constants.COMPONENT_INHERIT, true);
         this.doServices(description.getTagsByName(Constants.SERVICE, inherited), component, description);
 
         // collect properties and references from class tags and fields
@@ -231,7 +233,7 @@
             // properties
             final JavaTag[] props = currentDescription.getTagsByName(Constants.PROPERTY, false);
             for (int i=0; i < props.length; i++) {
-                this.testProperty(properties, props[i], null, description == currentDescription);
+                this.propertyHandler.testProperty(properties, props[i], null, description == currentDescription);
             }
 
             // references
@@ -252,14 +254,9 @@
                 if (tag != null) {
                     String defaultName = null;
                     if ( "java.lang.String".equals(fields[i].getType()) ) {
-                        defaultName = fields[i].getInitializationExpression().trim();
-                        int pos = defaultName.indexOf("\"");
-                        if ( pos != -1 ) {
-                            defaultName = defaultName.substring(pos + 1);
-                            defaultName = defaultName.substring(0, defaultName.lastIndexOf("\""));
-                        }
+                        defaultName = fields[i].getInitializationExpression();
                     }
-                    this.testProperty(properties, tag, defaultName, description == currentDescription);
+                    this.propertyHandler.testProperty(properties, tag, defaultName, description == currentDescription);
                 }
             }
 
@@ -272,7 +269,7 @@
             final Map.Entry entry = (Map.Entry)propIter.next();
             final String propName = entry.getKey().toString();
             final JavaTag tag = (JavaTag)entry.getValue();
-            this.doProperty(tag, propName, component, ocd);
+            this.propertyHandler.doProperty(tag, propName, component, ocd);
         }
 
         // process references
@@ -285,7 +282,7 @@
         }
 
         // pid handling
-        final boolean createPid = this.getBoolean(componentTag, Constants.COMPONENT_CREATE_PID, true);
+        final boolean createPid = getBoolean(componentTag, Constants.COMPONENT_CREATE_PID, true);
         if ( createPid ) {
             // check for an existing pid first
             boolean found = false;
@@ -343,9 +340,9 @@
         String name = tag.getNamedParameter(Constants.COMPONENT_NAME);
         component.setName(StringUtils.isEmpty(name) ? component.getImplementation().getClassame() : name);
 
-        component.setEnabled(Boolean.valueOf(this.getBoolean(tag, Constants.COMPONENT_ENABLED, true)));
+        component.setEnabled(Boolean.valueOf(getBoolean(tag, Constants.COMPONENT_ENABLED, true)));
         component.setFactory(tag.getNamedParameter(Constants.COMPONENT_FACTORY));
-        component.setImmediate(Boolean.valueOf(this.getBoolean(tag, Constants.COMPONENT_IMMEDIATE, true)));
+        component.setImmediate(Boolean.valueOf(getBoolean(tag, Constants.COMPONENT_IMMEDIATE, true)));
 
         // whether metatype information is to generated for the component
         final String metaType = tag.getNamedParameter(Constants.COMPONENT_METATYPE);
@@ -407,7 +404,7 @@
                 service.addInterface(interf);
             }
 
-            serviceFactory |= this.getBoolean(services[i], Constants.SERVICE_FACTORY, false);
+            serviceFactory |= getBoolean(services[i], Constants.SERVICE_FACTORY, false);
         }
 
         service.setServicefactory(serviceFactory);
@@ -433,134 +430,6 @@
         }
     }
 
-    /**
-     * @param property
-     * @param defaultName
-     * @param component
-     */
-    protected void doProperty(JavaTag property, String name, Component component, OCD ocd) {
-        final Property prop = new Property(property);
-        prop.setName(name);
-        prop.setType(property.getNamedParameter(Constants.PROPERTY_TYPE));
-        final String value = property.getNamedParameter(Constants.PROPERTY_VALUE);
-        if ( value != null ) {
-            prop.setValue(value);
-        } else {
-            // check for multivalue
-            final List values = new ArrayList();
-            final Map valueMap = property.getNamedParameterMap();
-            for (Iterator vi = valueMap.entrySet().iterator(); vi.hasNext();) {
-                final Map.Entry entry = (Map.Entry) vi.next();
-                final String key = (String) entry.getKey();
-                if (key.startsWith("values")) {
-                    values.add(entry.getValue());
-                }
-            }
-            if ( values.size() > 0 ) {
-                prop.setMultiValue((String[])values.toArray(new String[values.size()]));
-            }
-        }
-
-        // property is private if explicitly marked or a well known
-        // service property such as service.pid
-        final boolean isPrivate = getBoolean(property,
-            Constants.PROPERTY_PRIVATE, false)
-            || name.equals(org.osgi.framework.Constants.SERVICE_PID)
-            || name.equals(org.osgi.framework.Constants.SERVICE_DESCRIPTION)
-            || name.equals(org.osgi.framework.Constants.SERVICE_ID)
-            || name.equals(org.osgi.framework.Constants.SERVICE_RANKING)
-            || name.equals(org.osgi.framework.Constants.SERVICE_VENDOR)
-            || name.equals(ConfigurationAdmin.SERVICE_BUNDLELOCATION)
-            || name.equals(ConfigurationAdmin.SERVICE_FACTORYPID);
-
-        // if this is a public property and the component is generating metatype info
-        // store the information!
-        if ( !isPrivate && ocd != null ) {
-            final AttributeDefinition ad = new AttributeDefinition();
-            ocd.getProperties().add(ad);
-            ad.setId(prop.getName());
-            ad.setType(prop.getType());
-
-            String adName = property.getNamedParameter(Constants.PROPERTY_LABEL);
-            if ( adName == null ) {
-                adName = "%" + prop.getName() + ".name";
-            }
-            ad.setName(adName);
-            String adDesc = property.getNamedParameter(Constants.PROPERTY_DESCRIPTION);
-            if ( adDesc == null ) {
-                adDesc = "%" + prop.getName() + ".description";
-            }
-            ad.setDescription(adDesc);
-            // set optional multivalues, cardinality might be overwritten by setValues !!
-            final String cValue = property.getNamedParameter(Constants.PROPERTY_CARDINALITY);
-            if (cValue != null) {
-                if ("-".equals(cValue)) {
-                    // unlimited vector
-                    ad.setCardinality(new Integer(Integer.MIN_VALUE));
-                } else if ("+".equals(cValue)) {
-                   // unlimited array
-                    ad.setCardinality(new Integer(Integer.MAX_VALUE));
-                } else {
-                    try {
-                        ad.setCardinality(Integer.valueOf(cValue));
-                    } catch (NumberFormatException nfe) {
-                        // default to scalar in case of conversion problem
-                    }
-                }
-            }
-            ad.setDefaultValue(prop.getValue());
-            ad.setDefaultMultiValue(prop.getMultiValue());
-
-            // check options
-            String[] parameters = property.getParameters();
-            Map options = null;
-            for (int j=0; j < parameters.length; j++) {
-                if (Constants.PROPERTY_OPTIONS.equals(parameters[j])) {
-                    options = new LinkedHashMap();
-                } else if (options != null) {
-                    String optionLabel = parameters[j];
-                    String optionValue = (j < parameters.length-2) ? parameters[j+2] : null;
-                    if (optionValue != null) {
-                        options.put(optionLabel, optionValue);
-                    }
-                    j += 2;
-                }
-            }
-            ad.setOptions(options);
-        }
-
-        component.addProperty(prop);
-    }
-
-    protected String getPropertyName(JavaTag property, String defaultName) {
-        String name = property.getNamedParameter(Constants.PROPERTY_NAME);
-        if (StringUtils.isEmpty(name) && defaultName != null) {
-            name = defaultName;
-        }
-
-        if (!StringUtils.isEmpty(name)) {
-            return name;
-        }
-        return null;
-    }
-
-    protected void testProperty(Map properties, JavaTag property, String defaultName, boolean isInspectedClass)
-    throws MojoExecutionException {
-        final String propName = this.getPropertyName(property, defaultName);
-
-        if ( propName != null ) {
-            if ( properties.containsKey(propName) ) {
-                // if the current class is the class we are currently inspecting, we
-                // have found a duplicate definition
-                if ( isInspectedClass ) {
-                    throw new MojoExecutionException("Duplicate definition for property " + propName + " in class " + property.getJavaClassDescription().getName());
-                }
-            } else {
-                properties.put(propName, property);
-            }
-        }
-    }
-
     protected void testReference(Map references, JavaTag reference, String defaultName, boolean isInspectedClass)
     throws MojoExecutionException {
         final String refName = this.getReferenceName(reference, defaultName);
@@ -651,7 +520,7 @@
         component.addReference(ref);
     }
 
-    protected boolean getBoolean(JavaTag tag, String name, boolean defaultValue) {
+    public static boolean getBoolean(JavaTag tag, String name, boolean defaultValue) {
         String value = tag.getNamedParameter(name);
         return (value == null) ? defaultValue : Boolean.valueOf(value).booleanValue();
     }
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
index cbab33a..963fca4 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
@@ -60,8 +60,14 @@
      */
     String getName();
 
+    /**
+     * Get the fields of this class
+     * @return All fields or an empty array
+     */
     JavaField[] getFields();
 
+    JavaField getFieldByName(String name) throws MojoExecutionException;
+
     /**
      * Returns an array of the implemented interfaces of this class.
      * @return An array containing the interfaces or an empty array
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
index 20f1cdc..71895e0 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
@@ -18,21 +18,11 @@
  */
 package org.apache.felix.scrplugin.tags;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
+import java.util.*;
+import java.util.jar.*;
 
 import org.apache.felix.scrplugin.Constants;
 import org.apache.felix.scrplugin.om.Component;
@@ -214,7 +204,7 @@
     protected ClassLoader getCompileClassLoader(MavenProject project)
     throws MojoFailureException {
         List artifacts = project.getCompileArtifacts();
-        URL[] path = new URL[artifacts.size()];
+        URL[] path = new URL[artifacts.size() + 1];
         int i = 0;
         for (Iterator ai=artifacts.iterator(); ai.hasNext(); ) {
             Artifact a = (Artifact) ai.next();
@@ -224,6 +214,12 @@
                 throw new MojoFailureException("Unable to get compile class loader.");
             }
         }
+        final String targetDirectory = this.getProject().getBuild().getOutputDirectory();
+        try {
+            path[path.length - 1] = new File(targetDirectory).toURI().toURL();
+        } catch (IOException ioe) {
+            throw new MojoFailureException("Unable to add target directory to classloader.");
+        }
         return new URLClassLoader(path);
     }
 
@@ -273,10 +269,15 @@
      * Return all source descriptions of this project.
      * @return All contained java class descriptions.
      */
-    public JavaClassDescription[] getSourceDescriptions() {
+    public JavaClassDescription[] getSourceDescriptions() throws MojoExecutionException {
         final JavaClassDescription[] descs = new JavaClassDescription[this.sources.length];
         for(int i=0; i<this.sources.length; i++) {
-            descs[i] = new QDoxJavaClassDescription(this.sources[i], this);
+            final String className = this.sources[i].getClasses()[0].getFullyQualifiedName();
+            try {
+                descs[i] = new QDoxJavaClassDescription(this.classloader.loadClass(className), this.sources[i], this);
+            } catch (ClassNotFoundException e) {
+                throw new MojoExecutionException("Unable to load class " + className);
+            }
         }
         return descs;
     }
@@ -295,8 +296,12 @@
             int index = 0;
             while ( result == null && index < this.sources.length) {
                 if ( this.sources[index].getClasses()[0].getFullyQualifiedName().equals(className) ) {
-                    this.log.debug("Found qdox description for: " + className);
-                    result = new QDoxJavaClassDescription(this.sources[index], this);
+                    try {
+                        this.log.debug("Found qdox description for: " + className);
+                        result = new QDoxJavaClassDescription(this.classloader.loadClass(className), this.sources[index], this);
+                    } catch (ClassNotFoundException e) {
+                        throw new MojoExecutionException("Unable to load class " + className);
+                    }
                 } else {
                     index++;
                 }
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
index 4e8bf14..0755a6a 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
@@ -60,6 +60,27 @@
     }
 
     /**
+     * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getFieldByName(java.lang.String)
+     */
+    public JavaField getFieldByName(String name) throws MojoExecutionException {
+        Field field = null;
+        try {
+            field = this.clazz.getField(name);
+        } catch (SecurityException e) {
+            // ignore
+        } catch (NoSuchFieldException e) {
+            // ignore
+        }
+        if ( field != null ) {
+            return new ClassLoaderJavaField(field, this);
+        }
+        if ( this.getSuperClass() != null ) {
+            this.getSuperClass().getFieldByName(name);
+        }
+        return null;
+    }
+
+    /**
      * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getImplementedInterfaces()
      */
     public JavaClassDescription[] getImplementedInterfaces() throws MojoExecutionException {
@@ -213,7 +234,7 @@
     public boolean isPublic() {
         return Modifier.isPublic(this.clazz.getModifiers());
     }
-    
+
     public String toString() {
         return getName();
     }
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaField.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaField.java
index 2b2f8be..afebf4c 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaField.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaField.java
@@ -20,9 +20,7 @@
 
 import java.lang.reflect.Field;
 
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.*;
 
 /**
  * <code>ClassLoaderJavaField.java</code>...
@@ -43,8 +41,17 @@
      * @see org.apache.felix.scrplugin.tags.JavaField#getInitializationExpression()
      */
     public String getInitializationExpression() {
-        // TODO
-        return null;
+        try {
+            this.field.setAccessible(true);
+            final Object value = this.field.get(null);
+            if ( value != null ) {
+                return value.toString();
+            }
+            return null;
+        } catch (Exception e) {
+            // ignore and return null
+            return null;
+        }
     }
 
     /**
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
index 9a51a96..1861789 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
@@ -45,10 +45,14 @@
 
     protected final JavaSource source;
 
-    public QDoxJavaClassDescription(JavaSource source, JavaClassDescriptorManager m) {
+    /** The compiled class. */
+    protected final Class clazz;
+
+    public QDoxJavaClassDescription(Class clazz, JavaSource source, JavaClassDescriptorManager m) {
         this.javaClass = source.getClasses()[0];
         this.manager = m;
         this.source = source;
+        this.clazz = clazz;
     }
 
     /**
@@ -122,6 +126,21 @@
     }
 
     /**
+     * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getFieldByName(java.lang.String)
+     */
+    public JavaField getFieldByName(String name)
+    throws MojoExecutionException {
+        final com.thoughtworks.qdox.model.JavaField field = this.javaClass.getFieldByName(name);
+        if ( field != null ) {
+            return new QDoxJavaField(field, this);
+        }
+        if ( this.getSuperClass() != null ) {
+            return this.getSuperClass().getFieldByName(name);
+        }
+        return null;
+    }
+
+    /**
      * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getImplementedInterfaces()
      */
     public JavaClassDescription[] getImplementedInterfaces()
@@ -308,8 +327,15 @@
         meth.setModifiers(new String[] {"protected"});
         this.javaClass.addMethod(meth);
     }
-    
+
+    /**
+     * @see java.lang.Object#toString()
+     */
     public String toString() {
         return getName();
     }
+
+    public Class getCompiledClass() {
+        return this.clazz;
+    }
 }
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java
index e4d0564..3a08804 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java
@@ -18,7 +18,8 @@
  */
 package org.apache.felix.scrplugin.tags.qdox;
 
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
+import java.lang.reflect.Field;
+
 import org.apache.felix.scrplugin.tags.JavaField;
 import org.apache.felix.scrplugin.tags.JavaTag;
 
@@ -32,9 +33,9 @@
 
     protected final com.thoughtworks.qdox.model.JavaField field;
 
-    protected final JavaClassDescription description;
+    protected final QDoxJavaClassDescription description;
 
-    public QDoxJavaField(com.thoughtworks.qdox.model.JavaField f, JavaClassDescription d) {
+    public QDoxJavaField(com.thoughtworks.qdox.model.JavaField f, QDoxJavaClassDescription d) {
         this.field = f;
         this.description = d;
     }
@@ -43,7 +44,19 @@
      * @see org.apache.felix.scrplugin.tags.JavaField#getInitializationExpression()
      */
     public String getInitializationExpression() {
-        return this.field.getInitializationExpression();
+        final Class c = this.description.getCompiledClass();
+        try {
+            final Field field = c.getDeclaredField(this.getName());
+            field.setAccessible(true);
+            final Object value = field.get(null);
+            if ( value != null ) {
+                return value.toString();
+            }
+            return null;
+        } catch (Exception e) {
+            // ignore and return null
+            return null;
+        }
     }
 
     /**