geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r766261 - in /geronimo/sandbox/blueprint: ./ blueprint-api/ itests/ itests/src/test/java/org/apache/felix/blueprint/itests/ org.apache.felix.blueprint/ org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/ org.apache.felix.bl...
Date Sat, 18 Apr 2009 07:40:31 GMT
Author: gnodet
Date: Sat Apr 18 07:40:31 2009
New Revision: 766261

URL: http://svn.apache.org/viewvc?rev=766261&view=rev
Log:
Small refactoring: change the activator to only use a single SynchronousBundleListener and
use a thread to create the module contexts, change the parser to avoid class casts that are
not needed and could cause exceptions if custom parsing change the type of the metadata (the
spec does not really say anything about that), prepare the parser to have a multiple step
initialization (which will be required to wait for dependencies)

Added:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/AbstractBlueprintTest.java
Modified:
    geronimo/sandbox/blueprint/   (props changed)
    geronimo/sandbox/blueprint/blueprint-api/   (props changed)
    geronimo/sandbox/blueprint/itests/   (props changed)
    geronimo/sandbox/blueprint/itests/src/test/java/org/apache/felix/blueprint/itests/Test.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/   (props changed)
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/WaitForDependencyException.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
    geronimo/sandbox/blueprint/sample/   (props changed)

Propchange: geronimo/sandbox/blueprint/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Apr 18 07:40:31 2009
@@ -0,0 +1,4 @@
+*.iml
+*.ipr
+*.iws
+target

Propchange: geronimo/sandbox/blueprint/blueprint-api/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Apr 18 07:40:31 2009
@@ -0,0 +1,2 @@
+*.iml
+target

Propchange: geronimo/sandbox/blueprint/itests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Apr 18 07:40:31 2009
@@ -0,0 +1,2 @@
+*.iml
+target

Modified: geronimo/sandbox/blueprint/itests/src/test/java/org/apache/felix/blueprint/itests/Test.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/itests/src/test/java/org/apache/felix/blueprint/itests/Test.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/itests/src/test/java/org/apache/felix/blueprint/itests/Test.java
(original)
+++ geronimo/sandbox/blueprint/itests/src/test/java/org/apache/felix/blueprint/itests/Test.java
Sat Apr 18 07:40:31 2009
@@ -54,6 +54,7 @@
 	protected String[] getTestBundlesNames() {
         return new String[] {
                 getBundle("org.apache.xbean", "xbean-reflect"),
+                getBundle("org.apache.felix", "blueprint-api"),
                 getBundle("org.apache.felix", "org.apache.felix.blueprint"),
 		};
 	}

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Apr 18 07:40:31 2009
@@ -0,0 +1,2 @@
+*.iml
+target

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/Activator.java
Sat Apr 18 07:40:31 2009
@@ -25,6 +25,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import org.apache.felix.blueprint.HeaderParser.PathElement;
 import org.apache.felix.blueprint.context.DefaultModuleContextEventSender;
@@ -42,16 +44,15 @@
  *
  * TODO: handle ModuleContextListener
  */
-public class Activator implements BundleActivator, BundleListener {
+public class Activator implements BundleActivator, SynchronousBundleListener {
 
-    private StopBundleListener stopBundleListener = new StopBundleListener();
-    private Map<Bundle, ModuleContextImpl> contextMap = new HashMap<Bundle, ModuleContextImpl>();
+    private final ExecutorService executors = Executors.newSingleThreadExecutor();
+    private final Map<Bundle, ModuleContextImpl> contextMap = new HashMap<Bundle,
ModuleContextImpl>();
     private ModuleContextEventSender sender;
     private NamespaceHandlerRegistry handlers;
 
     public void start(BundleContext context) {
         System.out.println("Starting to listen for bundle events.");
-        context.addBundleListener(stopBundleListener);
         context.addBundleListener(this);
 
         sender = new DefaultModuleContextEventSender(context);
@@ -67,7 +68,7 @@
 
 
     public void stop(BundleContext context) {
-        context.removeBundleListener(stopBundleListener);
+        // TODO: destroy all contexts
         context.removeBundleListener(this);
         this.sender.destroy();
         this.handlers.destroy();
@@ -78,6 +79,8 @@
         System.out.println("bundle changed:" + event.getBundle().getSymbolicName() + "  "+
event.getType());
         if (event.getType() == BundleEvent.STARTED) {
             checkBundle(event.getBundle());
+        } else if (event.getType() == BundleEvent.STOPPING) {
+            destroyContext(event.getBundle());
         }
     }
 
@@ -103,7 +106,6 @@
                 }
             }
         }
