geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r955091 - in /geronimo/server/trunk: framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/ framework/modules/geronimo-kernel/src/main...
Date Tue, 15 Jun 2010 23:41:42 GMT
Author: djencks
Date: Tue Jun 15 23:41:42 2010
New Revision: 955091

URL: http://svn.apache.org/viewvc?rev=955091&view=rev
Log:
GERONIMO-5380 Allow exposing gbeans as osgi services (or service factories).  Replace the specialized code in connector with this new generic code.  This is not serialziation compatible with old GBeanInfo and GBeanData

Added:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java   (with props)
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java   (with props)
Removed:
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/ConnectionFactoryRegistration.java
Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanDataTest.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/GenericConnectionManagerGBean.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/JCAConnectionFactoryImpl.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/datasource/DataSourceGBean.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java
    geronimo/server/trunk/plugins/connector-1_6/transaction-1_6/src/main/history/dependencies.xml

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java Tue Jun 15 23:41:42 2010
@@ -20,10 +20,14 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Dictionary;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.Set;
 
@@ -47,6 +51,8 @@ public class GBeanData implements Extern
     private final Set<ReferencePatterns> dependencies;
     private AbstractName abstractName;
     private int priority;
+    private String[] serviceInterfaces;
+    private Dictionary serviceProperties;
 
 
     public GBeanData() {
@@ -91,6 +97,17 @@ public class GBeanData implements Extern
         references = new HashMap<String, ReferencePatterns>(gbeanData.references);
         dependencies = new HashSet<ReferencePatterns>(gbeanData.dependencies);
         abstractName = gbeanData.abstractName;
+        if (gbeanData.serviceInterfaces != null) {
+            serviceInterfaces = Arrays.copyOf(gbeanData.serviceInterfaces, gbeanData.serviceInterfaces.length);
+        }
+        if (gbeanData.serviceProperties != null) {
+            serviceProperties = new Hashtable();
+            for (Enumeration e = gbeanData.serviceProperties.keys(); e.hasMoreElements();) {
+                Object key = e.nextElement();
+                serviceProperties.put(key, gbeanData.serviceProperties.get(key));
+            }
+
+        }
     }
 
     public AbstractName getAbstractName() {
@@ -223,6 +240,25 @@ public class GBeanData implements Extern
         this.priority = priority;
     }
 
+    public String[] getServiceInterfaces() {
+        return serviceInterfaces;
+    }
+
+    public void setServiceInterfaces(String[] serviceInterfaces) {
+        this.serviceInterfaces = serviceInterfaces;
+    }
+
+    public Dictionary getServiceProperties() {
+        if (serviceProperties == null) {
+            serviceProperties = new Hashtable();
+        }
+        return serviceProperties;
+    }
+
+    public void setServiceProperties(Dictionary serviceProperties) {
+        this.serviceProperties = serviceProperties;
+    }
+
     public void writeExternal(ObjectOutput out) throws IOException {
         // write version index
         out.writeObject(backwardExternalizables.length - 1);
@@ -273,6 +309,8 @@ public class GBeanData implements Extern
                 throw (IOException) new IOException("Unable to write dependency pattern in gbean: " + abstractName).initCause(e);
             }
         }
+        out.writeObject(serviceInterfaces);
+        out.writeObject(serviceProperties);
     }
 
 
@@ -357,6 +395,9 @@ public class GBeanData implements Extern
                     ReferencePatterns depdendencyPattern = (ReferencePatterns) in.readObject();
                     dependencies.add(depdendencyPattern);
                 }
+
+                serviceInterfaces = (String[]) in.readObject();
+                serviceProperties = (Dictionary) in.readObject();
             } catch (IOException e) {
                 throw (IOException) new IOException("Unable to deserialize GBeanData " + abstractName).initCause(e);
             } catch (ClassNotFoundException e) {

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java Tue Jun 15 23:41:42 2010
@@ -45,7 +45,7 @@ public final class GBeanInfo implements 
     public static final int PRIORITY_CLASSLOADER = 1;
     public static final int PRIORITY_NORMAL = 5;
 
-    private static final Set DEFAULT_NOTIFICATIONS = Collections.unmodifiableSet(new HashSet(Arrays.asList(NotificationType.TYPES)));
+    private static final Set<String> DEFAULT_NOTIFICATIONS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(NotificationType.TYPES)));
 
     /**
      * Static helper to try to get the GBeanInfo from the class supplied.
@@ -70,77 +70,91 @@ public final class GBeanInfo implements 
     private final String className;
     private final String j2eeType;
     private final Set<GAttributeInfo> attributes;
-    private final Map attributesByName;
+    private final Map<String,GAttributeInfo> attributesByName;
     private final GConstructorInfo constructor;
-    private final Set operations;
-    private final Set notifications;
-    private final Set references;
-    private final Map referencesByName;
-    private final Set interfaces;
-    private int priority;
+    private final Set<GOperationInfo> operations;
+    private final Set<String> notifications;
+    private final Set<GReferenceInfo> references;
+    private final Map<String, GReferenceInfo> referencesByName;
+    private final Set<String> interfaces;
+    private final int priority;
+    private final boolean osgiService;
+    private final String[] serviceInterfaces;
 
     /**
      * @deprecated use GBeanInfoBuilder
      */
     public GBeanInfo(String name, String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces) {
-        this(null, name, className, j2eeType, attributes, constructor, operations, references, interfaces, DEFAULT_NOTIFICATIONS, PRIORITY_NORMAL);
+        this(null, name, className, j2eeType, attributes, constructor, operations, references, interfaces, DEFAULT_NOTIFICATIONS, PRIORITY_NORMAL, false, null);
     }
 
     /**
      * @deprecated use GBeanInfoBuilder
      */
     public GBeanInfo(String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces) {
-        this(null, className, className, j2eeType, attributes, constructor, operations, references, interfaces, DEFAULT_NOTIFICATIONS, PRIORITY_NORMAL);
+        this(null, className, className, j2eeType, attributes, constructor, operations, references, interfaces, DEFAULT_NOTIFICATIONS, PRIORITY_NORMAL, false, null);
     }
 
     /**
      * @deprecated use GBeanInfoBuilder
      */
     public GBeanInfo(String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces, Set notifications) {
-        this(null, className, className, j2eeType, attributes, constructor, operations, references, interfaces, notifications, PRIORITY_NORMAL);
+        this(null, className, className, j2eeType, attributes, constructor, operations, references, interfaces, notifications, PRIORITY_NORMAL, false, null);
     }
 
     /**
      * @deprecated use GBeanInfoBuilder
      */
     public GBeanInfo(String name, String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces, Set notifications) {
-        this(null, name, className, j2eeType, attributes, constructor, operations, references, interfaces, notifications, PRIORITY_NORMAL);
+        this(null, name, className, j2eeType, attributes, constructor, operations, references, interfaces, notifications, PRIORITY_NORMAL, false, null);
     }
 
