henning 2003/03/11 09:07:55
Modified: src/java/org/apache/turbine TurbineConstants.java
src/java/org/apache/turbine/services/assemblerbroker/util/python
PythonActionFactory.java PythonBaseFactory.java
PythonLayoutFactory.java
PythonNavigationFactory.java PythonPageFactory.java
PythonScreenFactory.java
Log:
- Python Factories now use the constants from TurbineConstants
- Base Factory uses getConfiguration()
- Logic for Python Class Loading reworked
- Some magic values replaced by constants
Revision Changes Path
1.22 +3 -1
jakarta-turbine-2/src/java/org/apache/turbine/TurbineConstants.java
Index: TurbineConstants.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/TurbineConstants.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- TurbineConstants.java 11 Mar 2003 14:34:15 -0000 1.21
+++ TurbineConstants.java 11 Mar 2003 17:07:55 -0000 1.22
@@ -320,4 +320,6 @@
/** Prefix for action related classes and templates */
String ACTION_PREFIX = "actions";
+ /** Prefix for page related classes and templates */
+ String PAGE_PREFIX = "pages";
}
1.7 +8 -6
jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonActionFactory.java
Index: PythonActionFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonActionFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PythonActionFactory.java 9 Mar 2003 03:06:24 -0000 1.6
+++ PythonActionFactory.java 11 Mar 2003 17:07:55 -0000 1.7
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-// Turbine Utility Classes
+import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Assembler;
/**
@@ -64,9 +64,11 @@
* of its subclasses.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class PythonActionFactory extends PythonBaseFactory
+public class PythonActionFactory
+ extends PythonBaseFactory
{
/**
* Get an Assembler.
@@ -75,9 +77,9 @@
* @return an Assembler
* @throws Exception generic exception
*/
- public Assembler getAssembler(String name) throws Exception
+ public Assembler getAssembler(String name)
+ throws Exception
{
- return getAssembler("actions", name);
+ return getAssembler(TurbineConstants.ACTION_PREFIX, name);
}
-
}
1.7 +46 -27
jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java
Index: PythonBaseFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonBaseFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PythonBaseFactory.java 9 Mar 2003 03:06:25 -0000 1.6
+++ PythonBaseFactory.java 11 Mar 2003 17:07:55 -0000 1.7
@@ -55,31 +55,49 @@
*/
import java.io.File;
+
+import org.apache.commons.configuration.Configuration;
+
+import org.apache.commons.lang.StringUtils;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.turbine.modules.Assembler;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
+import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
import org.apache.turbine.services.assemblerbroker.util.AssemblerFactory;
-import org.apache.turbine.services.resources.TurbineResources;
+
import org.python.core.Py;
import org.python.util.PythonInterpreter;
/**
- * A screen factory that attempts to load a python class in the
+ * A factory that attempts to load a python class in the
* JPython interpreter and execute it as a Turbine screen.
* The JPython script should inherit from Turbine Screen or one
* of its subclasses.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public abstract class PythonBaseFactory implements AssemblerFactory
+public abstract class PythonBaseFactory
+ implements AssemblerFactory
{
+ /** Key for the python path */
+ public static final String PYTHON_PATH = "python.path";
+
+ /** Global config file. This is executed before every screen */
+ public static final String PYTHON_CONFIG_FILE = "conf.py";
/** Logging */
private static Log log = LogFactory.getLog(PythonBaseFactory.class);
+ /** Our configuration */
+ private Configuration conf =
+ TurbineAssemblerBroker.getService().getConfiguration();
+
/**
* Get an Assembler.
*
@@ -91,29 +109,32 @@
public Assembler getAssembler(String subDirectory, String name)
throws Exception
{
- Assembler assembler = null;
- // The filename of the Python script
- String fName = null;
- String confName = null;
-
- log.info("Screen name for JPython " + name);
+ String path = conf.getString(PYTHON_PATH);
- try
- {
- String path = TurbineResources.getString(
- TurbineServices.SERVICE_PREFIX
- + AssemblerBrokerService.SERVICE_NAME
- + ".python.path") + "/";
- confName = path + "conf.py";
- fName = path + subDirectory + "/" + name.toLowerCase() + ".py";
- }
- catch (Exception e)
+ if (StringUtils.isEmpty(path))
{
throw new Exception(
"Python path not found - check your Properties");
}
+
+ log.debug("Screen name for JPython: " + name);
+
+ Assembler assembler = null;
+
+ String confName = path + "/" + PYTHON_CONFIG_FILE;
+
+ // The filename of the Python script
+ StringBuffer fName = new StringBuffer();
+
+ fName.append(path);
+ fName.append("/");
+ fName.append(subDirectory);
+ fName.append("/");
+ fName.append(name.toLowerCase());
+ fName.append(".py");
+
+ File f = new File(fName.toString());
- File f = new File(fName);
if (f.exists())
{
try
@@ -122,7 +143,7 @@
PythonInterpreter interp = new PythonInterpreter();
// Make sure the Py Interpreter use the right classloader
- // This is necissarry for servlet engines generally has
+ // This is necessary for servlet engines generally has
// their own classloader implementations and servlets aren't
// loaded in the system classloader. The python script will
// load java package
@@ -132,14 +153,14 @@
this.getClass().getClassLoader());
// We import the Python SYS module. Now we don't need to do this
- // explicitely in the scrypt. We always use the sys module to
+ // explicitely in the script. We always use the sys module to
// do stuff like loading java package
// org.apache.turbine.services.assemblerbroker.util.python;
interp.exec("import sys");
// Now we try to load the script file
interp.execfile(confName);
- interp.execfile(fName);
+ interp.execfile(fName.toString());
try
{
@@ -166,9 +187,7 @@
// We log the error here because this code is not widely tested
// yet. After we tested the code on a range of platforms this
// won't be usefull anymore.
- log.error("PYTHON SCRIPT SCREEN LOADER ERROR:");
- log.error(e.toString());
- // Let the error fall through like the normal way.
+ log.error("PYTHON SCRIPT SCREEN LOADER ERROR:", e);
throw e;
}
}
1.7 +8 -5
jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonLayoutFactory.java
Index: PythonLayoutFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonLayoutFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PythonLayoutFactory.java 9 Mar 2003 03:06:25 -0000 1.6
+++ PythonLayoutFactory.java 11 Mar 2003 17:07:55 -0000 1.7
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-// Turbine Utility Classes
+import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Assembler;
/**
@@ -64,9 +64,11 @@
* of its subclasses.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class PythonLayoutFactory extends PythonBaseFactory
+public class PythonLayoutFactory
+ extends PythonBaseFactory
{
/**
* Get an Assembler.
@@ -75,8 +77,9 @@
* @return an Assembler
* @throws Exception generic exception
*/
- public Assembler getAssembler(String name) throws Exception
+ public Assembler getAssembler(String name)
+ throws Exception
{
- return getAssembler("layouts", name);
+ return getAssembler(TurbineConstants.LAYOUT_PREFIX, name);
}
}
1.7 +8 -5
jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonNavigationFactory.java
Index: PythonNavigationFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonNavigationFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PythonNavigationFactory.java 9 Mar 2003 03:06:25 -0000 1.6
+++ PythonNavigationFactory.java 11 Mar 2003 17:07:55 -0000 1.7
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-// Turbine Classes
+import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Assembler;
/**
@@ -64,9 +64,11 @@
* of its subclasses.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class PythonNavigationFactory extends PythonBaseFactory
+public class PythonNavigationFactory
+ extends PythonBaseFactory
{
/**
* Get an Assembler.
@@ -75,8 +77,9 @@
* @return an Assembler
* @throws Exception generic exception
*/
- public Assembler getAssembler(String name) throws Exception
+ public Assembler getAssembler(String name)
+ throws Exception
{
- return getAssembler("navigations", name);
+ return getAssembler(TurbineConstants.NAVIGATION_PREFIX, name);
}
}
1.7 +8 -5
jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonPageFactory.java
Index: PythonPageFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonPageFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PythonPageFactory.java 9 Mar 2003 03:06:25 -0000 1.6
+++ PythonPageFactory.java 11 Mar 2003 17:07:55 -0000 1.7
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-// Turbine Classes
+import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Assembler;
/**
@@ -64,9 +64,11 @@
* of its subclasses.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class PythonPageFactory extends PythonBaseFactory
+public class PythonPageFactory
+ extends PythonBaseFactory
{
/**
* Get an Assembler.
@@ -75,8 +77,9 @@
* @return an Assembler
* @throws Exception generic exception
*/
- public Assembler getAssembler(String name) throws Exception
+ public Assembler getAssembler(String name)
+ throws Exception
{
- return getAssembler("pages", name);
+ return getAssembler(TurbineConstants.PAGE_PREFIX, name);
}
}
1.7 +8 -5
jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonScreenFactory.java
Index: PythonScreenFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/python/PythonScreenFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PythonScreenFactory.java 9 Mar 2003 03:06:25 -0000 1.6
+++ PythonScreenFactory.java 11 Mar 2003 17:07:55 -0000 1.7
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-// Turbine Classes
+import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Assembler;
/**
@@ -64,9 +64,11 @@
* of its subclasses.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class PythonScreenFactory extends PythonBaseFactory
+public class PythonScreenFactory
+ extends PythonBaseFactory
{
/**
* Get an Assembler.
@@ -75,8 +77,9 @@
* @return an Assembler
* @throws Exception generic exception
*/
- public Assembler getAssembler(String name) throws Exception
+ public Assembler getAssembler(String name)
+ throws Exception
{
- return getAssembler("screens", name);
+ return getAssembler(TurbineConstants.SCREEN_PREFIX, name);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]