-        
         if (urls.isEmpty()) {
             Enumeration e = bundle.findEntries("OSGI-INF/blueprint", "*.xml", true);
             if (e != null) {
@@ -113,22 +115,16 @@
                 }
             }
         }
-                
         if (!urls.isEmpty()) {
-            System.out.println("Found config files:" + urls);
-            ModuleContextImpl moduleContext = new ModuleContextImpl(bundle.getBundleContext(),
sender, handlers, urls);
+            final ModuleContextImpl moduleContext = new ModuleContextImpl(bundle.getBundleContext(),
sender, handlers, urls);
             contextMap.put(bundle, moduleContext);
-            moduleContext.create();
+            executors.submit(new Runnable() {
+                public void run() {
+                    moduleContext.create();
+                }
+            });
         }
     }
 
 
-    private class StopBundleListener implements SynchronousBundleListener {
-        public void bundleChanged(BundleEvent event) {
-            if (event.getType() == BundleEvent.STOPPING) {
-                destroyContext(event.getBundle());
-            }
-        }
-    }
-
 }

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
Sat Apr 18 07:40:31 2009
@@ -52,6 +52,7 @@
 import org.osgi.service.blueprint.reflect.SetValue;
 import org.osgi.service.blueprint.reflect.TypedStringValue;
 import org.osgi.service.blueprint.reflect.Value;
