You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sg...@apache.org on 2005/11/01 13:45:03 UTC
svn commit: r330049 - in /jakarta/turbine/core/trunk/src:
java/org/apache/turbine/services/
java/org/apache/turbine/services/avaloncomponent/
java/org/apache/turbine/services/localization/
java/org/apache/turbine/services/rundata/ java/org/apache/turbi...
Author: sgoeschl
Date: Tue Nov 1 04:44:34 2005
New Revision: 330049
URL: http://svn.apache.org/viewcvs?rev=330049&view=rev
Log:
Implementing transparent service lookup independent where the service is actually located (Turbine or Avalon container)
Added:
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/TurbineServiceProvider.java
Removed:
jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/crypto/CryptoRunningInECMTest.java
Modified:
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/BaseServiceBroker.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/InstantiationException.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/ServiceBroker.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/AvalonComponentService.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineAvalonComponentService.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineYaafiComponentService.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/Localization.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/LocalizationTool.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java
jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/security/BaseSecurityService.java
jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/LoadingComponentsTest.java
jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/cache/FulcrumCacheComponentTest.java
jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/intake/IntakeToolTest.java
jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/mimetype/FulcrumMimetypeComponentTest.java
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/BaseServiceBroker.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/BaseServiceBroker.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/BaseServiceBroker.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/BaseServiceBroker.java Tue Nov 1 04:44:34 2005
@@ -1,6 +1,5 @@
package org.apache.turbine.services;
-
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -19,6 +18,7 @@
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
@@ -38,6 +38,9 @@
* <li>Providing <code>Services</code> with a configuration based on
* system wide configuration mechanism.</li>
* </ul>
+ * <li>Integration of TurbineServiceProviders for looking up
+ * non-local services
+ * </ul>
*
* @author <a href="mailto:burton@apache.org">Kevin Burton</a>
* @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
@@ -52,19 +55,19 @@
/**
* Mapping of Service names to class names.
*/
- protected Configuration mapping = new BaseConfiguration();
+ private Configuration mapping = new BaseConfiguration();
/**
* A repository of Service instances.
*/
- protected Hashtable services = new Hashtable();
+ private Hashtable services = new Hashtable();
/**
* Configuration for the services broker.
* The configuration should be set by the application
* in which the services framework is running.
*/
- protected Configuration configuration;
+ private Configuration configuration;
/**
* A prefix for <code>Service</code> properties in
@@ -89,7 +92,7 @@
* the requirement of having init(Object) all
* together.
*/
- protected Hashtable serviceObjects = new Hashtable();
+ private Hashtable serviceObjects = new Hashtable();
/** Logging */
private static Log log = LogFactory.getLog(BaseServiceBroker.class);
@@ -98,15 +101,21 @@
* Application root path as set by the
* parent application.
*/
- protected String applicationRoot;
+ private String applicationRoot;
/**
+ * mapping from service names to instances of TurbineServiceProviders
+ */
+ private Hashtable serviceProviderInstanceMap = new Hashtable();
+
+ /**
* Default constructor, protected as to only be useable by subclasses.
*
* This constructor does nothing.
*/
protected BaseServiceBroker()
{
+ // nothing to do
}
/**
@@ -170,6 +179,7 @@
/**
* Get an application specific service object.
*
+ * @param name the name of the service object
* @return Object application specific service object
*/
public Object getServiceObject(String name)
@@ -383,12 +393,13 @@
if (service != null && service.getInit())
{
service.shutdown();
+
if (service.getInit() && service instanceof BaseService)
{
// BaseService::shutdown() does this by default,
// but could've been overriden poorly.
((BaseService) service).setInit(false);
- }
+ }
}
}
catch (InstantiationException e)
@@ -440,39 +451,53 @@
* @exception InstantiationException if the service is unknown or
* can't be initialized.
*/
- public Service getService(String name) throws InstantiationException
+ public Object getService(String name) throws InstantiationException
{
Service service;
- try
+
+ if (this.isLocalService(name))
{
- service = getServiceInstance(name);
- if (!service.getInit())
- {
- synchronized (service.getClass())
- {
- if (!service.getInit())
- {
- log.info("Start Initializing service (late): " + name);
- service.init();
- log.info("Finish Initializing service (late): " + name);
- }
- }
- }
- if (!service.getInit())
- {
- // this exception will be caught & rethrown by this very method.
- // getInit() returning false indicates some initialization issue,
- // which in turn prevents the InitableBroker from passing a
- // reference to a working instance of the initable to the client.
- throw new InitializationException(
- "init() failed to initialize service " + name);
- }
- return service;
+ try
+ {
+ service = getServiceInstance(name);
+ if (!service.getInit())
+ {
+ synchronized (service.getClass())
+ {
+ if (!service.getInit())
+ {
+ log.info("Start Initializing service (late): " + name);
+ service.init();
+ log.info("Finish Initializing service (late): " + name);
+ }
+ }
+ }
+ if (!service.getInit())
+ {
+ // this exception will be caught & rethrown by this very method.
+ // getInit() returning false indicates some initialization issue,
+ // which in turn prevents the InitableBroker from passing a
+ // reference to a working instance of the initable to the client.
+ throw new InitializationException(
+ "init() failed to initialize service " + name);
+ }
+ return service;
+ }
+ catch (InitializationException e)
+ {
+ throw new InstantiationException("Service " + name +
+ " failed to initialize", e);
+ }
+ }
+ else if (this.isNonLocalService(name))
+ {
+ return this.getNonLocalService(name);
}
- catch (InitializationException e)
+ else
{
- throw new InstantiationException("Service " + name +
- " failed to initialize", e);
+ throw new InstantiationException(
+ "ServiceBroker: unknown service " + name
+ + " requested");
}
}
@@ -502,7 +527,7 @@
{
String className=null;
- if (!mapping.containsKey(name))
+ if (!this.isLocalService(name))
{
throw new InstantiationException(
"ServiceBroker: unknown service " + name
@@ -517,8 +542,15 @@
{
try
{
- service = (Service)
- Class.forName(className).newInstance();
+ service = (Service) Class.forName(className).newInstance();
+
+ // check if the newly created service is also a
+ // service provider - if so then remember it
+ if (service instanceof TurbineServiceProvider)
+ {
+ this.serviceProviderInstanceMap.put(name,service);
+ }
+
}
// those two errors must be passed to the VM
catch (ThreadDeath t)
@@ -608,4 +640,75 @@
{
return applicationRoot;
}
+
+ /**
+ * Determines if the requested service is managed by this
+ * ServiceBroker.
+ *
+ * @param name The name of the Service requested.
+ * @return true if the service is managed by the this ServiceBroker
+ */
+ protected boolean isLocalService(String name)
+ {
+ return this.mapping.containsKey(name);
+ }
+
+ /**
+ * Determines if the requested service is managed by an initialized
+ * TurbineServiceProvider. We use the service names to lookup
+ * the TurbineServiceProvider to ensure that we get a fully
+ * inititialized service.
+ *
+ * @param name The name of the Service requested.
+ * @return true if the service is managed by a TurbineServiceProvider
+ */
+ protected boolean isNonLocalService(String name)
+ {
+ String serviceName = null;
+ TurbineServiceProvider turbineServiceProvider = null;
+ Enumeration list = this.serviceProviderInstanceMap.keys();
+
+ while (list.hasMoreElements())
+ {
+ serviceName = (String) list.nextElement();
+ turbineServiceProvider = (TurbineServiceProvider) this.getService(serviceName);
+
+ if (turbineServiceProvider.exists(name))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Get a non-local service managed by a TurbineServiceProvider.
+ *
+ * @param name The name of the Service requested.
+ * @return the requested service
+ * @throws InstantiationException the service couldn't be instantiated
+ */
+ protected Object getNonLocalService(String name)
+ throws InstantiationException
+ {
+ String serviceName = null;
+ TurbineServiceProvider turbineServiceProvider = null;
+ Enumeration list = this.serviceProviderInstanceMap.keys();
+
+ while (list.hasMoreElements())
+ {
+ serviceName = (String) list.nextElement();
+ turbineServiceProvider = (TurbineServiceProvider) this.getService(serviceName);
+
+ if (turbineServiceProvider.exists(name))
+ {
+ return turbineServiceProvider.get(name);
+ }
+ }
+
+ throw new InstantiationException(
+ "ServiceBroker: unknown non-local service " + name
+ + " requested");
+ }
}
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/InstantiationException.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/InstantiationException.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/InstantiationException.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/InstantiationException.java Tue Nov 1 04:44:34 2005
@@ -50,8 +50,7 @@
* and nested Throwable.
*
* @param msg The detail message.
- * @param nested the exception or error that caused this exception
- * to be thrown.
+ * @param t the root exception.
*/
public InstantiationException(String msg, Throwable t)
{
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/ServiceBroker.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/ServiceBroker.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/ServiceBroker.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/ServiceBroker.java Tue Nov 1 04:44:34 2005
@@ -89,7 +89,7 @@
* @exception InstantiationException if the service is unknown or
* can't be initialized.
*/
- Service getService(String name) throws InstantiationException;
+ Object getService(String name) throws InstantiationException;
/**
* Returns the configuration of a specific service. Services
Added: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/TurbineServiceProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/TurbineServiceProvider.java?rev=330049&view=auto
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/TurbineServiceProvider.java (added)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/TurbineServiceProvider.java Tue Nov 1 04:44:34 2005
@@ -0,0 +1,53 @@
+package org.apache.turbine.services;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+/**
+ * Interface for telling Turbine that the implementation class
+ * is an external service provider therefore can be used for looking
+ * up services not found by the Turbine implementation. It is
+ * assumed that the referenced service container handles the
+ * complete lifecycle of its services.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+public interface TurbineServiceProvider
+{
+ /**
+ * Returns an instance of the requested service. If the
+ * given servise is not available/found we throw a RuntimeException
+ * since this is less intrusive.
+ *
+ * @param roleName the name of the requested service
+ * @return an instance of the service
+ * @throws InstantiationException the service could not be instantiated
+ */
+ public Object get(String roleName) throws InstantiationException;
+
+ /**
+ * Releases the instance you got before. This is only really
+ * required when not working with service singletons.
+ *
+ * @param component the component to release
+ */
+ public void release(Object component);
+
+ /**
+ * Is the service known to the service container?
+ */
+ public boolean exists(String roleName);
+}
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/AvalonComponentService.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/AvalonComponentService.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/AvalonComponentService.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/AvalonComponentService.java Tue Nov 1 04:44:34 2005
@@ -18,6 +18,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.turbine.services.Service;
+import org.apache.turbine.services.TurbineServiceProvider;
/**
* This service allows access to avalon components.
@@ -27,7 +28,7 @@
* @version $Id$
*/
public interface AvalonComponentService
- extends Service, ServiceManager
+ extends Service, ServiceManager, TurbineServiceProvider
{
/** The publically visible name of the service */
String SERVICE_NAME = "AvalonComponentService";
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineAvalonComponentService.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineAvalonComponentService.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineAvalonComponentService.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineAvalonComponentService.java Tue Nov 1 04:44:34 2005
@@ -39,6 +39,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.Turbine;
import org.apache.turbine.services.InitializationException;
+import org.apache.turbine.services.InstantiationException;
import org.apache.turbine.services.TurbineBaseService;
/**
@@ -248,5 +249,40 @@
public boolean hasService(String roleName)
{
return manager.hasComponent(roleName);
+ }
+
+ // -------------------------------------------------------------
+ // TurbineServiceProvider
+ // -------------------------------------------------------------
+
+ /**
+ * @see org.apache.turbine.services.TurbineServiceProvider#exists(java.lang.String)
+ */
+ public boolean exists(String roleName)
+ {
+ return this.hasService(roleName);
+ }
+
+ /**
+ * @see org.apache.turbine.services.TurbineServiceProvider#get(java.lang.String)
+ */
+ public Object get(String roleName) throws InstantiationException
+ {
+ try
+ {
+ return this.lookup(roleName);
+ }
+ catch (ServiceException e)
+ {
+ String msg = "Unable to get the following service : " + roleName;
+ log.error(msg);
+ throw new InstantiationException(msg);
+ }
+ catch (Throwable t)
+ {
+ String msg = "Unable to get the following service : " + roleName;
+ log.error(msg,t);
+ throw new InstantiationException(msg,t);
+ }
}
}
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineYaafiComponentService.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineYaafiComponentService.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineYaafiComponentService.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/avaloncomponent/TurbineYaafiComponentService.java Tue Nov 1 04:44:34 2005
@@ -18,9 +18,6 @@
*/
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
@@ -38,6 +35,7 @@
import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory;
import org.apache.turbine.Turbine;
import org.apache.turbine.services.InitializationException;
+import org.apache.turbine.services.InstantiationException;
import org.apache.turbine.services.TurbineBaseService;
/**
@@ -131,7 +129,8 @@
// create the configuration for YAAFI
- ServiceContainerConfiguration config = this.createServiceContainerConfiguration(conf);
+ ServiceContainerConfiguration config =
+ this.createServiceContainerConfiguration(conf);
config.setLogger( this.createAvalonLogger() );
config.setApplicationRootDir( homePath );
@@ -149,19 +148,6 @@
String msg = "Initializing YAAFI failed";
log.error(msg,e);
throw e;
- }
-
- // lookup the services to be backward compatible
-
- try
- {
- this.lookupServices(conf);
- }
- catch (Exception e)
- {
- String msg = "Looking up the Avalon services failed";
- log.error(msg,e);
- throw e;
}
}
@@ -190,11 +176,8 @@
}
/**
- * Releases the component
+ * Releases the component.
*
- * @param source. The path to the handler for this component For example, if the object is a
- * java.sql.Connection object sourced from the "/turbine-merlin/datasource"
- * component, the call would be :- release("/turbine-merlin/datasource", conn);
* @param component the component to release
*/
public void release(Object component)
@@ -312,39 +295,38 @@
return result;
}
+ // -------------------------------------------------------------
+ // TurbineServiceProvider
+ // -------------------------------------------------------------
+
/**
- * Lookup the services defined in the Turbine config file. This
- * code is taken from the ECM implementation but I'm not sure
- * why it is needed at all.
- *
- * @throws Exception generic exception
- * @todo not sure why we need the additional component lookup
- */
- private void lookupServices( Configuration conf )
- throws Exception
- {
- List lookupComponents = conf.getList(
- COMPONENT_LOOKUP_KEY,
- new ArrayList()
- );
-
- for (Iterator it = lookupComponents.iterator(); it.hasNext();)
- {
- String serviceName = (String) it.next();
-
- try
- {
- Object service = this.container.lookup(serviceName);
- log.info("Lookup for service " + serviceName + " successful");
- this.container.release(service);
-
- }
- catch (Exception e)
- {
- String msg = "Lookup for service " + serviceName + " failed!";
- log.error(msg);
- throw e;
- }
- }
+ * @see org.apache.turbine.services.TurbineServiceProvider#exists(java.lang.String)
+ */
+ public boolean exists(String roleName)
+ {
+ return this.hasService(roleName);
+ }
+
+ /**
+ * @see org.apache.turbine.services.TurbineServiceProvider#get(java.lang.String)
+ */
+ public Object get(String roleName) throws InstantiationException
+ {
+ try
+ {
+ return this.lookup(roleName);
+ }
+ catch (ServiceException e)
+ {
+ String msg = "Unable to get the following service : " + roleName;
+ log.error(msg);
+ throw new InstantiationException(msg);
+ }
+ catch (Throwable t)
+ {
+ String msg = "Unable to get the following service : " + roleName;
+ log.error(msg,t);
+ throw new InstantiationException(msg,t);
+ }
}
}
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/Localization.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/Localization.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/Localization.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/Localization.java Tue Nov 1 04:44:34 2005
@@ -24,10 +24,9 @@
import javax.servlet.http.HttpServletRequest;
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.commons.lang.exception.NestableRuntimeException;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.util.RunData;
/**
@@ -244,14 +243,12 @@
protected static final LocalizationService getService()
{
try {
- AvalonComponentService acs = (AvalonComponentService) TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
- return (LocalizationService)acs.lookup(LocalizationService.class.getName());
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ return (LocalizationService)serviceManager.getService(LocalizationService.class.getName());
}
- catch (ServiceException se){
- throw new NestableRuntimeException(se);
+ catch (Exception e){
+ throw new NestableRuntimeException(e);
}
-
-
}
/**
@@ -272,11 +269,11 @@
public static boolean isInitialized() {
try {
- AvalonComponentService acs = (AvalonComponentService) TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
- acs.lookup(LocalizationService.class.getName());
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ serviceManager.getService(LocalizationService.class.getName());
return true;
}
- catch (ServiceException se){
+ catch (Exception e){
return false;
}
}
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/LocalizationTool.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/LocalizationTool.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/LocalizationTool.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/localization/LocalizationTool.java Tue Nov 1 04:44:34 2005
@@ -23,10 +23,11 @@
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.localization.LocalizationService;
import org.apache.turbine.services.InstantiationException;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.util.RunData;
+
/**
* A pull tool which provides lookups for localized text by delegating
* to the configured Fulcrum <code>LocalizationService</code>.
@@ -55,14 +56,17 @@
{
if (localizationService == null)
{
- AvalonComponentService ecm =
- (AvalonComponentService) TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
- try {
- localizationService = (LocalizationService)ecm.lookup(LocalizationService.ROLE);
- }
- catch (Exception e) {
- throw new InstantiationException("Problem looking up Localization Service:"+e.getMessage());
- }
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ try
+ {
+ localizationService = (LocalizationService)serviceManager.getService(
+ LocalizationService.ROLE
+ );
+ }
+ catch (Exception e)
+ {
+ throw new InstantiationException("Problem looking up Localization Service:"+e.getMessage());
+ }
}
return localizationService;
}
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java Tue Nov 1 04:44:34 2005
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.PrintWriter;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -34,21 +33,18 @@
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.ecs.Document;
import org.apache.ecs.Element;
import org.apache.ecs.StringElement;
import org.apache.fulcrum.mimetype.MimeTypeService;
-
import org.apache.turbine.Turbine;
import org.apache.turbine.TurbineConstants;
import org.apache.turbine.om.security.User;
import org.apache.turbine.pipeline.DefaultPipelineData;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.services.template.TurbineTemplate;
import org.apache.turbine.util.FormMessages;
import org.apache.turbine.util.ServerData;
@@ -320,10 +316,10 @@
if (!locale.equals(Locale.US))
{
log.debug("We don't have US Locale!");
- AvalonComponentService ecm= (AvalonComponentService)TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
+ ServiceManager serviceManager = TurbineServices.getInstance();
MimeTypeService mimeTypeService=null;
try {
- mimeTypeService= (MimeTypeService)ecm.lookup(MimeTypeService.ROLE);
+ mimeTypeService= (MimeTypeService)serviceManager.getService(MimeTypeService.ROLE);
}
catch (Exception e){
throw new RuntimeException(e);
Modified: jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/security/BaseSecurityService.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/security/BaseSecurityService.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/security/BaseSecurityService.java (original)
+++ jakarta/turbine/core/trunk/src/java/org/apache/turbine/services/security/BaseSecurityService.java Tue Nov 1 04:44:34 2005
@@ -33,9 +33,9 @@
import org.apache.turbine.om.security.Role;
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.InitializationException;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineBaseService;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.services.factory.FactoryService;
import org.apache.turbine.util.security.AccessControlList;
import org.apache.turbine.util.security.DataBackendException;
@@ -152,10 +152,10 @@
SecurityService.SECURE_PASSWORDS_ALGORITHM_KEY,
SecurityService.SECURE_PASSWORDS_ALGORITHM_DEFAULT);
- AvalonComponentService ecm = (AvalonComponentService)TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
CryptoService cs = null;
try {
- cs = (CryptoService)ecm.lookup(CryptoService.ROLE);
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ cs = (CryptoService)serviceManager.getService(CryptoService.ROLE);
}
catch (Exception e){
throw new RuntimeException("Could not access Crypto Service",e);
Modified: jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/LoadingComponentsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/LoadingComponentsTest.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/LoadingComponentsTest.java (original)
+++ jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/LoadingComponentsTest.java Tue Nov 1 04:44:34 2005
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import java.util.Locale;
+
import org.apache.fulcrum.cache.DefaultGlobalCacheService;
import org.apache.fulcrum.crypto.CryptoService;
import org.apache.fulcrum.factory.FactoryService;
@@ -25,12 +27,14 @@
import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.test.BaseTestCase;
import org.apache.turbine.util.TurbineConfig;
+
/**
* Unit test for verifing that we can load all the appropriate components from the
* appropriate Container. For now that is just ECM (AvalonComponentService)
* but in the future with mixed containers there could be multiple.
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
+ * @author <a href="mailto:sgoeschl@apache.org">Siegfried Goeschl</a>
* @version $Id$
*/
public class LoadingComponentsTest extends BaseTestCase
@@ -40,25 +44,103 @@
{
super(name);
}
- public void testLoading() throws Exception
+
+ /**
+ * Test to load a couple of Avalon services directly by the
+ * AvalonComponentService.
+ *
+ * @throws Exception loading failed
+ */
+ public void testLoadingByAvalonComponentService() throws Exception
{
- AvalonComponentService ecm =
+ AvalonComponentService avalonComponentService =
(AvalonComponentService) TurbineServices.getInstance().getService(
AvalonComponentService.SERVICE_NAME);
- DefaultGlobalCacheService dgcs = (DefaultGlobalCacheService)ecm.lookup(DefaultGlobalCacheService.ROLE);
- assertNotNull(dgcs);
- CryptoService cs = (CryptoService)ecm.lookup(CryptoService.ROLE);
+ assertNotNull(avalonComponentService);
+
+ DefaultGlobalCacheService dgcs = (DefaultGlobalCacheService)avalonComponentService.lookup(DefaultGlobalCacheService.ROLE);
+ assertNotNull(dgcs);
+ CryptoService cs = (CryptoService)avalonComponentService.lookup(CryptoService.ROLE);
+ assertNotNull(cs);
+ LocalizationService ls = (LocalizationService)avalonComponentService.lookup(LocalizationService.ROLE);
+ assertNotNull(ls);
+ IntakeService intake = (IntakeService)avalonComponentService.lookup(IntakeService.ROLE);
+ assertNotNull(intake);
+ FactoryService fs = (FactoryService)avalonComponentService.lookup(FactoryService.ROLE);
+ assertNotNull(fs);
+ MimeTypeService mimetype = (MimeTypeService)avalonComponentService.lookup(MimeTypeService.ROLE);
+ assertNotNull(mimetype);
+ }
+
+ /**
+ * Test to load a couple of Avalon services by using the
+ * TurbineServices which delegate the service retrieval to
+ * the AvalonComponentService
+ *
+ * @throws Exception loading failed
+ */
+ public void testLoadingByTurbineServices() throws Exception
+ {
+ ServiceManager serviceManager = TurbineServices.getInstance();
+
+ DefaultGlobalCacheService dgcs = (DefaultGlobalCacheService)serviceManager.getService(DefaultGlobalCacheService.ROLE);
+ assertNotNull(dgcs);
+ CryptoService cs = (CryptoService)serviceManager.getService(CryptoService.ROLE);
assertNotNull(cs);
- LocalizationService ls = (LocalizationService)ecm.lookup(LocalizationService.ROLE);
+ LocalizationService ls = (LocalizationService)serviceManager.getService(LocalizationService.ROLE);
assertNotNull(ls);
- IntakeService intake = (IntakeService)ecm.lookup(IntakeService.ROLE);
+ IntakeService intake = (IntakeService)serviceManager.getService(IntakeService.ROLE);
assertNotNull(intake);
- FactoryService fs = (FactoryService)ecm.lookup(FactoryService.ROLE);
+ FactoryService fs = (FactoryService)serviceManager.getService(FactoryService.ROLE);
assertNotNull(fs);
- MimeTypeService mimetype = (MimeTypeService)ecm.lookup(MimeTypeService.ROLE);
+ MimeTypeService mimetype = (MimeTypeService)serviceManager.getService(MimeTypeService.ROLE);
assertNotNull(mimetype);
}
+
+ /**
+ * Lookup up an unknown servie
+ * @throws Exception
+ */
+ public void testLookupUnknownService() throws Exception
+ {
+ ServiceManager serviceManager = TurbineServices.getInstance();
+
+ try
+ {
+ serviceManager.getService("foo");
+ fail("We expect an InstantiationException");
+ }
+ catch (InstantiationException e)
+ {
+ // that'w what we expect
+ return;
+ }
+ catch (Throwable t)
+ {
+ fail("We expect an InstantiationException");
+ }
+ }
+
+ /**
+ * Shutdown the AvalonComponentService where the MimeTypeService
+ * resides and lookup the MimeTypeService. This should trigger
+ * a late initialization of AvalonComponentService and returns
+ * a fully functional MimeTypeService.
+ */
+ public void testAvalonComponentServiceShutdown() throws Exception
+ {
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ serviceManager.shutdownService(AvalonComponentService.SERVICE_NAME);
+
+ MimeTypeService mimeTypeService = (MimeTypeService) serviceManager.getService(MimeTypeService.class.getName());
+ assertNotNull(mimeTypeService);
+
+ Locale locale = new Locale("en", "US");
+ String s = mimeTypeService.getCharSet(locale);
+ assertEquals("ISO-8859-1", s);
+ }
+
public void setUp() throws Exception
{
tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
Modified: jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/cache/FulcrumCacheComponentTest.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/cache/FulcrumCacheComponentTest.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/cache/FulcrumCacheComponentTest.java (original)
+++ jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/cache/FulcrumCacheComponentTest.java Tue Nov 1 04:44:34 2005
@@ -18,8 +18,8 @@
import org.apache.fulcrum.cache.CachedObject;
import org.apache.fulcrum.cache.GlobalCacheService;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.test.BaseTestCase;
import org.apache.turbine.util.TurbineConfig;
/**
@@ -38,13 +38,11 @@
}
public void testComponentAndFacaded() throws Exception
{
- AvalonComponentService acs = (AvalonComponentService) TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
- GlobalCacheService cache = (GlobalCacheService)acs.lookup(GlobalCacheService.ROLE);
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ GlobalCacheService cache = (GlobalCacheService)serviceManager.getService(GlobalCacheService.ROLE);
CachedObject inputObject = new CachedObject(new Double(10.2));
cache.addObject("testObj",inputObject);
-
}
-
public void setUp() throws Exception
{
Modified: jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/intake/IntakeToolTest.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/intake/IntakeToolTest.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/intake/IntakeToolTest.java (original)
+++ jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/intake/IntakeToolTest.java Tue Nov 1 04:44:34 2005
@@ -26,7 +26,6 @@
import org.apache.fulcrum.intake.model.Group;
import org.apache.turbine.om.security.User;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.services.rundata.RunDataService;
import org.apache.turbine.test.BaseTestCase;
import org.apache.turbine.test.EnhancedMockHttpServletRequest;
@@ -36,6 +35,7 @@
import com.mockobjects.servlet.MockHttpServletResponse;
import com.mockobjects.servlet.MockHttpSession;
import com.mockobjects.servlet.MockServletConfig;
+
/**
* Unit test for Localization Tool. Verifies that localization works the same using the
* deprecated Turbine localization service as well as the new Fulcrum Localization
@@ -104,17 +104,14 @@
RunData runData = rds.getRunData(request, response, config);
return runData;
}
+
public void setUp() throws Exception
{
tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
- tc.initialize();
-
- AvalonComponentService avalon =
- (AvalonComponentService) TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
-
- avalon.lookup(IntakeService.class.getName());
-
+ tc.initialize();
+ TurbineServices.getInstance().getService(IntakeService.class.getName());
}
+
public void tearDown() throws Exception
{
if (tc != null)
Modified: jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/mimetype/FulcrumMimetypeComponentTest.java
URL: http://svn.apache.org/viewcvs/jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/mimetype/FulcrumMimetypeComponentTest.java?rev=330049&r1=330048&r2=330049&view=diff
==============================================================================
--- jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/mimetype/FulcrumMimetypeComponentTest.java (original)
+++ jakarta/turbine/core/trunk/src/test/org/apache/turbine/services/mimetype/FulcrumMimetypeComponentTest.java Tue Nov 1 04:44:34 2005
@@ -1,6 +1,5 @@
package org.apache.turbine.services.mimetype;
-
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -17,18 +16,19 @@
* limitations under the License.
*/
-
import java.util.Locale;
import org.apache.fulcrum.mimetype.MimeTypeService;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.test.BaseTestCase;
import org.apache.turbine.util.TurbineConfig;
+
/**
* Unit test for Accessing the Fulcrum Mimetype component within Turbine.
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
+ * @author <a href="mailto:sgoeschl@apache.org">Siegfried Goeschl</a>
* @version $Id$
*/
public class FulcrumMimetypeComponentTest extends BaseTestCase
@@ -40,10 +40,8 @@
}
public void testComponent() throws Exception
{
- AvalonComponentService acs =
- (AvalonComponentService) TurbineServices.getInstance().getService(
- AvalonComponentService.SERVICE_NAME);
- MimeTypeService mimeTypeService = (MimeTypeService) acs.lookup(MimeTypeService.class.getName());
+ ServiceManager serviceManager = TurbineServices.getInstance();
+ MimeTypeService mimeTypeService = (MimeTypeService) serviceManager.getService(MimeTypeService.class.getName());
Locale locale = new Locale("en", "US");
String s = mimeTypeService.getCharSet(locale);
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org