geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r766183 - in /geronimo/sandbox/blueprint: org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/ org.apache.felix.blueprint/src/test/resources/ sampl...
Date Sat, 18 Apr 2009 00:07:19 GMT
Author: gawor
Date: Sat Apr 18 00:07:19 2009
New Revision: 766183

URL: http://svn.apache.org/viewvc?rev=766183&view=rev
Log:
with conversion delay we now know the expected type to convert to without explicitly specifying
it

Added:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
  (with props)
Modified:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml
    geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java?rev=766183&r1=766182&r2=766183&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
Sat Apr 18 00:07:19 2009
@@ -18,42 +18,40 @@
  */
 package org.apache.felix.blueprint.context;
 
-import java.lang.reflect.Type;
-import java.util.Set;
-import java.util.Collection;
 import java.util.ArrayList;
-import java.util.List;
-import java.util.HashSet;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
-import org.apache.xbean.recipe.AbstractRecipe;
 import org.apache.xbean.recipe.ArrayRecipe;
-import org.apache.xbean.recipe.Option;
-import org.apache.xbean.recipe.Repository;
-import org.apache.xbean.recipe.DefaultRepository;
-import org.apache.xbean.recipe.ObjectRecipe;
 import org.apache.xbean.recipe.CollectionRecipe;
-import org.apache.xbean.recipe.MapRecipe;
 import org.apache.xbean.recipe.ConstructionException;
-import org.apache.xbean.recipe.ReferenceRecipe;
+import org.apache.xbean.recipe.DefaultRepository;
+import org.apache.xbean.recipe.MapRecipe;
+import org.apache.xbean.recipe.ObjectRecipe;
+import org.apache.xbean.recipe.Option;
 import org.apache.xbean.recipe.Recipe;
-import org.osgi.framework.Bundle;
+import org.apache.xbean.recipe.ReferenceRecipe;
+import org.apache.xbean.recipe.Repository;
+import org.osgi.service.blueprint.convert.ConversionService;
+import org.osgi.service.blueprint.reflect.ArrayValue;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.ComponentValue;
+import org.osgi.service.blueprint.reflect.ListValue;
 import org.osgi.service.blueprint.reflect.LocalComponentMetadata;
-import org.osgi.service.blueprint.reflect.PropertyInjectionMetadata;
-import org.osgi.service.blueprint.reflect.Value;
+import org.osgi.service.blueprint.reflect.MapValue;
 import org.osgi.service.blueprint.reflect.NullValue;
-import org.osgi.service.blueprint.reflect.TypedStringValue;
+import org.osgi.service.blueprint.reflect.PropertiesValue;
+import org.osgi.service.blueprint.reflect.PropertyInjectionMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceNameValue;
 import org.osgi.service.blueprint.reflect.ReferenceValue;
-import org.osgi.service.blueprint.reflect.ListValue;
 import org.osgi.service.blueprint.reflect.SetValue;
