cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r293017 - in /cocoon/trunk: ./ src/java/ src/java/org/apache/cocoon/core/osgi/ src/osgi-servlet/ src/osgi-servlet/org/apache/cocoon/service/servlet/impl/ src/webapp/
Date Sat, 01 Oct 2005 19:34:06 GMT
Author: danielf
Date: Sat Oct  1 12:33:44 2005
New Revision: 293017

URL: http://svn.apache.org/viewcvs?rev=293017&view=rev
Log:
Followed Vadim's ideas and moved creation of Core and Cocoon from the cocoon bundle to the
webapp bundle. Core and Cocoon are registred as OSGi services through the ECM/OSGi Service
adapters and used in the osgi-servlet bundle. Also cleaned up manifests, imports and whitespace.

Modified:
    cocoon/trunk/init.xargs
    cocoon/trunk/src/java/Manifest.mf
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiCoreServiceManager.java
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/ServiceManagerActivator.java
    cocoon/trunk/src/osgi-servlet/Manifest.mf
    cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java
    cocoon/trunk/src/webapp/Manifest.mf

Modified: cocoon/trunk/init.xargs
URL: http://svn.apache.org/viewcvs/cocoon/trunk/init.xargs?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/init.xargs (original)
+++ cocoon/trunk/init.xargs Sat Oct  1 12:33:44 2005
@@ -68,5 +68,5 @@
 -start lib/core/knopflerfish-frameworkcommands-1.0.0.jar
 -start lib/core/knopflerfish-logcommands-1.0.0.jar
 -start lib/core/knopflerfish-http_all-1.1.0.jar
--start build/osgi/org.apache.cocoon_1.0.0.jar
+-start build/osgi/org.apache.cocoon_webapp_1.0.0.jar
 -start build/osgi/org.apache.cocoon_servlet_1.0.0.jar

Modified: cocoon/trunk/src/java/Manifest.mf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/Manifest.mf?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/java/Manifest.mf (original)
+++ cocoon/trunk/src/java/Manifest.mf Sat Oct  1 12:33:44 2005
@@ -9,8 +9,7 @@
 Bundle-Vendor: Apache
 Bundle-DocURL: http://cocoon.apache.org
 Bundle-ContactAddress: http://cocoon.apache.org
-Bundle-Activator: org.apache.cocoon.core.osgi.CoreBlockActivator
-Bundle-Category: block
+Bundle-Category: library
 Bundle-Classpath: 
  .,
  avalon-framework-api-4.3.jar,

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java Sat Oct  1 12:33:44
2005
@@ -21,7 +21,6 @@
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.service.ServiceException;
-import org.apache.cocoon.Cocoon;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.core.BootstrapEnvironment;
 import org.apache.cocoon.core.Core;
@@ -37,12 +36,12 @@
 
     public void start(final BundleContext ctx) throws Exception {
         
-	BootstrapEnvironment env = new OSGiBootstrapEnvironment(this.classLoader, ctx);
-	env.log("OSGiBootstrapEnvironment created");
-	CoreUtil coreUtil = new CoreUtil(env);
-	env.log("CoreUtil created");
-	this.core = coreUtil.getCore();
-	this.processor = coreUtil.createCocoon();
+        BootstrapEnvironment env = new OSGiBootstrapEnvironment(this.classLoader, ctx);
+        env.log("OSGiBootstrapEnvironment created");
+        CoreUtil coreUtil = new CoreUtil(env);
+        env.log("CoreUtil created");
+        this.core = coreUtil.getCore();
+        this.processor = coreUtil.createCocoon();
 
         super.start(ctx);
     }
@@ -71,6 +70,6 @@
     protected void addComponents(CoreServiceManager manager) 
     throws ServiceException, ConfigurationException {
         manager.addInstance(Core.ROLE, this.core);
-        manager.addInstance(Cocoon.class.getName(), this.processor);
+        manager.addInstance(Processor.ROLE, this.processor);
     }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java Sat Oct
 1 12:33:44 2005
@@ -59,7 +59,7 @@
         LoggerManager logManager = new OSGiLoggerManager(bc, LogService.LOG_DEBUG);
         this.logger = logManager.getDefaultLogger();
 
-        Bundle bundle = getSitemapBundle(bc, this.logger);
+        Bundle bundle = bc.getBundle();
         if (bundle == null) {
             throw new Exception("No sitemap bundle");
         }
@@ -180,31 +180,6 @@
     public String getClassPath(Settings settings) {
         return null;
     }
