[jboss-cvs] JBossAS SVN: r84728 - in projects/jboss-felix/trunk/modules: integration/felix/src/main/resources and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 25 07:33:00 EST 2009


Author: alesj
Date: 2009-02-25 07:32:59 -0500 (Wed, 25 Feb 2009)
New Revision: 84728

Added:
   projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/ServletContextAttributeProvider.java
   projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AbstractAttributeProvider.java
   projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AttributeProvider.java
Removed:
   projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/KernelLocator.java
Modified:
   projects/jboss-felix/trunk/modules/integration/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
   projects/jboss-felix/trunk/modules/integration/felix/src/main/resources/osgi-jboss-beans.xml
   projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java
   projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfiguration.java
   projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfigurationProvider.java
   projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerConfigurationProvider.java
Log:
Remove the KernelLocator hack.

Modified: projects/jboss-felix/trunk/modules/integration/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-felix/trunk/modules/integration/deployer/src/main/resources/osgi-deployers-jboss-beans.xml	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/integration/deployer/src/main/resources/osgi-deployers-jboss-beans.xml	2009-02-25 12:32:59 UTC (rev 84728)
@@ -2,11 +2,6 @@
 
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
 
-  <!-- Locate the single instance of the kernel -->
-  <bean name="jboss.osgi:service=KernelLocator" class="org.jboss.osgi.spi.internal.KernelLocator">
-    <property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
-  </bean>
-
   <!-- The OSGiFramework -->
   <bean name="jboss.osgi:service=Framework" class="org.jboss.osgi.felix.framework.FelixIntegration">
     <property name="felixProperties">

Modified: projects/jboss-felix/trunk/modules/integration/felix/src/main/resources/osgi-jboss-beans.xml
===================================================================
--- projects/jboss-felix/trunk/modules/integration/felix/src/main/resources/osgi-jboss-beans.xml	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/integration/felix/src/main/resources/osgi-jboss-beans.xml	2009-02-25 12:32:59 UTC (rev 84728)
@@ -3,11 +3,6 @@
 -->
 <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd" xmlns="urn:jboss:bean-deployer:2.0">
 
-  <!-- Locate the single instance of the kernel -->
-  <bean name="jboss.osgi:service=KernelLocator" class="org.jboss.osgi.spi.internal.KernelLocator">
-    <property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
-  </bean>
-  
   <!-- The OSGiFramework -->
   <bean name="jboss.osgi:service=Framework" class="org.jboss.osgi.felix.framework.FelixIntegration">
     <property name="felixProperties">

Modified: projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java
===================================================================
--- projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -65,7 +65,7 @@
     super.init(config);
 
     // Get the MBeanServer
-    OSGiFramework framework = OSGiConfiguration.getFramework();
+    OSGiFramework framework = OSGiConfiguration.getFramework(new ServletContextAttributeProvider(config.getServletContext()));
     BundleContext context = framework.getSystemBundleContext();
     ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
     MicrocontainerService service = (MicrocontainerService)context.getService(sref);

Added: projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/ServletContextAttributeProvider.java
===================================================================
--- projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/ServletContextAttributeProvider.java	                        (rev 0)
+++ projects/jboss-felix/trunk/modules/service/http/src/main/java/org/jboss/osgi/service/http/ServletContextAttributeProvider.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.service.http;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.osgi.spi.framework.AbstractAttributeProvider;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ServletContextAttributeProvider extends AbstractAttributeProvider
+{
+   private ServletContext context;
+
+   public ServletContextAttributeProvider(ServletContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null servlet context.");
+
+      this.context = context;
+   }
+
+   public Object getAttribute(String name)
+   {
+      return context.getAttribute(name);
+   }
+}

Added: projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AbstractAttributeProvider.java
===================================================================
--- projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AbstractAttributeProvider.java	                        (rev 0)
+++ projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AbstractAttributeProvider.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.framework;
+
+/**
+ * Provide proper attributes/parameters for configuration.
+ *
+ * @author ales.justin at jboss.com
+ */
+public abstract class AbstractAttributeProvider implements AttributeProvider
+{
+   public <T> T getAttribute(String name, Class<T> expectedType)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+
+      if (expectedType == null)
+         throw new IllegalArgumentException("Null expected type.");
+
+      Object attribute = getAttribute(name);
+      if (attribute != null)
+      {
+         if (expectedType.isInstance(attribute) == false)
+            throw new IllegalArgumentException("Attribute not of expected type [" + expectedType + "]: " + attribute);
+
+         return expectedType.cast(attribute);
+      }
+      return null;
+   }
+}
\ No newline at end of file

Copied: projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AttributeProvider.java (from rev 84710, projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfiguration.java)
===================================================================
--- projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AttributeProvider.java	                        (rev 0)
+++ projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/AttributeProvider.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.framework;
+
+/**
+ * Provide proper attributes/parameters for configuration.
+ *
+ * @author ales.justin at jboss.com
+ */
+public interface AttributeProvider
+{
+   /**
+    * Get the attribute.
+    *
+    * @param name the attribute name
+    * @return attribute
+    */
+   Object getAttribute(String name);
+
+   /**
+    * Get the attribute.
+    *
+    * @param <T> exact attribute type
+    * @param name the attribute name
+    * @param expectedType the expected type
+    * @return attribute
+    */
+   <T> T getAttribute(String name, Class<T> expectedType);
+}
\ No newline at end of file

