cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r292305 - in /cocoon/trunk: ./ src/java/ src/java/org/apache/cocoon/core/ src/java/org/apache/cocoon/core/osgi/ src/osgi-servlet/org/apache/cocoon/service/servlet/impl/
Date Wed, 28 Sep 2005 21:15:58 GMT
Author: danielf
Date: Wed Sep 28 14:15:47 2005
New Revision: 292305

URL: http://svn.apache.org/viewcvs?rev=292305&view=rev
Log:
Moving Core and Cocoon creation to from osgi-servlet to core but the osgi-servlet doesn't
use them yet. Added CoreBlockActivator that create the Core. Refactored ServiceManagerActivator
to be modifyable by extension and take the Avalon cContext from Core. Added getContext to
core to make the global Avalon Context available.

Added:
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java   (with props)
Modified:
    cocoon/trunk/init.xargs
    cocoon/trunk/src/java/Manifest.mf
    cocoon/trunk/src/java/org/apache/cocoon/core/Core.java
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/ServiceManagerActivator.java
    cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java

Modified: cocoon/trunk/init.xargs
URL: http://svn.apache.org/viewcvs/cocoon/trunk/init.xargs?rev=292305&r1=292304&r2=292305&view=diff
==============================================================================
--- cocoon/trunk/init.xargs (original)
+++ cocoon/trunk/init.xargs Wed Sep 28 14:15:47 2005
@@ -68,4 +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_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=292305&r1=292304&r2=292305&view=diff
==============================================================================
--- cocoon/trunk/src/java/Manifest.mf (original)
+++ cocoon/trunk/src/java/Manifest.mf Wed Sep 28 14:15:47 2005
@@ -9,7 +9,8 @@
 Bundle-Vendor: Apache
 Bundle-DocURL: http://cocoon.apache.org
 Bundle-ContactAddress: http://cocoon.apache.org
-Bundle-Category: library
+Bundle-Activator: org.apache.cocoon.core.osgi.CoreBlockActivator
+Bundle-Category: block
 Bundle-Classpath: 
  .,
  avalon-framework-api-4.3.jar,

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/Core.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/Core.java?rev=292305&r1=292304&r2=292305&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/Core.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/Core.java Wed Sep 28 14:15:47 2005
@@ -145,6 +145,14 @@
     }
     
     /**
+     * Return the Avalon context.
+     * @return The Avalon context.
+     */
+    public Context getContext() {
+        return this.context;
+    }
+    
+    /**
      * Return the current object model
      * @return The object model.
      */

Added: 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=292305&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java Wed Sep 28 14:15:47
2005
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ * Licensed  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.cocoon.core.osgi;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+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;
+import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.core.container.CoreServiceManager;
+import org.osgi.framework.BundleContext;
+
+public class CoreBlockActivator extends ServiceManagerActivator {
+
+    private ClassLoader classLoader = getClass().getClassLoader();;
+    private Core core;
+    private Processor processor;
+
+    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();
+
+        super.start(ctx);
+    }
+
+    public void stop(BundleContext ctx) throws Exception {
+        super.stop(ctx);
+    }
+
+    protected Context getContext() throws Exception {
+        return this.core.getContext();
+    }
+
+    /**
+     * This method may be overwritten by subclasses to provide an own
+     * configuration
+     */
+    protected Configuration getConfiguration() {
+        DefaultConfiguration config = new DefaultConfiguration("cocoon", "CoreBlockActivator");
+        return config;
+    }
+
+    /**
+     * This method may be overwritten by subclasses to add aditional
+     * components.
+     */
+    protected void addComponents(CoreServiceManager manager) 
+    throws ServiceException, ConfigurationException {
+        manager.addInstance(Core.ROLE, this.core);
+        manager.addInstance(Cocoon.class.getName(), this.processor);
+    }
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java
------------------------------------------------------------------------------
    svn:keywords = Id

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=292305&r1=292304&r2=292305&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 Wed Sep
28 14:15:47 2005
@@ -19,9 +19,14 @@
 import java.net.URL;
 
 import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.core.Core;
+import org.apache.cocoon.core.container.CoreServiceManager;
 import org.apache.cocoon.components.container.ComponentContext;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -32,6 +37,7 @@
 
 //  Registering services must go through the ServiceFactory class wrapping the componentHandler
     
