[jboss-osgi-commits] JBoss-OSGI SVN: r97440 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Dec 3 23:14:01 EST 2009


Author: alesj
Date: 2009-12-03 23:13:58 -0500 (Thu, 03 Dec 2009)
New Revision: 97440

Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
Prepare code for SF fix.
(can fail atm as I didn't upload new Kernel snapshot yet)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-04 04:01:59 UTC (rev 97439)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-04 04:13:58 UTC (rev 97440)
@@ -1228,7 +1228,7 @@
     * @param clazz the class
     * @return class or null
     */
-   private Class<?> loadClass(Bundle bundle, String clazz)
+   Class<?> loadClass(Bundle bundle, String clazz)
    {
       try
       {

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-12-04 04:01:59 UTC (rev 97439)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java	2009-12-04 04:13:58 UTC (rev 97440)
@@ -96,6 +96,9 @@
    /** The service or service factory */
    private Object serviceOrFactory;
 
+   /** Is this service facotry */
+   private boolean isServiceFactory;
+
    /** The service factory provided service cache */
    private Map<AbstractBundleState, Object> serviceCache;
 
@@ -136,8 +139,9 @@
       this.bundleState = bundleState;
       this.clazzes = clazzes;
       this.serviceOrFactory = service;
+      this.isServiceFactory = (service instanceof ServiceFactory);
 
-      if (service instanceof ServiceFactory == false)
+      if (isServiceFactory == false)
          checkObjClass(service);
 
       if (properties != null)
@@ -222,10 +226,16 @@
       Class<?> clazz = null;
 
       Object target = serviceOrFactory;
-      if (target != null && target instanceof ServiceFactory == false)
+      if (isServiceFactory == false)
+      {
          clazz = target.getClass();
+      }
       else if (clazzes.length == 1)
+      {
          className = clazzes[0];
+         OSGiBundleManager manager = bundleState.getBundleManager();
+         clazz = manager.loadClass(bundleState, className);
+      }
 
       ScopeInfo info = OSGiScopeInfo.createScopeInfo(getName(), className, clazz, this);
       setScopeInfo(info);
@@ -273,8 +283,7 @@
    @Override
    public Object getTarget()
    {
-      // get service directly
-      return getService(bundleState);
+      return isServiceFactory ? null : serviceOrFactory;
    }
 
    protected Object getActualUser(ControllerContext context)
@@ -322,6 +331,9 @@
     */
    protected BeanInfo getBeanInfo()
    {
+      if (isServiceFactory)
+         throw new IllegalArgumentException("Cannot use DispatchContext on ServiceFactory: " + this);
+
       if (isUnregistered())
          return null;
 
@@ -329,7 +341,8 @@
       {
          try
          {
-            Kernel kernel = bundleState.getBundleManager().getKernel();
+            OSGiBundleManager manager = bundleState.getBundleManager();
+            Kernel kernel = manager.getKernel();
             KernelConfigurator configurator = kernel.getConfigurator();
             Object service = getTarget(); // should not be null, we're not unregistered
             beanInfo = configurator.getBeanInfo(service.getClass());
@@ -470,13 +483,13 @@
       if (ct == null)
          return null;
 
+      OSGiBundleManager manager = bundleState.getBundleManager();
       Set<Object> users = ct.getUsers(this);
       Set<Bundle> bundles = new HashSet<Bundle>();
       for (Object user : users)
       {
          if (ct.getUsedByCount(this, user) > 0)
          {
-            OSGiBundleManager manager = bundleState.getBundleManager();
             AbstractBundleState abs = manager.getBundleForUser(user);
             bundles.add(abs.getBundleInternal());
          }



More information about the jboss-osgi-commits mailing list