[jboss-cvs] JBossAS SVN: r96606 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 19 19:10:16 EST 2009


Author: alesj
Date: 2009-11-19 19:10:15 -0500 (Thu, 19 Nov 2009)
New Revision: 96606

Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiScopeInfo.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
Fix scope info usage #3.

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiScopeInfo.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiScopeInfo.java	2009-11-19 23:56:49 UTC (rev 96605)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiScopeInfo.java	2009-11-20 00:10:15 UTC (rev 96606)
@@ -34,9 +34,12 @@
  */
 public class OSGiScopeInfo extends AbstractScopeInfo
 {
-   private OSGiScopeInfo(Object name, String className)
+   private OSGiServiceState serviceState;
+
+   private OSGiScopeInfo(Object name, String className, OSGiServiceState serviceState)
    {
       super(name, className);
+      this.serviceState = serviceState;
    }
 
    /**
@@ -45,30 +48,37 @@
     * @param name the name
     * @param className the class name
     * @param clazz the class
+    * @param serviceState the service state
     * @return new scope info
     */
-   static ScopeInfo createScopeInfo(Object name, String className, Class<?> clazz)
+   static ScopeInfo createScopeInfo(Object name, String className, Class<?> clazz, OSGiServiceState serviceState)
    {
       if (className == null && clazz != null)
          className = clazz.getName();
 
-      OSGiScopeInfo result = new OSGiScopeInfo(name, className);
+      OSGiScopeInfo result = new OSGiScopeInfo(name, className, serviceState);
       if (clazz != null)
-         result.update(clazz);
+      {
+         ScopeKey key = result.getScope();
+         key.addScope(new Scope(CommonLevels.CLASS, clazz));
+      }
       return result;
    }
 
-   /**
-    * Add class scope.
-    *
-    * @param clazz the class
-    */
-   void update(Class<?> clazz)
+   @Override
+   public ScopeKey getScope()
    {
-      if (clazz == null)
-         throw new IllegalArgumentException("Null class");
+      // THIS IS A HACK - the scope originally gets initialise with a class name, we fix it to have the class
+      ScopeKey key = super.getScope();
+      Scope scope = key.getScope(CommonLevels.CLASS);
+      if (scope == null)
+         return key;
+      Object qualifier = scope.getQualifier();
+      if (qualifier instanceof Class)
+         return key;
 
-      ScopeKey key = getScope();
+      Class<?> clazz = serviceState.getService().getClass();
       key.addScope(new Scope(CommonLevels.CLASS, clazz));
+      return key;
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-11-19 23:56:49 UTC (rev 96605)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-11-20 00:10:15 UTC (rev 96606)
@@ -195,9 +195,19 @@
       else if (clazzes.length == 1)
          className = clazzes[0];
 
-      setScopeInfo(OSGiScopeInfo.createScopeInfo(getName(), className, clazz));
+      setScopeInfo(OSGiScopeInfo.createScopeInfo(getName(), className, clazz, this));
    }
 
+   /**
+    * Get service directly.
+    *
+    * @return the service
+    */
+   Object getService()
+   {
+      return getService(bundleState);
+   }
+
    @Override
    public Object getTarget()
    {
@@ -207,12 +217,12 @@
    public Object ungetTarget()
    {
       bundleState.ungetService(this);
-      return getService(bundleState);
+      return getService();
    }
 
    public Object invoke(String name, Object[] parameters, String[] signature) throws Throwable
    {
-      Object service = getService(bundleState);
+      Object service = getService();
       return getBeanInfo().invoke(service, name, signature, parameters);
    }
 
@@ -232,13 +242,13 @@
 
    public Object get(String name) throws Throwable
    {
-      Object service = getService(bundleState);
+      Object service = getService();
       return getBeanInfo().getProperty(service, name);
    }
 
    public void set(String name, Object value) throws Throwable
    {
-      Object service = getService(bundleState);
+      Object service = getService();
       getBeanInfo().setProperty(service, name, value);
    }
 
@@ -250,7 +260,7 @@
          {
             Kernel kernel = bundleState.getBundleManager().getKernel();
             KernelConfigurator configurator = kernel.getConfigurator();
-            Object service = getService(bundleState);
+            Object service = getService();
             if (service != null)
                beanInfo = configurator.getBeanInfo(service.getClass());
          }
@@ -262,12 +272,6 @@
       return beanInfo;
    }
 
-   @Override
-   public OSGiScopeInfo getScopeInfo()
-   {
-      return (OSGiScopeInfo)super.getScopeInfo();
-   }
-
    /**
     * Get the service.
     * 
@@ -296,7 +300,6 @@
             {
                service = checkObjClass(serviceFactory.getService(bundleState.getBundle(), getRegistration()));
                serviceCache.put(bundleState, service);
-               getScopeInfo().update(service.getClass());
             }
             catch (Throwable t)
             {




More information about the jboss-cvs-commits mailing list