[jboss-osgi-commits] JBoss-OSGI SVN: r96816 - 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
Tue Nov 24 07:02:09 EST 2009
Author: alesj
Date: 2009-11-24 07:02:08 -0500 (Tue, 24 Nov 2009)
New Revision: 96816
Added:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
Log:
[JBOSGI-141]; add context registry action.
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java (from rev 96803, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextRegistryAction.java 2009-11-24 12:02:08 UTC (rev 96816)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.framework.bundle;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.tracker.ContextRegistry;
+
+/**
+ * Register osgi service into context registry.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+class ContextRegistryAction extends OSGiServiceAction
+{
+ /**
+ * Get context registry.
+ *
+ * @param context the context
+ * @return context registry or null if cannot be applied
+ */
+ protected ContextRegistry getContextRegistry(ControllerContext context)
+ {
+ Controller controller = context.getController();
+ return (controller instanceof ContextRegistry) ? ContextRegistry.class.cast(controller) : null;
+ }
+
+ /**
+ * Register / unregister contex under exposed classes to context registry.
+ *
+ * @param context the context
+ * @param register the registry
+ * @throws Throwable for any error
+ */
+ protected void handleContext(OSGiServiceState context, boolean register) throws Throwable
+ {
+ ContextRegistry registry = getContextRegistry(context);
+ if (registry != null)
+ {
+ ClassLoader cl = context.getClassLoader();
+ String[] classes = context.getClasses();
+ for (String clazz : classes)
+ {
+ Class<?> exposedClass = cl.loadClass(clazz);
+ if (register)
+ registry.registerInstantiatedContext(context, exposedClass);
+ else
+ registry.unregisterInstantiatedContext(context, exposedClass);
+ }
+ }
+ }
+
+ protected void installAction(OSGiServiceState context) throws Throwable
+ {
+ handleContext(context, true);
+ }
+
+ protected void uninstallAction(OSGiServiceState context)
+ {
+ try
+ {
+ handleContext(context, false);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Ignoring exception at un-registering context: " + t);
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java 2009-11-24 11:47:27 UTC (rev 96815)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java 2009-11-24 12:02:08 UTC (rev 96816)
@@ -21,7 +21,11 @@
*/
package org.jboss.osgi.framework.bundle;
-import org.jboss.dependency.spi.ControllerContext;
+import java.util.Collections;
+import java.util.Map;
+
+import org.jboss.dependency.plugins.AbstractControllerContextActions;
+import org.jboss.dependency.plugins.action.ControllerContextAction;
import org.jboss.dependency.spi.ControllerContextActions;
import org.jboss.dependency.spi.ControllerState;
@@ -30,15 +34,22 @@
*
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
*/
-class OSGiControllerContextActions implements ControllerContextActions
+class OSGiControllerContextActions extends AbstractControllerContextActions
{
static final ControllerContextActions ACTIONS = new OSGiControllerContextActions();
-
- public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+
+ private OSGiControllerContextActions()
{
+ super(getActions());
}
- public void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+ /**
+ * Get actions.
+ *
+ * @return the actions
+ */
+ private static Map<ControllerState, ControllerContextAction> getActions()
{
+ return Collections.<ControllerState, ControllerContextAction>singletonMap(ControllerState.INSTANTIATED, new ContextRegistryAction());
}
}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java 2009-11-24 12:02:08 UTC (rev 96816)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.framework.bundle;
+
+import org.jboss.dependency.plugins.action.SimpleControllerContextAction;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Handle OSGi service context.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class OSGiServiceAction extends SimpleControllerContextAction<OSGiServiceState>
+{
+ protected Logger log = Logger.getLogger(getClass());
+
+ protected OSGiServiceState contextCast(ControllerContext context)
+ {
+ return OSGiServiceState.class.cast(context);
+ }
+
+ protected boolean validateContext(ControllerContext context)
+ {
+ return (context instanceof OSGiServiceState);
+ }
+}
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list