[jboss-svn-commits] JBL Code SVN: r32338 - in labs/jbosstm/trunk: ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Apr 1 10:18:50 EDT 2010
Author: jhalliday
Date: 2010-04-01 10:18:48 -0400 (Thu, 01 Apr 2010)
New Revision: 32338
Added:
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/common/ClassloadingUtility.java
labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedAction.java
Removed:
labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedActionFactory.java
Modified:
labs/jbosstm/trunk/ArjunaCore/arjuna/build.xml
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBean.java
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBeanMBean.java
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/BasicAction.java
labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/CheckedActionTest.java
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java
Log:
Begin moving class loading responsibility to the environment bean classes. JBTM-735
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/build.xml
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/build.xml 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/build.xml 2010-04-01 14:18:48 UTC (rev 32338)
@@ -46,7 +46,7 @@
<tests>
<fileset dir="tests/classes" includes="**/*.java">
<exclude name="**/resources/**"/>
- <exclude name="**/DummyCheckedActionFactory.java"/>
+ <exclude name="**/DummyCheckedAction.java"/>
<exclude name="**/MyAccess.java"/>
<exclude name="**/Worker.java"/>
<exclude name="**/BasicCrashRecord.java"/>
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBean.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBean.java 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBean.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -20,6 +20,8 @@
*/
package com.arjuna.ats.arjuna.common;
+import com.arjuna.ats.arjuna.coordinator.CheckedActionFactory;
+import com.arjuna.ats.internal.arjuna.common.ClassloadingUtility;
import com.arjuna.common.internal.util.propertyservice.PropertyPrefix;
import com.arjuna.common.internal.util.propertyservice.FullPropertyName;
import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
@@ -33,7 +35,7 @@
@PropertyPrefix(prefix = "com.arjuna.ats.arjuna.coordinator.")
public class CoordinatorEnvironmentBean implements CoordinatorEnvironmentBeanMBean
{
- private volatile String actionStore = HashedActionStore.class.getName();
+ private volatile String actionStore = HashedActionStore.class.getName();
private volatile boolean asyncCommit = false;
private volatile boolean asyncPrepare = false;
private volatile boolean asyncRollback = false;
@@ -64,11 +66,13 @@
@FullPropertyName(name = "com.arjuna.ats.coordinator.beforeCompletionWhenRollbackOnly")
private volatile boolean beforeCompletionWhenRollbackOnly = false;
+
@FullPropertyName(name = "com.arjuna.ats.coordinator.checkedActionFactory")
- private volatile String checkedActionFactory = null;
+ private volatile String checkedActionFactoryClassName = "com.arjuna.ats.internal.arjuna.coordinator.CheckedActionFactoryImple";
+ private volatile CheckedActionFactory checkedActionFactory = null;
private volatile boolean alternativeRecordOrdering = false;
-
+
/**
* Returns the symbolic name for the action store type.
*
@@ -563,24 +567,82 @@
/**
* Returns the class name of an implementation of CheckedActionFactory
*
- * Default: null
+ * Default: "com.arjuna.ats.internal.arjuna.coordinator.CheckedActionFactoryImple"
* Equivalent deprecated property: com.arjuna.ats.coordinator.checkedActionFactory
*
* @return the class name of the CheckedActionFactory implementation to use.
*/
- public String getCheckedActionFactory()
+ public String getCheckedActionFactoryClassName()
{
+ return checkedActionFactoryClassName;
+ }
+
+ /**
+ * Sets the class name of the CheckedActionFactory implementation.
+ *
+ * @param checkedActionFactoryClassName the name of a class that implements CheckedActionFactory.
+ */
+ public void setCheckedActionFactoryClassName(String checkedActionFactoryClassName)
+ {
+ synchronized(this)
+ {
+ if(checkedActionFactoryClassName == null)
+ {
+ this.checkedActionFactory = null;
+ }
+ else if(!checkedActionFactoryClassName.equals(this.checkedActionFactoryClassName))
+ {
+ this.checkedActionFactory = null;
+ }
+ this.checkedActionFactoryClassName = checkedActionFactoryClassName;
+ }
+ }
+
+ /**
+ * Returns an instance of a class implementing CheckedActionFactory.
+ *
+ * If there is no pre-instantiated instance set and classloading or instantiation fails,
+ * this method will log appropriate warning and return null, not throw an exception.
+ *
+ * @return a CheckedActionFactory implementation instance, or null.
+ */
+ public CheckedActionFactory getCheckedActionFactory()
+ {
+ if(checkedActionFactory == null && checkedActionFactoryClassName != null)
+ {
+ synchronized (this) {
+ if(checkedActionFactory == null && checkedActionFactoryClassName != null) {
+ CheckedActionFactory instance = ClassloadingUtility.loadAndInstantiateClass(CheckedActionFactory.class, checkedActionFactoryClassName);
+ checkedActionFactory = instance;
+ }
+ }
+ }
+
return checkedActionFactory;
}
/**
- * Sets the class name of the checked CheckedActionFactory implementation.
+ * Sets the instance of CheckedActionFactory.
*
- * @param checkedActionFactory the name of a class that implements CheckedActionFactory.
+ * @param instance an Object that implements CheckedActionFactory, or null.
*/
- public void setCheckedActionFactory(String checkedActionFactory)
+ public void setCheckedActionFactory(CheckedActionFactory instance)
{
- this.checkedActionFactory = checkedActionFactory;
+ synchronized(this)
+ {
+ CheckedActionFactory oldInstance = this.checkedActionFactory;
+ checkedActionFactory = instance;
+
+ if(instance == null)
+ {
+ this.checkedActionFactoryClassName = null;
+ }
+ else if(instance != oldInstance)
+ {
+ String name = ClassloadingUtility.getNameForClass(instance);
+ this.checkedActionFactoryClassName = name;
+ }
+ }
}
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBeanMBean.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBeanMBean.java 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoordinatorEnvironmentBeanMBean.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -111,7 +111,7 @@
void setBeforeCompletionWhenRollbackOnly(boolean beforeCompletionWhenRollbackOnly);
- String getCheckedActionFactory();
+ String getCheckedActionFactoryClassName();
- void setCheckedActionFactory(String checkedActionFactory);
+ void setCheckedActionFactoryClassName(String checkedActionFactory);
}
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/BasicAction.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/BasicAction.java 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/BasicAction.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -1302,21 +1302,16 @@
/**
* Add the specified CheckedAction object to this transaction.
*
- * @return the previous <code>CheckedAction</code>.
* @see com.arjuna.ats.arjuna.coordinator.CheckedAction
*/
- public final synchronized CheckedAction setCheckedAction (CheckedAction c)
+ protected final synchronized void setCheckedAction (CheckedAction c)
{
criticalStart();
- CheckedAction toReturn = _checkedAction;
-
_checkedAction = c;
criticalEnd();
-
- return toReturn;
}
/**
@@ -4064,41 +4059,6 @@
// private Mutex _lock = new Mutex(); // TODO
- private static CheckedActionFactory _checkedActionFactory;
-
- static
- {
- /*
- * Make sure this can only be set once. Bad things can happen if the factory changes
- * during execution.
- */
-
- String checkedActionFactory = arjPropertyManager.getCoordinatorEnvironmentBean().getCheckedActionFactory();
-
- if (checkedActionFactory != null)
- {
- try
- {
- Class factory = Thread.currentThread().getContextClassLoader().loadClass(checkedActionFactory);
-
- _checkedActionFactory = (CheckedActionFactory) factory.newInstance();
- }
- catch (final Exception ex)
- {
- ex.printStackTrace();
-
- if (tsLogger.arjLoggerI18N.isWarnEnabled())
- {
- tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.checkedactionfactory",
- new Object[]{ checkedActionFactory }, ex);
- }
-
- throw new FatalError(tsLogger.arjLoggerI18N.getString("com.arjuna.ats.arjuna.coordinator.cafactoryerror")+" "+checkedActionFactory, ex);
- }
- }
- else
- _checkedActionFactory = new CheckedActionFactoryImple();
- }
-
+ private static CheckedActionFactory _checkedActionFactory = arjPropertyManager.getCoordinatorEnvironmentBean().getCheckedActionFactory();
}
Added: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/common/ClassloadingUtility.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/common/ClassloadingUtility.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/common/ClassloadingUtility.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates,
+ * and individual contributors as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2010,
+ * @author JBoss, by Red Hat.
+ */
+package com.arjuna.ats.internal.arjuna.common;
+
+import com.arjuna.ats.arjuna.logging.tsLogger;
+
+/**
+ * Utility functions, used mainly by the EnvironmentBeans, for managing dynamic classloading.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com) 2010-04
+ */
+public class ClassloadingUtility
+{
+ // this really belongs in common, but can't use logging from there at present.
+
+ /**
+ * Load, instantiate and return an instance of the named class, which is expected to be an implementation of
+ * the specified interface.
+ *
+ * In the event of error (ClassNotFound, ClassCast, can't instantiate, ...) this method will log the error and return null.
+ *
+ *
+ * @param iface the expected interface type.
+ * @param className the name of the class to load and instantiate.
+ * @param <T>
+ * @return an instantiate of the specified class, or null.
+ *
+ * @message com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_1 [com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_1] className is null
+ * @message com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_2 [com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_2] attempt to load {0} threw ClassNotFound. Wrong classloader?
+ * @message com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_3 [com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_3] class {0} does not implement {1}
+ * @message com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_4 [com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_4] can't create new instance of {0}
+ * @message com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_5 [com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_5] can't access {0}
+ */
+ public static <T> T loadAndInstantiateClass(Class<T> iface, String className) {
+
+ if (tsLogger.arjLogger.isDebugEnabled()) {
+ tsLogger.arjLogger.debug("Loading class " + className);
+ }
+
+ if (className == null)
+ {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_1");
+ return null;
+ }
+
+ Class<?> clazz;
+
+ try
+ {
+ clazz = Thread.currentThread().getContextClassLoader().loadClass( className ) ;
+ } catch(ClassNotFoundException e) {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_2", new Object[]{className}, e);
+ return null;
+ }
+
+ T instance = null;
+
+ try {
+ Class<? extends T> clazz2 = clazz.asSubclass(iface);
+ instance = (T)clazz2.newInstance();
+ } catch (ClassCastException e) {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_3", new Object[]{className, iface.getName()}, e);
+ }
+ catch (InstantiationException e) {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_4", new Object[]{className}, e);
+ } catch (IllegalAccessException e) {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.common.ClassloadingUtility_5", new Object[]{className}, e);
+ }
+
+ return instance;
+ }
+
+ /**
+ * Reverse mapping - obtain the class name for a given object.
+ *
+ * @param instance the object of interest
+ * @return the class name of the object, or null.
+ */
+ public static String getNameForClass(Object instance) {
+ if(instance == null) {
+ return null;
+ }
+
+ return instance.getClass().getName();
+ }
+}
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/CheckedActionTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/CheckedActionTest.java 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/CheckedActionTest.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -20,37 +20,23 @@
*/
package com.hp.mwtests.ts.arjuna.atomicaction;
-import java.util.Hashtable;
-
import com.arjuna.ats.arjuna.AtomicAction;
-import com.arjuna.ats.arjuna.common.Uid;
import com.arjuna.ats.arjuna.common.arjPropertyManager;
-import com.arjuna.ats.arjuna.coordinator.CheckedAction;
import org.junit.Test;
import static org.junit.Assert.*;
-class DummyCheckedAction extends CheckedAction
-{
- public void check (boolean isCommit, Uid actUid, Hashtable list)
- {
- _called = true;
- }
-
- public boolean called ()
- {
- return _called;
- }
-
- private boolean _called;
-}
+
public class CheckedActionTest
{
@Test
public void test()
{
- arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(DummyCheckedActionFactory.class.getCanonicalName());
+ arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactoryClassName(DummyCheckedAction.class.getName());
+ DummyCheckedAction.reset();
+ assertFalse(DummyCheckedAction.factoryCalled());
+ assertFalse(DummyCheckedAction.called());
AtomicAction A = new AtomicAction();
@@ -58,14 +44,19 @@
A.commit();
- assertTrue(success);
+ assertTrue(DummyCheckedAction.factoryCalled());
+ assertFalse(DummyCheckedAction.called());
}
@Test
public void testCheckedAction ()
{
+ arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactoryClassName(DummyCheckedAction.class.getName());
+ DummyCheckedAction.reset();
+ assertFalse(DummyCheckedAction.factoryCalled());
+ assertFalse(DummyCheckedAction.called());
+
AtomicAction A = new AtomicAction();
- DummyCheckedAction dca = new DummyCheckedAction();
A.begin();
@@ -75,13 +66,10 @@
*/
A.addChildThread(new Thread());
-
- A.setCheckedAction(dca);
A.commit();
- assertTrue(dca.called());
+ assertTrue(DummyCheckedAction.factoryCalled());
+ assertTrue(DummyCheckedAction.called());
}
-
- public static boolean success = false;
}
Added: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedAction.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedAction.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedAction.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package com.hp.mwtests.ts.arjuna.atomicaction;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.CheckedAction;
+import com.arjuna.ats.arjuna.coordinator.CheckedActionFactory;
+
+import java.util.Hashtable;
+
+public class DummyCheckedAction extends CheckedAction implements CheckedActionFactory
+{
+ private static CheckedAction instance = new DummyCheckedAction();
+ private static boolean _instanceCalled;
+ private static boolean _factoryCalled;
+
+ @Override
+ public CheckedAction getCheckedAction(Uid txId, String actionType)
+ {
+ _factoryCalled = true;
+ return instance;
+ }
+
+ public void check (boolean isCommit, Uid actUid, Hashtable list)
+ {
+ _instanceCalled = true;
+ }
+
+ public static boolean factoryCalled()
+ {
+ return _factoryCalled;
+ }
+
+ public static boolean called ()
+ {
+ return _instanceCalled;
+ }
+
+ public static void reset() {
+ _factoryCalled = false;
+ _instanceCalled = false;
+ }
+}
\ No newline at end of file
Deleted: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedActionFactory.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedActionFactory.java 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/atomicaction/DummyCheckedActionFactory.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-package com.hp.mwtests.ts.arjuna.atomicaction;
-
-import com.arjuna.ats.arjuna.common.Uid;
-import com.arjuna.ats.arjuna.coordinator.CheckedAction;
-import com.arjuna.ats.arjuna.coordinator.CheckedActionFactory;
-
-public class DummyCheckedActionFactory implements CheckedActionFactory
-{
- public CheckedAction getCheckedAction(final Uid txId,
- final String actionType)
- {
- CheckedActionTest.success = true;
-
- return new CheckedAction();
- }
-}
Modified: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java 2010-04-01 13:48:05 UTC (rev 32337)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java 2010-04-01 14:18:48 UTC (rev 32338)
@@ -20,16 +20,17 @@
*/
package com.arjuna.common.tests.simple;
-import com.arjuna.common.internal.util.propertyservice.ConcatenationPrefix;
-import com.arjuna.common.internal.util.propertyservice.PropertyPrefix;
import org.junit.Test;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.util.*;
import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
* EnvironmentBean tests
@@ -147,6 +148,11 @@
inputValue = new Integer(1001);
setter.invoke(bean, new Object[] {inputValue});
+ } else if(field.getType().toString().startsWith("interface ")) {
+
+ handleInterfaceField(bean, field, setter, getter);
+ return;
+
} else {
throw new Exception("unknown field type "+field.getType());
@@ -160,4 +166,42 @@
private static String capitalizeFirstLetter(String string) {
return (string.length()>0) ? (Character.toUpperCase(string.charAt(0))+string.substring(1)) : string;
}
+
+ private static void handleInterfaceField(Object bean, Field field, Method setter, Method getter)
+ throws Exception
+ {
+ Class interfaceType = field.getType();
+
+ String setterMethodName = setter.getName()+"ClassName";
+ Method classNameSetter = bean.getClass().getMethod(setterMethodName, new Class[] {String.class});
+
+ String getterMethodName = getter.getName()+"ClassName";
+ Method classNameGetter = bean.getClass().getMethod(getterMethodName, new Class[] {});
+
+ ///////
+
+ InvocationHandler invocationHandler = new DummyInvocationhandler();
+ Object proxy = Proxy.newProxyInstance(interfaceType.getClassLoader(), new Class[] { interfaceType }, invocationHandler);
+
+ setter.invoke(bean, new Object[] { proxy }); // setFoo()
+ assertSame(getter.invoke(bean, new Object[] {}), proxy); // getFoo
+
+ setter.invoke(bean, new Object[] { null }); // setFoo()
+ assertNull(getter.invoke(bean, new Object[] {})); // getFoo
+ assertNull(classNameGetter.invoke(bean, new Object[] {})); // getFooClassName
+
+ String bogusClassName = "bogusClassName";
+ classNameSetter.invoke(bean, new Object[] { bogusClassName });
+ assertNull(getter.invoke(bean, new Object[] {}));
+ assertEquals(bogusClassName, classNameGetter.invoke(bean, new Object[] {}));
+ }
+
+ private static class DummyInvocationhandler implements InvocationHandler {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return null;
+ }
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list