felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r565751 - in /felix/sandbox/cziegeler/maven-scr-plugin: ./ src/main/java/org/apache/felix/sandbox/scrplugin/ src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/ src/main/java/org/apache/felix/sandbox/scrplugin/tags/ src/main/java/...
Date Tue, 14 Aug 2007 13:45:37 GMT
Author: cziegeler
Date: Tue Aug 14 06:45:36 2007
New Revision: 565751

URL: http://svn.apache.org/viewvc?view=rev&rev=565751
Log:
Finish refactoring - use unified om and remove dependency to xstream by self generating/reading xml.

Added:
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Constants.java
      - copied, changed from r562420, felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptor.java
Removed:
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/AbstractDescriptorElement.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Property.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Reference.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptor.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Service.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/XMLWriter.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Component.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Components.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Implementation.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Interface.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Property.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Reference.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/Service.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/XMLHandler.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/resources/
Modified:
    felix/sandbox/cziegeler/maven-scr-plugin/pom.xml
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptorMojo.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/JavaClassDescriptorManager.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaTag.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java

Modified: felix/sandbox/cziegeler/maven-scr-plugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/pom.xml?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/pom.xml (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/pom.xml Tue Aug 14 06:45:36 2007
@@ -63,11 +63,6 @@
 		    <artifactId>commons-io</artifactId>
 		    <version>1.3.2</version>
 		</dependency>
-        <dependency>
-            <groupId>com.thoughtworks.xstream</groupId>
-            <artifactId>xstream</artifactId>
-            <version>1.2.2</version>
-        </dependency>
 
 		<dependency>
 			<groupId>org.apache.maven</groupId>

Copied: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Constants.java (from r562420, felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptor.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Constants.java?view=diff&rev=565751&p1=felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptor.java&r1=562420&p2=felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Constants.java&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptor.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/Constants.java Tue Aug 14 06:45:36 2007
@@ -18,21 +18,12 @@
  */
 package org.apache.felix.sandbox.scrplugin;
 
-import java.util.Iterator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.felix.sandbox.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.sandbox.scrplugin.tags.JavaMethod;
-import org.apache.felix.sandbox.scrplugin.tags.JavaParameter;
-import org.apache.felix.sandbox.scrplugin.tags.JavaTag;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
+import java.io.File;
 
 /**
- * Model: scr base descriptor
+ * Constants
  */
-public class SCRDescriptor extends AbstractDescriptorElement {
+public class Constants {
 
     public static final String COMPONENT = "scr.component";
 
@@ -94,345 +85,10 @@
 
     public static final String REFERENCE_UNDBIND = "unbind";
 
-    private String name;
+    public static final String ABSTRACT_DESCRIPTOR_FILENAME = "scrinfo.xml";
 
-    private String label;
+    public static final String ABSTRACT_DESCRIPTOR_RELATIVE_PATH = "OSGI-INF" + File.separator + "scr-plugin" + File.separator + ABSTRACT_DESCRIPTOR_FILENAME;
 
-    private String description;
+    public static final String ABSTRACT_DESCRIPTOR_ARCHIV_PATH = "OSGI-INF/scr-plugin/" + ABSTRACT_DESCRIPTOR_FILENAME;
 
-    private boolean enabled;
-
-    private String factory;
-
-    private boolean immediate;
-
-    private String implClass;
-
-    private boolean serviceFactory;
-
-    private boolean hasMetaType;
-
-    private boolean isAbstract;
-
-    // map of properties
-    private Set properties = new TreeSet();
-
-    // list of service interfaces
-    private Set services = new TreeSet();
-
-    // list of service references
-    private Set references = new TreeSet();
-
-    SCRDescriptor(Log log, JavaTag tag) {
-        super(log, tag);
-
-        // whether metatype information is to generated for the component
-        String metaType = tag.getNamedParameter(COMPONENT_METATYPE);
-        this.hasMetaType = metaType == null || "yes".equalsIgnoreCase(metaType)
-            || "true".equalsIgnoreCase(metaType);
-        // check if this is an abstract definition
-        String abstractType = tag.getNamedParameter(COMPONENT_ABSTRACT);
-        this.isAbstract = (abstractType == null ? false : "yes".equalsIgnoreCase(abstractType) || "true".equalsIgnoreCase(abstractType));
-    }
-
-    boolean isAbstract() {
-        return this.isAbstract;
-    }
-
-    // validates the descriptor and returns an array of issues or null
-    boolean validate() throws MojoExecutionException {
-
-        JavaClassDescription javaClass = this.tag.getJavaClassDescription();
-        if (javaClass == null) {
-            this.log("Tag not declared in a Java Class");
-            return false;
-        }
-
-        boolean valid = true;
-
-        // if the service is abstract, we do not validate everything
-        if ( !this.isAbstract ) {
-            // ensure non-abstract, public class
-            if (!javaClass.isPublic()) {
-                this.log("Class must be public");
-                valid = false;
-            }
-            if (javaClass.isAbstract() || javaClass.isInterface()) {
-                this.log("Class must be concrete class (not abstract or interface)");
-                valid = false;
-            }
-
-            // check activate and deactivate methods
-            this.checkActivationMethod(javaClass, "activate");
-            this.checkActivationMethod(javaClass, "deactivate");
-
-            // ensure public default constructor
-            boolean constructorFound = true;
-            JavaMethod[] methods = javaClass.getMethods();
-            for (int i = 0; methods != null && i < methods.length; i++) {
-                if (methods[i].isConstructor()) {
-                    // if public default, succeed
-                    if (methods[i].isPublic()
-                        && (methods[i].getParameters() == null || methods[i].getParameters().length == 0)) {
-                        constructorFound = true;
-                        break;
-                    }
-
-                    // non-public/non-default constructor found, must have explicit
-                    constructorFound = false;
-                }
-            }
-            if (!constructorFound) {
-                this.log("Class must have public default constructor");
-                valid = false;
-            }
-
-            // verify properties
-            for (Iterator pi = this.getProperties(); pi.hasNext();) {
-                Property prop = (Property) pi.next();
-                valid &= prop.validate();
-            }
-
-            // verify services
-            for (Iterator si = this.getServices(); si.hasNext();) {
-                Service service = (Service) si.next();
-                valid &= service.validate();
-            }
-
-            // serviceFactory must not be true for immediate of component factory
-            if (this.isServiceFactory() && this.isImmediate() && this.getFactory() != null) {
-                this.log("Component must not be a ServiceFactory, if immediate and/or component factory");
-                valid = false;
-            }
-
-            // verify references
-            for (Iterator ri = this.getReferences(); ri.hasNext();) {
-                Reference ref = (Reference) ri.next();
-                valid &= ref.validate();
-            }
-        }
-        return valid;
-    }
-
-    private void checkActivationMethod(JavaClassDescription javaClass, String methodName) {
-        JavaMethod[] methods = javaClass.getMethods();
-        JavaMethod activation = null;
-        for (int i=0; i < methods.length; i++) {
-            // ignore method not matching the name
-            if (!methodName.equals(methods[i].getName())) {
-                continue;
-            }
-
-            // if the method has the correct parameter type, check protected
-            JavaParameter[] params = methods[i].getParameters();
-            if (params == null || params.length != 1) {
-                continue;
-            }
-
-            // this might be considered, if it is an overload, drop out of check
-            if (activation != null) {
-                return;
-            }
-
-            // consider this method for further checks
-            activation = methods[i];
-        }
-
-        // no activation method found
-        if (activation == null) {
-            return;
-        }
-
-        // check protected
-        if (activation.isPublic()) {
-            this.warn("Activation method " + activation.getName() + " should be declared protected");
-        } else if (!activation.isProtected()) {
-            this.warn("Activation method " + activation.getName() + " has wrong qualifier, public or protected required");
-        }
-
-        // check paramter (we know there is exactly one)
-        JavaParameter param = activation.getParameters()[0];
-        if (!"org.osgi.service.component.ComponentContext".equals(param.getType())) {
-            this.warn("Activation method " + methodName + " has wrong argument type " + param.getType());
-        }
-    }
-
-    void generate(XMLWriter xw) {
-        xw.printElementStart("component", true);
-        xw.printAttribute("name", this.getName());
-        if (!this.isEnabled())
-            xw.printAttribute("enabled", String.valueOf(this.isEnabled()));
-        if (this.getFactory() != null) xw.printAttribute("factory", this.getFactory());
-        xw.printAttribute("immediate", String.valueOf(this.isImmediate()));
-        xw.printElementStartClose(false);
-
-        xw.indent();
-
-        xw.printElementStart("implementation", true);
-        xw.printAttribute("class", this.getImplClass());
-        xw.printElementStartClose(true);
-
-        // properties
-        for (Iterator pi = this.getProperties(); pi.hasNext();) {
-            ((Property) pi.next()).generate(xw);
-        }
-
-        // services
-        Iterator si = this.getServices();
-        if (si.hasNext()) {
-            xw.printElementStart("service", this.isServiceFactory());
-            if (this.isServiceFactory()) {
-                xw.printAttribute("servicefactory", "true");
-                xw.printElementStartClose(false);
-            }
-            xw.indent();
-            while (si.hasNext()) {
-                ((Service) si.next()).generate(xw);
-            }
-            xw.outdent();
-            xw.printElementEnd("service");
-        }
-
-        // references
-        for (Iterator ri = this.getReferences(); ri.hasNext();) {
-            ((Reference) ri.next()).generate(xw);
-        }
-
-        xw.outdent();
-        xw.printElementEnd("component");
-    }
-
-    void generateMetaTypeInfo(XMLWriter xw) {
-
-        // if there is no metatype, we return early
-        if (!this.hasMetaType) {
-            return;
-        }
-
-        xw.printElementStart("OCD", true);
-        xw.printAttribute("id", this.getName());
-
-        if (this.getLabel() != null) {
-            xw.printAttribute("name", this.getLabel());
-        } else {
-            // use the name as a localizable key by default
-            xw.printAttribute("name", "%" + this.getName() + ".name");
-        }
-
-        if (this.getDescription() != null) {
-            xw.printAttribute("description", this.getDescription());
-        } else {
-            // use the name as a localizable key by default
-            xw.printAttribute("description", "%" + this.getName() + ".description");
-        }
-
-        xw.printElementStartClose(false);
-
-        // properties
-        for (Iterator pi = this.getProperties(); pi.hasNext();) {
-            ((Property) pi.next()).generateMetaTypeInfo(xw);
-        }
-
-        xw.printElementEnd("OCD");
-
-        xw.printElementStart("Designate", true);
-        xw.printAttribute("pid", this.getName());
-        xw.printElementStartClose(false);
-
-        xw.printElementStart("Object", true);
-        xw.printAttribute("ocdref", this.getName());
-        xw.printElementStartClose(true);
-
-        xw.printElementEnd("Designate");
-    }
-
-    // ---------- Setters and Getters for the properties -----------------------
-
-    public boolean isEnabled() {
-        return this.enabled;
-    }
-
-    void setEnabled(boolean enabled) {
-        this.enabled = enabled;
-    }
-
-    public String getFactory() {
-        return this.factory;
-    }
-
-    void setFactory(String factory) {
-        this.factory = factory;
-    }
-
-    public boolean isImmediate() {
-        return this.immediate;
-    }
-
-    void setImmediate(boolean immediate) {
-        this.immediate = immediate;
-    }
-
-    public String getImplClass() {
-        return this.implClass;
-    }
-
-    void setImplClass(String implClass) {
-        this.implClass = implClass;
-    }
-
-    public String getName() {
-        return this.name;
-    }
-
-    void setName(String name) {
-        this.name = name;
-    }
-
-    String getLabel() {
-        return this.label;
-    }
-
-    void setLabel(String label) {
-        this.label = label;
-    }
-
-    String getDescription() {
-        return this.description;
-    }
-
-    void setDescription(String description) {
-        this.description = description;
-    }
-
-    public Iterator getProperties() {
-        return this.properties.iterator();
-    }
-
-    void addProperty(Property property) {
-        this.properties.add(property);
-    }
-
-    public Iterator getReferences() {
-        return this.references.iterator();
-    }
-
-    void addReference(Reference reference) {
-        this.references.add(reference);
-    }
-
-    public boolean isServiceFactory() {
-        return this.serviceFactory;
-    }
-
-    void setServiceFactory(boolean serviceFactory) {
-        this.serviceFactory = serviceFactory;
-    }
-
-    public Iterator getServices() {
-        return this.services.iterator();
-    }
-
-    void addService(Service service) {
-        this.services.add(service);
-    }
 }

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptorMojo.java?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptorMojo.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/SCRDescriptorMojo.java Tue Aug 14 06:45:36 2007
@@ -19,8 +19,6 @@
 package org.apache.felix.sandbox.scrplugin;
 
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -40,12 +38,12 @@
 import org.apache.felix.sandbox.scrplugin.tags.JavaField;
 import org.apache.felix.sandbox.scrplugin.tags.JavaTag;
 import org.apache.felix.sandbox.scrplugin.xml.ComponentDescriptorIO;
+import org.apache.felix.sandbox.scrplugin.xml.MetaTypeIO;
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -90,44 +88,32 @@
         JavaClassDescriptorManager jManager = new JavaClassDescriptorManager(this.getLog(),
                                                                              this.project);
         // iterate through all source classes and check for component tag
-        final List descriptors = new ArrayList();
-        final List abstractDescriptors = new ArrayList();
         final JavaClassDescription[] javaSources = jManager.getSourceDescriptions();
 
-        // test the new om?
-        boolean testNewOM = false;
         final Components components = new Components();
         final Components abstractComponents = new Components();
+        boolean hasMetaTypeInfo = false;
 
         for (int i = 0; i < javaSources.length; i++) {
             this.getLog().debug("Testing source " + javaSources[i].getName());
-            final JavaTag tag = javaSources[i].getTagByName(SCRDescriptor.COMPONENT);
+            final JavaTag tag = javaSources[i].getTagByName(Constants.COMPONENT);
             if (tag != null) {
                 this.getLog().debug("Processing service class " + javaSources[i].getName());
-                final SCRDescriptor descriptor = this.createSCRDescriptor(javaSources[i]);
-                if (descriptor != null) {
-                    if ( descriptor.isAbstract() ) {
-                        this.getLog().debug("Adding abstract descriptor " + descriptor);
-                        abstractDescriptors.add(descriptor);
+                final Component comp = this.createComponent(javaSources[i]);
+                if (comp != null) {
+                    if ( comp.isAbstract() ) {
+                        this.getLog().debug("Adding abstract descriptor " + comp);
+                        abstractComponents.addComponent(comp);
                     } else {
-                        this.getLog().debug("Adding descriptor " + descriptor);
-                        descriptors.add(descriptor);
+                        this.getLog().debug("Adding descriptor " + comp);
+                        components.addComponent(comp);
+                        if ( comp.getOcd() != null ) {
+                            hasMetaTypeInfo = true;
+                        }
                     }
                 } else {
                     hasFailures = true;
                 }
-                if ( testNewOM ) {
-                    final Component comp = this.createComponent(javaSources[i]);
-                    if (comp != null) {
-                        if ( comp.isAbstract() ) {
-                            this.getLog().debug("Adding abstract descriptor " + descriptor);
-                            abstractComponents.addComponent(comp);
-                        } else {
-                            this.getLog().debug("Adding descriptor " + descriptor);
-                            components.addComponent(comp);
-                        }
-                    }
-                }
             }
         }
 
@@ -136,82 +122,51 @@
             throw new MojoFailureException("SCR Descriptor parsing had failures (see log)");
         }
 
-        jManager.writeAbstractDescriptorsFile(abstractDescriptors, this.outputDirectory);
+        // if we have abstract descriptors, write them
+        final File adFile = new File(this.outputDirectory, Constants.ABSTRACT_DESCRIPTOR_RELATIVE_PATH);
+        if ( !abstractComponents.getComponents().isEmpty() ) {
+            this.getLog().info("Writing abstract service descriptor " + adFile + " with " + components.getComponents().size() + " entries.");
+            adFile.getParentFile().mkdirs();
+            ComponentDescriptorIO.write(abstractComponents, adFile);
+        } else {
+            this.getLog().debug("No abstract SCR Descriptors found in project");
+            // remove file
+            if ( adFile.exists() ) {
+                this.getLog().debug("Removing obsolete abstract service descriptor " + adFile);
+                adFile.delete();
+            }
+        }
 
-        // terminate if there is nothing to write
-        if (descriptors.isEmpty()) {
-            this.getLog().info("No SCR Descriptors found in project");
+        // terminate if there is nothing else to write
+        if (components.getComponents().isEmpty()) {
+            this.getLog().debug("No SCR Descriptors found in project");
             return;
         }
 
-        // finally the descriptors have to be written ....
+        // check file name
         if (StringUtils.isEmpty(this.finalName)) {
             this.getLog().error("Descriptor file name must not be empty");
             return;
         }
 
+        // finally the descriptors have to be written ....
         File descriptorFile = new File(new File(this.outputDirectory, "OSGI-INF"), this.finalName);
         descriptorFile.getParentFile().mkdirs(); // ensure parent dir
 
-        this.getLog().info("Generating " + descriptors.size()
+        this.getLog().info("Generating " + components.getComponents().size()
                 + " Service Component Descriptors to " + descriptorFile);
 
-        FileOutputStream descriptorStream = null;
-        XMLWriter xw = null;
-        try {
-            if ( testNewOM ) {
-                ComponentDescriptorIO.write(components, descriptorFile);
-            } else {
-                descriptorStream = new FileOutputStream(descriptorFile);
-                xw = new XMLWriter(descriptorStream);
-
-                for (Iterator di=descriptors.iterator(); di.hasNext(); ) {
-                    SCRDescriptor sd = (SCRDescriptor) di.next();
-                    sd.generate(xw);
-                }
-            }
-
-        } catch (IOException ioe) {
-            hasFailures = true;
-            this.getLog().error("Cannot write descriptor to " + descriptorFile, ioe);
-            throw new MojoFailureException("Failed to write descriptor to " + descriptorFile);
-        } finally {
-            IOUtil.close(xw);
-            IOUtil.close(descriptorStream);
-
-            // remove the descriptor file in case of write failure
-            if (hasFailures) {
-                descriptorFile.delete();
-            }
-        }
+        ComponentDescriptorIO.write(components, descriptorFile);
 
         // create metatype information
         File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator + "metatype.xml");
         mtFile.getParentFile().mkdirs();
-
-        xw = null;
-        descriptorStream = null;
-        try {
-            descriptorStream = new FileOutputStream(mtFile);
-            xw = new XMLWriter(descriptorStream);
-
-            xw.printElementStart("MetaData", true);
-            xw.printAttribute("localization", "metatype");
-            xw.printElementStartClose(false);
-
-            for (Iterator di=descriptors.iterator(); di.hasNext(); ) {
-                SCRDescriptor sd = (SCRDescriptor) di.next();
-                sd.generateMetaTypeInfo(xw);
-            }
-
-            xw.printElementEnd("MetaData");
-
-        } catch (IOException ioe) {
-            this.getLog().error("Cannot write meta type descriptor", ioe);
-            throw new MojoFailureException("Failed to write meta type descriptor");
-        } finally {
-            IOUtil.close(xw);
-            IOUtil.close(descriptorStream);
+        if ( hasMetaTypeInfo ) {
+            MetaTypeIO.write(components, mtFile);
+        } else {
+            if ( mtFile.exists() ) {
+                mtFile.delete();
+            }
         }
 
         // now add the descriptor file to the maven resources
@@ -231,45 +186,6 @@
         this.project.getProperties().setProperty("Service-Component", "OSGI-INF/" + this.finalName);
     }
 
-    private SCRDescriptor createSCRDescriptor(JavaClassDescription description)
-    throws MojoExecutionException {
-
-        final JavaTag component = description.getTagByName(SCRDescriptor.COMPONENT);
-        final SCRDescriptor sd = new SCRDescriptor(this.getLog(), component);
-        sd.setImplClass(description.getName());
-
-        boolean inherited = this.getBoolean(component, SCRDescriptor.COMPONENT_INHERIT, false);
-
-        this.doComponent(component, sd);
-
-        boolean serviceFactory = this.doServices(description.getTagsByName(SCRDescriptor.SERVICE, inherited), sd, description);
-        sd.setServiceFactory(serviceFactory);
-
-        this.doProperties(description.getTagsByName(SCRDescriptor.PROPERTY, inherited), sd);
-
-        this.doReferences(description.getTagsByName(SCRDescriptor.REFERENCE, inherited), sd);
-
-        do {
-            JavaField[] fields = description.getFields();
-            for (int i=0; fields != null && i < fields.length; i++) {
-                JavaTag tag = fields[i].getTagByName(SCRDescriptor.REFERENCE);
-                if (tag != null) {
-                    this.doReference(tag, fields[i].getName(), sd);
-                }
-
-                tag = fields[i].getTagByName(SCRDescriptor.PROPERTY);
-                if (tag != null) {
-                    this.doProperty(tag, fields[i].getInitializationExpression(), sd);
-                }
-            }
-
-            description = description.getSuperClass();
-        } while (inherited && description != null);
-
-        // return nothing if validation fails
-        return sd.validate() ? sd : null;
-    }
-
     /**
      * Create a component for the java class description.
      * @param description
@@ -279,7 +195,7 @@
     protected Component createComponent(JavaClassDescription description)
     throws MojoExecutionException {
 
-        final JavaTag componentTag = description.getTagByName(SCRDescriptor.COMPONENT);
+        final JavaTag componentTag = description.getTagByName(Constants.COMPONENT);
         final Component component = new Component(componentTag);
 
         // set implementation
@@ -287,12 +203,12 @@
 
         this.doComponent(componentTag, component);
 
-        boolean inherited = this.getBoolean(componentTag, SCRDescriptor.COMPONENT_INHERIT, false);
-        boolean serviceFactory = this.doServices(description.getTagsByName(SCRDescriptor.SERVICE, inherited), component, description);
+        boolean inherited = this.getBoolean(componentTag, Constants.COMPONENT_INHERIT, false);
+        boolean serviceFactory = this.doServices(description.getTagsByName(Constants.SERVICE, inherited), component, description);
         component.setServiceFactory(serviceFactory);
 
         // properties
-        final JavaTag[] properties = description.getTagsByName(SCRDescriptor.PROPERTY, inherited);
+        final JavaTag[] properties = description.getTagsByName(Constants.PROPERTY, inherited);
         if (properties != null && properties.length > 0) {
             for (int i=0; i < properties.length; i++) {
                 this.doProperty(properties[i], null, component);
@@ -300,7 +216,7 @@
         }
 
         // references
-        final JavaTag[] references = description.getTagsByName(SCRDescriptor.REFERENCE, inherited);
+        final JavaTag[] references = description.getTagsByName(Constants.REFERENCE, inherited);
         if (references != null || references.length > 0) {
             for (int i=0; i < references.length; i++) {
                 this.doReference(references[i], null, component);
@@ -311,12 +227,12 @@
         do {
             JavaField[] fields = description.getFields();
             for (int i=0; fields != null && i < fields.length; i++) {
-                JavaTag tag = fields[i].getTagByName(SCRDescriptor.REFERENCE);
+                JavaTag tag = fields[i].getTagByName(Constants.REFERENCE);
                 if (tag != null) {
                     this.doReference(tag, fields[i].getName(), component);
                 }
 
-                tag = fields[i].getTagByName(SCRDescriptor.PROPERTY);
+                tag = fields[i].getTagByName(Constants.PROPERTY);
                 if (tag != null) {
                     this.doProperty(tag, fields[i].getInitializationExpression(), component);
                 }
@@ -351,18 +267,18 @@
     protected void doComponent(JavaTag tag, Component component) {
 
         // check if this is an abstract definition
-        final String abstractType = tag.getNamedParameter(SCRDescriptor.COMPONENT_ABSTRACT);
+        final String abstractType = tag.getNamedParameter(Constants.COMPONENT_ABSTRACT);
         component.setAbstract((abstractType == null ? false : "yes".equalsIgnoreCase(abstractType) || "true".equalsIgnoreCase(abstractType)));
 
-        String name = tag.getNamedParameter(SCRDescriptor.COMPONENT_NAME);
+        String name = tag.getNamedParameter(Constants.COMPONENT_NAME);
         component.setName(StringUtils.isEmpty(name) ? component.getImplementation().getClassame() : name);
 
-        component.setEnabled(Boolean.valueOf(this.getBoolean(tag, SCRDescriptor.COMPONENT_ENABLED, true)));
-        component.setFactory(tag.getNamedParameter(SCRDescriptor.COMPONENT_FACTORY));
-        component.setImmediate(Boolean.valueOf(this.getBoolean(tag, SCRDescriptor.COMPONENT_IMMEDIATE, true)));
+        component.setEnabled(Boolean.valueOf(this.getBoolean(tag, Constants.COMPONENT_ENABLED, true)));
+        component.setFactory(tag.getNamedParameter(Constants.COMPONENT_FACTORY));
+        component.setImmediate(Boolean.valueOf(this.getBoolean(tag, Constants.COMPONENT_IMMEDIATE, true)));
 
         // whether metatype information is to generated for the component
-        final String metaType = tag.getNamedParameter(SCRDescriptor.COMPONENT_METATYPE);
+        final String metaType = tag.getNamedParameter(Constants.COMPONENT_METATYPE);
         final boolean hasMetaType = metaType == null || "yes".equalsIgnoreCase(metaType)
             || "true".equalsIgnoreCase(metaType);
         if ( hasMetaType ) {
@@ -370,12 +286,12 @@
             final OCD ocd = new OCD();
             component.setOcd(ocd);
             ocd.setId(component.getName());
-            String ocdName = tag.getNamedParameter(SCRDescriptor.COMPONENT_LABEL);
+            String ocdName = tag.getNamedParameter(Constants.COMPONENT_LABEL);
             if ( ocdName == null ) {
                 ocdName = "%" + component.getName() + ".name";
             }
             ocd.setName(ocdName);
-            String ocdDescription = tag.getNamedParameter(SCRDescriptor.COMPONENT_DESCRIPTION);
+            String ocdDescription = tag.getNamedParameter(Constants.COMPONENT_DESCRIPTION);
             if ( ocdDescription == null ) {
                 ocdDescription = "%" + component.getName() + ".description";
             }
@@ -410,7 +326,7 @@
         component.setService(service);
         boolean serviceFactory = false;
         for (int i=0; i < services.length; i++) {
-            String name = services[i].getNamedParameter(SCRDescriptor.SERVICE_INTERFACE);
+            String name = services[i].getNamedParameter(Constants.SERVICE_INTERFACE);
             if (StringUtils.isEmpty(name)) {
 
                 while (description != null) {
@@ -430,120 +346,19 @@
                 service.addInterface(interf);
             }
 
-            serviceFactory |= this.getBoolean(services[i], SCRDescriptor.SERVICE_FACTORY, false);
+            serviceFactory |= this.getBoolean(services[i], Constants.SERVICE_FACTORY, false);
         }
 
         return serviceFactory;
     }
 
-    private void doComponent(JavaTag comp, SCRDescriptor sd) {
-        String name = comp.getNamedParameter(SCRDescriptor.COMPONENT_NAME);
-        sd.setName(StringUtils.isEmpty(name) ? sd.getImplClass() : name);
-
-        sd.setEnabled(this.getBoolean(comp, SCRDescriptor.COMPONENT_ENABLED, true));
-        sd.setFactory(comp.getNamedParameter(SCRDescriptor.COMPONENT_FACTORY));
-        sd.setImmediate(this.getBoolean(comp, SCRDescriptor.COMPONENT_IMMEDIATE,
-            true));
-
-        sd.setLabel(comp.getNamedParameter(SCRDescriptor.COMPONENT_LABEL));
-        sd.setDescription(comp.getNamedParameter(SCRDescriptor.COMPONENT_DESCRIPTION));
-    }
-
-    private boolean doServices(JavaTag[] services, SCRDescriptor sd, JavaClassDescription description)
-    throws MojoExecutionException {
-        // no services, hence certainly no service factory
-        if (services == null || services.length == 0) {
-            return false;
-        }
-
-        boolean serviceFactory = false;
-        for (int i=0; i < services.length; i++) {
-            String name = services[i].getNamedParameter(SCRDescriptor.SERVICE_INTERFACE);
-            if (StringUtils.isEmpty(name)) {
-
-                while (description != null) {
-                    JavaClassDescription[] interfaces = description.getImplementedInterfaces();
-                    for (int j=0; interfaces != null && j < interfaces.length; j++) {
-                        Service service = new Service(this.getLog(), services[i]);
-                        service.setInterfaceName(interfaces[j].getName());
-                        sd.addService(service);
-                    }
-
-                    // try super class
-                    description = description.getSuperClass();
-                }
-            } else {
-                Service service = new Service(this.getLog(), services[i]);
-                service.setInterfaceName(name);
-                sd.addService(service);
-            }
-
-            serviceFactory |= this.getBoolean(services[i], SCRDescriptor.SERVICE_FACTORY, false);
-        }
-
-        return serviceFactory;
-    }
-
-    private void doProperties(JavaTag[] properties, SCRDescriptor sd) {
-        if (properties == null || properties.length == 0) {
-            return;
-        }
-
-        for (int i=0; i < properties.length; i++) {
-            this.doProperty(properties[i], null, sd);
-        }
-    }
-
-    private void doProperty(JavaTag property, String defaultName, SCRDescriptor sd) {
-        String name = property.getNamedParameter(SCRDescriptor.PROPERTY_NAME);
-        if (StringUtils.isEmpty(name) && defaultName!= null) {
-            name = defaultName.trim();
-            if (name.startsWith("\"")) name = name.substring(1);
-            if (name.endsWith("\"")) name = name.substring(0, name.length()-1);
-        }
-
-        if (!StringUtils.isEmpty(name)) {
-            Property prop = new Property(this.getLog(), property);
-            prop.setName(name);
-            prop.setLabel(property.getNamedParameter(SCRDescriptor.PROPERTY_LABEL));
-            prop.setDescription(property.getNamedParameter(SCRDescriptor.PROPERTY_DESCRIPTION));
-            prop.setValue(property.getNamedParameter(SCRDescriptor.PROPERTY_VALUE));
-            prop.setType(property.getNamedParameter(SCRDescriptor.PROPERTY_TYPE));
-            prop.setPrivateProperty(this.getBoolean(property,
-                SCRDescriptor.PROPERTY_PRIVATE, prop.isPrivateProperty()));
-
-            // set optional multivalues, cardinailty might be overwritten by setValues !!
-            prop.setCardinality(property.getNamedParameter(SCRDescriptor.PROPERTY_CARDINALITY));
-            prop.setValues(property.getNamedParameterMap());
-
-            // check options
-            String[] parameters = property.getParameters();
-            Map options = null;
-            for (int j=0; j < parameters.length; j++) {
-                if (SCRDescriptor.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;
-                }
-            }
-            prop.setOptions(options);
-
-            sd.addProperty(prop);
-        }
-    }
-
     /**
      * @param property
      * @param defaultName
      * @param component
      */
     protected void doProperty(JavaTag property, String defaultName, Component component) {
-        String name = property.getNamedParameter(SCRDescriptor.PROPERTY_NAME);
+        String name = property.getNamedParameter(Constants.PROPERTY_NAME);
         if (StringUtils.isEmpty(name) && defaultName!= null) {
             name = defaultName.trim();
             if (name.startsWith("\"")) name = name.substring(1);
@@ -553,8 +368,8 @@
         if (!StringUtils.isEmpty(name)) {
             org.apache.felix.sandbox.scrplugin.om.Property prop = new org.apache.felix.sandbox.scrplugin.om.Property(property);
             prop.setName(name);
-            prop.setType(property.getNamedParameter(SCRDescriptor.PROPERTY_TYPE));
-            final String value = property.getNamedParameter(SCRDescriptor.PROPERTY_VALUE);
+            prop.setType(property.getNamedParameter(Constants.PROPERTY_TYPE));
+            final String value = property.getNamedParameter(Constants.PROPERTY_VALUE);
             if ( value != null ) {
                 prop.setValue(value);
             } else {
@@ -573,7 +388,7 @@
                 }
             }
 
-            final boolean isPrivate = this.getBoolean(property, SCRDescriptor.PROPERTY_PRIVATE, false);
+            final boolean isPrivate = this.getBoolean(property, Constants.PROPERTY_PRIVATE, false);
             // if this is a public property and the component is generating metatype info
             // store the information!
             if ( !isPrivate && component.getOcd() != null ) {
@@ -583,18 +398,18 @@
                 ad.setId(prop.getName());
                 ad.setType(prop.getType());
 
-                String adName = property.getNamedParameter(SCRDescriptor.PROPERTY_LABEL);
+                String adName = property.getNamedParameter(Constants.PROPERTY_LABEL);
                 if ( adName == null ) {
                     adName = "%" + prop.getName() + ".name";
                 }
                 ad.setName(adName);
-                String adDesc = property.getNamedParameter(SCRDescriptor.PROPERTY_DESCRIPTION);
+                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(SCRDescriptor.PROPERTY_CARDINALITY);
+                final String cValue = property.getNamedParameter(Constants.PROPERTY_CARDINALITY);
                 if (cValue != null) {
                     if ("-".equals(cValue)) {
                         // unlimited vector
@@ -617,7 +432,7 @@
                 String[] parameters = property.getParameters();
                 Map options = null;
                 for (int j=0; j < parameters.length; j++) {
-                    if (SCRDescriptor.PROPERTY_OPTIONS.equals(parameters[j])) {
+                    if (Constants.PROPERTY_OPTIONS.equals(parameters[j])) {
                         options = new LinkedHashMap();
                     } else if (options != null) {
                         String optionLabel = parameters[j];
@@ -641,13 +456,13 @@
      * @param component
      */
     protected void doReference(JavaTag reference, String defaultName, Component component) {
-        String name = reference.getNamedParameter(SCRDescriptor.REFERENCE_NAME);
+        String name = reference.getNamedParameter(Constants.REFERENCE_NAME);
         if (StringUtils.isEmpty(name)) {
             name = defaultName;
         }
 
         // ensure interface
-        String type = reference.getNamedParameter(SCRDescriptor.REFERENCE_INTERFACE);
+        String type = reference.getNamedParameter(Constants.REFERENCE_INTERFACE);
         if (StringUtils.isEmpty(type)) {
             if ( reference.getField() != null ) {
                 type = reference.getField().getType();
@@ -658,56 +473,19 @@
             org.apache.felix.sandbox.scrplugin.om.Reference ref = new org.apache.felix.sandbox.scrplugin.om.Reference(reference);
             ref.setName(name);
             ref.setInterfacename(type);
-            ref.setCardinality(reference.getNamedParameter(SCRDescriptor.REFERENCE_CARDINALITY));
-            ref.setPolicy(reference.getNamedParameter(SCRDescriptor.REFERENCE_POLICY));
-            ref.setTarget(reference.getNamedParameter(SCRDescriptor.REFERENCE_TARGET));
+            ref.setCardinality(reference.getNamedParameter(Constants.REFERENCE_CARDINALITY));
+            ref.setPolicy(reference.getNamedParameter(Constants.REFERENCE_POLICY));
+            ref.setTarget(reference.getNamedParameter(Constants.REFERENCE_TARGET));
             String value;
-            value = reference.getNamedParameter(SCRDescriptor.REFERENCE_BIND);
+            value = reference.getNamedParameter(Constants.REFERENCE_BIND);
             if ( value != null ) {
                 ref.setBind(value);
             }
-            value = reference.getNamedParameter(SCRDescriptor.REFERENCE_UNDBIND);
+            value = reference.getNamedParameter(Constants.REFERENCE_UNDBIND);
             if ( value != null ) {
                 ref.setUnbind(value);
             }
             component.addReference(ref);
-        }
-    }
-
-    private void doReferences(JavaTag[] references, SCRDescriptor sd) {
-        if (references == null || references.length == 0) {
-            return;
-        }
-
-        for (int i=0; i < references.length; i++) {
-            this.doReference(references[i], null, sd);
-        }
-    }
-
-    private void doReference(JavaTag reference, String defaultName, SCRDescriptor sd) {
-        String name = reference.getNamedParameter(SCRDescriptor.REFERENCE_NAME);
-        if (StringUtils.isEmpty(name)) {
-            name = defaultName;
-        }
-
-        // ensure interface
-        String type = reference.getNamedParameter(SCRDescriptor.REFERENCE_INTERFACE);
-        if (StringUtils.isEmpty(type)) {
-            if ( reference.getField() != null ) {
-                type = reference.getField().getType();
-            }
-        }
-
-        if (!StringUtils.isEmpty(name)) {
-            Reference ref = new Reference(this.getLog(), reference);
-            ref.setName(name);
-            ref.setInterface(type);
-            ref.setCardinality(reference.getNamedParameter(SCRDescriptor.REFERENCE_CARDINALITY));
-            ref.setPolicy(reference.getNamedParameter(SCRDescriptor.REFERENCE_POLICY));
-            ref.setTarget(reference.getNamedParameter(SCRDescriptor.REFERENCE_TARGET));
-            ref.setBind(reference.getNamedParameter(SCRDescriptor.REFERENCE_BIND));
-            ref.setUnbind(reference.getNamedParameter(SCRDescriptor.REFERENCE_UNDBIND));
-            sd.addReference(ref);
         }
     }
 

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/JavaClassDescriptorManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/JavaClassDescriptorManager.java?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/JavaClassDescriptorManager.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/JavaClassDescriptorManager.java Tue Aug 14 06:45:36 2007
@@ -34,18 +34,12 @@
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
-import org.apache.felix.sandbox.scrplugin.Property;
-import org.apache.felix.sandbox.scrplugin.Reference;
-import org.apache.felix.sandbox.scrplugin.SCRDescriptor;
-import org.apache.felix.sandbox.scrplugin.Service;
+import org.apache.felix.sandbox.scrplugin.Constants;
+import org.apache.felix.sandbox.scrplugin.om.Component;
+import org.apache.felix.sandbox.scrplugin.om.Components;
 import org.apache.felix.sandbox.scrplugin.tags.cl.ClassLoaderJavaClassDescription;
 import org.apache.felix.sandbox.scrplugin.tags.qdox.QDoxJavaClassDescription;
-import org.apache.felix.sandbox.scrplugin.xml.Component;
 import org.apache.felix.sandbox.scrplugin.xml.ComponentDescriptorIO;
-import org.apache.felix.sandbox.scrplugin.xml.Components;
-import org.apache.felix.sandbox.scrplugin.xml.Implementation;
-import org.apache.felix.sandbox.scrplugin.xml.Interface;
-import org.apache.felix.sandbox.scrplugin.xml.XMLHandler;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -63,12 +57,6 @@
  */
 public class JavaClassDescriptorManager {
 
-    public static final String ABSTRACT_DESCRIPTOR_FILENAME = "scrinfo.xml";
-
-    public static final String ABSTRACT_DESCRIPTOR_RELATIVE_PATH = "OSGI-INF" + File.separator + "scr-plugin" + File.separator + ABSTRACT_DESCRIPTOR_FILENAME;
-
-    public static final String ABSTRACT_DESCRIPTOR_ARCHIV_PATH = "OSGI-INF/scr-plugin/" + ABSTRACT_DESCRIPTOR_FILENAME;
-
     protected static final String SERVICE_COMPONENT = "Service-Component";
 
     /** The sources read by qdox. */
@@ -80,9 +68,6 @@
     /** The classloader used to compile the classes. */
     protected final ClassLoader classloader;
 
-    /** The xml handler to read and write the service descriptors. */
-    protected final XMLHandler xmlHandler = new XMLHandler();
-
     /** A cache containing the java class descriptions hashed by classname. */
     protected final Map javaClassDescriptions = new HashMap();
 
@@ -153,7 +138,7 @@
                     }
                     this.log.debug("Trying to get scrinfo from artifact " + artifact);
                     try {
-                        final File scrInfoFile = this.getFile(artifact, ABSTRACT_DESCRIPTOR_ARCHIV_PATH);
+                        final File scrInfoFile = this.getFile(artifact, Constants.ABSTRACT_DESCRIPTOR_ARCHIV_PATH);
                         if ( scrInfoFile != null ) {
                             components.addAll(this.parseServiceComponentDescriptor(artifact, scrInfoFile).getComponents());
                         } else {
@@ -192,125 +177,6 @@
     }
 
     /**
-     * Create the abstract descriptors file or delete it of no abstract descriptors are available.
-     * @param abstractDescriptors
-     */
-    public void writeAbstractDescriptorsFile(List abstractDescriptors, File outputDirectory)
-    throws MojoExecutionException {
-        try {
-            // if we have abstract descriptors, write them first
-            final File adFile = new File(outputDirectory, ABSTRACT_DESCRIPTOR_RELATIVE_PATH);
-            if ( !abstractDescriptors.isEmpty() ) {
-                this.getLog().info("Writing abstract service descriptor " + adFile + " with " + abstractDescriptors.size() + " entries.");
-                final Components container = new Components();
-                final Iterator i = abstractDescriptors.iterator();
-                while ( i.hasNext() ) {
-                    final SCRDescriptor current = (SCRDescriptor) i.next();
-                    // component
-                    final Component component = new Component();
-                    // enabled and immediate do not make sense for abstract components
-                    //component.setEnabled(Boolean.valueOf(current.isEnabled()));
-                    //component.setImmediate(Boolean.valueOf(current.isImmediate()));
-                    component.setName(current.getName());
-                    // do we support abstract factories or should we throw an exception? (TODO)
-                    component.setFactory(current.getFactory());
-
-                    // implementation
-                    final Implementation impl = new Implementation();
-                    impl.setClassname(current.getImplClass());
-                    component.setImplementation(impl);
-
-                    // properties
-                    final Iterator pI = current.getProperties();
-                    while ( pI.hasNext() ) {
-                        final Property p = (Property)pI.next();
-                        final org.apache.felix.sandbox.scrplugin.xml.Property prop = new org.apache.felix.sandbox.scrplugin.xml.Property();
-                        prop.setName(p.getName());
-                        if ( !"String".equals(p.getType())) {
-                            prop.setType(p.getType());
-                        }
-                        if (p.getValue() instanceof List) {
-                            final StringBuffer buffer = new StringBuffer();
-                            List values = (List) p.getValue();
-                            for (Iterator vi = values.iterator(); vi.hasNext();) {
-                                buffer.append(vi.next()).append('\n');
-                            }
-                        } else if (p.getValue() != null) {
-                            prop.setValue(p.getValue().toString());
-                        }
-                        component.getProperties().add(prop);
-                    }
-
-                    // services
-                    final Iterator sI = current.getServices();
-                    if (sI.hasNext()) {
-                        final org.apache.felix.sandbox.scrplugin.xml.Service srvc = new org.apache.felix.sandbox.scrplugin.xml.Service();
-                        component.setService(srvc);
-                        if ( current.isServiceFactory() ) {
-                            srvc.setServicefactory("true");
-                        }
-                        while (sI.hasNext()) {
-                            final Service s = (Service)sI.next();
-                            final Interface interf = new Interface();
-                            interf.setInterfacename(s.getInterfaceName());
-                            srvc.getInterfaces().add(interf);
-                        }
-                    }
-
-                    // references
-                    final Iterator rI = current.getReferences();
-                    while ( rI.hasNext() ) {
-                        final Reference r = (Reference)rI.next();
-                        final org.apache.felix.sandbox.scrplugin.xml.Reference ref = new org.apache.felix.sandbox.scrplugin.xml.Reference();
-                        ref.setName(r.getName());
-                        ref.setInterfacename(r.getInterfaceName());
-                        ref.setTarget(r.getTarget());
-                        ref.setCardinality(r.getCardinality());
-                        ref.setPolicy(r.getPolicy());
-                        ref.setBind(r.getBind());
-                        ref.setUnbind(r.getUnbind());
-
-                        component.getReferences().add(ref);
-                    }
-
-                    container.getComponents().add(component);
-                }
-                adFile.getParentFile().mkdirs();
-                this.xmlHandler.write(adFile, container);
-            } else {
-                // remove file
-                if ( adFile.exists() ) {
-                    this.getLog().debug("Removing obsolete abstract service descriptor " + adFile);
-                    adFile.delete();
-                }
-            }
-        } catch (IOException ioe) {
-            throw new MojoExecutionException("Failed to write scr-plugin scrinfo.xml", ioe);
-        }
-    }
-
-    /**
-     * Create the abstract descriptors file or delete it of no abstract descriptors are available.
-     * @param abstractDescriptors
-     */
-    public void writeAbstractDescriptorFile(org.apache.felix.sandbox.scrplugin.om.Components components, File outputDirectory)
-    throws MojoExecutionException {
-        // if we have abstract descriptors, write them
-        final File adFile = new File(outputDirectory, ABSTRACT_DESCRIPTOR_RELATIVE_PATH);
-        if ( !components.getComponents().isEmpty() ) {
-            this.getLog().info("Writing abstract service descriptor " + adFile + " with " + components.getComponents().size() + " entries.");
-            adFile.getParentFile().mkdirs();
-            ComponentDescriptorIO.write(components, adFile);
-        } else {
-            // remove file
-            if ( adFile.exists() ) {
-                this.getLog().debug("Removing obsolete abstract service descriptor " + adFile);
-                adFile.delete();
-            }
-        }
-    }
-
-    /**
      * Read the service component description.
      * @param artifact
      * @param entry
@@ -330,7 +196,7 @@
     protected Components parseServiceComponentDescriptor(Artifact artifact, File file)
     throws IOException, MojoExecutionException {
         this.log.debug("Parsing " + file);
-        final Components list = this.xmlHandler.read(file);
+        final Components list = ComponentDescriptorIO.read(file);
         return list;
     }
 

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java Tue Aug 14 06:45:36 2007
@@ -24,14 +24,14 @@
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.felix.sandbox.scrplugin.SCRDescriptor;
+import org.apache.felix.sandbox.scrplugin.Constants;
+import org.apache.felix.sandbox.scrplugin.om.Component;
+import org.apache.felix.sandbox.scrplugin.om.Reference;
 import org.apache.felix.sandbox.scrplugin.tags.JavaClassDescription;
 import org.apache.felix.sandbox.scrplugin.tags.JavaClassDescriptorManager;
 import org.apache.felix.sandbox.scrplugin.tags.JavaField;
 import org.apache.felix.sandbox.scrplugin.tags.JavaMethod;
 import org.apache.felix.sandbox.scrplugin.tags.JavaTag;
-import org.apache.felix.sandbox.scrplugin.xml.Component;
-import org.apache.felix.sandbox.scrplugin.xml.Reference;
 import org.apache.maven.plugin.MojoExecutionException;
 
 /**
@@ -128,11 +128,11 @@
     throws MojoExecutionException {
         JavaTag[] javaTags = EMPTY_TAGS;
         if ( this.component != null ) {
-            if ( SCRDescriptor.SERVICE.equals(name) ) {
+            if ( Constants.SERVICE.equals(name) ) {
 
-            } else if ( SCRDescriptor.PROPERTY.equals(name) ) {
+            } else if ( Constants.PROPERTY.equals(name) ) {
 
-            } else if ( SCRDescriptor.REFERENCE.equals(name) ) {
+            } else if ( Constants.REFERENCE.equals(name) ) {
                 if ( this.component.getReferences().size() > 0 ) {
                     javaTags = new JavaTag[this.component.getReferences().size()];
                     for(int i=0; i<this.component.getReferences().size(); i++) {

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaTag.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaTag.java?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaTag.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/tags/cl/ClassLoaderJavaTag.java Tue Aug 14 06:45:36 2007
@@ -21,11 +21,11 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.felix.sandbox.scrplugin.SCRDescriptor;
+import org.apache.felix.sandbox.scrplugin.Constants;
+import org.apache.felix.sandbox.scrplugin.om.Reference;
 import org.apache.felix.sandbox.scrplugin.tags.JavaClassDescription;
 import org.apache.felix.sandbox.scrplugin.tags.JavaField;
 import org.apache.felix.sandbox.scrplugin.tags.JavaTag;
-import org.apache.felix.sandbox.scrplugin.xml.Reference;
 
 /**
  * <code>ClassLoaderJavaTag.java</code>...
@@ -58,7 +58,7 @@
      */
     public String getName() {
         if ( this.reference != null ) {
-            return SCRDescriptor.REFERENCE;
+            return Constants.REFERENCE;
         }
         return null;
     }
@@ -80,13 +80,13 @@
     public Map getNamedParameterMap() {
         if ( this.reference != null ) {
             final Map map = new HashMap();
-            map.put(SCRDescriptor.REFERENCE_BIND, this.reference.getBind());
-            map.put(SCRDescriptor.REFERENCE_CARDINALITY, this.reference.getCardinality());
-            map.put(SCRDescriptor.REFERENCE_INTERFACE, this.reference.getInterfacename());
-            map.put(SCRDescriptor.REFERENCE_NAME, this.reference.getName());
-            map.put(SCRDescriptor.REFERENCE_POLICY, this.reference.getPolicy());
-            map.put(SCRDescriptor.REFERENCE_TARGET, this.reference.getTarget());
-            map.put(SCRDescriptor.REFERENCE_UNDBIND, this.reference.getUnbind());
+            map.put(Constants.REFERENCE_BIND, this.reference.getBind());
+            map.put(Constants.REFERENCE_CARDINALITY, this.reference.getCardinality());
+            map.put(Constants.REFERENCE_INTERFACE, this.reference.getInterfacename());
+            map.put(Constants.REFERENCE_NAME, this.reference.getName());
+            map.put(Constants.REFERENCE_POLICY, this.reference.getPolicy());
+            map.put(Constants.REFERENCE_TARGET, this.reference.getTarget());
+            map.put(Constants.REFERENCE_UNDBIND, this.reference.getUnbind());
             return map;
         }
         return null;

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java Tue Aug 14 06:45:36 2007
@@ -38,7 +38,10 @@
 import org.apache.felix.sandbox.scrplugin.om.Component;
 import org.apache.felix.sandbox.scrplugin.om.Components;
 import org.apache.felix.sandbox.scrplugin.om.Implementation;
+import org.apache.felix.sandbox.scrplugin.om.Interface;
 import org.apache.felix.sandbox.scrplugin.om.Property;
+import org.apache.felix.sandbox.scrplugin.om.Reference;
+import org.apache.felix.sandbox.scrplugin.om.Service;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
@@ -86,7 +89,7 @@
 
     private static final SAXTransformerFactory FACTORY = (SAXTransformerFactory) TransformerFactory.newInstance();
 
-    public static org.apache.felix.sandbox.scrplugin.om.Components read(File file)
+    public static Components read(File file)
     throws MojoExecutionException {
         try {
             final Transformer transformer = FACTORY.newTransformer();
@@ -107,7 +110,7 @@
      * @param file
      * @throws MojoExecutionException
      */
-    public static void write(org.apache.felix.sandbox.scrplugin.om.Components components, File file)
+    public static void write(Components components, File file)
     throws MojoExecutionException {
         try {
             FileWriter writer = new FileWriter(file);
@@ -211,7 +214,7 @@
      * @param contentHandler
      * @throws SAXException
      */
-    protected static void generateXML(org.apache.felix.sandbox.scrplugin.om.Service service, ContentHandler contentHandler)
+    protected static void generateXML(Service service, ContentHandler contentHandler)
     throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         addAttribute(ai, "servicefactory", service.getServicefactory());
@@ -235,7 +238,7 @@
     protected static void generateXML(Interface interf, ContentHandler contentHandler)
     throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
-        addAttribute(ai, "interface", interf.getInterfaceame());
+        addAttribute(ai, "interface", interf.getInterfacename());
         contentHandler.startElement(NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME, ai);
         contentHandler.endElement(NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME);
     }
@@ -324,7 +327,7 @@
         protected Component currentComponent;
 
         /** The current service. */
-        protected org.apache.felix.sandbox.scrplugin.om.Service currentService;
+        protected Service currentService;
 
         /** Pending property. */
         protected Property pendingProperty;
@@ -396,19 +399,19 @@
 
                 } else if (localName.equals(SERVICE)) {
 
-                    this.currentService = new org.apache.felix.sandbox.scrplugin.om.Service();
+                    this.currentService = new Service();
 
                     this.currentService.setServicefactory(attributes.getValue("servicefactory"));
 
                     this.currentComponent.setService(this.currentService);
 
                 } else if (localName.equals(INTERFACE)) {
-                    final org.apache.felix.sandbox.scrplugin.om.Interface interf = new org.apache.felix.sandbox.scrplugin.om.Interface();
+                    final Interface interf = new Interface();
                     this.currentService.addInterface(interf);
                     interf.setInterfacename(attributes.getValue("interface"));
 
                 } else if (localName.equals(REFERENCE)) {
-                    org.apache.felix.sandbox.scrplugin.om.Reference ref = new org.apache.felix.sandbox.scrplugin.om.Reference();
+                    final Reference ref = new Reference();
 
                     ref.setName(attributes.getValue("name"));
                     ref.setInterfacename(attributes.getValue("interface"));

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java?view=diff&rev=565751&r1=565750&r2=565751
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java (original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java Tue Aug 14 06:45:36 2007
@@ -19,25 +19,30 @@
 package org.apache.felix.sandbox.scrplugin.xml;
 
 import java.io.File;
-import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.felix.sandbox.scrplugin.om.metatype.Definitions;
+import org.apache.felix.sandbox.scrplugin.om.Component;
+import org.apache.felix.sandbox.scrplugin.om.Components;
+import org.apache.felix.sandbox.scrplugin.om.metatype.AttributeDefinition;
+import org.apache.felix.sandbox.scrplugin.om.metatype.Designate;
+import org.apache.felix.sandbox.scrplugin.om.metatype.MTObject;
+import org.apache.felix.sandbox.scrplugin.om.metatype.OCD;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
 
-import com.thoughtworks.xstream.XStream;
 
 /**
  * <code>MetaType</code>
@@ -47,68 +52,163 @@
  */
 public class MetaTypeIO {
 
-    protected final XStream xstream;
+    private static final SAXTransformerFactory FACTORY = (SAXTransformerFactory) TransformerFactory.newInstance();
 
-    public MetaTypeIO() {
-        this.xstream = new XStream();
-        this.xstream.setMode(XStream.NO_REFERENCES);
-
-        this.xstream.alias("OCD", org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class);
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "id");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "name");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "description");
-
-        this.xstream.alias("AD", org.apache.felix.sandbox.scrplugin.om.metatype.AttributeDefinition.class);
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.AttributeDefinition.class, "id");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.AttributeDefinition.class, "type");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "name");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "description");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "cardinality");
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.OCD.class, "defaultValue");
-
-        this.xstream.alias("Designate", org.apache.felix.sandbox.scrplugin.om.metatype.Designate.class);
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.Designate.class, "pid");
-
-        this.xstream.alias("Object", org.apache.felix.sandbox.scrplugin.om.metatype.MTObject.class);
-        this.xstream.useAttributeFor(org.apache.felix.sandbox.scrplugin.om.metatype.MTObject.class, "ocdref");
-    }
-
-    public Definitions read(File file) throws IOException, MojoExecutionException {
-        Writer buffer = new StringWriter();
-        final TransformerFactory factory = TransformerFactory.newInstance();
-        Transformer transformer;
+    public static final String NAMESPACE_URI = "http://www.osgi.org/xmlns/metatype/v1.0.0";
+
+    public static final String PREFIX = "metatype";
+
+    protected static final String METADATA_ELEMENT = "MetaData";
+    protected static final String METADATA_ELEMENT_QNAME = PREFIX + ':' + METADATA_ELEMENT;
+
+    protected static final String OCD_ELEMENT = "OCD";
+    protected static final String OCD_ELEMENT_QNAME = PREFIX + ':' + OCD_ELEMENT;
+
+    protected static final String DESIGNATE_ELEMENT = "Designate";
+    protected static final String DESIGNATE_ELEMENT_QNAME = PREFIX + ':' + DESIGNATE_ELEMENT;
+
+    protected static final String OBJECT_ELEMENT = "Object";
+    protected static final String OBJECT_ELEMENT_QNAME = PREFIX + ':' + OBJECT_ELEMENT;
+
+    protected static final String AD_ELEMENT = "AD";
+    protected static final String AD_ELEMENT_QNAME = PREFIX + ':' + AD_ELEMENT;
+
+    public static void write(Components components, File file)
+    throws MojoExecutionException {
         try {
-            IOUtils.copy(new FileReader(file), buffer);
-            String xmlDoc = buffer.toString();
-            buffer = new StringWriter();
-            int pos = xmlDoc.indexOf("?>");
-            if ( pos > 0 ) {
-                xmlDoc = xmlDoc.substring(pos+2);
-            }
-            xmlDoc = "<components>" + xmlDoc + "</components>";
-            transformer = factory.newTransformer(new StreamSource(this.getClass().getResourceAsStream("/org/apache/felix/sandbox/scrplugin/xml/read.xsl")));
-            transformer.setOutputProperty(OutputKeys.INDENT, "no");
-            transformer.transform(new StreamSource(new StringReader(xmlDoc)), new StreamResult(buffer));
-            return (Definitions)this.xstream.fromXML(new StringReader(buffer.toString()));
+            FileWriter writer = new FileWriter(file);
+            final TransformerHandler transformerHandler = FACTORY.newTransformerHandler();
+            final Transformer transformer = transformerHandler.getTransformer();
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformerHandler.setResult(new StreamResult(writer));
+
+            generateXML(components, transformerHandler);
         } catch (TransformerException e) {
-            throw new MojoExecutionException("Unable to read xml.", e);
+            throw new MojoExecutionException("Unable to write xml to " + file, e);
+        } catch (SAXException e) {
+            throw new MojoExecutionException("Unable to generate xml for " + file, e);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Unable to write xml to " + file, e);
         }
     }
 
-    public void write(File file, Definitions defs)
-    throws IOException, MojoExecutionException {
-        Writer buffer = new StringWriter();
-        this.xstream.toXML(defs, buffer);
+    /**
+     * Generate the xml top level element and start streaming
+     * the components.
+     * @param components
+     * @param contentHandler
+     * @throws SAXException
+     */
+    protected static void generateXML(Components components, ContentHandler contentHandler)
+    throws SAXException {
+        contentHandler.startDocument();
+        contentHandler.startPrefixMapping(PREFIX, NAMESPACE_URI);
+
+        final AttributesImpl ai = new AttributesImpl();
+        addAttribute(ai, "localization", "metatype");
+
+        contentHandler.startElement(NAMESPACE_URI, METADATA_ELEMENT, METADATA_ELEMENT_QNAME, ai);
+
+        final Iterator i = components.getComponents().iterator();
+        while ( i.hasNext() ) {
+            final Component component = (Component)i.next();
+            if ( component.getOcd() != null ) {
+                generateXML(component.getOcd(), contentHandler);
+                generateXML(component.getDesignate(), contentHandler);
+            }
+        }
+        // end wrapper element
+        contentHandler.endElement(NAMESPACE_URI, METADATA_ELEMENT, METADATA_ELEMENT_QNAME);
+        contentHandler.endPrefixMapping(PREFIX);
+        contentHandler.endDocument();
+    }
 
-        final TransformerFactory factory = TransformerFactory.newInstance();
-        Transformer transformer;
-        try {
-            transformer = factory.newTransformer(new StreamSource(this.getClass().getResourceAsStream("/org/apache/felix/sandbox/scrplugin/xml/write.xsl")));
-            transformer.setOutputProperty(OutputKeys.INDENT, "no");
+    protected static void generateXML(OCD ocd, ContentHandler contentHandler)
+    throws SAXException {
+        final AttributesImpl ai = new AttributesImpl();
+        addAttribute(ai, "id", ocd.getId());
+        addAttribute(ai, "name", ocd.getName());
+        addAttribute(ai, "description", ocd.getDescription());
+        contentHandler.startElement(NAMESPACE_URI, OCD_ELEMENT, OCD_ELEMENT_QNAME, ai);
+
+        final Iterator i = ocd.getProperties().iterator();
+        while ( i.hasNext() ) {
+            final AttributeDefinition ad = (AttributeDefinition) i.next();
+            generateXML(ad, contentHandler);
+        }
 
-            transformer.transform(new StreamSource(new StringReader(buffer.toString())), new StreamResult(new FileWriter(file)));
-        } catch (TransformerException e) {
-            throw new MojoExecutionException("Unable to write xml.", e);
+        contentHandler.endElement(NAMESPACE_URI, OCD_ELEMENT, OCD_ELEMENT_QNAME);
+    }
+
+    protected static void generateXML(AttributeDefinition ad, ContentHandler contentHandler)
+    throws SAXException {
+        final AttributesImpl ai = new AttributesImpl();
+        addAttribute(ai, "id", ad.getId());
+        addAttribute(ai, "type", ad.getType());
+        if ( ad.getDefaultMultiValue() != null ) {
+            final StringBuffer buf = new StringBuffer();
+            for(int i=0; i<ad.getDefaultMultiValue().length; i++) {
+                if ( i > 0 ) {
+                    buf.append(',');
+                }
+                buf.append(ad.getDefaultMultiValue()[i]);
+            }
+            addAttribute(ai, "default", buf);
+        } else {
+            addAttribute(ai, "default", ad.getDefaultValue());
+        }
+        addAttribute(ai, "name", ad.getName());
+        addAttribute(ai, "description", ad.getDescription());
+        addAttribute(ai, "cardinality", ad.getCardinality());
+        contentHandler.startElement(NAMESPACE_URI, AD_ELEMENT, AD_ELEMENT_QNAME, ai);
+
+        if (ad.getOptions() != null) {
+            for (Iterator oi=ad.getOptions().entrySet().iterator(); oi.hasNext(); ) {
+                final Map.Entry entry = (Map.Entry) oi.next();
+                ai.clear();
+                addAttribute(ai, "value", String.valueOf(entry.getKey()));
+                addAttribute(ai, "label", String.valueOf(entry.getValue()));
+                contentHandler.startElement(NAMESPACE_URI, "Option", PREFIX + ':' + "Option", ai);
+            }
         }
+
+        contentHandler.endElement(NAMESPACE_URI, AD_ELEMENT, AD_ELEMENT_QNAME);
     }
+
+    protected static void generateXML(Designate designate, ContentHandler contentHandler)
+    throws SAXException {
+        final AttributesImpl ai = new AttributesImpl();
+        addAttribute(ai, "pid", designate.getPid());
+        contentHandler.startElement(NAMESPACE_URI, DESIGNATE_ELEMENT, DESIGNATE_ELEMENT_QNAME, ai);
+
+        generateXML(designate.getObject(), contentHandler);
+
+        contentHandler.endElement(NAMESPACE_URI, DESIGNATE_ELEMENT, DESIGNATE_ELEMENT_QNAME);
+    }
+
+    protected static void generateXML(MTObject obj, ContentHandler contentHandler)
+    throws SAXException {
+        final AttributesImpl ai = new AttributesImpl();
+        addAttribute(ai, "ocdref", obj.getOcdref());
+        contentHandler.startElement(NAMESPACE_URI, OBJECT_ELEMENT, OBJECT_ELEMENT_QNAME, ai);
+        contentHandler.endElement(NAMESPACE_URI, OBJECT_ELEMENT, OBJECT_ELEMENT_QNAME);
+    }
+
+    /**
+     * Helper method to add an attribute.
+     * This implementation adds a new attribute with the given name
+     * and value. Before adding the value is checked for non-null.
+     * @param ai    The attributes impl receiving the additional attribute.
+     * @param name  The name of the attribute.
+     * @param value The value of the attribute.
+     */
+    protected static void addAttribute(AttributesImpl ai, String name, Object value) {
+        if ( value != null ) {
+            ai.addAttribute("", name, name, "CDATA", value.toString());
+        }
+    }
+
 }



Mime
View raw message