+    private ServiceManager parentManager;
     private OSGiCoreServiceManager manager;
 
     public void start(final BundleContext ctx) throws Exception {
@@ -41,17 +47,17 @@
         LoggerManager logManager = new OSGiLoggerManager(ctx, LogService.LOG_DEBUG);
 
         // Create a parent manager that will lookup registered OSGi services
-        ServiceManager parentManager = new OSGiServiceManager(ctx);
+        this.parentManager = new OSGiServiceManager(ctx);
         
         // Create a regular manager
         this.manager = new OSGiCoreServiceManager(parentManager, this.getClass().getClassLoader(),
ctx) {
         };
-        
+
         //---- LogEnabled
         this.manager.enableLogging(logManager.getDefaultLogger());
         
         //---- Contextualizable
-        DefaultContext avalonCtx = new ComponentContext();
+        //DefaultContext avalonCtx = new ComponentContext();
         // Context entries defined in CocoonServlet/CoreUtil:
         // "servlet-config"
         // "servlet-context"
@@ -66,7 +72,7 @@
         // Core.ROLE (???)
         // Constants.CONTEXT_CLASSPATH
 
-        this.manager.contextualize(avalonCtx);
+        this.manager.contextualize(this.getContext());
         
         //---- LoggerManager
         this.manager.setLoggerManager(logManager);
@@ -76,14 +82,8 @@
         this.manager.setRoleManager(null);
         
         //---- Configurable
-        // Create a configuration object with one include directive. ECM++ will do the rest!
-        DefaultConfiguration config = new DefaultConfiguration("cocoon");
-        DefaultConfiguration include = new DefaultConfiguration("include");
-        URL confURL = ctx.getBundle().getResource("/BLOCK-INF/block.xconf");
-        include.setAttribute("src", confURL.toExternalForm());
-        config.addChild(include);
-        
-        this.manager.configure(config);
+        this.manager.configure(this.getConfiguration());
+        this.addComponents(this.manager);
         
         //---- Initializable
         this.manager.initialize();
@@ -93,5 +93,34 @@
     public void stop(BundleContext ctx) throws Exception {
         // Dispose the ServiceManager
         this.manager.dispose();
+    }
+
+    protected Context getContext() throws Exception {
+	Core core = (Core)this.parentManager.lookup(Core.ROLE);
+	return core.getContext();
+    }
+
+    /**
+     * This method may be overwritten by subclasses to provide an own
+     * configuration
+     */
+    protected Configuration getConfiguration() {
+        // Create a configuration object with one include directive. ECM++ will do the rest!
+        DefaultConfiguration config = new DefaultConfiguration("cocoon", "ServiceManagerActivator");
+//         DefaultConfiguration include = new DefaultConfiguration("include");
+//         URL confURL = ctx.getBundle().getResource("/BLOCK-INF/block.xconf");
+//         include.setAttribute("src", confURL.toExternalForm());
+//         config.addChild(include);
+
+        return config;
+    }
+
+    /**
+     * This method may be overwritten by subclasses to add aditional
+     * components.
+     */
+    protected void addComponents(CoreServiceManager manager) 
+    throws ServiceException, ConfigurationException {
+        // subclasses can add components here
     }
 }

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=292305&r1=292304&r2=292305&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 Wed
Sep 28 14:15:47 2005
@@ -27,7 +27,6 @@
 import org.apache.cocoon.core.osgi.OSGiLoggerManager;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
@@ -50,22 +49,18 @@
     private Core core;
     private Processor processor;
 
-    public void start(BundleContext bc) throws BundleException {
+    public void start(BundleContext bc) throws Exception {
 
         Activator.bc  = bc;
-        try {
-            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();
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new BundleException("Failed to create core util", e);
-        }
+
+        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();
 
         ServiceListener listener = new ServiceListener() {
                 public void serviceChanged(ServiceEvent ev) {
@@ -97,7 +92,7 @@
         }
     }
 
-    public void stop(BundleContext bc) throws BundleException {
+    public void stop(BundleContext bc) throws Exception {
     }
 
     private void setRoot(ServiceReference sr) {



Mime
View raw message