-
-    private Bundle getSitemapBundle(BundleContext bc, Logger log) {
-        String SITEMAP = "sitemap";
-        Bundle[] bundles = bc.getBundles();
-        for (int i = 0; i < bundles.length; i++) {
-            Bundle bundle = bundles[i];
-            try {
-                log.info("checking bundle " + bundle + " name=" + bundle.getHeaders().get(Constants.BUNDLE_NAME)
+ " category=" + bundle.getHeaders().get(Constants.BUNDLE_CATEGORY) + " state=" + bundle.getState());
-                if ((bundle.getState() == Bundle.INSTALLED ||
-                     bundle.getState() == Bundle.RESOLVED ||
-                     bundle.getState() == Bundle.ACTIVE)) {
-                    log.info("ok state");
-                    if (SITEMAP.equals(bundle.getHeaders().get(Constants.BUNDLE_CATEGORY)))
{
-                        log.info("sitemap");
-                        return bundle;
-                    }
-                }
-            } catch (NullPointerException e) {
-                // BUNDLE_CATEGORY not present in the headers of the
-                // bundle, nothing to do.
-            }
-        }
-        return null;
-    }
-
 
     public class OSGiContext extends AbstractContext {
 

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiCoreServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiCoreServiceManager.java?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiCoreServiceManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiCoreServiceManager.java Sat Oct
 1 12:33:44 2005
@@ -21,6 +21,7 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.components.ComponentInfo;
 import org.apache.cocoon.core.container.CoreServiceManager;
@@ -58,24 +59,43 @@
      */
     public void addComponent(String role, String className, Configuration configuration,
ComponentInfo info) throws ConfigurationException {
         super.addComponent(role, className, configuration, info);
-        if (configuration.getAttributeAsBoolean("exported", false)) {
+        if (configuration.getAttributeAsBoolean("exported", true)) {
             ComponentHandler handler = (ComponentHandler)super.componentHandlers.get(role);
             if (!handler.isSingleton()) {
                 throw new ConfigurationException("Only singleton services can be exported
as OSGi services, at " +
-                        configuration.getLocation());
+                                                 configuration.getLocation());
             }
-            
-            String itfName = OSGiServiceManager.getServiceInterface(role);
-            String hint = OSGiServiceManager.getServiceHint(role);
-            Dictionary dict = null;
-            if (hint != null) {
-                dict = new Hashtable();
-                dict.put(OSGiServiceManager.HINT_PROPERTY, hint);
-            }
-            
-            Object service = new ComponentHandlerFactory(handler);
-            ctx.registerService(itfName, service, dict);
+            this.addService(role, handler);
+        }
+    }
+    
+    /**
+     * Catch a component insertion and register it as OSGi services.
+     */
+    public void addInstance(String role, Object instance) throws ServiceException {
+        super.addInstance(role, instance);
+        ComponentHandler handler = (ComponentHandler)super.componentHandlers.get(role);
+        if (!handler.isSingleton()) {
+            throw new ServiceException("Only singleton services can be exported as OSGi services,
at " +
+                                       instance.toString());
         }
+        this.addService(role, handler);
+    }
+
+    /**
+     * Register a component as an OSGi service.
+     */
+    protected void addService(String role, ComponentHandler handler) {
+        String itfName = OSGiServiceManager.getServiceInterface(role);
+        String hint = OSGiServiceManager.getServiceHint(role);
+        Dictionary dict = null;
+        if (hint != null) {
+            dict = new Hashtable();
+            dict.put(OSGiServiceManager.HINT_PROPERTY, hint);
+        }
+
+        Object service = new ComponentHandlerFactory(handler);
+        ctx.registerService(itfName, service, dict);
     }
     
     /**

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/ServiceManagerActivator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/ServiceManagerActivator.java?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/ServiceManagerActivator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/ServiceManagerActivator.java Sat Oct
 1 12:33:44 2005
@@ -96,8 +96,8 @@
     }
 
     protected Context getContext() throws Exception {
-	Core core = (Core)this.parentManager.lookup(Core.ROLE);
-	return core.getContext();
+        Core core = (Core)this.parentManager.lookup(Core.ROLE);
+        return core.getContext();
     }
 
     /**

Modified: cocoon/trunk/src/osgi-servlet/Manifest.mf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/osgi-servlet/Manifest.mf?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/osgi-servlet/Manifest.mf (original)
+++ cocoon/trunk/src/osgi-servlet/Manifest.mf Sat Oct  1 12:33:44 2005
@@ -14,7 +14,6 @@
  javax.servlet,
  javax.servlet.http,
  org.apache.avalon.excalibur.logger,
- org.apache.avalon.framework.context,
  org.apache.avalon.framework.logger,
  org.apache.cocoon,
  org.apache.cocoon.core,
@@ -22,20 +21,11 @@
  org.apache.cocoon.components.notification,
  org.apache.cocoon.environment,
  org.apache.cocoon.environment.http,
- org.apache.cocoon.servlet,
  org.apache.cocoon.servlet.multipart,
- org.apache.cocoon.util,
- org.apache.commons.lang,
  org.apache.commons.lang.time,
- org.apache.excalibur.source.impl,
- org.apache.excalibur.xml.impl,
- org.apache.excalibur.xml.xpath,
- org.apache.excalibur.xml.xslt,
- org.apache.excalibur.xmlizer,
  org.osgi.framework,
  org.osgi.service.http,
- org.osgi.service.log,
- org.osgi.util.tracker
+ org.osgi.service.log
 DynamicImport-Package: org.apache.cocoon.*
 Bundle-UUID: org.apache.cocoon:cocoon_servlet:1.0.0:impl
 Built-From: C:\cygwin\usr\local\svn\cocoon\osgi\bundles\cocoon_servlet

Modified: cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java (original)
+++ cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java Sat
Oct  1 12:33:44 2005
@@ -20,11 +20,9 @@
 import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.cocoon.Processor;
-import org.apache.cocoon.core.BootstrapEnvironment;
 import org.apache.cocoon.core.Core;
-import org.apache.cocoon.core.CoreUtil;
-import org.apache.cocoon.core.osgi.OSGiBootstrapEnvironment;
 import org.apache.cocoon.core.osgi.OSGiLoggerManager;
+import org.apache.cocoon.core.osgi.OSGiServiceManager;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceEvent;
@@ -41,7 +39,6 @@
 
     static BundleContext bc;
     static final String  SERVLET_ALIAS = "/";     // the http server root
-    static final String  SITEMAP = "sitemap";
 
     private HashSet registrations = new HashSet();
     private ClassLoader classLoader = getClass().getClassLoader();
@@ -53,14 +50,12 @@
 
         Activator.bc  = bc;
 
-        BootstrapEnvironment env = new OSGiBootstrapEnvironment(this.classLoader, Activator.bc);
-        env.log("OSGiBootstrapEnvironment created");
-        CoreUtil coreUtil = new CoreUtil(env);
-        env.log("CoreUtil created");
         LoggerManager logManager = new OSGiLoggerManager(bc, LogService.LOG_DEBUG);
         this.logger = logManager.getDefaultLogger();
-        this.core = coreUtil.getCore();
-        this.processor = coreUtil.createCocoon();
+
+        OSGiServiceManager manager = new OSGiServiceManager(Activator.bc);
+        this.core = (Core)manager.lookup(Core.ROLE);
+        this.processor = (Processor)manager.lookup(Processor.ROLE);
 
         ServiceListener listener = new ServiceListener() {
                 public void serviceChanged(ServiceEvent ev) {

Modified: cocoon/trunk/src/webapp/Manifest.mf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/Manifest.mf?rev=293017&r1=293016&r2=293017&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/Manifest.mf (original)
+++ cocoon/trunk/src/webapp/Manifest.mf Sat Oct  1 12:33:44 2005
@@ -8,12 +8,10 @@
 Bundle-Vendor: Apache
 Bundle-DocURL: http://cocoon.apache.org
 Bundle-ContactAddress: http://cocoon.apache.org
-Bundle-Activator: 
+Bundle-Activator: org.apache.cocoon.core.osgi.CoreBlockActivator
 Bundle-Category: sitemap
-Import-Package: org.osgi.framework
+Import-Package: 
+ org.osgi.framework,
+ org.apache.cocoon
+DynamicImport-Package: org.apache.cocoon.*
 Bundle-UUID: org.apache.cocoon:cocoon_webapp:1.0.0:impl
-Built-From: F:\os\cocoon\whiteboard\osgi\bundles\cocoon_webapp
-Build-Date: Wed June 29 2005, 12:58:41
-Bundle-SubversionURL: https://svn.apache.org/repos/asf/cocoon/whiteboa
- rd/osgi/
-



Mime
View raw message