-import org.osgi.service.blueprint.reflect.MapValue;
-import org.osgi.service.blueprint.reflect.ComponentValue;
-import org.osgi.service.blueprint.reflect.ArrayValue;
-import org.osgi.service.blueprint.reflect.ReferenceNameValue;
-import org.osgi.service.blueprint.reflect.PropertiesValue;
+import org.osgi.service.blueprint.reflect.TypedStringValue;
+import org.osgi.service.blueprint.reflect.Value;
 
 /**
  * TODO: javadoc
@@ -124,7 +122,6 @@
             recipe.allow(Option.PRIVATE_PROPERTIES);
             recipe.setName(component.getName());
             for (PropertyInjectionMetadata property : (Collection<PropertyInjectionMetadata>)
local.getPropertyInjectionMetadata()) {
-                // TODO: must pass the expected property type
                 Object value = getValue(property.getValue(), null);
                 recipe.setProperty(property.getName(), value);
             }
@@ -142,14 +139,14 @@
         }
     }
 
-    private Object getValue(Value v, Class hint) throws Exception {
+    private Object getValue(Value v, Class groupingType) throws Exception {
         if (v instanceof NullValue) {
             return null;
         } else if (v instanceof TypedStringValue) {
             TypedStringValue stringValue = (TypedStringValue) v; 
             String value = stringValue.getStringValue();
             Class type = loadType(stringValue.getTypeName());
-            return new ValueRecipe(value, type, hint);
+            return new ValueRecipe(getConversionService(), value, type, groupingType);
         } else if (v instanceof ReferenceValue) {
             String componentName = ((ReferenceValue) v).getComponentName();
             return new ReferenceRecipe(componentName);
@@ -183,8 +180,7 @@
         } else if (v instanceof ArrayValue) {
             ArrayValue arrayValue = (ArrayValue) v;
             Class type = loadType(arrayValue.getValueType());
-            type = determineType(type, hint);
-            ArrayRecipe ar = new ArrayRecipe(type);
+            ArrayRecipe ar = (type == null) ? new ArrayRecipe() : new ArrayRecipe(type);
             for (Value value : arrayValue.getArray()) {
                 ar.add(getValue(value, type));
             }
@@ -200,22 +196,8 @@
         }
     }
     
-    private static Class determineType(Class type, Class hint) throws RuntimeException {
-        if (type != null) {
-            if (hint == null || hint.isAssignableFrom(type)) {
-                return type;
-            } else {
-                throw new RuntimeException(type.getName() + " cannot be assigned to " + hint.getName());
-            }
-        } else if (hint != null) {
-            return hint;
-        } else {
-            return Object.class;
-        }
-    }
-    
-    protected Object convert(Object source, Class type) throws Exception {
-        return moduleContext.getConversionService().convert(source, type);
+    protected ConversionService getConversionService() {
+        return moduleContext.getConversionService();
     }
     
     private Class loadType(String typeName) throws ClassNotFoundException {
@@ -255,34 +237,5 @@
             }
         }
     }
-    
-    private class ValueRecipe extends AbstractRecipe {
-
-        private String value;
-        private Class type;
-        private Class hint;
-
-        private ValueRecipe(String value, Class type, Class hint) {
-            this.value = value;
-            this.type = type;
-            this.hint = hint;
-        }
-        
-        @Override
-        protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws
ConstructionException {
-            Class myType = determineType(type, hint);
-            //System.out.println("create: " + expectedType + " " + type + " " + hint + "
" + myType);
-            try {
-                return convert(value, myType);
-            } catch (Exception e) {
-                throw new ConstructionException(e);
-            }
-        }
-
-        public boolean canCreate(Type expectedType) {
-            return true;
-        }
-        
-    }
-
+            
 }

Added: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java?rev=766183&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
(added)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
Sat Apr 18 00:07:19 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.blueprint.context;
+
+import java.lang.reflect.Type;
+
+import org.apache.xbean.recipe.AbstractRecipe;
+import org.apache.xbean.recipe.ConstructionException;
+import org.apache.xbean.recipe.RecipeHelper;
+import org.osgi.service.blueprint.convert.ConversionService;
+
+public class ValueRecipe extends AbstractRecipe {
+
+    private ConversionService conversionService;
+    private String value;
+    private Class type;
+    private Class groupingType;
+
+    public ValueRecipe(ConversionService conversionService, String value, Class type, Class
groupingType) {
+        this.conversionService = conversionService;
+        this.value = value;
+        this.type = type;
+        this.groupingType = groupingType;
+    }
+
+    private static Class determineType(Class type, Class groupingType, Class defaultType)
throws RuntimeException {
+        if (type != null) {
+            if (groupingType == null || groupingType.isAssignableFrom(type)) {
+                return type;
+            } else {
+                throw new RuntimeException(type.getName() + " cannot be assigned to " + groupingType.getName());
+            }
+        } else if (groupingType != null) {
+            return groupingType;
+        } else {
+            return defaultType;
+        }
+    }
+
+    @Override
+    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
+        Class myType = determineType(type, groupingType, RecipeHelper.toClass(expectedType));
+
+        try {
+            return conversionService.convert(value, myType);
+        } catch (Exception e) {
+            throw new ConstructionException(e);
+        }
+    }
+
+    public boolean canCreate(Type expectedType) {
+        return true;
+    }
+
+}

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ValueRecipe.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java?rev=766183&r1=766182&r2=766183&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
Sat Apr 18 00:07:19 2009
@@ -31,6 +31,7 @@
 import org.apache.felix.blueprint.pojos.PojoB;
 import org.apache.xbean.recipe.ObjectGraph;
 import org.apache.xbean.recipe.Repository;
+import org.osgi.service.blueprint.convert.ConversionService;
 
 public class WiringTest extends TestCase {
 
@@ -104,8 +105,8 @@
         }
         
         @Override
-        public Object convert(Object source, Class type) throws Exception {
-            return conversionService.convert(source, type);
+        public ConversionService getConversionService() {
+            return conversionService;
         }
         
     }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml?rev=766183&r1=766182&r2=766183&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/resources/test-wiring.xml
Sat Apr 18 00:07:19 2009
@@ -45,14 +45,14 @@
             </array>
         </property>
         <property name="intArray">
-            <array value-type="int">
+            <array>
                 <value>1</value>
                 <value>50</value>
                 <value>100</value>
             </array>
         </property>
         <property name="numberArray">
-            <array value-type="java.lang.Number">
+            <array>
                 <value type="java.lang.Integer">1</value>
                 <value type="java.math.BigInteger">50</value>
                 <value type="java.lang.Long">100</value>

Modified: geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=766183&r1=766182&r2=766183&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml (original)
+++ geronimo/sandbox/blueprint/sample/src/main/resources/OSGI-INF/blueprint/config.xml Sat
Apr 18 00:07:19 2009
@@ -14,10 +14,10 @@
         <property name="b" value="10" />
         <property name="bar" ref="bar" />
         <property name="currency">
-              <value type="java.util.Currency">PLN</value>
+              <value>PLN</value>
         </property>
         <property name="date">
-              <value type="java.util.Date">2009.04.17</value>
+              <value>2009.04.17</value>
         </property>
     </component>
 
@@ -26,7 +26,7 @@
         <property name="context" ref="bundleContext"/>
         <property name="list">
             <list>
-                <value>a list element followed by a reference</value>
+                <value>a list element</value>
                 <value type = "java.lang.Integer">5</value>
             </list>        
         </property>



Mime
View raw message