[jboss-cvs] JBossAS SVN: r62281 - in projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi: spi/metadata and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 11 13:27:45 EDT 2007


Author: alesj
Date: 2007-04-11 13:27:45 -0400 (Wed, 11 Apr 2007)
New Revision: 62281

Added:
   projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/CollectionValueCreator.java
Modified:
   projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java
   projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java
Log:
Handling collection of parameters in OSGi headers.

Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/CollectionValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/CollectionValueCreator.java	                        (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/CollectionValueCreator.java	2007-04-11 17:27:45 UTC (rev 62281)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import java.util.Collection;
+
+/**
+ * Create value from collection of attributes.
+ *
+ * @param <T> expected type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface CollectionValueCreator<T>
+{
+   /**
+    * Create value from string attribute.
+    *
+    * @param attributes collection of strings to get value from
+    * @return value
+    */
+   T createValue(Collection<String> attributes);
+}

Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java	2007-04-11 17:11:42 UTC (rev 62280)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java	2007-04-11 17:27:45 UTC (rev 62281)
@@ -21,9 +21,12 @@
 */
 package org.jboss.osgi.plugins.metadata;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.jboss.logging.Logger;
 import org.jboss.osgi.spi.metadata.Parameter;
 import org.jboss.osgi.spi.metadata.VersionRange;
 import static org.osgi.framework.Constants.*;
@@ -36,15 +39,22 @@
  */
 public class OSGiParameters
 {
+   protected static Logger log = Logger.getLogger(OSGiParameters.class);
+
    protected Map<String, Parameter> parameters;
    protected Map<String, Object> cachedAttributes;
 
    public OSGiParameters(Map<String, Parameter> parameters)
    {
-      this.parameters = parameters;
+      this.parameters = Collections.unmodifiableMap(parameters);
       this.cachedAttributes = new HashMap<String, Object>();
    }
 
+   protected Map<String, Parameter> getParameters()
+   {
+      return parameters;
+   }
+
    public VersionRange getVersion()
    {
       return get(VERSION_ATTRIBUTE, ValueCreatorUtil.VERSION_RANGE_VC);
@@ -88,7 +98,15 @@
             Object paramValue = parameter.getValue();
             if(parameter.isCollection())
             {
-               // todo
+               if (creator instanceof CollectionValueCreator)
+               {
+                  CollectionValueCreator<T> cvc = (CollectionValueCreator<T>)creator;
+                  value = cvc.createValue((Collection<String>)paramValue);
+               }
+               else
+               {
+                  log.warn("Unable to create proper value from " + creator + " for parameter: " + parameter);
+               }
             }
             else
             {

Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java	2007-04-11 17:11:42 UTC (rev 62280)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java	2007-04-11 17:27:45 UTC (rev 62281)
@@ -46,7 +46,7 @@
    /**
     * Has multiple values.
     * Used when same name is used for multiple parameter values.
-    * Value _can_ be casted into Collection.
+    * Value _can_ be casted into Collection<String>.
     *
     * @return true is returned type is Collection, otherwise false
     */




More information about the jboss-cvs-commits mailing list