geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r785323 [2/2] - in /geronimo/sandbox/blueprint: blueprint-api/src/main/java/org/osgi/service/blueprint/container/ blueprint-api/src/main/java/org/osgi/service/blueprint/reflect/ blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compe...
Date Tue, 16 Jun 2009 17:52:29 GMT
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java?rev=785323&r1=785322&r2=785323&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java
Tue Jun 16 17:52:28 2009
@@ -21,10 +21,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 
 import org.apache.geronimo.blueprint.mutable.MutableServiceReferenceMetadata;
-import org.osgi.service.blueprint.reflect.Listener;
+import org.osgi.service.blueprint.reflect.ReferenceListener;
 import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
 import org.osgi.service.blueprint.reflect.Target;
 
@@ -40,7 +39,7 @@
     protected String interfaceName;
     protected String componentName;
     protected String filter;
-    protected Collection<Listener> serviceListeners;
+    protected Collection<ReferenceListener> referenceListeners;
     protected int proxyMethod;
 
     public ServiceReferenceMetadataImpl() {
@@ -52,8 +51,8 @@
         this.interfaceName = source.getInterfaceName();
         this.componentName = source.getComponentName();
         this.filter = source.getFilter();
-        for (Listener listener : source.getServiceListeners()) {
-            addServiceListener(new ListenerImpl(listener));
+        for (ReferenceListener listener : source.getReferenceListeners()) {
+            addServiceListener(new ReferenceListenerImpl(listener));
         }
     }
 
@@ -89,34 +88,34 @@
         this.filter = filter;
     }
 
