io.odysz.module.xtable.XUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of semantic.DA Show documentation
Show all versions of semantic.DA Show documentation
JDBC Data Access with Semantics Support
/**
*
*/
package io.odysz.module.xtable;
import java.lang.reflect.Constructor;
/** * @author [email protected] */
public class XUtil {
/**Construct instance of class specified in classRecs,
* return object instantiated with constructorParas.
* For ex.:
* Object[] p = new Object[2];
* p[0] = res;
* p[1] = skinid;
* skin = (IMetronomeSkin) XUtil.getClassInstance(st, "class", p);
* @param classRecs xtable for class config.
* @param classField class name field's name
* @param constructorParas paras for constructing new instance.
* @return new class instance
* @throws Exception
*/
static public Object getClassInstance(XMLTable classRecs, String classField, Object[] constructorParas) throws Exception {
String clsname = classRecs.getString(classField);
Class> cls = Class.forName(clsname);
Class>[] constructorTypes;
if (constructorParas != null) {
constructorTypes = new Class[constructorParas.length];
for (int i = 0; i < constructorParas.length; i++)
constructorTypes[i] = constructorParas[i].getClass();
}
else
constructorTypes = new Class[0];
// Constructor> constor = cls.getConstructor(constructorTypes[0], constructorTypes[1], constructorTypes[2], constructorTypes[3], constructorTypes[4]);
// return constor.newInstance(constructorParas);
Constructor> contor = cls.getConstructor(constructorTypes);
return contor.newInstance(constructorParas);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy