geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r764955 - in /geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint: Activator.java BlueprintConstants.java context/DefaultModuleContextEventSender.java context/ModuleContextImpl.java
Date Tue, 14 Apr 2009 21:16:44 GMT
Author: gawor
Date: Tue Apr 14 21:16:42 2009
New Revision: 764955

URL: http://svn.apache.org/viewvc?rev=764955&view=rev
Log:
refactored some constants and added some code to discover certain blueprint directives

Added:
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
  (with props)
Modified:
    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/DefaultModuleContextEventSender.java
    geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/ModuleContextImpl.java

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=764955&r1=764954&r2=764955&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
Tue Apr 14 21:16:42 2009
@@ -93,7 +93,7 @@
 
         List<URL> urls = new ArrayList<URL>();
         Dictionary headers = bundle.getHeaders();
-        String blueprintHeader = (String)headers.get("Bundle-Blueprint");
+        String blueprintHeader = (String)headers.get(BlueprintConstants.BUNDLE_BLUEPRINT_HEADER);
         if (blueprintHeader != null) {
             List<PathElement> paths = HeaderParser.parseHeader(blueprintHeader);
             for (PathElement path : paths) {

Added: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java?rev=764955&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
(added)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
Tue Apr 14 21:16:42 2009
@@ -0,0 +1,33 @@
+/**
+ * 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;
+
+public class BlueprintConstants  {
+   
+    public static final String BUNDLE_BLUEPRINT_HEADER = "Bundle-Blueprint";
+    
+    public static final String TIMEOUT_DIRECTIVE = "blueprint.timeout";
+    
+    public static final String WAIT_FOR_DEPENDENCIES_DIRECTIVE = "blueprint.wait-for-dependencies";
+    
+    public static final String BUNDLE_VERSION = "bundle.version";
+    
+    public static final String SERVICE_FILTER = "service.Filter";
+    
+}

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/BlueprintConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/DefaultModuleContextEventSender.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/DefaultModuleContextEventSender.java?rev=764955&r1=764954&r2=764955&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/DefaultModuleContextEventSender.java
(original)
+++ geronimo/sandbox/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/DefaultModuleContextEventSender.java
Tue Apr 14 21:16:42 2009
@@ -23,11 +23,15 @@
 
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
 import org.osgi.service.blueprint.context.ModuleContextEventConstants;
 import org.osgi.service.blueprint.context.ModuleContext;
+import org.apache.felix.blueprint.BlueprintConstants;
 import org.apache.felix.blueprint.ModuleContextEventSender;
 
 /**
@@ -35,9 +39,11 @@
  */
 public class DefaultModuleContextEventSender implements ModuleContextEventSender {
 
+    private final Bundle extenderBundle;
     private final ServiceTracker eventAdminServiceTracker;
 
     public DefaultModuleContextEventSender(BundleContext bundleContext) {
+        this.extenderBundle = bundleContext.getBundle();
         this.eventAdminServiceTracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(),
null);
         this.eventAdminServiceTracker.open();
     }
@@ -79,22 +85,26 @@
         Bundle bundle = moduleContext.getBundleContext().getBundle();
 
         Dictionary props = new Hashtable();
-        props.put("bundle.symbolicName", bundle.getSymbolicName());
-        props.put("bundle.id", bundle.getBundleId());
-        props.put("bundle", bundle);
-        props.put("bundle.version", "NA");
-        props.put("timestamp", System.currentTimeMillis());
-        props.put(ModuleContextEventConstants.EXTENDER_BUNDLE, "NA");
-        props.put(ModuleContextEventConstants.EXTENDER_ID, "NA");
-        props.put(ModuleContextEventConstants.EXTENDER_SYMBOLICNAME, "NA");
+        props.put(EventConstants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
+        props.put(EventConstants.BUNDLE_ID, bundle.getBundleId());
+        props.put(EventConstants.BUNDLE, bundle);
+        Version version = getBundleVersion(bundle);
+        if (version != null) {
+            props.put(BlueprintConstants.BUNDLE_VERSION, version);
+        }
+        props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
+        props.put(ModuleContextEventConstants.EXTENDER_BUNDLE, extenderBundle);
+        props.put(ModuleContextEventConstants.EXTENDER_ID, extenderBundle.getBundleId());
+        props.put(ModuleContextEventConstants.EXTENDER_SYMBOLICNAME, extenderBundle.getSymbolicName());
+        
         if (cause != null) {
-            props.put("exception", cause);
+            props.put(EventConstants.EXCEPTION, cause);
         }
         if (serviceObjectClass != null) {
-            props.put("service.objectClass", serviceObjectClass);
+            props.put(EventConstants.SERVICE_OBJECTCLASS, serviceObjectClass);
         }
         if (serviceFilter != null) {
-            props.put("service.filter", serviceFilter);
+            props.put(BlueprintConstants.SERVICE_FILTER, serviceFilter);
         }
 
         Event event = new Event(topic, props);
@@ -102,6 +112,12 @@
         System.out.println("Event sent: " + topic);
     }
 
+    private static Version getBundleVersion(Bundle bundle) {
+        Dictionary headers = bundle.getHeaders();
+        String version = (String)headers.get(Constants.BUNDLE_VERSION);
+        return (version != null) ? Version.parseVersion(version) : null;
+    }
+    
     private EventAdmin getEventAdmin() {
         return (EventAdmin)this.eventAdminServiceTracker.getService();
     }

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=764955&r1=764954&r2=764955&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
Tue Apr 14 21:16:42 2009
@@ -21,15 +21,21 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.List;
 import java.util.Set;
 import java.net.URL;
 
+import org.apache.felix.blueprint.HeaderParser.PathElement;
 import org.apache.felix.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.felix.blueprint.BlueprintConstants;
+import org.apache.felix.blueprint.HeaderParser;
 import org.apache.felix.blueprint.ModuleContextEventSender;
 import org.apache.xbean.recipe.Repository;
 import org.apache.xbean.recipe.ObjectGraph;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.service.blueprint.context.ModuleContext;
 import org.osgi.service.blueprint.context.NoSuchComponentException;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -56,7 +62,26 @@
         this.urls = urls;
     }
 
+    private void checkDirectives() {
+        Bundle bundle = bundleContext.getBundle();
+        Dictionary headers = bundle.getHeaders();
+        String symbolicName = (String)headers.get(Constants.BUNDLE_SYMBOLICNAME);
+        List<PathElement> paths = HeaderParser.parseHeader(symbolicName);
+        String timeout = paths.get(0).getDirective(BlueprintConstants.TIMEOUT_DIRECTIVE);
+        String waitForDependencies = paths.get(0).getDirective(BlueprintConstants.WAIT_FOR_DEPENDENCIES_DIRECTIVE);
+
+        // TODO: hook this up
+        
+        if (timeout != null) {
+            System.out.println("Timeout: " + timeout);
+        }
+        if (waitForDependencies != null) {
+            System.out.println("Wait-for-dependencies: " + waitForDependencies);
+        }
+    }
+    
     public void create() {
+        checkDirectives();
         sender.sendCreating(this);
         try {
             Parser parser = new Parser();



Mime
View raw message