-    GBeanInfo(String sourceClass, String name, String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces, int priority) {
-        this(sourceClass, name, className, j2eeType, attributes, constructor, operations, references, interfaces, DEFAULT_NOTIFICATIONS, priority);
+    public GBeanInfo(String sourceClass, String name, String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces, int priority, boolean osgiService, String[] serviceInterfaces) {
+        this(sourceClass, name, className, j2eeType, attributes, constructor, operations, references, interfaces, DEFAULT_NOTIFICATIONS, priority, osgiService, serviceInterfaces);
     }
 
-    GBeanInfo(String sourceClass, String name, String className, String j2eeType, Collection attributes, GConstructorInfo constructor, Collection operations, Set references, Set interfaces, Set notifications, int priority) {
+    GBeanInfo(String sourceClass,
+              String name,
+              String className,
+              String j2eeType,
+              Collection<GAttributeInfo> attributes,
+              GConstructorInfo constructor,
+              Collection<GOperationInfo> operations,
+              Set<GReferenceInfo> references,
+              Set<String> interfaces,
+              Set<String> notifications,
+              int priority,
+              boolean osgiService,
+              String[] serviceInterfaces) {
         this.sourceClass = sourceClass;
         this.name = name;
         this.className = className;
         this.j2eeType = j2eeType;
         if (attributes == null) {
-            this.attributes = Collections.EMPTY_SET;
-            this.attributesByName = Collections.EMPTY_MAP;
+            this.attributes = Collections.emptySet();
+            this.attributesByName = Collections.emptyMap();
         } else {
-            Map map = new HashMap();
+            Map<String, GAttributeInfo> map = new HashMap<String, GAttributeInfo>();
             for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
                 GAttributeInfo attribute = (GAttributeInfo) iterator.next();
                 map.put(attribute.getName(), attribute);
             }
             this.attributesByName = Collections.unmodifiableMap(map);
-            this.attributes = Collections.unmodifiableSet(new HashSet(map.values()));
+            this.attributes = Collections.unmodifiableSet(new HashSet<GAttributeInfo>(map.values()));
         }
         if (constructor == null) {
-            this.constructor = new GConstructorInfo(Collections.EMPTY_LIST);
+            this.constructor = new GConstructorInfo(Collections.<Object>emptyList());
         } else {
             this.constructor = constructor;
         }
         if (operations == null) {
-            this.operations = Collections.EMPTY_SET;
+            this.operations = Collections.emptySet();
         } else {
-            this.operations = Collections.unmodifiableSet(new HashSet(operations));
+            this.operations = Collections.unmodifiableSet(new HashSet<GOperationInfo>(operations));
         }
         if (references == null) {
-            this.references = Collections.EMPTY_SET;
-            this.referencesByName = Collections.EMPTY_MAP;
+            this.references = Collections.emptySet();
+            this.referencesByName = Collections.emptyMap();
         } else {
             Map map = new HashMap();
             for (Iterator iterator = references.iterator(); iterator.hasNext();) {
@@ -161,6 +175,8 @@ public final class GBeanInfo implements 
             this.notifications = Collections.unmodifiableSet(new HashSet(notifications));
         }
         this.priority = priority;
+        this.osgiService = osgiService;
+        this.serviceInterfaces = serviceInterfaces == null? new String[0]: serviceInterfaces;
     }
 
     /**
@@ -257,11 +273,19 @@ public final class GBeanInfo implements 
         return priority;
     }
 
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-        priority = GBeanInfo.PRIORITY_NORMAL;
-        in.defaultReadObject();
+    public boolean isOsgiService() {
+        return osgiService;
+    }
+
+    public String[] getServiceInterfaces() {
+        return serviceInterfaces;
     }
 
+//    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+//        priority = GBeanInfo.PRIORITY_NORMAL;
+//        in.defaultReadObject();
+//    }
+
     public String toString() {
         StringBuffer result = new StringBuffer("[GBeanInfo:");
         result.append(" id=").append(super.toString());

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java Tue Jun 15 23:41:42 2010
@@ -134,6 +134,10 @@ public class GBeanInfoBuilder {
 
     private int priority = GBeanInfo.PRIORITY_NORMAL;
 
+    private boolean osgiService;
+
+    private Set<String> serviceInterfaces = new HashSet<String>();
+
     public GBeanInfoBuilder(Class gbeanType) {
         this(checkNotNull(gbeanType).getName(), gbeanType, null, null);
     }
@@ -466,6 +470,14 @@ public class GBeanInfoBuilder {
         this.priority = priority;
     }
 
+    public void setOsgiService(boolean osgiService) {
+        this.osgiService = osgiService;
+    }
+
+    public Set<String> getServiceInterfaces() {
+        return serviceInterfaces;
+    }
+
     public GBeanInfo getBeanInfo() {
         // get the types of the constructor args
         // this also verifies that we have a valid constructor
@@ -502,7 +514,7 @@ public class GBeanInfoBuilder {
             referenceInfos.add(new GReferenceInfo(referenceName, referenceType, proxyType, setterName, namingType));
         }
 
-        return new GBeanInfo(sourceClass, name, gbeanType.getName(), j2eeType, attributes.values(), constructor, operations.values(), referenceInfos, interfaces, priority);
+        return new GBeanInfo(sourceClass, name, gbeanType.getName(), j2eeType, attributes.values(), constructor, operations.values(), referenceInfos, interfaces, priority, osgiService, serviceInterfaces.toArray(new String[serviceInterfaces.size()]));
     }
 
     private Map getConstructorTypes() throws InvalidConfigurationException {

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java?rev=955091&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java Tue Jun 15 23:41:42 2010
@@ -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.gbean;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ServiceInterfaces {
+    /**
+     * For a GBean that is to be registered in the OSGI service registry,
+     * supply the interfaces to register under.
+     * @return the names of interfaces to register an osgi service or service factory under.
+     */
+    String[] getServiceInterfaces();
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/ServiceInterfaces.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java Tue Jun 15 23:41:42 2010
@@ -26,6 +26,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.WildcardType;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
@@ -44,9 +45,9 @@ import org.apache.geronimo.gbean.GRefere
 public class AnnotationGBeanInfoBuilder {
     private static final String DEFAULT_J2EE_TYPE = "GBean";
     
-    private final Class gbeanClass;
+    private final Class<?> gbeanClass;
     
-    public AnnotationGBeanInfoBuilder(Class gbeanClass) {
+    public AnnotationGBeanInfoBuilder(Class<?> gbeanClass) {
         if (null == gbeanClass) {
             throw new IllegalArgumentException("gbeanClass is required");
         }
@@ -60,6 +61,7 @@ public class AnnotationGBeanInfoBuilder 
             GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(name, gbeanClass, j2eeType);
 
             setPriority(infoBuilder);
+            setOsgiService(infoBuilder);
             setConstructor(infoBuilder);
             markPersistent(infoBuilder);
             addReferences(infoBuilder);
@@ -69,9 +71,17 @@ public class AnnotationGBeanInfoBuilder 
             throw new GBeanAnnotationException("Could not fully load class: " + gbeanClass.getName() + "\n due to: " + e.getMessage() +  "\n in classloader \n" + gbeanClass.getClassLoader(), e);
         }
     }
-    
+
+    private void setOsgiService(GBeanInfoBuilder infoBuilder) {
+        OsgiService osgiService = gbeanClass.getAnnotation(OsgiService.class);
+        infoBuilder.setOsgiService(osgiService != null);
+        if (osgiService != null) {
+            infoBuilder.getServiceInterfaces().addAll(Arrays.asList(osgiService.serviceInterfaces()));
+        }
+    }
+
     protected void setPriority(GBeanInfoBuilder infoBuilder) {
-        Priority priority = (Priority) gbeanClass.getAnnotation(Priority.class);
+        Priority priority = gbeanClass.getAnnotation(Priority.class);
         if (null == priority) {
             return;
         }
@@ -162,7 +172,7 @@ public class AnnotationGBeanInfoBuilder 
         infoBuilder.setConstructor(cstrNames);
     }
 
-    protected Set<Method> filterSettersByAnnotation(Class annotationClass) {
+    protected Set<Method> filterSettersByAnnotation(Class<? extends Annotation> annotationClass) {
         Set<Method> filteredMethods = new HashSet<Method>();
         Method[] methods = gbeanClass.getMethods();
         for (Method method : methods) {

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java?rev=955091&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java Tue Jun 15 23:41:42 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.gbean.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Documented
+@Retention(value = RUNTIME)
+@Target(value = {TYPE})
+public @interface OsgiService {
+    String[] serviceInterfaces() default {};
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/OsgiService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java Tue Jun 15 23:41:42 2010
@@ -19,10 +19,13 @@ package org.apache.geronimo.gbean.runtim
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -31,6 +34,8 @@ import java.util.Set;
 
 import javax.management.ObjectName;
 
+import org.apache.geronimo.gbean.ServiceInterfaces;
+import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.geronimo.gbean.AbstractName;
@@ -66,8 +71,7 @@ import org.osgi.framework.BundleContext;
  *
  * @version $Rev:385718 $ $Date$
  */
-public final class GBeanInstance implements StateManageable
-{
+public final class GBeanInstance implements StateManageable {
     private static final Logger log = LoggerFactory.getLogger(GBeanInstance.class);
 
     private static final int DESTROYED = 0;
@@ -212,10 +216,14 @@ public final class GBeanInstance impleme
 
     private String stateReason;
 
+    private String[] serviceInterfaces;
+    private Dictionary serviceProperties;
+    private ServiceRegistration serviceRegistration;
+
     /**
      * Construct a GBeanMBean using the supplied GBeanData and bundle
      *
-     * @param gbeanData   the data for the new GBean including GBeanInfo, intial attribute values, and reference patterns
+     * @param gbeanData     the data for the new GBean including GBeanInfo, intial attribute values, and reference patterns
      * @param bundleContext
      * @throws org.apache.geronimo.gbean.InvalidConfigurationException
      *          if the gbeanInfo is inconsistent with the actual java classes, such as
@@ -240,12 +248,12 @@ public final class GBeanInstance impleme
         name = gbeanInfo.getName();
 
         // interfaces
-        interfaces = (String[]) gbeanInfo.getInterfaces().toArray(new String[0]);
+        interfaces = gbeanInfo.getInterfaces().toArray(new String[gbeanInfo.getInterfaces().size()]);
 
         // attributes
         attributes = buildAttributes(gbeanInfo);
         for (int i = 0; i < attributes.length; i++) {
-            attributeIndex.put(attributes[i].getName(), new Integer(i));
+            attributeIndex.put(attributes[i].getName(), i);
         }
 
         // references
@@ -255,7 +263,7 @@ public final class GBeanInstance impleme
 
         references = referencesSet.toArray(new GBeanReference[referencesSet.size()]);
         for (int i = 0; i < references.length; i++) {
-            referenceIndex.put(references[i].getName(), new Integer(i));
+            referenceIndex.put(references[i].getName(), i);
         }
 
         //dependencies
@@ -281,13 +289,13 @@ public final class GBeanInstance impleme
         int opCounter = 0;
         for (Map.Entry<GOperationSignature, GBeanOperation> entry : operationsMap.entrySet()) {
             operations[opCounter] = entry.getValue();
-            operationIndex.put(entry.getKey(), new Integer(opCounter));
+            operationIndex.put(entry.getKey(), opCounter);
             opCounter++;
         }
 
         // rebuild the gbean info based on the current attributes, operations, and references because
         // the above code add new attributes and operations
-        this.gbeanInfo = rebuildGBeanInfo(gbeanInfo.getConstructor(), gbeanInfo.getJ2eeType());
+        this.gbeanInfo = rebuildGBeanInfo(gbeanInfo.getConstructor(), gbeanInfo.getJ2eeType(), gbeanInfo.getPriority(), gbeanInfo.isOsgiService(), gbeanInfo.getServiceInterfaces());
 
         objectRecipe = newObjectRecipe(gbeanData);
 
@@ -302,6 +310,9 @@ public final class GBeanInstance impleme
         for (int i = 0; i < dependencies.length; i++) {
             dependencies[i].online();
         }
+
+        this.serviceInterfaces = gbeanData.getServiceInterfaces();
+        this.serviceProperties = gbeanData.getServiceProperties();
     }
 
     protected ObjectRecipe newObjectRecipe(GBeanData gbeanData) {
@@ -341,14 +352,14 @@ public final class GBeanInstance impleme
                 objectRecipe.setProperty(attributeName, attribute.getPersistentValue());
             }
         }
-        
+
         return objectRecipe;
     }
 
     protected void buildReferencesAndDependencies(GBeanData gbeanData,
-        GBeanInfo gbeanInfo,
-        Set<GBeanReference> referencesSet,
-        Set<GBeanDependency> dependencySet) {
+                                                  GBeanInfo gbeanInfo,
+                                                  Set<GBeanReference> referencesSet,
+                                                  Set<GBeanDependency> dependencySet) {
         Map<String, ReferencePatterns> dataReferences = gbeanData.getReferences();
         for (GReferenceInfo referenceInfo : gbeanInfo.getReferences()) {
             String referenceName = referenceInfo.getName();
@@ -373,7 +384,7 @@ public final class GBeanInstance impleme
             attributesMap.put(attributeInfo.getName(), new GBeanAttribute(this, attributeInfo));
         }
         addManagedObjectAttributes(attributesMap);
-        
+
         return attributesMap.values().toArray(new GBeanAttribute[attributesMap.size()]);
     }
 
@@ -416,7 +427,7 @@ public final class GBeanInstance impleme
     }
 
     /**
-     * The bundle used to build this gbean.  
+     * The bundle used to build this gbean.
      *
      * @return the bundle used to build this gbean
      */
@@ -435,6 +446,7 @@ public final class GBeanInstance impleme
 
     /**
      * Gets the reason we are in the current state.
+     *
      * @return the reason we are in the current state
      */
     public String getStateReason() {
@@ -443,12 +455,13 @@ public final class GBeanInstance impleme
 
     /**
      * Sets the reason we are in the current state.
-     * @param reason  The reason we are in the current state
+     *
+     * @param reason The reason we are in the current state
      */
     public void setStateReason(String reason) {
         stateReason = reason;
     }
-    
+
     /**
      * The java type of the wrapped gbean instance
      *
@@ -601,18 +614,18 @@ public final class GBeanInstance impleme
         for (int i = 0; i < references.length; i++) {
             GBeanReference reference = references[i];
             String name = reference.getName();
-            if(reference instanceof GBeanSingleReference) {
+            if (reference instanceof GBeanSingleReference) {
                 AbstractName abstractName = ((GBeanSingleReference) reference).getTargetName();
-                if(abstractName != null) {
+                if (abstractName != null) {
                     gbeanData.setReferencePattern(name, abstractName);
                 }
-            } else if(reference instanceof GBeanCollectionReference) {
+            } else if (reference instanceof GBeanCollectionReference) {
                 Set patterns = ((GBeanCollectionReference) reference).getPatterns();
-                if(patterns != null) {
+                if (patterns != null) {
                     gbeanData.setReferencePatterns(name, patterns);
                 }
             } else {
-                throw new IllegalStateException("Unrecognized GBeanReference '"+reference.getClass().getName()+"'");
+                throw new IllegalStateException("Unrecognized GBeanReference '" + reference.getClass().getName() + "'");
             }
         }
         //TODO copy the dependencies??
@@ -931,7 +944,7 @@ public final class GBeanInstance impleme
             if (unsetProperties.size() > 0) {
                 throw new ConstructionException("Error creating gbean of class: " + gbeanInfo.getClassName() + ", attempting to set nonexistent properties: " + unsetProperties.keySet());
             }
-            
+
             // write the target variable in a synchronized block so it is available to all threads
             // we do this before calling the setters or start method so the bean can be called back
             // from a setter start method
@@ -952,7 +965,7 @@ public final class GBeanInstance impleme
                     throw e;
                 }
             }
-            
+
             if (instance instanceof GBeanLifecycle) {
                 checkIfShouldFail();
                 try {
@@ -970,6 +983,29 @@ public final class GBeanInstance impleme
                 if (instanceRegistry != null) {
                     instanceRegistry.instanceCreated(instance, this);
                 }
+                if (gbeanInfo.isOsgiService()) {
+                    String[] serviceInterfaces;
+                    if (this.serviceInterfaces != null) {
+                        serviceInterfaces = this.serviceInterfaces;
+                    } else if (instance instanceof ServiceInterfaces) {
+                        serviceInterfaces = ((ServiceInterfaces)instance).getServiceInterfaces();
+                    } else if (gbeanInfo.getServiceInterfaces().length > 0) {
+                        serviceInterfaces = gbeanInfo.getServiceInterfaces();
+                    } else {
+                        Set<String> classes = new HashSet<String>(gbeanInfo.getInterfaces());
+                        classes.add(gbeanInfo.getClassName());
+                        serviceInterfaces = classes.toArray(new String[classes.size()]);
+                    }
+                    Dictionary serviceProperties;
+                    if (this.serviceProperties != null) {
+                        serviceProperties = this.serviceProperties;
+                    } else {
+                        serviceProperties = new Hashtable();
+                        serviceProperties.put("org.apache.geronimo.abstractName", abstractName);
+                    }
+                    serviceRegistration = bundleContext.registerService(serviceInterfaces, instance, serviceProperties);
+                    log.debug("Registered gbean " + abstractName + " as osgi service under interfaces " + Arrays.asList(serviceInterfaces) + " with properties " + serviceProperties);
+                }
                 instanceState = RUNNING;
                 this.notifyAll();
             }
@@ -1064,7 +1100,7 @@ public final class GBeanInstance impleme
             }
             assert instanceState == RUNNING;
             stateReason = null;
-            
+
             // we are definately going to stop... if this fails the must clean up these variables
             instanceState = DESTROYING;
             instance = target;
@@ -1150,6 +1186,11 @@ public final class GBeanInstance impleme
             if (instanceRegistry != null) {
                 instanceRegistry.instanceDestroyed(instance);
             }
+            if (serviceRegistration != null) {
+                serviceRegistration.unregister();
+                serviceRegistration = null;
+                log.debug("unregistered gbean as osgi service: " + abstractName);
+            }
             startTime = 0;
         }
 
@@ -1206,7 +1247,11 @@ public final class GBeanInstance impleme
 
     }
 
-    private GBeanInfo rebuildGBeanInfo(GConstructorInfo constructor, String j2eeType) {
+    private GBeanInfo rebuildGBeanInfo(GConstructorInfo constructor,
+                                       String j2eeType,
+                                       int priority,
+                                       boolean osgiService,
+                                       String[] serviceInterfaces) {
         Set<GAttributeInfo> attributeInfos = new HashSet<GAttributeInfo>();
         for (int i = 0; i < attributes.length; i++) {
             GBeanAttribute attribute = attributes[i];
@@ -1227,14 +1272,18 @@ public final class GBeanInstance impleme
             interfaceInfos.add(interfaces[i]);
         }
 
-        return new GBeanInfo(name,
+        return new GBeanInfo(null,
+                name,
                 type.getName(),
                 j2eeType,
                 attributeInfos,
                 constructor,
                 operationInfos,
                 referenceInfos,
-                interfaceInfos);
+                interfaceInfos,
+                priority,
+                osgiService,
+                serviceInterfaces);
     }
 
     public boolean equals(Object obj) {

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanDataTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanDataTest.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanDataTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanDataTest.java Tue Jun 15 23:41:42 2010
@@ -23,6 +23,9 @@ import java.io.FileInputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
+import org.apache.geronimo.gbean.annotation.AnnotationGBeanInfoBuilder;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.OsgiService;
 import org.apache.geronimo.testsupport.TestSupport;
 
 /**
@@ -30,22 +33,44 @@ import org.apache.geronimo.testsupport.T
  */
 public class GBeanDataTest extends TestSupport {
 
-  public void testBackwardCompatibility() throws Exception {
-      FileInputStream fis = new FileInputStream(resolveFile("src/test/data/gbeandata/SERIALIZATION_-1012491431781444074.ser"));
-      ObjectInputStream is = new ObjectInputStream(fis);
-      is.readObject();
-    }
-    
+//    public void testBackwardCompatibility() throws Exception {
+//        FileInputStream fis = new FileInputStream(resolveFile("src/test/data/gbeandata/SERIALIZATION_-1012491431781444074.ser"));
+//        ObjectInputStream is = new ObjectInputStream(fis);
+//        is.readObject();
+//    }
+
     public void testCurrentSerialization() throws Exception {
         GBeanData beanData = new GBeanData();
-        
+
         ByteArrayOutputStream memOut = new ByteArrayOutputStream();
         ObjectOutputStream os = new ObjectOutputStream(memOut);
         os.writeObject(beanData);
-        
+
         ByteArrayInputStream memIn = new ByteArrayInputStream(memOut.toByteArray());
         ObjectInputStream is = new ObjectInputStream(memIn);
         is.readObject();
     }
-    
+
+    public void testCurrentSerialization2() throws Exception {
+        GBeanData beanData = new GBeanData(new AnnotationGBeanInfoBuilder(AnnotationGBean.class).buildGBeanInfo());
+        beanData.setServiceInterfaces(new String[] {TestSupport.class.getName()});
+        beanData.getServiceProperties().put("foo", "bar");
+
+        ByteArrayOutputStream memOut = new ByteArrayOutputStream();
+        ObjectOutputStream os = new ObjectOutputStream(memOut);
+        os.writeObject(beanData);
+
+        ByteArrayInputStream memIn = new ByteArrayInputStream(memOut.toByteArray());
+        ObjectInputStream is = new ObjectInputStream(memIn);
+        GBeanData beanData2 = (GBeanData) is.readObject();
+        assertEquals(1, beanData2.getServiceInterfaces().length);
+        assertEquals(TestSupport.class.getName(), beanData2.getServiceInterfaces()[0]);
+        assertEquals(1, beanData2.getServiceProperties().size());
+        assertEquals("bar", beanData2.getServiceProperties().get("foo"));
+    }
+
+    @GBean
+    @OsgiService
+    public static class AnnotationGBean {}
+
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java Tue Jun 15 23:41:42 2010
@@ -25,6 +25,9 @@ import java.io.ObjectOutputStream;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.geronimo.gbean.annotation.AnnotationGBeanInfoBuilder;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.OsgiService;
 import org.apache.geronimo.testsupport.TestSupport;
 import org.apache.geronimo.kernel.osgi.MockBundleContext;
 
@@ -94,12 +97,12 @@ public class GBeanInfoTest extends TestS
         assertEquals(gbeanInfo.toString(), MockGBean.getGBeanInfo().toString());
     }
 
-    public void testBackwardCompatibility() throws Exception {
-        FileInputStream fis = new FileInputStream(resolveFile("src/test/data/gbeaninfo/SERIALIZATION_-6198804067155550221.ser"));
-        ObjectInputStream is = new ObjectInputStream(fis);
-        GBeanInfo beanInfo = (GBeanInfo) is.readObject();
-        assertEquals(GBeanInfo.PRIORITY_NORMAL, beanInfo.getPriority());
-    }
+//    public void testBackwardCompatibility() throws Exception {
+//        FileInputStream fis = new FileInputStream(resolveFile("src/test/data/gbeaninfo/SERIALIZATION_-6198804067155550221.ser"));
+//        ObjectInputStream is = new ObjectInputStream(fis);
+//        GBeanInfo beanInfo = (GBeanInfo) is.readObject();
+//        assertEquals(GBeanInfo.PRIORITY_NORMAL, beanInfo.getPriority());
+//    }
 
     public void testCurrentSerialization() throws Exception {
         GBeanInfo beanInfo = MockGBean.GBEAN_INFO;
@@ -114,6 +117,20 @@ public class GBeanInfoTest extends TestS
         assertEquals(GBeanInfo.PRIORITY_CLASSLOADER, beanInfo.getPriority());
     }
     
+    public void testCurrentSerializationAnnotation() throws Exception {
+        GBeanInfo beanInfo = new AnnotationGBeanInfoBuilder(AnnotationGBean.class).buildGBeanInfo();
+
+        ByteArrayOutputStream memOut = new ByteArrayOutputStream();
+        ObjectOutputStream os = new ObjectOutputStream(memOut);
+        os.writeObject(beanInfo);
+
+        ByteArrayInputStream memIn = new ByteArrayInputStream(memOut.toByteArray());
+        ObjectInputStream is = new ObjectInputStream(memIn);
+        beanInfo = (GBeanInfo) is.readObject();
+        assertEquals(GBeanInfo.PRIORITY_NORMAL, beanInfo.getPriority());
+        assertEquals(true, beanInfo.isOsgiService());
+    }
+
     GBeanInfo gbeanInfo;
 
     final static String nonPersistentAttrName = "nonPersistentAttribute";
@@ -176,5 +193,11 @@ public class GBeanInfoTest extends TestS
         public String removeSomething(String something){
            return null; 
         }
+
+    }
+    @GBean(j2eeType = "Foo")
+    @OsgiService
+    public static class AnnotationGBean {
+
     }
 }

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/GenericConnectionManagerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/GenericConnectionManagerGBean.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/GenericConnectionManagerGBean.java (original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/GenericConnectionManagerGBean.java Tue Jun 15 23:41:42 2010
@@ -56,7 +56,6 @@ import org.osgi.framework.ServiceRegistr
 public class GenericConnectionManagerGBean extends GenericConnectionManager implements GBeanLifecycle, Serializable, Externalizable {
     private Kernel kernel;
     private AbstractName abstractName;
-    private transient ConnectionFactoryRegistration connectionRegistration;
     //externalizable format version
     private static final int VERSION = 1;
 
@@ -77,11 +76,6 @@ public class GenericConnectionManagerGBe
         
         doRecovery();
         
-        connectionRegistration = new ConnectionFactoryRegistration(this, 
-                                                                   bundleContext, 
-                                                                   abstractName, 
-                                                                   managedConnectionFactoryWrapper.getJndiName(), 
-                                                                   new String [] { managedConnectionFactoryWrapper.getConnectionFactoryInterface() });
     }
 
     public GenericConnectionManagerGBean() {
@@ -98,17 +92,6 @@ public class GenericConnectionManagerGBe
         }
     }
 
-    public void doFail() {
-    }
-
-    public void doStart() throws Exception {
-        connectionRegistration.register();
-    }
-   
-    public void doStop() throws Exception {
-        connectionRegistration.unregister();
-    }
-    
     private static SubjectSource getSubjectSource(boolean containerManagedSecurity) {
         if (containerManagedSecurity) {
             return new SubjectSource() {

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/JCAConnectionFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/JCAConnectionFactoryImpl.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/JCAConnectionFactoryImpl.java (original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/connector/wrapper/outbound/JCAConnectionFactoryImpl.java Tue Jun 15 23:41:42 2010
@@ -21,6 +21,7 @@ import java.util.Hashtable;
 import javax.management.ObjectName;
 import javax.resource.ResourceException;
 import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.OsgiService;
 import org.apache.geronimo.gbean.annotation.ParamReference;
 import org.apache.geronimo.gbean.annotation.ParamSpecial;
 import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
@@ -30,12 +31,17 @@ import org.apache.geronimo.kernel.Object
 import org.apache.geronimo.management.geronimo.JCAConnectionFactory;
 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
 import org.apache.geronimo.naming.ResourceSource;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceException;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * @version $Rev$ $Date$
  */
 @GBean(j2eeType = NameFactory.JCA_CONNECTION_FACTORY)
-public class JCAConnectionFactoryImpl implements JCAConnectionFactory, ResourceSource<ResourceException> {
+@OsgiService
+public class JCAConnectionFactoryImpl implements JCAConnectionFactory, ResourceSource<ResourceException>, ServiceFactory {
     private final String objectName;
     private final GenericConnectionManagerGBean connectionManager;
 
@@ -99,11 +105,24 @@ public class JCAConnectionFactoryImpl im
         }
     }
 
+    @Override
+    public Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
+        try {
+            return connectionManager.createConnectionFactory();
+        } catch (ResourceException e) {
+            throw new ServiceException("Error creating connection factory", e);
+        }
+    }
+
+    @Override
+    public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object o) {
+    }
 
     /**
      * ObjectName must match this pattern:
      * <p/>
      * domain:j2eeType=JCAConnectionFactory,name=MyName,J2EEServer=MyServer,JCAResource=MyJCAResource
+     * @param objectName ObjectName to verify for compliance to jsr77 rules.
      */
     private void verifyObjectName(ObjectName objectName) {
         if (objectName.isPattern()) {

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/datasource/DataSourceGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/datasource/DataSourceGBean.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/datasource/DataSourceGBean.java (original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-1_6/src/main/java/org/apache/geronimo/datasource/DataSourceGBean.java Tue Jun 15 23:41:42 2010
@@ -28,7 +28,6 @@ import javax.sql.ConnectionPoolDataSourc
 import javax.sql.DataSource;
 import javax.sql.XAConnection;
 import javax.sql.XADataSource;
-
 import org.apache.geronimo.connector.outbound.GenericConnectionManager;
 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
@@ -37,10 +36,9 @@ import org.apache.geronimo.connector.out
 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions;
 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
-import org.apache.geronimo.connector.wrapper.outbound.ConnectionFactoryRegistration;
 import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.OsgiService;
 import org.apache.geronimo.gbean.annotation.ParamAttribute;
 import org.apache.geronimo.gbean.annotation.ParamReference;
 import org.apache.geronimo.gbean.annotation.ParamSpecial;
@@ -50,7 +48,11 @@ import org.apache.geronimo.naming.Resour
 import org.apache.geronimo.transaction.manager.RecoverableTransactionManager;
 import org.apache.xbean.recipe.ObjectRecipe;
 import org.apache.xbean.recipe.Option;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceException;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tranql.connector.CredentialExtractor;
@@ -63,15 +65,15 @@ import org.tranql.connector.jdbc.Abstrac
  * @version $Revision$
  */
 @GBean
-public class DataSourceGBean implements GBeanLifecycle, ResourceSource<ResourceException> {
+@OsgiService
+public class DataSourceGBean implements ResourceSource<ResourceException>, ServiceFactory {
     
     private static final Logger log = LoggerFactory.getLogger(DataSourceGBean.class);
         
     private final DataSourceDescription dataSourceDescription;
     private final transient ClassLoader classLoader;
     private final transient GenericConnectionManager connectionManager;
-    private final transient ConnectionFactoryRegistration connectionRegistration;
-    
+
     public DataSourceGBean(@ParamAttribute(name="dataSourceDescription") DataSourceDescription dataSourceDescription,
                            @ParamAttribute(name="defaultMaxSize") int defaultMaxSize,
                            @ParamAttribute(name="defaultMinSize") int defaultMinSize,
@@ -91,7 +93,6 @@ public class DataSourceGBean implements 
         
         String dsName = dataSourceDescription.getName();
         String dsClass = dataSourceDescription.getClassName();
-        String dsJndiName = getOsgiJndiName();
         
         TransactionSupport transactionSupport;
         PoolingSupport pooling;
@@ -138,14 +139,21 @@ public class DataSourceGBean implements 
             new GenericConnectionManager(transactionSupport, pooling, null, connectionTracker, transactionManager, mcf, objectName, classLoader);
                 
         connectionManager.doRecovery();
-        
-        connectionRegistration = new ConnectionFactoryRegistration(connectionManager, 
-                                                                   bundleContext, 
-                                                                   abstractName, 
-                                                                   dsJndiName, 
-                                                                   new String [] { DataSource.class.getName() });
     }
     
+    @Override
+    public Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
+        try {
+            return connectionManager.createConnectionFactory();
+        } catch (ResourceException e) {
+            throw new ServiceException("Error creating connection factory", e);
+        }
+    }
+
+    @Override
+    public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object o) {
+    }
+
     private Object createDataSource() throws Exception {
         String className = dataSourceDescription.getClassName();
         Class clazz = classLoader.loadClass(className);
@@ -196,15 +204,7 @@ public class DataSourceGBean implements 
             properties.put(name, value);
         }
     }
-          
-    private String getOsgiJndiName() {
-        if (dataSourceDescription.getProperties() != null) {
-            return dataSourceDescription.getProperties().remove(ConnectionFactoryRegistration.OSGI_JNDI_SERVICE_NAME);
-        } else {
-            return null;
-        }        
-    }
-    
+
     private PoolingSupport createPool(int defaultMinSize, 
                                       int defaultMaxSize, 
                                       int defaultBlockingTimeoutMilliseconds, 
@@ -223,17 +223,6 @@ public class DataSourceGBean implements 
         return connectionManager.createConnectionFactory();
     }
     
-    public void doFail() {
-    }
-
-    public void doStart() throws Exception {
-        connectionRegistration.register();
-    }
- 
-    public void doStop() throws Exception {
-        connectionRegistration.unregister();
-    }
-      
     private class PooledConnectionDataSourceMCF extends AbstractPooledConnectionDataSourceMCF {
         
         public PooledConnectionDataSourceMCF(ConnectionPoolDataSource ds) {

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java (original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java Tue Jun 15 23:41:42 2010
@@ -167,6 +167,7 @@ public class ConnectorModuleBuilder impl
     private static QName CONNECTOR_QNAME = GerConnectorDocument.type.getDocumentElementName();
     static final String GERCONNECTOR_NAMESPACE = CONNECTOR_QNAME.getNamespaceURI();
     private static final Map<String, String> NAMESPACE_UPDATES = new HashMap<String, String>();
+    public static final String OSGI_JNDI_SERVICE_NAME = "osgi.jndi.service.name";
 
     static {
         NAMESPACE_UPDATES.put("http://geronimo.apache.org/xml/ns/j2ee/connector", "http://geronimo.apache.org/xml/ns/j2ee/connector-1.2");
@@ -1321,9 +1322,15 @@ public class ConnectorModuleBuilder impl
         setDynamicGBeanDataAttributes(managedConnectionFactoryInstanceGBeanData, connectiondefinitionInstance.getConfigPropertySettingArray(), bundle);
 
         String jndiName = connectiondefinitionInstance.getJndiName();
-        if (jndiName != null) {
-            managedConnectionFactoryInstanceGBeanData.setAttribute("jndiName", jndiName.trim());
+        if (jndiName == null) {
+            jndiName = connectionFactoryAbstractName.getArtifact().getGroupId() + "/" +
+                            connectionFactoryAbstractName.getArtifact().getArtifactId() + "/" +
+                            connectionFactoryAbstractName.getNameProperty("j2eeType") + "/" +
+                            connectionFactoryAbstractName.getNameProperty("name");
+        } else {
+            jndiName = jndiName.trim();
         }
+//        managedConnectionFactoryInstanceGBeanData.setAttribute("jndiName", jndiName.trim());
         
         //Check if Driver class is available here. This should be available in cl. If not log a warning as
         //the plan gets deployed and while starting GBean an error is thrown
@@ -1337,20 +1344,21 @@ public class ConnectorModuleBuilder impl
             }
         }
 
+        Set<String> implementedInterfaces = new HashSet<String>();
+        implementedInterfaces.add((String) managedConnectionFactoryInstanceGBeanData.getAttribute("connectionFactoryInterface"));
+        implementedInterfaces.add((String) managedConnectionFactoryInstanceGBeanData.getAttribute("connectionFactoryImplClass"));
         try {
             if (resourceAdapterAbstractName != null) {
                 managedConnectionFactoryInstanceGBeanData.setReferencePattern("ResourceAdapterWrapper", resourceAdapterAbstractName);
             }
             //additional interfaces implemented by connection factory
-            String[] implementedInterfaces = connectiondefinitionInstance.getImplementedInterfaceArray();
-            if (implementedInterfaces != null) {
-                for (int i = 0; i < implementedInterfaces.length; i++) {
-                    implementedInterfaces[i] = implementedInterfaces[i].trim();
+            String[] additionalInterfaces = connectiondefinitionInstance.getImplementedInterfaceArray();
+            if (additionalInterfaces != null) {
+                for (int i = 0; i < additionalInterfaces.length; i++) {
+                    implementedInterfaces.add(additionalInterfaces[i].trim());
                 }
-            } else {
-                implementedInterfaces = new String[0];
             }
-            managedConnectionFactoryInstanceGBeanData.setAttribute("implementedInterfaces", implementedInterfaces);
+            managedConnectionFactoryInstanceGBeanData.setAttribute("implementedInterfaces", implementedInterfaces.toArray(new String[implementedInterfaces.size()]));
 
         } catch (Exception e) {
             throw new DeploymentException(e);
@@ -1368,6 +1376,8 @@ public class ConnectorModuleBuilder impl
         // ConnectionFactory
         GBeanData connectionFactoryGBeanData = new GBeanData(connectionFactoryAbstractName, JCAConnectionFactoryImpl.class);
         connectionFactoryGBeanData.setReferencePattern("ConnectionManager", connectionManagerName);
+        connectionFactoryGBeanData.setServiceInterfaces(implementedInterfaces.toArray(new String[implementedInterfaces.size()]));
+        connectionFactoryGBeanData.getServiceProperties().put(OSGI_JNDI_SERVICE_NAME, jndiName);
 
         try {
             earContext.addGBean(connectionFactoryGBeanData);

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java (original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java Tue Jun 15 23:41:42 2010
@@ -27,6 +27,7 @@ import javax.annotation.sql.DataSourceDe
 import javax.resource.ResourceException;
 import javax.sql.DataSource;
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.connector.deployment.ConnectorModuleBuilder;
 import org.apache.geronimo.datasource.DataSourceDescription;
 import org.apache.geronimo.datasource.DataSourceGBean;
 import org.apache.geronimo.gbean.AbstractName;
@@ -168,6 +169,19 @@ public class DataSourceBuilder extends A
         
         dataSourceGBean.setReferencePattern("ConnectionTracker", earContext.getConnectionTrackerName());
         dataSourceGBean.setReferencePattern("TransactionManager", earContext.getTransactionManagerName());
+
+        dataSourceGBean.setServiceInterfaces(new String[] {DataSource.class.getName()});
+        String osgiJndiName = null;
+        if (dsDescription.getProperties() != null) {
+            osgiJndiName = dsDescription.getProperties().get(ConnectorModuleBuilder.OSGI_JNDI_SERVICE_NAME);
+        }
+        if (osgiJndiName == null) {
+            osgiJndiName = dataSourceAbstractName.getArtifact().getGroupId() + "/" +
+                     dataSourceAbstractName.getArtifact().getArtifactId() + "/" +
+                     dataSourceAbstractName.getNameProperty("j2eeType") + "/" +
+                     dataSourceAbstractName.getNameProperty("name");
+        }
+        dataSourceGBean.getServiceProperties().put(ConnectorModuleBuilder.OSGI_JNDI_SERVICE_NAME, osgiJndiName);
         
         earContext.addGBean(dataSourceGBean);
                 

Modified: geronimo/server/trunk/plugins/connector-1_6/transaction-1_6/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/transaction-1_6/src/main/history/dependencies.xml?rev=955091&r1=955090&r2=955091&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/transaction-1_6/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/connector-1_6/transaction-1_6/src/main/history/dependencies.xml Tue Jun 15 23:41:42 2010
@@ -23,6 +23,16 @@
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.framework</groupId>
+        <artifactId>geronimo-cli</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.framework</groupId>
+        <artifactId>geronimo-main</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.framework</groupId>
         <artifactId>j2ee-security</artifactId>
         <type>car</type>
     </dependency>
@@ -38,15 +48,50 @@
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.specs</groupId>
+        <artifactId>geronimo-ejb_3.1_spec</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.specs</groupId>
         <artifactId>geronimo-j2ee-connector_1.6_spec</artifactId>
         <type>jar</type>
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.specs</groupId>
+        <artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.specs</groupId>
+        <artifactId>geronimo-jaxrpc_1.1_spec</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.specs</groupId>
         <artifactId>geronimo-jpa_2.0_spec</artifactId>
         <type>jar</type>
     </dependency>
     <dependency>
+        <groupId>org.apache.geronimo.specs</groupId>
+        <artifactId>geronimo-osgi-registry</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.servicemix.bundles</groupId>
+        <artifactId>org.apache.servicemix.bundles.xpp3</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-bundleutils</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-finder</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.tranql</groupId>
         <artifactId>tranql-connector</artifactId>
         <type>jar</type>



Mime
View raw message