[jboss-cvs] JBossAS SVN: r97229 - 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
Tue Dec 1 08:52:57 EST 2009
Author: alesj
Date: 2009-12-01 08:52:56 -0500 (Tue, 01 Dec 2009)
New Revision: 97229
Added:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DictionaryFactory.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceStateDictionaryFactory.java
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
Log:
Introduce instance metadata factory - adds OSGi's Dictionary to MDR.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java 2009-12-01 13:48:30 UTC (rev 97228)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java 2009-12-01 13:52:56 UTC (rev 97229)
@@ -30,6 +30,7 @@
import org.jboss.metadata.spi.scope.CommonLevels;
import org.jboss.metadata.spi.scope.Scope;
import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
/**
* Describe osgi service.
@@ -47,6 +48,16 @@
ScopeKey key = new ScopeKey(scope);
MutableMetaDataRepository mutable = repository.getMetaDataRepository();
MetaDataRetrieval retrieval = mutable.getMetaDataRetrieval(key);
+ if (retrieval == null)
+ {
+ retrieval = new MemoryMetaDataLoader(key);
+ mutable.addMetaDataRetrieval(retrieval);
+ }
+ else if (retrieval.retrieveMetaData(Dictionary.class) != null)
+ {
+ return; // we already have Dictionary
+ }
+
if (retrieval instanceof MutableMetaDataLoader)
{
MutableMetaDataLoader mmdl = (MutableMetaDataLoader)retrieval;
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DictionaryFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DictionaryFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DictionaryFactory.java 2009-12-01 13:52:56 UTC (rev 97229)
@@ -0,0 +1,49 @@
+/*
+* 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 java.util.Dictionary;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Get OSGi's dictionary from controller context instance.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface DictionaryFactory<T extends ControllerContext>
+{
+ /**
+ * Get context type.
+ *
+ * @return the context type
+ */
+ Class<T> getContextType();
+
+ /**
+ * Get dictionary for context.
+ *
+ * @param context the context
+ * @return dictionary
+ */
+ Dictionary<String, Object> getDictionary(T context);
+}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java (from rev 97217, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/InstanceMetaDataRetrievalFactory.java 2009-12-01 13:52:56 UTC (rev 97229)
@@ -0,0 +1,115 @@
+/*
+* 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 java.util.Dictionary;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalFactory;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * Add OSGi's dictionary to MDR.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class InstanceMetaDataRetrievalFactory implements MetaDataRetrievalFactory
+{
+ private Controller controller;
+ private Set<DictionaryFactory> factories = new CopyOnWriteArraySet<DictionaryFactory>();
+
+ public InstanceMetaDataRetrievalFactory(Controller controller)
+ {
+ if (controller == null)
+ throw new IllegalArgumentException("Null controller");
+ this.controller = controller;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public MetaDataRetrieval getMetaDataRetrieval(Scope scope)
+ {
+ if (scope == null)
+ throw new IllegalArgumentException("Null scope");
+ if (CommonLevels.INSTANCE.equals(scope.getScopeLevel()) == false)
+ throw new IllegalArgumentException("Not an instance scope: " + scope);
+
+ MemoryMetaDataLoader loader = new MemoryMetaDataLoader(new ScopeKey(scope));
+ Object qualifier = scope.getQualifier();
+ ControllerContext context = controller.getContext(qualifier, null);
+ if (context != null)
+ {
+ DictionaryFactory factory = null;
+ for (DictionaryFactory df : factories)
+ {
+ Class<?> contextType = df.getContextType();
+ if (contextType.isInstance(context))
+ {
+ factory = df;
+ break;
+ }
+ }
+ if (factory != null)
+ {
+ Dictionary<String, Object> dictionary = factory.getDictionary(context);
+ loader.addMetaData(dictionary, Dictionary.class);
+ }
+ }
+ return loader;
+ }
+
+ /**
+ * Add dictonary factory.
+ *
+ * @param factory the factory
+ * @return Set#add
+ */
+ public boolean addFactory(DictionaryFactory factory)
+ {
+ if (factory == null)
+ throw new IllegalArgumentException("Null factory");
+ if (factory.getContextType() == null)
+ throw new IllegalArgumentException("Null context type on factory: " + factory);
+
+ return factories.add(factory);
+ }
+
+ /**
+ * Remove dictonary factory.
+ *
+ * @param factory the factory
+ * @return Set#add
+ */
+ public boolean removeFactory(DictionaryFactory factory)
+ {
+ if (factory == null)
+ throw new IllegalArgumentException("Null factory");
+
+ return factories.remove(factory);
+ }
+}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java 2009-12-01 13:52:56 UTC (rev 97229)
@@ -0,0 +1,48 @@
+/*
+* 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 java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.osgi.framework.Constants;
+
+/**
+ * Kernel dictionary factory.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class KernelDictionaryFactory implements DictionaryFactory<KernelControllerContext>
+{
+ public Class<KernelControllerContext> getContextType()
+ {
+ return KernelControllerContext.class;
+ }
+
+ public Dictionary<String, Object> getDictionary(KernelControllerContext context)
+ {
+ Dictionary<String, Object> table = new Hashtable<String, Object>();
+ table.put(Constants.OBJECTCLASS, new String[0]);
+ return table;
+ }
+}
\ No newline at end of file
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-01 13:48:30 UTC (rev 97228)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-12-01 13:52:56 UTC (rev 97229)
@@ -68,6 +68,8 @@
import org.jboss.metadata.spi.loader.MutableMetaDataLoader;
import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalFactory;
+import org.jboss.metadata.spi.scope.CommonLevels;
import org.jboss.metadata.spi.scope.ScopeKey;
import org.jboss.osgi.deployment.deployer.Deployment;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
@@ -151,6 +153,9 @@
/** The deployment registry */
private DeploymentRegistry registry;
+ /** The instance metadata factory */
+ private MetaDataRetrievalFactory factory;
+
/** The executor */
private Executor executor;
@@ -271,9 +276,38 @@
repository.removeMetaDataRetrieval(mmdl.getScope());
}
}
+
+ if (register)
+ {
+ MetaDataRetrievalFactory mdrFactory = factory;
+ if (mdrFactory == null)
+ {
+ Controller controller = kernel.getController();
+ InstanceMetaDataRetrievalFactory imdrf = new InstanceMetaDataRetrievalFactory(controller);
+ imdrf.addFactory(new OSGiServiceStateDictionaryFactory());
+ imdrf.addFactory(new KernelDictionaryFactory());
+ // TODO - JMX?
+ mdrFactory = imdrf;
+ }
+ repository.addMetaDataRetrievalFactory(CommonLevels.INSTANCE, mdrFactory);
+ }
+ else
+ {
+ repository.removeMetaDataRetrievalFactory(CommonLevels.INSTANCE);
+ }
}
/**
+ * Set instance metadata factory.
+ *
+ * @param factory the instance metadata factory
+ */
+ public void setInstanceMetaDataFactory(MetaDataRetrievalFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ /**
* Get bundle for user tracker.
*
* @param user the user tracker object
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceStateDictionaryFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceStateDictionaryFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceStateDictionaryFactory.java 2009-12-01 13:52:56 UTC (rev 97229)
@@ -0,0 +1,42 @@
+/*
+* 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 java.util.Dictionary;
+
+/**
+ * OSGi controller context dictionary factory.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class OSGiServiceStateDictionaryFactory implements DictionaryFactory<OSGiServiceState>
+{
+ public Class<OSGiServiceState> getContextType()
+ {
+ return OSGiServiceState.class;
+ }
+
+ public Dictionary<String, Object> getDictionary(OSGiServiceState context)
+ {
+ return new ServiceRefDictionary(context);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list