-    public Collection<Listener> getServiceListeners() {
-        if (this.serviceListeners == null) {
+    public Collection<ReferenceListener> getReferenceListeners() {
+        if (this.referenceListeners == null) {
             return Collections.emptyList();
         } else {
-            return Collections.unmodifiableCollection(this.serviceListeners);
+            return Collections.unmodifiableCollection(this.referenceListeners);
         }
     }
 
-    public void setServiceListeners(Collection<Listener> listeners) {
-        this.serviceListeners = listeners != null ? new ArrayList<Listener>(listeners)
: null;
+    public void setReferenceListeners(Collection<ReferenceListener> listeners) {
+        this.referenceListeners = listeners != null ? new ArrayList<ReferenceListener>(listeners)
: null;
     }
 
-    public void addServiceListener(Listener bindingListenerMetadata) {
-        if (this.serviceListeners == null) {
-            this.serviceListeners = new ArrayList<Listener>();
+    public void addServiceListener(ReferenceListener bindingListenerMetadata) {
+        if (this.referenceListeners == null) {
+            this.referenceListeners = new ArrayList<ReferenceListener>();
         }
-        this.serviceListeners.add(bindingListenerMetadata);
+        this.referenceListeners.add(bindingListenerMetadata);
     }
 
-    public Listener addServiceListener(Target listenerComponent, String bindMethodName, String
unbindMethodName) {
-        Listener listener = new ListenerImpl(listenerComponent, bindMethodName, unbindMethodName);
+    public ReferenceListener addServiceListener(Target listenerComponent, String bindMethodName,
String unbindMethodName) {
+        ReferenceListener listener = new ReferenceListenerImpl(listenerComponent, bindMethodName,
unbindMethodName);
         addServiceListener(listener);
         return listener;
     }
 
-    public void removeServiceListener(Listener listener) {
-        if (this.serviceListeners != null) {
-            this.serviceListeners.remove(listener);
+    public void removeReferenceListener(ReferenceListener listener) {
+        if (this.referenceListeners != null) {
+            this.referenceListeners.remove(listener);
         }
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java?rev=785323&r1=785322&r2=785323&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
Tue Jun 16 17:52:28 2009
@@ -33,8 +33,12 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.Arrays;
+import java.util.Queue;
+import java.util.LinkedList;
+import java.util.Stack;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.BlockingQueue;
 
 import static org.apache.geronimo.blueprint.utils.TypeUtils.getTypeParameters;
 import static org.apache.geronimo.blueprint.utils.TypeUtils.toClass;
@@ -164,6 +168,8 @@
             return LinkedHashSet.class;
         } else if (List.class.isAssignableFrom(type)) {
             return ArrayList.class;
+        } else if (Queue.class.isAssignableFrom(type)) {
+            return LinkedList.class;
         } else {
             return ArrayList.class;
         }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java?rev=785323&r1=785322&r2=785323&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java
Tue Jun 16 17:52:28 2009
@@ -23,6 +23,11 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.osgi.framework.Bundle;
+import org.apache.geronimo.blueprint.di.ExecutionContext;
 
 /**
  * @version $Rev: 6687 $ $Date: 2005-12-28T21:08:56.733437Z $
@@ -148,4 +153,117 @@
         }
         return null;
     }
+
+    private static Map<String, Class> primitiveClasses = new HashMap<String, Class>();
+
+    static {
+        primitiveClasses.put("int", int.class);
+        primitiveClasses.put("short", short.class);
+        primitiveClasses.put("long", long.class);
+        primitiveClasses.put("byte", byte.class);
+        primitiveClasses.put("char", char.class);
+        primitiveClasses.put("float", float.class);
+        primitiveClasses.put("double", double.class);
+        primitiveClasses.put("boolean", boolean.class);
+    }
+
+    public static Type parseJavaType(String type, Object loader) throws ClassNotFoundException
{
+        type = type.trim();
+        // Check if this is an array
+        if (type.endsWith("[]")) {
+            return new GenericArrayTypeImpl(parseJavaType(type.substring(0, type.length()
- 2), loader));
+        }
+        // Check if this is a generic
+        int genericIndex = type.indexOf('<');
+        if (genericIndex > 0) {
+            if (!type.endsWith(">")) {
+                throw new IllegalArgumentException("Can not load type: " + type);
+            }
+            Type base = parseJavaType(type.substring(0, genericIndex), loader);
+            String[] params = type.substring(genericIndex + 1, type.length() - 1).split(",");
+            Type[] types = new Type[params.length];
+            for (int i = 0; i < params.length; i++) {
+                types[i] = parseJavaType(params[i], loader);
+            }
+            return new ParameterizedTypeImpl(base, types);
+        }
+        // Primitive
+        if (primitiveClasses.containsKey(type)) {
+            return primitiveClasses.get(type);
+        }
+        // Class
+        if (loader instanceof ClassLoader) {
+            return ((ClassLoader) loader).loadClass(type);
+        } else if (loader instanceof Bundle) {
+            return ((Bundle) loader).loadClass(type);
+        } else if (loader instanceof ExecutionContext) {
+            return ((ExecutionContext) loader).loadClass(type);
+        } else {
+            throw new IllegalArgumentException("Unsupported loader: " + loader);
+        }
+    }
+
+    private static class ParameterizedTypeImpl implements ParameterizedType {
+
+        private final Type base;
+        private final Type[] params;
+
+        private ParameterizedTypeImpl(Type base, Type[] params) {
+            this.base = base;
+            this.params = params;
+        }
+
+        public Type[] getActualTypeArguments() {
+            return params;
+        }
+
+        public Type getRawType() {
+            return base;
+        }
+
+        public Type getOwnerType() {
+            return null;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            sb.append(getDescription(base));
+            sb.append("<");
+            for (int i = 0; i < params.length; i++) {
+                if (i > 0) {
+                    sb.append(",");
+                }
+                sb.append(getDescription(params[i]));
+            }
+            sb.append(">");
+            return sb.toString();
+        }
+    }
+
+    private static class GenericArrayTypeImpl implements GenericArrayType {
+
+        private final Type genericComponentType;
+
+        private GenericArrayTypeImpl(Type genericComponentType) {
+            this.genericComponentType = genericComponentType;
+        }
+
+        public Type getGenericComponentType() {
+            return genericComponentType;
+        }
+
+        @Override
+        public String toString() {
+            return getDescription(genericComponentType) + "[]";
+        }
+    }
+
+    private static String getDescription(Type type) {
+        if (type instanceof Class) {
+            return ((Class) type).getName();
+        } else {
+            return type.toString();
+        }
+    }
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/blueprint.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/blueprint.xsd?rev=785323&r1=785322&r2=785323&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/blueprint.xsd
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/blueprint.xsd
Tue Jun 16 17:52:28 2009
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!--
     /*
-    * $Revision: 7333 $
+    * $Revision: 7376 $
     *
     * Copyright (c) OSGi Alliance (2008, 2009). All Rights Reserved.
     *
@@ -339,7 +339,7 @@
             <xsd:group ref="value" minOccurs="0"/>
         </xsd:sequence>
         <xsd:attribute name="index" type="xsd:nonNegativeInteger" />
-        <xsd:attribute name="type" type="Tclass" />
+        <xsd:attribute name="type" type="Ttype" />
         <xsd:attribute name="ref" type="Tidref" />
         <xsd:attribute name="value" type="TstringValue" />
     </xsd:complexType>
@@ -557,7 +557,7 @@
         <xsd:sequence>
             <xsd:element name="description" type="Tdescription" minOccurs="0" />
             <!-- listener -->
-            <xsd:element name="listener" type="TreferenceListener" minOccurs="0"
+            <xsd:element name="reference-listener" type="TreferenceListener" minOccurs="0"
                 maxOccurs="unbounded">
                 <xsd:annotation>
                     <xsd:documentation>
@@ -878,7 +878,7 @@
               ]]>
             </xsd:documentation>
         </xsd:annotation>
-        <xsd:attribute name="type" type="Tclass" use="optional" />
+        <xsd:attribute name="type" type="Ttype" use="optional" />
     </xsd:complexType>
 
     <!-- Collection Values -->
@@ -892,7 +892,7 @@
               ]]>
             </xsd:documentation>
         </xsd:annotation>
-        <xsd:attribute name="value-type" type="Tclass" />
+        <xsd:attribute name="value-type" type="Ttype" />
     </xsd:complexType>
 
 
@@ -957,7 +957,7 @@
                 <xsd:sequence>
                     <xsd:element name="entry" type="TmapEntry" minOccurs="0" maxOccurs="unbounded"
/>
                 </xsd:sequence>
-                <xsd:attribute name="key-type" type="Tclass" />
+                <xsd:attribute name="key-type" type="Ttype" />
             </xsd:extension>
         </xsd:complexContent>
     </xsd:complexType>
@@ -1069,13 +1069,27 @@
             <xsd:documentation>
               <![CDATA[
               Tclass is a base type that should be used for all attributes that
-              refer to java class names or java types.
+              refer to java class names.
               ]]>
             </xsd:documentation>
         </xsd:annotation>
         <xsd:restriction base="xsd:NCName" />
     </xsd:simpleType>
 
+    <xsd:simpleType name="Ttype">
+        <xsd:annotation>
+            <xsd:documentation>
+                <![CDATA[
+                Ttype is a base type that refer to java types such as classes or
+                arrays.
+                ]]>
+            </xsd:documentation>
+        </xsd:annotation>
+        <xsd:restriction base="xsd:token">
+            <xsd:pattern value="[\i-[:]][\c-[:]]*(\[\])*" />
+        </xsd:restriction>
+    </xsd:simpleType>
+
     <xsd:simpleType name="Tmethod">
         <xsd:annotation>
             <xsd:documentation>

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java?rev=785323&r1=785322&r2=785323&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
Tue Jun 16 17:52:28 2009
@@ -114,8 +114,8 @@
         assertTrue(param.getValue() instanceof RefMetadata);
         assertEquals("pojoB", ((RefMetadata) param.getValue()).getComponentId());
         
-        assertEquals(null, local.getInitMethodName());
-        assertEquals(null, local.getDestroyMethodName());
+        assertEquals(null, local.getInitMethod());
+        assertEquals(null, local.getDestroyMethod());
                 
         // test pojoB
         ComponentMetadata pojoB = registry.getComponentDefinition("pojoB");
@@ -123,8 +123,8 @@
         assertEquals("pojoB", pojoB.getId());
         assertTrue(pojoB instanceof BeanMetadata);
         BeanMetadata pojoBLocal = (BeanMetadata) pojoB;
-        assertEquals("initPojo", pojoBLocal.getInitMethodName());
-//        assertEquals("", pojoBLocal.getDestroyMethodName());
+        assertEquals("initPojo", pojoBLocal.getInitMethod());
+//        assertEquals("", pojoBLocal.getDestroyMethod());
         
         params = pojoBLocal.getArguments();
         assertNotNull(params);

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/TypeUtilsTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/TypeUtilsTest.java?rev=785323&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/TypeUtilsTest.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/TypeUtilsTest.java
Tue Jun 16 17:52:28 2009
@@ -0,0 +1,33 @@
+/**
+ * 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.geronimo.blueprint.utils;
+
+import java.lang.reflect.Type;
+
+import junit.framework.TestCase;
+
+public class TypeUtilsTest extends TestCase {
+
+    public void testParseTypes() throws ClassNotFoundException {
+        Type type = TypeUtils.parseJavaType("java.util.List<java.lang.String[]>", getClass().getClassLoader());
+        System.out.println(type);
+
+        type = TypeUtils.parseJavaType("java.util.Map<int, java.util.List<java.lang.Integer>[]>",
getClass().getClassLoader());
+        System.out.println(type);
+    }
+
+}

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=785323&r1=785322&r2=785323&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Tue Jun 16 17:52:28 2009
@@ -81,13 +81,13 @@
     <bean id="fooRegistrationListener" class="org.apache.geronimo.blueprint.sample.FooRegistrationListener"/>
 
     <reference id="ref2" interface="org.apache.geronimo.blueprint.sample.InterfaceA" timeout="100">
-        <listener bind-method="bind" unbind-method="unbind" ref="bindingListener" />
+        <reference-listener bind-method="bind" unbind-method="unbind" ref="bindingListener"
/>
     </reference>
 
     <bean id="bindingListener" class="org.apache.geronimo.blueprint.sample.BindingListener"/>
 
     <ref-list id="ref-list" interface="org.apache.geronimo.blueprint.sample.InterfaceA">
-        <listener bind-method="bind" unbind-method="unbind" ref="listBindingListener"
/>
+        <reference-listener bind-method="bind" unbind-method="unbind" ref="listBindingListener"
/>
     </ref-list>
 
     <bean id="listBindingListener" class="org.apache.geronimo.blueprint.sample.BindingListener"/>
@@ -95,9 +95,10 @@
     <bean id="circularReference" class="org.apache.geronimo.blueprint.sample.BindingListener"
init-method="init">
         <property name="list">
             <ref-list interface="org.apache.geronimo.blueprint.sample.InterfaceA" availability="optional">
-                <listener bind-method="bind" unbind-method="unbind" ref="circularReference"/>
+                <reference-listener bind-method="bind" unbind-method="unbind" ref="circularReference"/>
             </ref-list>
         </property>
     </bean>
+
 </blueprint>
 



Mime
View raw message