Methods Summary |
---|
private java.lang.String | convertToString(java.lang.Object obj)Converts the object to String if it belongs to Wrapper class of primitive
type or a string itself. For all other types empty String is returned.
if(obj == null) {
return new String();
}
if(obj instanceof String) {
return (String)obj;
}else if( obj instanceof Integer ||
obj instanceof Float ||
obj instanceof Long ||
obj instanceof Double ||
obj instanceof Character ||
obj instanceof Boolean ||
obj instanceof Byte ||
obj instanceof Short ) {
return String.valueOf(obj);
} else {
return new String();
}
|
private java.lang.reflect.Method | correspondingGetMethod(java.lang.reflect.Method setMethod, java.lang.Class loadedClass)Returns the getXXX() or isXXX() for the setXXX method passed.
XXX is the javabean property.
Check is made if there are no parameters for the getXXX() and isXXX()
methods. If there is any parameter, null is returned.
Method[] allMethods = loadedClass.getMethods();
if(allMethods == null) {
return null;
}
int length = "set".length();
String methodName = setMethod.getName();
Class[] parameterTypes = null;
String[] possibleGetMethodNames = new String[2];
possibleGetMethodNames[0] = "is"+methodName.substring(length);
possibleGetMethodNames[1] = "get"+methodName.substring(length);
for(int i = 0;i < allMethods.length;++i) {
if(allMethods[i].getName().equals(possibleGetMethodNames[0]) ||
allMethods[i].getName().equals(possibleGetMethodNames[1])) {
parameterTypes = allMethods[i].getParameterTypes();
if(parameterTypes != null && parameterTypes.length == 0) {
return allMethods[i];
}
}
}
return null;
|
private java.lang.String | getPropName(java.lang.reflect.Method method)Gets the property name of the method passed. It strips the first three
charaters (size of "set") of the method name and converts the first
character (for the string after stripping) to upper case and returns
that string.
if(method == null) {
return null;
}
String methodName = method.getName();
int length = "set".length();
String retValue =
methodName.substring(length,length+1).toUpperCase() +
methodName.substring(length+1);
return retValue;
|
private java.lang.String | getPropType(java.lang.reflect.Method method)
Class[] parameterTypeClass = method.getParameterTypes();
if(parameterTypeClass.length != 1) {
return null;
}
if(parameterTypeClass[0].isPrimitive() ||
parameterTypeClass[0].getName().equals("java.lang.String")) {
return parameterTypeClass[0].getName();
} else {
return null;
}
|
private java.lang.String | getPropValue(java.lang.reflect.Method method, java.lang.Class loadedClass, java.lang.Object loadedInstance)Invokes the method passed and returns the value obtained. If method
invocation fails empty string is returned. If the return type is not
of Wrapper class of the primitive types, empty string is returned.
Object retValue = null;
Method getMethod = correspondingGetMethod(method, loadedClass);
if(getMethod != null) {
try {
retValue = getMethod.invoke(loadedInstance, (java.lang.Object[])null);
} catch (IllegalAccessException ie) {
_logger.log(Level.FINE,
"rardeployment.illegalaccess_error",loadedClass.getName());
} catch (InvocationTargetException ie) {
_logger.log(Level.FINE,
"Failed to invoke the method",loadedClass.getName());
}
}
return convertToString(retValue);
|
private java.lang.Object | instantiate(java.lang.Class loadedClass)Instantiates the class
try {
return loadedClass.newInstance();
} catch(InstantiationException ie) {
_logger.log(Level.FINE,
"rardeployment.class_instantiation_error",loadedClass.getName());
throw new ConnectorRuntimeException(
"Could not instantiate class : " + loadedClass.getName());
} catch (IllegalAccessException ie) {
_logger.log(Level.FINE,
"rardeployment.illegalaccess_error",loadedClass.getName());
throw new ConnectorRuntimeException(
"Couldnot access class : "+loadedClass.getName());
}
|
public java.util.Properties | introspectJavaBean(java.lang.String className, java.util.Set ddPropsSet)
return introspectJavaBean(className, ddPropsSet, false, null);
|
public java.util.Properties | introspectJavaBean(java.lang.String className, java.util.Set ddPropsSet, boolean associateResourceAdapter, java.lang.String resourceAdapterName)
Class loadedClass = loadClass(className);
Object loadedInstance = instantiate(loadedClass);
try {
if (associateResourceAdapter) {
ActiveResourceAdapter activeRA = ConnectorRegistry.getInstance().
getActiveResourceAdapter(resourceAdapterName);
if (activeRA == null) {
//Check and Load RAR
(new ConnectorServiceImpl()).loadDeferredResourceAdapter(
resourceAdapterName);
activeRA = ConnectorRegistry.getInstance().
getActiveResourceAdapter(resourceAdapterName);
}
//Associate RAR
if (activeRA instanceof ActiveInboundResourceAdapter) {
ResourceAdapter raInstance =
((ActiveInboundResourceAdapter)(activeRA)).getResourceAdapter();
if (loadedInstance instanceof ResourceAdapterAssociation) {
((ResourceAdapterAssociation)loadedInstance).
setResourceAdapter(raInstance);
}
}
}
} catch (Exception e) {
_logger.log(Level.WARNING,
"rardeployment.error_associating_ra",e);
_logger.log(Level.FINE,
"Exception while associating the resource adapter" +
"to the JavaBean",e);
}
return introspectJavaBean(loadedInstance, ddPropsSet);
|
public java.util.Properties | introspectJavaBean(java.lang.Object javaBeanInstance, java.util.Set ddPropsSet)Introspects the javabean and returns only the introspected properties
not present in the configuration in ra.xml for the corresponding
javabean. If no definite value is obtained while introspection of
a method empty string is taken as the value.
Class loadedClass = javaBeanInstance.getClass();
Method[] methods = loadedClass.getMethods();
if(methods == null) {
return null;
}
Properties props = new Properties();
String name = null;
String value = null;
Object[] ddProps = null;
if(ddPropsSet != null) {
ddProps = ddPropsSet.toArray();
}
for(int i=0; i<methods.length;++i) {
_logger.fine("Method -> " + methods[i].getName() + ":" + methods[i].getReturnType());
if(isProperty(methods[i]) && !presentInDDProps(methods[i],ddProps)
&& isValid(methods[i], loadedClass)) {
name = getPropName(methods[i]);
value = getPropValue(methods[i], loadedClass, javaBeanInstance);
props.setProperty(name,value);
}
}
return props;
|
public java.util.Properties | introspectJavaBeanReturnTypes(java.lang.String className, java.util.Set ddPropsSet)Introspects the javabean and returns only the introspected properties
and their datatypes not present in the configuration in ra.xml for
the corresponding javabean.
Class loadedClass = loadClass(className);
Object loadedInstance = instantiate(loadedClass);
Method[] methods = loadedClass.getMethods();
if(methods == null) {
return null;
}
Properties props = new Properties();
String name = null;
String value = null;
Object[] ddProps = null;
if(ddPropsSet != null) {
ddProps = ddPropsSet.toArray();
}
for(int i=0; i<methods.length;++i) {
if(isProperty(methods[i])&&!presentInDDProps(methods[i],ddProps)) {
name = getPropName(methods[i]);
value = getPropType(methods[i]);
if(value != null) {
props.setProperty(name,value);
}
}
}
return props;
|
private boolean | isProperty(java.lang.reflect.Method method)Checks whether the method pertains to a valid javabean property.
i.e it check whether the method starts with "set" and it has only
one parameter. It more than one parameter is present it is taken as
not a property
if(method == null) {
return false;
}
String methodName = method.getName();
Class[] parameterTypes = method.getParameterTypes();
if(methodName.startsWith("set") &&
parameterTypes != null && parameterTypes.length == 1) {
return true;
} else {
return false;
}
|
private boolean | isValid(java.lang.reflect.Method setMethod, java.lang.Class loadedClass)Checks whether the property is valid or not.
Method getMethod = correspondingGetMethod( setMethod, loadedClass);
if (getMethod != null) {
return RARUtils.isValidRABeanConfigProperty(getMethod.getReturnType());
} else {
return false;
}
|
private java.lang.Class | loadClass(java.lang.String className)Loads and instantiates the class
Throws ConnectorRuntimeException if loading or instantiation fails.
ClassLoader classLoader = ConnectorClassLoader.getInstance();
try {
return classLoader.loadClass(className);
} catch(ClassNotFoundException ce) {
_logger.log(Level.FINE,
"rardeployment.class_not_found",className);
throw new ConnectorRuntimeException(
"ClassNot Found : " + className);
}
|
public java.util.Properties | mergeProps(java.util.Set ddVals, java.util.Properties introspectedVals)Merges the properties obtained by introspecting the javabean and the
properties present in ra.xml for the corresponding javabean.
Properties mergedVals = new Properties(introspectedVals);
if(ddVals != null) {
Object[] ddProps = ddVals.toArray();
String name = null;
String value = null;
for (int i = 0; i < ddProps.length; i++) {
name = ((EnvironmentProperty)ddProps[i]).getName();
value =((EnvironmentProperty)ddProps[i]).getValue();
mergedVals.setProperty(name,value);
}
}
return mergedVals;
|
public java.util.Properties | mergePropsReturnTypes(java.util.Set ddVals, java.util.Properties introspectedVals)Merges the datatype of properties obtained by introspecting the
javabean and the datatypes of properties present in ra.xml for
the corresponding javabean. It is a Properties object consisting of
property name and the property data type.
Properties mergedVals = new Properties(introspectedVals);
if(ddVals != null) {
Object[] ddProps = ddVals.toArray();
String name = null;
String value = null;
for (int i = 0; i < ddProps.length; i++) {
name = ((EnvironmentProperty)ddProps[i]).getName();
value = ((EnvironmentProperty)ddProps[i]).getType();
mergedVals.setProperty(name,value);
}
}
return mergedVals;
|
private boolean | presentInDDProps(java.lang.reflect.Method method, java.lang.Object[] ddProps)Checks whether the property pertaining to the method is already presenti
in the array of Properties passed as second argument.
The properties already present in ra.xml for the corresponding
javabean is passed as the second argument.
String name = null;
String ddPropName = null;
int length = "set".length();
if(method != null) {
name = method.getName().substring(length);
}
for(int i=0; name != null && ddProps != null && i<ddProps.length;++i) {
ddPropName = ((EnvironmentProperty)ddProps[i]).getName();
if(name.equalsIgnoreCase(ddPropName) == true) {
return true;
}
}
return false;
|