[jboss-cvs] JBossAS SVN: r109864 - in projects/jboss-jca/trunk: adapters/src/main/java/org/jboss/jca/adapters and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 13 04:29:18 EST 2010
Author: jesper.pedersen
Date: 2010-12-13 04:29:17 -0500 (Mon, 13 Dec 2010)
New Revision: 109864
Added:
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/Injection.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/SecurityActions.java
Removed:
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/
Modified:
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java
projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/LRUCachePolicy.java
projects/jboss-jca/trunk/build.xml
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java
Log:
[JBJCA-462] Fungal 0.9.0.Beta7
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java 2010-12-13 09:13:51 UTC (rev 109863)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnectionFactory.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -29,6 +29,7 @@
import org.jboss.jca.adapters.jdbc.spi.StaleConnectionChecker;
import org.jboss.jca.adapters.jdbc.spi.URLSelectorStrategy;
import org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker;
+import org.jboss.jca.adapters.jdbc.util.Injection;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -57,8 +58,6 @@
import org.jboss.logging.Logger;
-import com.github.fungal.api.util.Injection;
-
/**
* BaseWrapperManagedConnectionFactory
*
@@ -774,7 +773,7 @@
Injection injection = new Injection();
for (Entry<Object, Object> prop : exceptionSorterProps.entrySet())
{
- injection.inject(null, (String) prop.getKey(), (String) prop.getValue(), exceptionSorter);
+ injection.inject(exceptionSorter, (String)prop.getKey(), (String)prop.getValue());
}
return exceptionSorter.isExceptionFatal(e);
}
@@ -814,7 +813,7 @@
Injection injection = new Injection();
for (Entry<Object, Object> prop : validConnectionCheckerProps.entrySet())
{
- injection.inject(null, (String) prop.getKey(), (String) prop.getValue(), connectionChecker);
+ injection.inject(connectionChecker, (String)prop.getKey(), (String)prop.getValue());
}
return connectionChecker.isValidConnection(c);
}
@@ -857,7 +856,7 @@
Injection injection = new Injection();
for (Entry<Object, Object> prop : staleConnectionCheckerProps.entrySet())
{
- injection.inject(null, (String) prop.getKey(), (String) prop.getValue(), staleConnectionChecker);
+ injection.inject(staleConnectionChecker, (String)prop.getKey(), (String)prop.getValue());
}
return staleConnectionChecker.isStaleConnection(e);
}
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java 2010-12-13 09:13:51 UTC (rev 109863)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/PreparedStatementCache.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -22,7 +22,7 @@
package org.jboss.jca.adapters.jdbc;
-import org.jboss.jca.adapters.util.LRUCachePolicy;
+import org.jboss.jca.adapters.jdbc.util.LRUCachePolicy;
import java.sql.ResultSet;
import java.sql.SQLException;
Copied: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util (from rev 109858, projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util)
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/Injection.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/Injection.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/Injection.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -0,0 +1,377 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.adapters.jdbc.util;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Locale;
+
+/**
+ * Injection utility which can inject values into objects. This file is a copy
+ * of the <code>com.github.fungal.api.util.Injection</code> class.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Injection
+{
+ /**
+ * Constructor
+ */
+ public Injection()
+ {
+ }
+
+ /**
+ * Inject a value into an object property
+ * @param object The object
+ * @param propertyName The property name
+ * @param propertyValue The property value
+ * @exception NoSuchMethodException If the property method cannot be found
+ * @exception IllegalAccessException If the property method cannot be accessed
+ * @exception InvocationTargetException If the property method cannot be executed
+ */
+ @SuppressWarnings("unchecked")
+ public void inject(Object object, String propertyName, Object propertyValue)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ inject(object, propertyName, propertyValue, null, false);
+ }
+
+ /**
+ * Inject a value into an object property
+ * @param object The object
+ * @param propertyName The property name
+ * @param propertyValue The property value
+ * @param propertyType The property type as a fully quilified class name
+ * @exception NoSuchMethodException If the property method cannot be found
+ * @exception IllegalAccessException If the property method cannot be accessed
+ * @exception InvocationTargetException If the property method cannot be executed
+ */
+ @SuppressWarnings("unchecked")
+ public void inject(Object object, String propertyName, Object propertyValue, String propertyType)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ inject(object, propertyName, propertyValue, propertyType, false);
+ }
+
+ /**
+ * Inject a value into an object property
+ * @param object The object
+ * @param propertyName The property name
+ * @param propertyValue The property value
+ * @param propertyType The property type as a fully quilified class name
+ * @param includeFields Should fields be included for injection if a method can't be found
+ * @exception NoSuchMethodException If the property method cannot be found
+ * @exception IllegalAccessException If the property method cannot be accessed
+ * @exception InvocationTargetException If the property method cannot be executed
+ */
+ @SuppressWarnings("unchecked")
+ public void inject(Object object,
+ String propertyName, Object propertyValue, String propertyType,
+ boolean includeFields)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ if (object == null)
+ throw new IllegalArgumentException("Object is null");
+
+ if (propertyName == null || propertyName.trim().equals(""))
+ throw new IllegalArgumentException("PropertyName is undefined");
+
+ String methodName = "set" + propertyName.substring(0, 1).toUpperCase(Locale.US);
+ if (propertyName.length() > 1)
+ {
+ methodName += propertyName.substring(1);
+ }
+
+ Method method = findMethod(object.getClass(), methodName, propertyType);
+
+ if (method != null)
+ {
+ Class<?> parameterClass = method.getParameterTypes()[0];
+ Object parameterValue = null;
+ try
+ {
+ parameterValue = getValue(propertyName, parameterClass, propertyValue,
+ object.getClass().getClassLoader());
+ }
+ catch (Throwable t)
+ {
+ throw new InvocationTargetException(t, t.getMessage());
+ }
+
+ if (!parameterClass.isPrimitive() || parameterValue != null)
+ method.invoke(object, new Object[] {parameterValue});
+ }
+ else
+ {
+ if (!includeFields)
+ throw new NoSuchMethodException("Method " + methodName + " not found");
+
+ // Ok, we didn't find a method - assume field
+ Field field = findField(object.getClass(), propertyName, propertyType);
+
+ if (field != null)
+ {
+ Class<?> fieldClass = field.getType();
+ Object fieldValue = null;
+ try
+ {
+ fieldValue = getValue(propertyName, fieldClass, propertyValue,
+ object.getClass().getClassLoader());
+ }
+ catch (Throwable t)
+ {
+ throw new InvocationTargetException(t, t.getMessage());
+ }
+
+ field.set(object, fieldValue);
+ }
+ else
+ {
+ throw new NoSuchMethodException("Field " + propertyName + " not found");
+ }
+ }
+ }
+
+ /**
+ * Find a method
+ * @param clz The class
+ * @param methodName The method name
+ * @param propertyType The property type; can be <code>null</code>
+ * @return The method; <code>null</code> if not found
+ */
+ protected Method findMethod(Class<?> clz, String methodName, String propertyType)
+ {
+ while (!clz.equals(Object.class))
+ {
+ Method[] methods = clz.getDeclaredMethods();
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method method = methods[i];
+ if (methodName.equals(method.getName()) && method.getParameterTypes().length == 1)
+ {
+ if (propertyType == null || propertyType.equals(method.getParameterTypes()[0].getName()))
+ return method;
+ }
+ }
+
+ clz = clz.getSuperclass();
+ }
+
+ return null;
+ }
+
+ /**
+ * Find a field
+ * @param clz The class
+ * @param fieldName The field name
+ * @param fieldType The field type; can be <code>null</code>
+ * @return The field; <code>null</code> if not found
+ */
+ protected Field findField(Class<?> clz, String fieldName, String fieldType)
+ {
+ while (!clz.equals(Object.class))
+ {
+ Field[] fields = clz.getDeclaredFields();
+ for (int i = 0; i < fields.length; i++)
+ {
+ Field field = fields[i];
+ if (fieldName.equals(field.getName()))
+ {
+ if (fieldType == null || fieldType.equals(field.getType().getName()))
+ return field;
+ }
+ }
+
+ clz = clz.getSuperclass();
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the value
+ * @param name The value name
+ * @param clz The value class
+ * @param v The value
+ * @param cl The class loader
+ * @return The substituted value
+ * @exception Exception Thrown in case of an error
+ */
+ protected Object getValue(String name, Class<?> clz, Object v, ClassLoader cl) throws Exception
+ {
+ if (v instanceof String)
+ {
+ String substituredValue = getSubstitutionValue((String)v);
+
+ if (clz.equals(String.class))
+ {
+ v = substituredValue;
+ }
+ else if (clz.equals(byte.class) || clz.equals(Byte.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Byte.valueOf(substituredValue);
+ }
+ else if (clz.equals(short.class) || clz.equals(Short.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Short.valueOf(substituredValue);
+ }
+ else if (clz.equals(int.class) || clz.equals(Integer.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Integer.valueOf(substituredValue);
+ }
+ else if (clz.equals(long.class) || clz.equals(Long.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Long.valueOf(substituredValue);
+ }
+ else if (clz.equals(float.class) || clz.equals(Float.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Float.valueOf(substituredValue);
+ }
+ else if (clz.equals(double.class) || clz.equals(Double.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Double.valueOf(substituredValue);
+ }
+ else if (clz.equals(boolean.class) || clz.equals(Boolean.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Boolean.valueOf(substituredValue);
+ }
+ else if (clz.equals(char.class) || clz.equals(Character.class))
+ {
+ if (substituredValue != null && !substituredValue.trim().equals(""))
+ v = Character.valueOf(substituredValue.charAt(0));
+ }
+ else if (clz.equals(InetAddress.class))
+ {
+ v = InetAddress.getByName(substituredValue);
+ }
+ else if (clz.equals(Class.class))
+ {
+ v = Class.forName(substituredValue, true, cl);
+ }
+ else
+ {
+ try
+ {
+ Constructor<?> constructor = clz.getConstructor(String.class);
+ v = constructor.newInstance(substituredValue);
+ }
+ catch (Throwable t)
+ {
+ // Try static String valueOf method
+ try
+ {
+ Method valueOf = clz.getMethod("valueOf", String.class);
+ v = valueOf.invoke((Object)null, substituredValue);
+ }
+ catch (Throwable inner)
+ {
+ throw new IllegalArgumentException("Unknown property resolution for property " + name);
+ }
+ }
+ }
+ }
+
+ return v;
+ }
+
+ /**
+ * System property substitution
+ * @param input The input string
+ * @return The output
+ */
+ protected String getSubstitutionValue(String input)
+ {
+ if (input == null || input.trim().equals(""))
+ return input;
+
+ while (input.indexOf("${") != -1)
+ {
+ int from = input.indexOf("${");
+ int to = input.indexOf("}");
+ int dv = input.indexOf(":", from + 2);
+
+ if (dv != -1)
+ {
+ if (dv > to)
+ dv = -1;
+ }
+
+ String systemProperty = "";
+ String defaultValue = "";
+ if (dv == -1)
+ {
+ String s = input.substring(from + 2, to);
+ if ("/".equals(s))
+ {
+ systemProperty = File.separator;
+ }
+ else if (":".equals(s))
+ {
+ systemProperty = File.pathSeparator;
+ }
+ else
+ {
+ systemProperty = SecurityActions.getSystemProperty(s);
+ }
+ }
+ else
+ {
+ systemProperty = SecurityActions.getSystemProperty(input.substring(from + 2, dv));
+ defaultValue = input.substring(dv + 1, to);
+ }
+ String prefix = "";
+ String postfix = "";
+
+ if (from != 0)
+ {
+ prefix = input.substring(0, from);
+ }
+
+ if (to + 1 < input.length() - 1)
+ {
+ postfix = input.substring(to + 1);
+ }
+
+ if (systemProperty != null && !systemProperty.trim().equals(""))
+ {
+ input = prefix + systemProperty + postfix;
+ }
+ else if (defaultValue != null && !defaultValue.trim().equals(""))
+ {
+ input = prefix + defaultValue + postfix;
+ }
+ }
+ return input;
+ }
+}
Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/LRUCachePolicy.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/util/LRUCachePolicy.java 2010-12-12 16:29:22 UTC (rev 109858)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/LRUCachePolicy.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.jca.adapters.util;
+package org.jboss.jca.adapters.jdbc.util;
import java.util.HashMap;
import java.util.Map;
Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/SecurityActions.java (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/util/SecurityActions.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.adapters.jdbc.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{
+ /**
+ * Constructor
+ */
+ private SecurityActions()
+ {
+ }
+
+ /**
+ * Get a system property
+ * @param name The property name
+ * @return The property value
+ */
+ static String getSystemProperty(final String name)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return System.getProperty(name);
+ }
+ else
+ {
+ return (String)AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ return System.getProperty(name);
+ }
+ });
+ }
+ }
+}
Modified: projects/jboss-jca/trunk/build.xml
===================================================================
--- projects/jboss-jca/trunk/build.xml 2010-12-13 09:13:51 UTC (rev 109863)
+++ projects/jboss-jca/trunk/build.xml 2010-12-13 09:29:17 UTC (rev 109864)
@@ -94,7 +94,7 @@
<property name="version.dom4j" value="1.6.1"/>
<property name="version.mockito" value="1.8.5"/>
<property name="version.eclipse.ecj" value="3.5.1"/>
- <property name="version.fungal" value="0.9.0.Beta6"/>
+ <property name="version.fungal" value="0.9.0.Beta7"/>
<property name="version.h2" value="1.2.145"/>
<property name="version.hibernate-validator" value="4.1.0.Final"/>
<property name="version.javassist" value="3.14.0-GA"/>
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java 2010-12-13 09:13:51 UTC (rev 109863)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/AbstractFungalRADeployer.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -143,8 +143,8 @@
}
if (setValue)
- injector.inject(cpmd.getConfigPropertyType().getValue(), cpmd.getConfigPropertyName().getValue(),
- cpmd.getConfigPropertyValue().getValue(), o);
+ injector.inject(o, cpmd.getConfigPropertyName().getValue(),
+ cpmd.getConfigPropertyValue().getValue(), cpmd.getConfigPropertyType().getValue());
}
}
}
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java 2010-12-13 09:13:51 UTC (rev 109863)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java 2010-12-13 09:29:17 UTC (rev 109864)
@@ -232,8 +232,8 @@
for (ConfigProperty cpmd : configs)
{
if (cpmd.isValueSet())
- injector.inject(cpmd.getConfigPropertyType().getValue(), cpmd.getConfigPropertyName().getValue(),
- cpmd.getConfigPropertyValue().getValue(), o);
+ injector.inject(o, cpmd.getConfigPropertyName().getValue(),
+ cpmd.getConfigPropertyValue().getValue(), cpmd.getConfigPropertyType().getValue());
}
}
More information about the jboss-cvs-commits
mailing list