felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r565639 - in /felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin: ./ om/ om/metatype/ xml/
Date Tue, 14 Aug 2007 06:32:12 GMT
Author: cziegeler
Date: Mon Aug 13 23:32:11 2007
New Revision: 565639

URL: http://svn.apache.org/viewvc?view=rev&rev=565639
Log:
Update metatype om implementation and fix some bugs in xml generation.

Added:
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AttributeDefinition.java
      - copied, changed from r565378, felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AD.java
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
  (with props)
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java
  (with props)
Removed:
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AD.java
Modified:
    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/om/Property.java

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=565639&r1=565638&r2=565639
==============================================================================
--- 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
Mon Aug 13 23:32:11 2007
@@ -31,7 +31,7 @@
 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.metatype.AD;
+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;
@@ -562,7 +562,7 @@
             // store the information!
             if ( !isPrivate && component.getOcd() != null ) {
                 final OCD ocd = component.getOcd();
-                final AD ad = new AD();
+                final AttributeDefinition ad = new AttributeDefinition();
                 ocd.getProperties().add(ad);
                 ad.setId(prop.getName());
                 ad.setType(prop.getType());
@@ -595,6 +595,7 @@
                     }
                 }
                 ad.setDefaultValue(prop.getValue());
+                ad.setText(prop.getText());
 
                 // check options
                 String[] parameters = property.getParameters();

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/Property.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/Property.java?view=diff&rev=565639&r1=565638&r2=565639
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/Property.java
(original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/Property.java
Mon Aug 13 23:32:11 2007
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.sandbox.scrplugin.om;
 
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -32,7 +31,7 @@
 public class Property extends AbstractObject {
 
     protected String name;
-    protected Object value;
+    protected String value;
     protected String type;
     protected String text;
 
@@ -58,12 +57,13 @@
         this.name = name;
     }
 
-    public Object getValue() {
+    public String getValue() {
         return this.value;
     }
 
     public void setValue(String value) {
         this.value = value;
+        this.text = null;
     }
 
     public String getType() {
@@ -80,20 +80,18 @@
 
     public void setText(String text) {
         this.text = text;
+        this.value = null;
     }
 
     public void setValues(Map valueMap) {
-        List values = new ArrayList();
+        this.value = null;
+        this.text = "";
         for (Iterator vi = valueMap.entrySet().iterator(); vi.hasNext();) {
             Map.Entry entry = (Map.Entry) vi.next();
             String key = (String) entry.getKey();
             if (key.startsWith("values")) {
-                values.add(entry.getValue());
+                this.text = this.text + entry.getValue() + "\n";
             }
-        }
-
-        if (!values.isEmpty()) {
-            this.value = values;
         }
     }
 

Copied: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AttributeDefinition.java
(from r565378, felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AD.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AttributeDefinition.java?view=diff&rev=565639&p1=felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AD.java&r1=565378&p2=felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AttributeDefinition.java&r2=565639
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AD.java
(original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/AttributeDefinition.java
Mon Aug 13 23:32:11 2007
@@ -18,19 +18,20 @@
  */
 package org.apache.felix.sandbox.scrplugin.om.metatype;
 
-import java.util.List;
 import java.util.Map;
 
-public class AD {
+public class AttributeDefinition {
 
     protected String id;
 
     protected String type;
 
-    protected Object defaultValue;
+    protected String defaultValue;
 
     protected String name;
 
+    protected String text;
+
     protected String description;
 
     protected Integer cardinality;
@@ -57,14 +58,21 @@
         return this.defaultValue;
     }
 
-    public void setDefaultValue(Object defaultValue) {
+    public void setDefaultValue(String defaultValue) {
         this.defaultValue = defaultValue;
-        if ( defaultValue instanceof List ) {
-            // assume array if set to scalar currently
-            if ( ((List)defaultValue).size() > 0 && this.cardinality == null )
{
-                this.cardinality = new Integer(Integer.MAX_VALUE);
-            }
+        this.text = null;
+    }
+
+    public void setText(String v) {
+        this.defaultValue = null;
+        this.text = v;
+        if (v != null && v.length() > 0 && this.cardinality == null )
{
+            this.cardinality = new Integer(Integer.MAX_VALUE);
         }
+    }
+
+    public String getText() {
+        return this.text;
     }
 
     public String getName() {

Added: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java?view=auto&rev=565639
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
(added)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
Mon Aug 13 23:32:11 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.sandbox.scrplugin.om.metatype;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>Definitions</code>...
+ *
+ * Definitions is just a collection of {@link OCD}s and
+ * {@link Designate}s.
+ */
+public class Definitions {
+
+    /** The list of {@link OCD}s. */
+    protected List ocds = new ArrayList();
+
+    /**
+     * Return the list of {@link OCD}s.
+     */
+    public List getOCDs() {
+        return this.ocds;
+    }
+
+    /**
+     * Set the list of {@link OCDs}s.
+     */
+    public void setOCDs(List c) {
+        this.ocds = c;
+    }
+}

Propchange: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/om/metatype/Definitions.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: 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=auto&rev=565639
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java
(added)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java
Mon Aug 13 23:32:11 2007
@@ -0,0 +1,114 @@
+/*
+ * 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.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 javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+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.maven.plugin.MojoExecutionException;
+
+import com.thoughtworks.xstream.XStream;
+
+/**
+ * <code>MetaType</code>
+ *
+ * is a helper class to read and write meta type service files.
+ *
+ */
+public class MetaTypeIO {
+
+    protected final XStream xstream;
+
+    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;
+        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()));
+        } catch (TransformerException e) {
+            throw new MojoExecutionException("Unable to read xml.", e);
+        }
+    }
+
+    public void write(File file, Definitions defs)
+    throws IOException, MojoExecutionException {
+        Writer buffer = new StringWriter();
+        this.xstream.toXML(defs, buffer);
+
+        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");
+
+            transformer.transform(new StreamSource(new StringReader(buffer.toString())),
new StreamResult(new FileWriter(file)));
+        } catch (TransformerException e) {
+            throw new MojoExecutionException("Unable to write xml.", e);
+        }
+    }
+}

Propchange: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/MetaTypeIO.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message