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/05/09 13:58:42 UTC
cvs commit: jakarta-turbine-fulcrum/yaafi/src/java/org/apache/fulcrum/yaafi/service/baseservice BaseService.java BaseServiceImpl.java
sgoeschl 2005/05/09 04:58:42
Modified: yaafi/src/java/org/apache/fulcrum/yaafi/service/baseservice
BaseService.java BaseServiceImpl.java
Log:
Updated implementation to be used in production
Revision Changes Path
1.3 +3 -1 jakarta-turbine-fulcrum/yaafi/src/java/org/apache/fulcrum/yaafi/service/baseservice/BaseService.java
Index: BaseService.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/src/java/org/apache/fulcrum/yaafi/service/baseservice/BaseService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseService.java 20 Jan 2005 15:46:38 -0000 1.2
+++ BaseService.java 9 May 2005 11:58:42 -0000 1.3
@@ -18,7 +18,9 @@
*/
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Reconfigurable;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.parameters.Parameterizable;
@@ -33,7 +35,7 @@
*/
public interface BaseService
- extends LogEnabled, Contextualizable, Serviceable, Configurable, Parameterizable
+ extends LogEnabled, Contextualizable, Serviceable, Configurable, Parameterizable, Reconfigurable, Disposable
{
// This interface doesn't exposes any other methods
}
1.5 +239 -24 jakarta-turbine-fulcrum/yaafi/src/java/org/apache/fulcrum/yaafi/service/baseservice/BaseServiceImpl.java
Index: BaseServiceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/src/java/org/apache/fulcrum/yaafi/service/baseservice/BaseServiceImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BaseServiceImpl.java 1 Mar 2005 10:43:44 -0000 1.4
+++ BaseServiceImpl.java 9 May 2005 11:58:42 -0000 1.5
@@ -17,6 +17,8 @@
* limitations under the License.
*/
+import java.io.File;
+
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.context.Context;
@@ -29,7 +31,8 @@
/**
* Base class for a service implementation capturing the Avalon
- * configuration artifats
+ * serviceConfiguration artifacts. Take care that using this class
+ * introduces a dependency to the YAAFI library.
*
* @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
*/
@@ -38,27 +41,56 @@
extends AbstractLogEnabled
implements BaseService
{
- /** The name of the service - we don't know it yet */
- // private String name;
+ /** The name of the service as defined in the role configuration file */
+ private String serviceName;
- /** The context supplied by the avalon framework */
- private Context context;
+ /** The context supplied by the Avalon framework */
+ private Context serviceContext;
- /** The service manager supplied by the avalon framework */
+ /** The service manager supplied by the Avalon framework */
private ServiceManager serviceManager;
- /** The configuraton supplied by the avalon framework */
- private Configuration configuration;
+ /** The configuraton supplied by the Avalon framework */
+ private Configuration serviceConfiguration;
/** The parameters supplied by the avalon framework */
- private Parameters parameters;
+ private Parameters serviceParameters;
+
+ /** the Avalon application directory */
+ private File serviceApplicationDir;
+
+ /** the Avalon temp directory */
+ private File serviceTempDir;
+
+ /** the Avalon partition name */
+ private String servicePartitionName;
+
+ /** the class loader for this service */
+ private ClassLoader serviceClassLoader;
+
+ /////////////////////////////////////////////////////////////////////////
+ // Avalon Lifecycle Implementation
+ /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Constructor
+ */
+ public BaseServiceImpl()
+ {
+ // nothing to do
+ }
/**
* @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
*/
public void contextualize(Context context) throws ContextException
{
- this.context = context;
+ this.serviceContext = context;
+ this.serviceName = (String) context.get("urn:avalon:name");
+ this.serviceApplicationDir = (File) context.get("urn:avalon:home");
+ this.serviceTempDir = (File) context.get("urn:avalon:temp");
+ this.servicePartitionName = (String) context.get("urn:avalon:partition");
+ this.serviceClassLoader = (ClassLoader) context.get("urn:avalon:classloader");
}
/**
@@ -70,43 +102,194 @@
}
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ * @see org.apache.avalon.framework.serviceConfiguration.Configurable#configure(org.apache.avalon.framework.serviceConfiguration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException
{
- this.configuration = configuration;
+ this.serviceConfiguration = configuration;
}
/**
- * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+ * @see org.apache.avalon.framework.servieParameters.Parameterizable#parameterize(org.apache.avalon.framework.servieParameters.Parameters)
*/
public void parameterize(Parameters parameters) throws ParameterException
{
- this.parameters = parameters;
+ this.serviceParameters = parameters;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void reconfigure(Configuration configuration) throws ConfigurationException
+ {
+ this.serviceConfiguration = configuration;
}
/**
- * @return Returns the configuration.
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
- protected Configuration getConfiguration()
+ public void dispose()
{
- return this.configuration;
+ this.serviceApplicationDir = null;
+ this.serviceClassLoader = null;
+ this.serviceConfiguration = null;
+ this.serviceContext = null;
+ this.serviceManager = null;
+ this.serviceName = null;
+ this.serviceParameters = null;
+ this.servicePartitionName = null;
+ this.serviceTempDir = null;
}
+
+ /////////////////////////////////////////////////////////////////////////
+ // Service Implementation
+ /////////////////////////////////////////////////////////////////////////
/**
- * @return Returns the context.
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+
+ result.append( getClass().getName() + "@" + Integer.toHexString(hashCode()));
+
+ result.append("{");
+
+ result.append("serviceName: ");
+ result.append(this.getServiceName());
+ result.append(";");
+
+ result.append(" servicePartitionName: ");
+ result.append(this.getServicePartitionName());
+ result.append(";");
+
+ result.append(" serviceApplicatonDir: ");
+ result.append(this.getServiceApplicationDir().getAbsolutePath());
+ result.append(";");
+
+ result.append(" serviceTempDir: ");
+ result.append(this.getServiceTempDir().getAbsolutePath());
+ result.append(";");
+
+ result.append(" serviceContext: ");
+ result.append(this.getServiceContext().toString());
+ result.append(";");
+
+ result.append(" serviceConfiguration: ");
+ result.append(this.getServiceConfiguration().toString());
+ result.append(";");
+
+ result.append(" serviceParameters: ");
+ result.append(Parameters.toProperties(this.getServiceParameters()));
+ result.append(";");
+
+ result.append(" serviceClassLoader: ");
+ result.append(this.getServiceClassLoader());
+ result.append(";");
+
+ result.append(" serviceLogger: ");
+ result.append(this.getLogger());
+ result.append(";");
+
+ result.append(" serviceManager: ");
+ result.append(this.getServiceManager());
+
+ result.append("}");
+
+ return result.toString();
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
+ */
+ protected boolean hasService(String key)
+ {
+ return this.getServiceManager().hasService(key);
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
+ */
+ protected Object lookup(String key)
+ {
+ try
+ {
+ return this.getServiceManager().lookup(key);
+ }
+ catch (ServiceException e)
+ {
+ String msg = "Unable to lookup the following service : " + key;
+ this.getLogger().error(msg,e);
+ throw new RuntimeException(msg);
+ }
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
*/
- protected Context getContext()
+ protected void release(Object object)
{
- return this.context;
+ this.release(object);
}
+
+ /**
+ * Determines the absolute file based on the application directory
+ * @param fileName the filename
+ * @return the absolute file
+ */
+ protected File createAbsoluteFile( String fileName )
+ {
+ File result = new File(fileName);
+
+ if( result.isAbsolute() == false )
+ {
+ result = new File( this.getServiceApplicationDir(), fileName );
+ }
+ return result;
+ }
+
+ /**
+ * Determines the absolute path based on the application directory
+ * @param fileName the filename
+ * @return the absolute path
+ */
+ protected String createAbsolutePath( String fileName )
+ {
+ return this.createAbsoluteFile(fileName).getAbsolutePath();
+ }
+
+ /**
+ * @return Returns the serviceApplicationDir.
+ */
+ protected File getServiceApplicationDir()
+ {
+ return serviceApplicationDir;
+ }
+
+ /**
+ * @return Returns the serviceClassLoader.
+ */
+ protected ClassLoader getServiceClassLoader()
+ {
+ return serviceClassLoader;
+ }
+
+ /**
+ * @return Returns the serviceConfiguration.
+ */
+ protected Configuration getServiceConfiguration()
+ {
+ return serviceConfiguration;
+ }
+
/**
- * @return Returns the parameters.
+ * @return Returns the serviceContext.
*/
- protected Parameters getParameters()
+ protected Context getServiceContext()
{
- return this.parameters;
+ return serviceContext;
}
/**
@@ -114,6 +297,38 @@
*/
protected ServiceManager getServiceManager()
{
- return this.serviceManager;
+ return serviceManager;
+ }
+
+ /**
+ * @return Returns the serviceName.
+ */
+ protected String getServiceName()
+ {
+ return serviceName;
+ }
+
+ /**
+ * @return Returns the serviceParameters.
+ */
+ protected Parameters getServiceParameters()
+ {
+ return serviceParameters;
}
+
+ /**
+ * @return Returns the servicePartitionName.
+ */
+ protected String getServicePartitionName()
+ {
+ return servicePartitionName;
+ }
+
+ /**
+ * @return Returns the serviceTempDir.
+ */
+ protected File getServiceTempDir()
+ {
+ return serviceTempDir;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org