+import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
 
 /**
  * TODO: javadoc

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java
Sat Apr 18 07:40:31 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.blueprint.context;
 
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -26,18 +27,16 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.net.URL;
 
-import org.apache.felix.blueprint.HeaderParser.PathElement;
-import org.apache.felix.blueprint.convert.ConversionServiceImpl;
-import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
-import org.apache.felix.blueprint.namespace.NamespaceHandlerRegistryImpl;
 import org.apache.felix.blueprint.BlueprintConstants;
 import org.apache.felix.blueprint.HeaderParser;
+import org.apache.felix.blueprint.HeaderParser.PathElement;
 import org.apache.felix.blueprint.ModuleContextEventSender;
 import org.apache.felix.blueprint.NamespaceHandlerRegistry;
-import org.apache.xbean.recipe.Repository;
+import org.apache.felix.blueprint.convert.ConversionServiceImpl;
+import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.xbean.recipe.ObjectGraph;
+import org.apache.xbean.recipe.Repository;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -65,8 +64,8 @@
     private final ModuleContextEventSender sender;
     private final NamespaceHandlerRegistry handlers;
     private final List<URL> urls;
-    private ComponentDefinitionRegistryImpl componentDefinitionRegistry;
-    private ConversionServiceImpl conversionService;
+    private final ComponentDefinitionRegistryImpl componentDefinitionRegistry;
+    private final ConversionServiceImpl conversionService;
 
     public ModuleContextImpl(BundleContext bundleContext, ModuleContextEventSender sender,
NamespaceHandlerRegistry handlers, List<URL> urls) {
         this.bundleContext = bundleContext;
@@ -74,6 +73,7 @@
         this.handlers = handlers;
         this.urls = urls;
         this.conversionService = new ConversionServiceImpl();
+        this.componentDefinitionRegistry = new ComponentDefinitionRegistryImpl();
     }
 
     private void checkDirectives() {
@@ -98,10 +98,8 @@
         checkDirectives();
         sender.sendCreating(this);
         try {
-            Parser parser = new Parser();
-            parser.setNamespaceHandlerRegistry(handlers);
-            parser.parse(urls);
-            componentDefinitionRegistry = parser.getRegistry();
+            Parser parser = new Parser(handlers, componentDefinitionRegistry, urls);
+            parser.parse();
             Instanciator i = new Instanciator(this);
             Repository repository = i.createRepository(componentDefinitionRegistry);
             ObjectGraph graph = new ObjectGraph(repository);
@@ -112,7 +110,7 @@
                         
             sender.sendCreated(this);
         } catch (WaitForDependencyException e) {
-            sender.sendWaiting(this, null, null); // TODO: give correct args
+            sender.sendWaiting(this, e.getServiceObjectClass(), e.getServiceFilter());
             // TODO: wait for dependency
         } catch (Exception e) {
             e.printStackTrace();

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Parser.java
Sat Apr 18 07:40:31 2009
@@ -33,6 +33,16 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.w3c.dom.Attr;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 import org.apache.felix.blueprint.NamespaceHandlerRegistry;
 import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.felix.blueprint.namespace.ParserContextImpl;
@@ -60,7 +70,6 @@
 import org.osgi.service.blueprint.reflect.CollectionBasedServiceReferenceComponentMetadata;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.ListValue;
-import org.osgi.service.blueprint.reflect.LocalComponentMetadata;
 import org.osgi.service.blueprint.reflect.MapValue;
 import org.osgi.service.blueprint.reflect.NullValue;
 import org.osgi.service.blueprint.reflect.PropertiesValue;
@@ -69,15 +78,6 @@
 import org.osgi.service.blueprint.reflect.ServiceReferenceComponentMetadata;
 import org.osgi.service.blueprint.reflect.SetValue;
 import org.osgi.service.blueprint.reflect.Value;
-import org.w3c.dom.Attr;
-import org.w3c.dom.CharacterData;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 
 /**
@@ -178,6 +178,7 @@
     public static final String LAZY_INIT_DEFAULT = BOOLEAN_FALSE;
 
     private DocumentBuilderFactory documentBuilderFactory;
+    private List<URL> urls;
     private ComponentDefinitionRegistryImpl registry;
     private NamespaceHandlerRegistry namespaceHandlerRegistry;
     private int nameCounter;
@@ -187,20 +188,15 @@
     private String defaultInitMethod;
     private String defaultDestroyMethod;
 
-    public Parser() {
-        registry = new ComponentDefinitionRegistryImpl();
-        // TODO: Register conversionService, bundle, bundleContext, moduleContext in the
registry
-    }
-
-    public void setNamespaceHandlerRegistry(NamespaceHandlerRegistry namespaceHandlerRegistry)
{
-        this.namespaceHandlerRegistry = namespaceHandlerRegistry;
-    }
-    
-    public ComponentDefinitionRegistryImpl getRegistry() {
-        return registry;
+    public Parser(NamespaceHandlerRegistry handlers,
+                  ComponentDefinitionRegistryImpl registry,
+                  List<URL> urls) {
+        this.urls = urls;
+        this.registry = registry;
+        this.namespaceHandlerRegistry = handlers;
     }
 
-    public void parse(List<URL> urls) throws Exception {
+    public void parse() throws Exception {
         List<Document> documents = new ArrayList<Document>();
         // Load documents
         for (URL url : urls) {
@@ -219,7 +215,12 @@
         for (Document doc : documents) {
             findNamespaces(namespaces, doc);
         }
-        // TODO: check namespaces and wait for dependencies
+        for (String namespace : namespaces) {
+            NamespaceHandler handler = namespaceHandlerRegistry.getNamespaceHandler(URI.create(namespace));
+            if (handler == null) {
+                throw new WaitForDependencyException(NamespaceHandler.class.getName(), null);
+            }
+        }
         // Parse components
         for (Document doc : documents) {
             loadComponents(doc);
@@ -229,7 +230,7 @@
     private void findNamespaces(Set<String> namespaces, Node node) {
         if (node instanceof Element || node instanceof Attr) {
             String ns = node.getNamespaceURI();
-            if (ns != null) {
+            if (ns != null && !isBlueprintNamespace(ns) && !isBlueprintCompendiumNamespace(ns))
{
                 namespaces.add(ns);
             }
         }
@@ -307,19 +308,19 @@
         } else if (nodeNameEquals(element, TYPE_CONVERTERS_ELEMENT)) {
             parseTypeConverters(element);
         } else if (nodeNameEquals(element, COMPONENT_ELEMENT)) {
-            LocalComponentMetadata component = parseComponentMetadata(element);
+            ComponentMetadata component = parseComponentMetadata(element);
             registry.registerComponentDefinition(component);
         } else if (nodeNameEquals(element, SERVICE_ELEMENT)) {
-            ServiceExportComponentMetadata service = parseService(element);
+            ComponentMetadata service = parseService(element);
             registry.registerComponentDefinition(service);
         } else if (nodeNameEquals(element, REFERENCE_ELEMENT)) {
-            ServiceReferenceComponentMetadata reference = parseUnaryReference(element);
+            ComponentMetadata reference = parseUnaryReference(element);
             registry.registerComponentDefinition(reference);
         } else if (nodeNameEquals(element, REFLIST_ELEMENT) ) {
-            CollectionBasedServiceReferenceComponentMetadata references = parseReferenceCollection(element,
List.class);
+            ComponentMetadata references = parseReferenceCollection(element, List.class);
             registry.registerComponentDefinition(references);
         } else if (nodeNameEquals(element, REFSET_ELEMENT)) {
-            CollectionBasedServiceReferenceComponentMetadata references = parseReferenceCollection(element,
Set.class);
+            ComponentMetadata references = parseReferenceCollection(element, Set.class);
             registry.registerComponentDefinition(references);
         } else {
             throw new ComponentDefinitionException("Unknown element " + element.getNodeName()
+ " in namespace " + BLUEPRINT_NAMESPACE);
@@ -338,7 +339,7 @@
             if (node instanceof Element) {
                 Element e = (Element) node;
                 if (nodeNameEquals(e, COMPONENT_ELEMENT)) {
-                    LocalComponentMetadata metadata = parseComponentMetadata(e);
+                    ComponentMetadata metadata = parseComponentMetadata(e);
                     registry.registerTypeConverter(new ComponentValueImpl(metadata));
                 } else if (nodeNameEquals(e, REF_ELEMENT)) {
                     String componentName = e.getAttribute(COMPONENT_ATTRIBUTE);
@@ -348,7 +349,7 @@
         }
     }
 
-    private LocalComponentMetadata parseComponentMetadata(Element element) {
+    private ComponentMetadata parseComponentMetadata(Element element) {
         LocalComponentMetadataImpl metadata = new LocalComponentMetadataImpl();
         metadata.setName(getName(element));
         if (element.hasAttribute(CLASS_ATTRIBUTE)) {
@@ -407,19 +408,19 @@
                 }
             }
         }
-        
+
         ComponentMetadata m = metadata;
-        
+
         // Parse custom attributes
         m = handleCustomAttributes(element.getAttributes(), m);
         
         // Parse custom elements;
         m = handleCustomElements(element, m);
         
-        return (LocalComponentMetadata)m;
+        return m;
     }
 
-    private ServiceExportComponentMetadata parseService(Element element) {
+    private ComponentMetadata parseService(Element element) {
         ServiceExportComponentMetadataImpl service = new ServiceExportComponentMetadataImpl();
         service.setName(getName(element));
         if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
@@ -484,7 +485,7 @@
         // Parse custom elements;
         s = handleCustomElements(element, s);
         
-        return (ServiceExportComponentMetadata)s;
+        return s;
     }
 
     private ArrayValue parseArray(Element element, ComponentMetadata enclosingComponent)
{
@@ -639,13 +640,13 @@
                     }
                     listenerComponent = new ReferenceValueImpl(component);
                 } else if (nodeNameEquals(e, COMPONENT_ELEMENT)) {
-                    LocalComponentMetadata component = parseComponentMetadata(e);
+                    ComponentMetadata component = parseComponentMetadata(e);
                     listenerComponent = new ComponentValueImpl(component);
                 } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
-                    ServiceReferenceComponentMetadata reference = parseUnaryReference(e);
+                    ComponentMetadata reference = parseUnaryReference(e);
                     listenerComponent = new ComponentValueImpl(reference);
                 } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
-                    ServiceExportComponentMetadata service = parseService(e);
+                    ComponentMetadata service = parseService(e);
                     listenerComponent = new ComponentValueImpl(service);
                 }
             }
@@ -668,7 +669,7 @@
         return listener;
     }
 
-    private ServiceReferenceComponentMetadata parseUnaryReference(Element element) {
+    private ComponentMetadata parseUnaryReference(Element element) {
         UnaryServiceReferenceComponentMetadataImpl reference = new UnaryServiceReferenceComponentMetadataImpl();
         reference.setName(getName(element));
         parseReference(element, reference);
@@ -684,10 +685,10 @@
         // Parse custom elements;
         r = handleCustomElements(element, r);
         
-        return (ServiceReferenceComponentMetadata)r;
+        return r;
     }
 
-    private CollectionBasedServiceReferenceComponentMetadata parseReferenceCollection(Element
element, Class collectionType) {
+    private ComponentMetadata parseReferenceCollection(Element element, Class collectionType)
{
         CollectionBasedServiceReferenceComponentMetadataImpl references = new CollectionBasedServiceReferenceComponentMetadataImpl();
         references.setName(getName(element));
         references.setCollectionType(collectionType);
@@ -731,7 +732,7 @@
         // Parse custom elements;
         r = handleCustomElements(element, r);
         
-        return (CollectionBasedServiceReferenceComponentMetadata)r;
+        return r;
     }
 
     private void parseComparator(Element element, CollectionBasedServiceReferenceComponentMetadataImpl
references) {
@@ -749,13 +750,13 @@
                         }
                         comparator = new ReferenceValueImpl(component);
                     } else if (nodeNameEquals(e, COMPONENT_ELEMENT)) {
-                        LocalComponentMetadata component = parseComponentMetadata(e);
+                        ComponentMetadata component = parseComponentMetadata(e);
                         comparator = new ComponentValueImpl(component);
                     } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
-                        ServiceReferenceComponentMetadata reference = parseUnaryReference(e);
+                        ComponentMetadata reference = parseUnaryReference(e);
                         comparator = new ComponentValueImpl(reference);
                     } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
-                        ServiceExportComponentMetadata service = parseService(e);
+                        ComponentMetadata service = parseService(e);
                         comparator = new ComponentValueImpl(service);
                     }
                 } else {
@@ -837,19 +838,19 @@
                         if (listener.getListenerComponent() != null) {
                             throw new ComponentDefinitionException("Attribute " + REF_ATTRIBUTE
+ " can not be set in addition to a child element");
                         }
-                        LocalComponentMetadata component = parseComponentMetadata(e);
+                        ComponentMetadata component = parseComponentMetadata(e);
                         listener.setListenerComponent(new ComponentValueImpl(component));
                     } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
                         if (listener.getListenerComponent() != null) {
                             throw new ComponentDefinitionException("Attribute " + REF_ATTRIBUTE
+ " can not be set in addition to a child element");
                         }
-                        ServiceReferenceComponentMetadata reference = parseUnaryReference(e);
+                        ComponentMetadata reference = parseUnaryReference(e);
                         listener.setListenerComponent(new ComponentValueImpl(reference));
                     } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
                         if (listener.getListenerComponent() != null) {
                             throw new ComponentDefinitionException("Attribute " + REF_ATTRIBUTE
+ " can not be set in addition to a child element");
                         }
-                        ServiceExportComponentMetadata service = parseService(e);
+                        ComponentMetadata service = parseService(e);
                         listener.setListenerComponent(new ComponentValueImpl(service));
                     }
                 } else {
@@ -907,7 +908,7 @@
     private Value parseValueElement(Element element, ComponentMetadata enclosingComponent,
boolean allowNull) {
         if (isBlueprintNamespace(element.getNamespaceURI())) {
             if (nodeNameEquals(element, COMPONENT_ELEMENT)) {
-                LocalComponentMetadata inner = parseComponentMetadata(element);
+                ComponentMetadata inner = parseComponentMetadata(element);
                 return new ComponentValueImpl(inner);
             } else if (nodeNameEquals(element, NULL_ELEMENT) && allowNull) {
                 return NullValue.NULL;
@@ -967,7 +968,6 @@
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
             if (node instanceof Element) {
-                Element e = (Element) node;
                 if (!isBlueprintNamespace(node.getNamespaceURI())) {
                     enclosingComponent = decorateCustomNode(node, enclosingComponent);
                 }
@@ -1015,7 +1015,7 @@
         }
         return documentBuilderFactory;
     }
-    
+
     private String getName(Element element) {
         if (element.hasAttribute(ID_ATTRIBUTE)) {
             return element.getAttribute(ID_ATTRIBUTE);

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/WaitForDependencyException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/WaitForDependencyException.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/WaitForDependencyException.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/WaitForDependencyException.java
Sat Apr 18 07:40:31 2009
@@ -27,10 +27,23 @@
  */
 public class WaitForDependencyException extends Exception {
 
-    public WaitForDependencyException() {
+    private final String[] serviceObjectClass;
+    private final String serviceFilter;
+
+    public WaitForDependencyException(String[] serviceObjectClass, String serviceFilter)
{
+        this.serviceObjectClass = serviceObjectClass;
+        this.serviceFilter = serviceFilter;
+    }
+
+    public WaitForDependencyException(String serviceObjectClass, String serviceFilter) {
+        this(new String[] { serviceObjectClass }, serviceFilter);
+    }
+
+    public String[] getServiceObjectClass() {
+        return serviceObjectClass;
     }
 
-    public WaitForDependencyException(String message) {
-        super(message);
+    public String getServiceFilter() {
+        return serviceFilter;
     }
 }

Added: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/AbstractBlueprintTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/AbstractBlueprintTest.java?rev=766261&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/AbstractBlueprintTest.java
(added)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/AbstractBlueprintTest.java
Sat Apr 18 07:40:31 2009
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.blueprint;
+
+import java.net.URI;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
+import org.osgi.service.blueprint.namespace.NamespaceHandler;
+import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.felix.blueprint.context.Parser;
+
+public abstract class AbstractBlueprintTest extends TestCase {
+
+    protected ComponentDefinitionRegistryImpl parse(String name) throws Exception {
+        NamespaceHandlerRegistry handlers = new NamespaceHandlerRegistry() {
+            public NamespaceHandler getNamespaceHandler(URI uri) {
+                return null;
+            }
+            public void addCallback(Runnable runnable) {
+            }
+            public void destroy() {
+            }
+        };
+        return parse(name, handlers);
+    }
+
+    protected ComponentDefinitionRegistryImpl parse(String name, NamespaceHandlerRegistry
handlers) throws Exception {
+        ComponentDefinitionRegistryImpl registry = new ComponentDefinitionRegistryImpl();
+        Parser parser = new Parser(handlers, registry, Collections.singletonList(getClass().getResource(name)));
+        parser.parse();
+        return registry;
+    }
+
+}

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
Sat Apr 18 07:40:31 2009
@@ -20,13 +20,17 @@
 
 import java.net.URI;
 import java.net.URL;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
-import junit.framework.TestCase;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
+import junit.framework.TestCase;
 import org.apache.felix.blueprint.context.Parser;
+import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.felix.blueprint.reflect.LocalComponentMetadataImpl;
 import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
 import org.osgi.service.blueprint.namespace.NamespaceHandler;
@@ -42,19 +46,15 @@
 import org.osgi.service.blueprint.reflect.ReferenceValue;
 import org.osgi.service.blueprint.reflect.TypedStringValue;
 import org.osgi.service.blueprint.reflect.Value;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 
 /**
  * TODO: constructor injection
  * TODO: Dependency#setMethod 
  */
-public class ParserTest extends TestCase {
+public class ParserTest extends AbstractBlueprintTest {
 
     public void testParseComponent() throws Exception {
-        Parser parser = parse("/test-simple-component.xml");
-        ComponentDefinitionRegistry registry = parser.getRegistry();
+        ComponentDefinitionRegistry registry = parse("/test-simple-component.xml");
         assertNotNull(registry);
         ComponentMetadata component = registry.getComponentDefinition("pojoA");
         assertNotNull(component);
@@ -124,17 +124,12 @@
     }
 
     public void testParse() throws Exception {
-        Parser parser = new Parser();
-        parser.parse(Arrays.asList( getClass().getResource("/test.xml") ));
-        ComponentDefinitionRegistry registry = parser.getRegistry();
-        assertNotNull(registry);
+        parse("/test.xml");
     }
 
+
     public void testCustomNodes() throws Exception {
-        Parser parser = new Parser();
-        parser.setNamespaceHandlerRegistry(new TestNamespaceHandlerRegistry());
-        parser.parse(Arrays.asList( getClass().getResource("/test-custom-nodes.xml") ));
-        ComponentDefinitionRegistry registry = parser.getRegistry();
+        ComponentDefinitionRegistry registry = parse("/test-custom-nodes.xml", new TestNamespaceHandlerRegistry());
         
         ComponentMetadata metadata;
         
@@ -166,12 +161,6 @@
         assertEquals("org.apache.geronimo.Cache", comp3.getClassName());         
     }
 
-    protected Parser parse(String name) throws Exception {
-        Parser parser = new Parser();
-        parser.parse(Arrays.asList( getClass().getResource(name) ));
-        return parser;
-    }
-    
     private static class TestNamespaceHandlerRegistry implements NamespaceHandlerRegistry
{
         
         public void destroy() {

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java?rev=766261&r1=766260&r2=766261&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/test/java/org/apache/felix/blueprint/WiringTest.java
Sat Apr 18 07:40:31 2009
@@ -20,26 +20,22 @@
 
 import java.math.BigInteger;
 import java.net.URI;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
 
 import org.apache.felix.blueprint.context.Instanciator;
-import org.apache.felix.blueprint.context.Parser;
 import org.apache.felix.blueprint.convert.ConversionServiceImpl;
+import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.felix.blueprint.pojos.PojoA;
 import org.apache.felix.blueprint.pojos.PojoB;
 import org.apache.xbean.recipe.ObjectGraph;
 import org.apache.xbean.recipe.Repository;
 import org.osgi.service.blueprint.convert.ConversionService;
 
-public class WiringTest extends TestCase {
+public class WiringTest extends AbstractBlueprintTest {
 
     public void testWiring() throws Exception {
-        Parser parser = parse("/test-wiring.xml");
-
+        ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         Instanciator i = new TestInstanciator();
-        Repository repository = i.createRepository(parser.getRegistry());
+        Repository repository = i.createRepository(registry);
         ObjectGraph graph = new ObjectGraph(repository);
         
         Object obj1 = graph.create("pojoA");
@@ -91,12 +87,6 @@
         assertEquals(new Long(100), pojoa.getNumberArray()[2]);
     }
 
-    protected Parser parse(String name) throws Exception {
-        Parser parser = new Parser();
-        parser.parse(Arrays.asList( getClass().getResource(name) ));
-        return parser;
-    }
-
     private static class TestInstanciator extends Instanciator {
         ConversionServiceImpl conversionService = new ConversionServiceImpl();
         

Propchange: geronimo/sandbox/blueprint/sample/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Apr 18 07:40:31 2009
@@ -0,0 +1,2 @@
+*.iml
+target



Mime
View raw message