geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r765145 - in /geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi: context/ModuleContextImpl.java reflect/ComponentMetadataImpl.java
Date Wed, 15 Apr 2009 11:45:39 GMT
Author: rickmcguire
Date: Wed Apr 15 11:45:38 2009
New Revision: 765145

URL: http://svn.apache.org/viewvc?rev=765145&view=rev
Log:
starting to fill in the blanks in ModuleContextImpl

Modified:
    geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/context/ModuleContextImpl.java
    geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/reflect/ComponentMetadataImpl.java

Modified: geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/context/ModuleContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/context/ModuleContextImpl.java?rev=765145&r1=765144&r2=765145&view=diff
==============================================================================
--- geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/context/ModuleContextImpl.java
(original)
+++ geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/context/ModuleContextImpl.java
Wed Apr 15 11:45:38 2009
@@ -17,14 +17,31 @@
 package org.apache.geronimo.osgi.context;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Set;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.HashMap;
 
 import org.osgi.framework.BundleContext;
 import org.osgi.service.blueprint.context.ModuleContext;
 import org.osgi.service.blueprint.context.NoSuchComponentException;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.LocalComponentMetadata;
+import org.osgi.service.blueprint.reflect.ServiceReferenceComponentMetadata;
+import org.osgi.service.blueprint.reflect.ServiceExportComponentMetadata;
+
+import org.apache.geronimo.osgi.reflect.ComponentMetadataImpl;
 
 public class ModuleContextImpl implements ModuleContext {
+    // this is our mapping between names and the associated metadata
+    protected Map<String,ComponentMetadataImpl> components = new HashMap<String,ComponentMetadataImpl>();
+    // the set of local components
+    protected ArrayList<LocalComponentMetadata> localComponents = new ArrayList<LocalComponentMetadata>();
+    // the set of exported metadata information
+    protected ArrayList<ServiceExportComponentMetadata> exportedServices = new ArrayList<ServiceExportComponentMetadata>();
+    // the set of exported metadata information
+    protected ArrayList<ServiceReferenceComponentMetadata> referencedServices = new
ArrayList<ServiceReferenceComponentMetadata>();
 
     private BundleContext bundleContext;
 
@@ -37,31 +54,56 @@
         return this.bundleContext;
     }
 
+    /**
+     * Retrieve the component instance for a given named
+     * component.
+     *
+     * @param name   The target name.
+     *
+     * @return If the component exists, returns the given component instance.
+     * @exception NoSuchComponentException
+     */
     public Object getComponent(String name) throws NoSuchComponentException {
-        return null;
+        // the metadata creates/manages its own components
+        return ((ComponentMetadataImpl)getComponentMetadata(name)).getComponent();
     }
 
     public ComponentMetadata getComponentMetadata(String name) throws NoSuchComponentException
{
-        return null;
+        // first check the metadata mapping...we throw the exception
+        // if not found
+        ComponentMetadataImpl meta = components.get(name);
+        if (meta == null) {
+            throw new NoSuchComponentException("Unknown blueprint component " + name + "
for bundle " + getBundleSymbolicName());
+        }
+        return meta;
     }
 
     public Set getComponentNames() {
-        return null;
+        // just return the keyset for our collection
+        return Collections.unmodifiableSet(components.keySet());
     }
 
     public Collection getExportedServicesMetadata() {
-        return null;
+        // we need an immutable version of this
+        return Collections.unmodifiableCollection(exportedServices);
     }
 
     public Collection getLocalComponentsMetadata() {
-        return null;
+        // we need an immutable version of this
+        return Collections.unmodifiableCollection(localComponents);
     }
 
     public Collection getReferencedServicesMetadata() {
-        return null;
+        // we need an immutable version of this
+        return Collections.unmodifiableCollection(referencedServices);
     }
 
     public void destroy() {
         System.out.println("Module context destroyed: " + this.bundleContext);
     }
+
+
+    protected String getBundleSymbolicName() {
+        return bundleContext.getBundle().getSymbolicName();
+    }
 }
\ No newline at end of file

Modified: geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/reflect/ComponentMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/reflect/ComponentMetadataImpl.java?rev=765145&r1=765144&r2=765145&view=diff
==============================================================================
--- geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/reflect/ComponentMetadataImpl.java
(original)
+++ geronimo/sandbox/gawor/rfc124/extender/src/main/java/org/apache/geronimo/osgi/reflect/ComponentMetadataImpl.java
Wed Apr 15 11:45:38 2009
@@ -20,6 +20,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.osgi.service.blueprint.context.ComponentDefinitionException;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 
 public class ComponentMetadataImpl implements ComponentMetadata {
@@ -74,5 +75,37 @@
     public void addDependency(String name) {
         dependencies.add(name);
     }
+
+
+    /**
+     * Method for creating a component instance.  This will
+     * handle singleton/prototype scope, returning either the
+     * singleton instance or create a new instance, as appropriate
+     * for the component type.
+     *
+     * @return The instantiated component object.
+     * @exception ComponentDefinitionException
+     *                   Thrown for any errors involved with creating the component
+     *                   instance.
+     */
+    public Object getComponent() throws ComponentDefinitionException {
+        throw new ComponentDefinitionException("Not implemented for component type");
+    }
+
+
+    /**
+     * Method for creating a component instance.  This will
+     * create a new instance, regardless of the scope
+     * definition.  Used for implementing bundle scope
+     * in service factories.
+     *
+     * @return The instantiated component object.
+     * @exception ComponentDefinitionException
+     *                   Thrown for any errors involved with creating the component
+     *                   instance.
+     */
+    public Object createComponent() throws ComponentDefinitionException {
+        throw new ComponentDefinitionException("Not implemented for component type");
+    }
 }
 



Mime
View raw message