You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/02/25 19:12:58 UTC
svn commit: r380964 - in /cocoon/trunk/cocoon-core/src:
main/java/org/apache/cocoon/core/container/spring/
test/java/org/apache/cocoon/ test/java/org/apache/cocoon/core/
test/java/org/apache/cocoon/core/container/
test/java/org/apache/cocoon/environmen...
Author: cziegeler
Date: Sat Feb 25 10:12:54 2006
New Revision: 380964
URL: http://svn.apache.org/viewcvs?rev=380964&view=rev
Log:
Fix handling of default component for a selector
Start fixing test cases
Removed:
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/RoleManagerTestCase.java
Modified:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/MockProcessor.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestBootstrapEnvironment.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/CoreServiceManagerTestCase.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java Sat Feb 25 10:12:54 2006
@@ -240,10 +240,7 @@
String category) {
final ComponentInfo component = (ComponentInfo)context.getConfigurationInfo().getComponents().get(category + "Selector");
if ( component != null ) {
- final String defaultComponent = component.getConfiguration().getAttribute("default", null);
- if ( defaultComponent != null ) {
- info.setDefaultType(category, defaultComponent);
- }
+ info.setDefaultType(category, component.getDefaultValue());
}
}
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java Sat Feb 25 10:12:54 2006
@@ -19,35 +19,80 @@
import org.apache.avalon.framework.parameters.Parameters;
/**
- * Meta-information about a component.
+ * Meta-information about an Avalon based component.
+ * This simple bean holds most information of a component defined in the
+ * Avalon based configuration files, like the configuration for the component,
+ * it's logger etc.
+ *
+ * Avalon supports different component models:
+ * MODEL_PRIMITIVE: Each time a component of this type is requested, a new instance is
+ * created.
+ * MODEL_SINGLETON: Only on component of this type exists per container.
+ * MODEL_POOLED: The container creates a pool of components for this type and serves
+ * a request out of this pool. If the pool exceeds, then the pool will
+ * create new instances which are not put into the pool, so the
+ * model "primitive" will be used.
*
* @since 2.2
* @version $Id$
*/
public final class ComponentInfo {
+ /** The model of the component is unknown. Reflection is used later on to determine the model. */
public static final int MODEL_UNKNOWN = -1;
+ /** New instance per lookup. */
public static final int MODEL_PRIMITIVE = 0;
+ /** One single instance per container. */
public static final int MODEL_SINGLETON = 1;
+ /** Several instances are pooled by the container. */
public static final int MODEL_POOLED = 2;
- public static final int MODEL_NON_THREAD_SAFE_POOLED = 3;
- public static final String TYPE_SINGLETON = "singleton";
- public static final String TYPE_POOLED = "pooled";
- public static final String TYPE_NON_THREAD_SAFE_POOLED = "non-thread-safe-pooled";
+ /** One single instance per container. */
+ private static final String TYPE_SINGLETON = "singleton";
+ /** Several instances are pooled by the container. */
+ private static final String TYPE_POOLED = "pooled";
+ /** Several instances are pooled by the container. */
+ private static final String TYPE_NON_THREAD_SAFE_POOLED = "non-thread-safe-pooled";
+ /** The model for this component. */
private int model;
+
+ /** An optional method which is invoked by the container on initialization. */
private String initMethodName;
+
+ /** An optional method which is invoked by the container on destruction. */
private String destroyMethodName;
+
+ /** An optional method which is invoked by the container when the component is put back into the pool. */
private String poolInMethodName;
+
+ /** An optional method which is invoked by the container when the component is fetched from the pool. */
private String poolOutMethodName;
+
+ /** The class name of the component. */
private String componentClassName;
+
+ /** The configuration of the component. */
private Configuration configuration;
+
+ /** The configuration of the component as parameters. */
private Parameters parameters;
+
+ /** The optional logger category (relative to the category of the container). */
private String loggerCategory;
+
+ /** The role of the component (= bean name in Spring). */
private String role;
+
+ /** An alias for the component role. */
private String alias;
+ /** The default component for selectors. */
+ private String defaultValue;
+
+ /**
+ * Create a new info.
+ */
public ComponentInfo() {
this.model = MODEL_PRIMITIVE;
}
@@ -154,33 +199,38 @@
return this.configuration.getLocation();
}
- /* (non-Javadoc)
+ /**
* @see java.lang.Object#toString()
*/
public String toString() {
return "ServiceInfo: {class=" + this.getComponentClassName()+"}";
}
- public void fill(Configuration attr) {
+ public void fill(Configuration config) {
// test model
- final String model = attr.getAttribute("model", null);
+ final String model = config.getAttribute("model", null);
if ( TYPE_POOLED.equals(model) ) {
this.setModel(ComponentInfo.MODEL_POOLED);
- this.setPoolInMethodName(attr.getAttribute("pool-in", null));
- this.setPoolOutMethodName(attr.getAttribute("pool-out", null));
+ this.setPoolInMethodName(config.getAttribute("pool-in", null));
+ this.setPoolOutMethodName(config.getAttribute("pool-out", null));
} else if (TYPE_NON_THREAD_SAFE_POOLED.equals(model)) {
- this.setModel(ComponentInfo.MODEL_NON_THREAD_SAFE_POOLED);
- this.setPoolInMethodName(attr.getAttribute("pool-in", null));
- this.setPoolOutMethodName(attr.getAttribute("pool-out", null));
+ this.setModel(ComponentInfo.MODEL_POOLED);
+ this.setPoolInMethodName(config.getAttribute("pool-in", null));
+ this.setPoolOutMethodName(config.getAttribute("pool-out", null));
} else if ( TYPE_SINGLETON.equals(model) ) {
this.setModel(ComponentInfo.MODEL_SINGLETON);
}
// init/destroy methods
- this.setInitMethodName(attr.getAttribute("init", null));
- this.setDestroyMethodName(attr.getAttribute("destroy", null));
+ this.setInitMethodName(config.getAttribute("init", null));
+ this.setDestroyMethodName(config.getAttribute("destroy", null));
// logging
- this.setLoggerCategory(attr.getAttribute("logger", null));
- this.setRole(attr.getAttribute("role", null));
+ this.setLoggerCategory(config.getAttribute("logger", null));
+ this.setRole(config.getAttribute("role", null));
+ // default value
+ final String newDefaultValue = config.getAttribute("default", null);
+ if ( newDefaultValue != null ) {
+ this.defaultValue = newDefaultValue;
+ }
}
/**
@@ -236,5 +286,31 @@
return true;
}
return false;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * Create a new component info with the same configuration
+ * as the current one.
+ * @return An identical component info.
+ */
+ public ComponentInfo copy() {
+ final ComponentInfo info = new ComponentInfo();
+ info.model = this.model;
+ info.initMethodName = this.initMethodName;
+ info.destroyMethodName = this.destroyMethodName;
+ info.poolInMethodName = this.poolInMethodName;
+ info.poolOutMethodName = this.poolOutMethodName;
+ info.componentClassName = this.componentClassName;
+ info.configuration = this.configuration;
+ info.parameters = this.parameters;
+ info.loggerCategory = this.loggerCategory;
+ info.role = this.role;
+ info.alias = this.alias;
+ info.defaultValue = this.defaultValue;
+ return info;
}
}
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java Sat Feb 25 10:12:54 2006
@@ -87,7 +87,7 @@
while ( i.hasNext() ) {
final ComponentInfo current = (ComponentInfo)i.next();
if ( current.isSelector() ) {
- this.configInfo.getClassNames().put(current.getRole(), current);
+ this.configInfo.getClassNames().put(current.getRole(), current.copy());
}
}
} else {
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java Sat Feb 25 10:12:54 2006
@@ -91,8 +91,7 @@
current.setModel(ComponentInfo.MODEL_POOLED);
}
}
- if ( current.getModel() == ComponentInfo.MODEL_NON_THREAD_SAFE_POOLED
- || current.getModel() == ComponentInfo.MODEL_POOLED ) {
+ if ( current.getModel() == ComponentInfo.MODEL_POOLED ) {
poolable = true;
singleton = false;
} else if ( current.getModel() != ComponentInfo.MODEL_SINGLETON ) {
@@ -119,10 +118,9 @@
buffer.append(" <constructor-arg type=\"java.lang.String\"><value>");
buffer.append(role.substring(0, role.length()-8));
buffer.append("</value></constructor-arg>\n");
- if ( current.getConfiguration() != null
- && current.getConfiguration().getAttribute("default", null) != null ) {
+ if ( current.getDefaultValue() != null ) {
buffer.append(" <property name=\"default\"><value>");
- buffer.append(current.getConfiguration().getAttribute("default"));
+ buffer.append(current.getDefaultValue());
buffer.append("</value></property>\n");
}
buffer.append("</bean>\n");
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/MockProcessor.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/MockProcessor.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/MockProcessor.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/MockProcessor.java Sat Feb 25 10:12:54 2006
@@ -15,7 +15,8 @@
*/
package org.apache.cocoon;
-import org.apache.avalon.framework.configuration.Configuration;
+import java.util.Map;
+
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.SourceResolver;
@@ -37,7 +38,7 @@
/* (non-Javadoc)
* @see org.apache.cocoon.Processor#getComponentConfigurations()
*/
- public Configuration[] getComponentConfigurations() {
+ public Map getComponentConfigurations() {
return null;
}
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java Sat Feb 25 10:12:54 2006
@@ -74,7 +74,6 @@
new TestBootstrapEnvironment(this.getConfiguration(),
this.classDir,
environmentContext,
- this.logger,
this.processorClassName);
this.coreUtil = new TestCoreUtil(env);
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestBootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestBootstrapEnvironment.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestBootstrapEnvironment.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestBootstrapEnvironment.java Sat Feb 25 10:12:54 2006
@@ -15,7 +15,6 @@
*/
package org.apache.cocoon.core;
-import java.io.File;
import java.net.URL;
import org.apache.avalon.framework.context.DefaultContext;
@@ -36,40 +35,14 @@
public TestBootstrapEnvironment(String configuration,
String contextPath,
Context environmentContext,
- Logger logger,
String processorClassName) {
this.configuration = configuration;
this.contextPath = contextPath;
this.environmentContext = environmentContext;
- this.logger = logger;
this.processorClassName = processorClassName;
}
/**
- * @see org.apache.cocoon.core.BootstrapEnvironment#getBootstrapLogger(org.apache.cocoon.core.BootstrapEnvironment.LogLevel)
- */
- public Logger getBootstrapLogger(LogLevel logLevel) {
- return this.logger;
- }
-
- /** Log a message during bootstrapping. This is used to log
- * information before the logging system is setup.
- * @param message A message.
- */
- public void log(String message) {
- this.logger.info(message);
- }
-
- /** Log a message during bootstrapping. This is used to log
- * information before the logging system is setup.
- * @param message A message.
- * @param error An error.
- */
- public void log(String message, Throwable error) {
- this.logger.info(message, error);
- }
-
- /**
* Pass the root logger back to the environment. As soon as the
* logging system is set up, this method is called.
* @param rootLogger The root logger.
@@ -87,10 +60,6 @@
settings.setProcessorClassName(this.processorClassName);
}
- public void configureLoggingContext(DefaultContext context) {
- // simply do nothing
- }
-
public void configure(DefaultContext context) {
}
@@ -103,15 +72,6 @@
*/
public String getContextURL() {
return this.contextPath;
- }
-
- /**
- * Returns a file to the application context.
- * @return A file pointing to the context or null if the context is not
- * writeable.
- */
- public File getContextForWriting() {
- return null;
}
/**
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java Sat Feb 25 10:12:54 2006
@@ -15,47 +15,22 @@
*/
package org.apache.cocoon.core;
-import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.logger.Logger;
import org.apache.cocoon.core.BootstrapEnvironment;
import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.environment.mock.MockContext;
public class TestCoreUtil extends CoreUtil {
+
public TestCoreUtil(BootstrapEnvironment env) throws Exception {
- super(env);
+ super(env, new MockContext());
this.classloader = TestCoreUtil.class.getClassLoader();
}
// Simplified logging
protected void initLogger() {
this.log = ((TestBootstrapEnvironment)this.env).logger;
- this.loggerManager = new DefaultLoggerManager(this.log);
}
// Simplified classloader handling
protected void updateEnvironment() throws Exception {}
-
- /**
- * We use this simple logger manager that sends all output to the console (logger)
- */
- protected static class DefaultLoggerManager implements LoggerManager {
-
- private Logger logger;
-
- public DefaultLoggerManager(Logger logger) {
- this.logger = logger;
- }
- /* (non-Javadoc)
- * @see org.apache.avalon.excalibur.logger.LoggerManager#getDefaultLogger()
- */
- public Logger getDefaultLogger() {
- return this.logger;
- }
- /* (non-Javadoc)
- * @see org.apache.avalon.excalibur.logger.LoggerManager#getLoggerForCategory(java.lang.String)
- */
- public Logger getLoggerForCategory(String arg0) {
- return this.logger;
- }
- }
}
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/CoreServiceManagerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/CoreServiceManagerTestCase.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/CoreServiceManagerTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/CoreServiceManagerTestCase.java Sat Feb 25 10:12:54 2006
@@ -82,7 +82,6 @@
// we setup a hierarchy of service managers
// let's start with a core component and settings
MutableSettings settings = new MutableSettings();
- settings.setLazyMode(false);
settings.makeReadOnly();
Core core = new Core(settings, null);
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java Sat Feb 25 10:12:54 2006
@@ -15,9 +15,6 @@
*/
package org.apache.cocoon.environment.commandline.test;
-import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.avalon.framework.logger.Logger;
-
import org.apache.cocoon.environment.commandline.CommandLineContext;
import junit.framework.TestCase;
@@ -69,11 +66,7 @@
commandLineContextDir = System.getProperty("java.io.tmpdir", "/tmp");
new File(commandLineContextDir, "foo" + File.separator + "bar").mkdirs();
- String level = System.getProperty("junit.test.loglevel", "" + ConsoleLogger.LEVEL_DEBUG);
- Logger logger = new ConsoleLogger(Integer.parseInt(level));
-
commandLineContext = new CommandLineContext(commandLineContextDir);
- commandLineContext.enableLogging(logger);
}
/**
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java?rev=380964&r1=380963&r2=380964&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java Sat Feb 25 10:12:54 2006
@@ -80,4 +80,13 @@
mappings.clear();
initparameters.clear();
}
+
+ public void log(Exception arg0, String arg1) {
+ }
+
+ public void log(String arg0, Throwable arg1) {
+ }
+
+ public void log(String arg0) {
+ }
}