Modified: projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfiguration.java
===================================================================
--- projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfiguration.java	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfiguration.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -53,6 +53,7 @@
 
   /*
    * Get the OSGi Framework for this configuration
+   *
    * @return The configured instance of a Framework
    */
   public static OSGiFramework getFramework()
@@ -61,12 +62,26 @@
   }
 
   /*
+   * Get the OSGi Framework for this configuration
+   *
+   * @param attributeProvider the attribute provider
+   * @return The configured instance of a Framework
+   */
+  public static OSGiFramework getFramework(AttributeProvider attributeProvider)
+  {
+    return getConfigurationProvider().getFramework(attributeProvider);
+  }
+
+  /*
    * Get a Framework with a given name from this configuration
+   *
+   * @param attributeProvider the attribute provider
+   * @param frameworkName  the framework name
    * @return The configured instance of a Framework
    */
-  public static OSGiFramework getFramework(String frameworkName)
+  public static OSGiFramework getFramework(AttributeProvider attributeProvider, String frameworkName)
   {
-    return getConfigurationProvider().getFramework(frameworkName);
+    return getConfigurationProvider().getFramework(attributeProvider, frameworkName);
   }
 
   /*

Modified: projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfigurationProvider.java
===================================================================
--- projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfigurationProvider.java	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/framework/OSGiConfigurationProvider.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -37,15 +37,29 @@
 {
   /**
    * Get a Framework from this ConfigurationProvider
+   * Note: the instance itself *must* be a AttributeProvider
+   *
    * @return The configured instance of a Framework
+   * @throws IllegalArgumentException if this is not AttributeProvider instance
    */
    OSGiFramework getFramework();
-  
+
   /**
+   * Get a Framework from this ConfigurationProvider
+   *
+   * @param attributeProvider the attribute provider
+   * @return The configured instance of a Framework
+   */
+   OSGiFramework getFramework(AttributeProvider attributeProvider);
+
+  /**
    * Get a Framework with a given name from this ConfigurationProvider
+   *
+   * @param attributeProvider the attribute provider
+   * @param name the framework name
    * @return The configured instance of a Framework
    */
-   OSGiFramework getFramework(String name);
+   OSGiFramework getFramework(AttributeProvider attributeProvider, String name);
   
   /**
    * Configure this provider from the given URL

Deleted: projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/KernelLocator.java
===================================================================
--- projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/KernelLocator.java	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/KernelLocator.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.spi.internal;
-
-//$Id$
-
-import org.jboss.kernel.Kernel;
-
-/**
- * Locate the single instance of the kernel 
- * 
- * @author Thomas.Diesler at jboss.org
- * @since 12-May-2006
- */
-public class KernelLocator
-{
-   private static Kernel kernel;
-
-   public static Kernel getKernel()
-   {
-      return KernelLocator.kernel;
-   }
-
-   public void setKernel(Kernel kernel)
-   {
-      KernelLocator.kernel = kernel;
-   }
-}
\ No newline at end of file

Modified: projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerConfigurationProvider.java
===================================================================
--- projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerConfigurationProvider.java	2009-02-25 12:30:31 UTC (rev 84727)
+++ projects/jboss-felix/trunk/modules/spi/src/main/java/org/jboss/osgi/spi/internal/MicrocontainerConfigurationProvider.java	2009-02-25 12:32:59 UTC (rev 84728)
@@ -32,6 +32,8 @@
 import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.framework.OSGiConfigurationProvider;
 import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.osgi.spi.framework.AttributeProvider;
+import org.jboss.osgi.spi.framework.AbstractAttributeProvider;
 
 /**
  * The ConfigurationProvider provides a Framework through a given configuration method
@@ -39,7 +41,7 @@
  * @author thomas.diesler at jboss.com
  * @since 18-Jun-2008
  */
-public class MicrocontainerConfigurationProvider implements OSGiConfigurationProvider
+public class MicrocontainerConfigurationProvider extends AbstractAttributeProvider implements OSGiConfigurationProvider, AttributeProvider
 {
   /* The Framework bean name - jboss.osgi:service=Framework */
   public static final String DEFAULT_BEAN_NAME = "jboss.osgi:service=Framework";
@@ -47,19 +49,23 @@
   public static final String DEFAULT_BEANS_CONFIG = "osgi-jboss-beans.xml";
 
   private Kernel kernel;
-  
+
   public OSGiFramework getFramework()
   {
-    return getFramework(DEFAULT_BEAN_NAME);
+     return getFramework(this);
   }
 
+  public OSGiFramework getFramework(AttributeProvider attributeProvider)
+  {
+    return getFramework(attributeProvider, DEFAULT_BEAN_NAME);
+  }
+
   @SuppressWarnings("deprecation")
-  public OSGiFramework getFramework(String beanName)
+  public OSGiFramework getFramework(AttributeProvider attributeProvider, String beanName)
   {
+    kernel = attributeProvider.getAttribute(Kernel.class.getName(), Kernel.class);
+
     if (kernel == null)
-      kernel = KernelLocator.getKernel();
-    
-    if (kernel == null)
       configure(DEFAULT_BEANS_CONFIG);
 
     Controller controller = kernel.getController();
@@ -95,4 +101,17 @@
     if (kernel == null)
       throw new IllegalStateException("Cannot obtain kernel, after beans deployment");
   }
+
+   public Object getAttribute(String name)
+   {
+      if (kernel == null)
+         return null;
+
+      if (Kernel.class.getName().equals(name))
+         return kernel;
+
+      Controller controller = kernel.getController();
+      ControllerContext context = controller.getInstalledContext(name); 
+      return context.getTarget();
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list