cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r515024 - in /cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src: changes/changes.xml main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
Date Tue, 06 Mar 2007 08:36:12 GMT
Author: reinhard
Date: Tue Mar  6 00:36:11 2007
New Revision: 515024

URL: http://svn.apache.org/viewvc?view=rev&rev=515024
Log:
      <action dev="reinhard" type="add">
        Apples can Spring beans. In order to lookup a bean, prepand #, e.g. to lookup a bean
of name 'myBean',
        use &lt;map:call function="#myBean"/&gt;.
      </action>         
      <action dev="reinhard" type="add">
        Add an AppleNotFoundException which informs why an Apple can't be initialized.
      </action>      

Added:
    cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
  (with props)
Modified:
    cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/changes/changes.xml
    cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java

Modified: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/changes/changes.xml?view=diff&rev=515024&r1=515023&r2=515024
==============================================================================
--- cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/changes/changes.xml (original)
+++ cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/changes/changes.xml Tue Mar 
6 00:36:11 2007
@@ -24,7 +24,14 @@
     +-->
 <document>
   <body>
-    <release version="1.0.0-RC1" date="2007-02-05" description="unreleased">  
+    <release version="1.0.0-RC1" date="2007-??-??" description="unreleased"> 
+      <action dev="reinhard" type="add">
+        Apples can Spring beans. In order to lookup a bean, prepand #, e.g. to lookup a bean
of name 'myBean',
+        use &lt;map:call function="#myBean"/&gt;.
+      </action>         
+      <action dev="reinhard" type="add">
+        Add an AppleNotFoundException which informs why an Apple can't be initialized.
+      </action>      
       <action dev="reinhard" type="add">
         Add sendStatus() to the AppleResponse interface.
       </action>

Added: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java?view=auto&rev=515024
==============================================================================
--- cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
(added)
+++ cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
Tue Mar  6 00:36:11 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.cocoon.components.flow.apples;
+
+/**
+ * Throw this exception, if an Apple can't be looked up.
+ */
+public class AppleNotFoundException extends Exception {
+
+	public AppleNotFoundException(String message) {
+		super(message);
+	}
+	
+	public AppleNotFoundException(String message, Throwable t) {
+		super(message, t);
+	}
+	
+}

Propchange: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/AppleNotFoundException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java?view=diff&rev=515024&r1=515023&r2=515024
==============================================================================
--- cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
(original)
+++ cocoon/trunk/blocks/cocoon-apples/cocoon-apples-impl/src/main/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
Tue Mar  6 00:36:11 2007
@@ -22,6 +22,7 @@
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.components.LifecycleHelper;
@@ -48,7 +49,15 @@
 public class ApplesProcessor extends AbstractInterpreter implements ContinuationsDisposer
{
 
     public void callFunction(String className, List params, Redirector redirector) throws
Exception {
-        AppleController app = instantiateController(className);
+        // Use the current sitemap's service manager for components
+        ServiceManager sitemapManager;
+        try {
+            sitemapManager = (ServiceManager) avalonContext.get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
+        } catch (ContextException e) {
+            throw new CascadingRuntimeException("Cannot get sitemap service manager", e);
+        }    	
+    	
+        AppleController app = instantiateController(className, sitemapManager);
 
         WebContinuation wk = null;
         if (!(app instanceof StatelessAppleController)) {
@@ -62,13 +71,6 @@
             appleContext.put("continuation-id", wk.getId());
         }
 
-        // Use the current sitemap's service manager for components
-        ServiceManager sitemapManager;
-        try {
-            sitemapManager = (ServiceManager) avalonContext.get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
-        } catch (ContextException e) {
-            throw new CascadingRuntimeException("Cannot get sitemap service manager", e);
-        }
 
         LifecycleHelper.setupComponent(app, getLogger(), appleContext, sitemapManager, null,
true);
         processApple(params, redirector, app, wk);
@@ -93,10 +95,30 @@
 
     }
 
-    protected AppleController instantiateController(String className) throws Exception {
-        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
-        Object o = clazz.newInstance();
-        return (AppleController) o;
+    protected AppleController instantiateController(String appleName, ServiceManager sitemapManager)
throws AppleNotFoundException {
+    	if(appleName.startsWith("#")) {
+    		String beanName = appleName.substring(1);
+    		try {
+    			return (AppleController) sitemapManager.lookup(beanName);
+    		} catch(ClassCastException e) {
+    			throw new AppleNotFoundException("The bean '" + beanName + "' doesn't implement the
AppleController interface.", e);
+    		} catch (ServiceException e) {
+    			throw new AppleNotFoundException("Can't find any bean of name '" + beanName + "'.",
e);
+			}
+    	}
+        AppleController appleController = null;
+		try {
+			Class clazz = Thread.currentThread().getContextClassLoader().loadClass(appleName);
+	        Object o = clazz.newInstance();
+	        appleController = (AppleController) o;			
+		} catch (ClassNotFoundException e) {
+			throw new AppleNotFoundException("Can't find a class of name '" + appleName + "'.", e);
+		} catch (InstantiationException e) {
+			throw new AppleNotFoundException("Can't instatiate the class '" + appleName + "'.", e);
+		} catch (IllegalAccessException e) {
+			throw new AppleNotFoundException("The class '" + appleName + "' can't be accessed. Check
the class modifiers.", e);
+		}
+		return appleController;
     }
 
     private void processApple(List params, Redirector redirector, AppleController app, WebContinuation
wk)



Mime
View raw message