[CVS spice] Added methods to transform objects to Avalon lifecycle interfaces.

mauro-yCVjj/[email protected] 17 Jun 2004 22:27:22 -0000
Newsgroups gmane.comp.java.spice.cvs
Message-ID <[email protected]>
Commit in spice/components/alchemist/src/java/org/codehaus/spice/alchemist on MAIN

activity/ActivityAlchemist.java +82 added 1.1

configuration/ConfigurationAlchemist.java +33 -1 1.1 -> 1.2

logger/LoggerAlchemist.java +34 -1 1.1 -> 1.2

+149 -2

1 added + 2 modified, total 3 files

Added methods to transform objects to Avalon lifecycle interfaces.

----------

spice/components/alchemist/src/java/org/codehaus/spice/alchemist/activity

ActivityAlchemist.java added at 1.1

diff -N ActivityAlchemist.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ActivityAlchemist.java 17 Jun 2004 22:27:22 -0000 1.1
@@ -0,0 +1,82 @@

+/*
+ * Copyright (C) The Spice Group. All rights reserved.
+ *
+ * This software is published under the terms of the Spice
+ * Software License version 1.1, a copy of which has been included
+ * with this distribution in the LICENSE.txt file.
+ */
+package org.codehaus.spice.alchemist.activity;
+
+/**
+ * Utility class containing methods to transform Activity objects.
+ *
+ * @author Mauro Talevi
+ * @version $Revision: 1.1 $ $Date: 2004/06/17 22:27:22 $
+ */
+public class ActivityAlchemist {
+
+ /**
+ * Determines if an object is Avalon Initializable
+ *
+ * @param object the Object to check
+ * @return A boolean <code>true</code> if the object is an instance of
+ * {@link org.apache.avalon.framework.activity.Initializable}
+ */
+ public static boolean isAvalonInitializable( final Object object ){
+ if ( object instanceof org.apache.avalon.framework.activity.Initializable )
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Casts an object to Avalon Initializable if possible.
+ *
+ * @param object the Object to cast
+ * @return A {@link org.apache.avalon.framework.activity.Initializable}
+ * @throws IllegalArgumentException if not Avalon Initializable.
+ */
+ public static org.apache.avalon.framework.activity.Initializable toAvalonInitializable( final Object object ){
+ if ( isAvalonInitializable( object ) )
+ {
+ return (org.apache.avalon.framework.activity.Initializable)object;
+ }
+ final String message = ( object != null ? object.getClass().getName() : "Object" )
+ + " is not Avalon Initializable";
+ throw new IllegalArgumentException( message );
+ }
+
+ /**
+ * Determines if an object is Avalon Disposable
+ *
+ * @param object the Object to check
+ * @return A boolean <code>true</code> if the object is an instance of
+ * {@link org.apache.avalon.framework.activity.Disposable}
+ */
+ public static boolean isAvalonDisposable( final Object object ){
+ if ( object instanceof org.apache.avalon.framework.activity.Disposable )
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Casts an object to Avalon Disposable if possible.
+ *
+ * @param object the Object to cast
+ * @return A {@link org.apache.avalon.framework.activity.Disposable}
+ * @throws IllegalArgumentException if not Avalon Disposable.
+ */
+ public static org.apache.avalon.framework.activity.Disposable toAvalonDisposable( final Object object ){
+ if ( isAvalonDisposable( object ) )
+ {
+ return (org.apache.avalon.framework.activity.Disposable)object;
+ }
+ final String message = ( object != null ? object.getClass().getName() : "Object" )
+ + " is not Avalon Disposable";
+ throw new IllegalArgumentException( message );
+ }
+
+}

----------

spice/components/alchemist/src/java/org/codehaus/spice/alchemist/configuration

ConfigurationAlchemist.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- ConfigurationAlchemist.java 13 Jun 2004 13:35:14 -0000 1.1
+++ ConfigurationAlchemist.java 17 Jun 2004 22:27:22 -0000 1.2
@@ -13,7 +13,7 @@

* Utility class containing methods to transform Configuration objects.
*
* @author Mauro Talevi

- * @version $Revision: 1.1 $ $Date: 2004/06/13 13:35:14 $

+ * @version $Revision: 1.2 $ $Date: 2004/06/17 22:27:22 $

*/
public class ConfigurationAlchemist
{

@@ -37,5 +37,37 @@

public static org.apache.avalon.framework.configuration.Configuration toAvalonConfiguration( final Configuration configuration )
{
return new AvalonConfiguration( configuration );

+ }
+
+ /**
+ * Determines if an object is Avalon Configurable
+ *
+ * @param object the Object to check
+ * @return A boolean <code>true</code> if the object is an instance of
+ * {@link org.apache.avalon.framework.configuration.Configurable}
+ */
+ public static boolean isAvalonConfigurable( final Object object ){
+ if ( object instanceof org.apache.avalon.framework.configuration.Configurable )
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Casts an object to Avalon Configurable if possible.
+ *
+ * @param object the Object to cast
+ * @return A {@link org.apache.avalon.framework.configuration.Configurable}
+ * @throws IllegalArgumentException if not Avalon Configurable.
+ */
+ public static org.apache.avalon.framework.configuration.Configurable toAvalonConfigurable( final Object object ){
+ if ( isAvalonConfigurable( object ) )
+ {
+ return (org.apache.avalon.framework.configuration.Configurable)object;
+ }
+ final String message = ( object != null ? object.getClass().getName() : "Object" )
+ + " is not Avalon Configurable";
+ throw new IllegalArgumentException( message );

}
}

----------

spice/components/alchemist/src/java/org/codehaus/spice/alchemist/logger

LoggerAlchemist.java 1.1 -> 1.2

diff -u -r1.1 -r1.2
--- LoggerAlchemist.java 13 Jun 2004 13:35:14 -0000 1.1
+++ LoggerAlchemist.java 17 Jun 2004 22:27:22 -0000 1.2
@@ -13,7 +13,7 @@

* Utility class containing methods to transform Logger objects.
*
* @author Mauro Talevi

- * @version $Revision: 1.1 $ $Date: 2004/06/13 13:35:14 $

+ * @version $Revision: 1.2 $ $Date: 2004/06/17 22:27:22 $

*/
public class LoggerAlchemist
{

@@ -38,4 +38,37 @@

{
return new AvalonLogger( logger );
}

+
+ /**
+ * Determines if an object is Avalon LogEnabled
+ *
+ * @param object the Object to check
+ * @return A boolean <code>true</code> if the object is an instance of
+ * {@link org.apache.avalon.framework.logger.LogEnabled}
+ */
+ public static boolean isAvalonLogEnabled( final Object object ){
+ if ( object instanceof org.apache.avalon.framework.logger.LogEnabled )
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Casts an object to Avalon LogEnabled if possible.
+ *
+ * @param object the Object to cast
+ * @return A {@link org.apache.avalon.framework.logger.LogEnabled}
+ * @throws IllegalArgumentException if not Avalon LogEnabled.
+ */
+ public static org.apache.avalon.framework.logger.LogEnabled toAvalonLogEnabled( final Object object ){
+ if ( isAvalonLogEnabled( object ) )
+ {
+ return (org.apache.avalon.framework.logger.LogEnabled)object;
+ }
+ final String message = ( object != null ? object.getClass().getName() : "Object" )
+ + " is not Avalon LogEnabled";
+ throw new IllegalArgumentException( message );
+ }
+

}

CVSspam 0.2.8