use of org.talend.utils.classloader.TalendURLClassLoader in project tdq-studio-se by Talend.
the class UDIMasterPage method isClassNameExistInJars.
/**
* check whether the ClassName Exist In Jars.
*
* @return boolean
*/
private boolean isClassNameExistInJars() {
if (classNameForSave != null && jarPathForSave != null && !classNameForSave.trim().equals(PluginConstant.EMPTY_STRING) && !jarPathForSave.trim().equals(PluginConstant.EMPTY_STRING)) {
// MOD by zshen for bug 18724 2011.02.23
for (IFile file : UDIUtils.getContainJarFile(jarPathForSave)) {
TalendURLClassLoader cl;
try {
// Note that the 2nd parameter (classloader) is needed to load class UserDefinitionIndicator from
// org.talend.dataquality plugin.
cl = new TalendURLClassLoader(new URL[] { file.getLocation().toFile().toURI().toURL() }, IndicatorDefinitionMaterPage.class.getClassLoader());
Class<?> theClass = cl.findClass(classNameForSave);
if (theClass != null) {
return true;
}
} catch (MalformedURLException e1) {
log.error(e1.getStackTrace());
} catch (ClassNotFoundException e1) {
log.error(e1.getStackTrace());
}
}
return false;
} else {
return false;
}
}
use of org.talend.utils.classloader.TalendURLClassLoader in project tdq-studio-se by Talend.
the class UDIHelper method adaptToJavaUDI.
/**
* DOC mzhao feature 11128, If the execute engine and by the same time Java User Defined Indicator is also defined,
* then compute via Java UDI, here convert common udi to a Java UDI.
*
* @param udi
* @return
* @throws Exception
*/
public static Indicator adaptToJavaUDI(Indicator indicator) throws Throwable {
Indicator returnIndicator = getUDIFromMap(indicator);
if (returnIndicator != null) {
return returnIndicator;
}
UserDefIndicator adaptedUDI = null;
if (userDefIndSwitch.doSwitch(indicator) != null) {
EList<TaggedValue> taggedValues = indicator.getIndicatorDefinition().getTaggedValue();
String userJavaClassName = null;
String jarPath = null;
for (TaggedValue tv : taggedValues) {
if (tv.getTag().equals(TaggedValueHelper.CLASS_NAME_TEXT)) {
userJavaClassName = tv.getValue();
continue;
}
if (tv.getTag().equals(TaggedValueHelper.JAR_FILE_PATH)) {
jarPath = tv.getValue();
}
}
// MOD by zshen for feature 18724
if (validateJavaUDI(userJavaClassName, jarPath)) {
List<URL> jarUrls = new ArrayList<URL>();
for (File file : getContainJarFile(jarPath)) {
jarUrls.add(file.toURI().toURL());
}
TalendURLClassLoader cl;
// Note that the 2nd parameter (classloader) is needed to load class UserDefinitionIndicator from
// org.talend.dataquality plugin.
cl = new TalendURLClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), UDIHelper.class.getClassLoader());
Class<?> clazz = null;
clazz = cl.findClass(userJavaClassName);
if (clazz != null) {
// MOD yyin 20121012 TDQ-6259
UserDefIndicator judi = (UserDefIndicator) clazz.newInstance();
// judi.setIndicatorDefinition(indicator.getIndicatorDefinition());
PropertyUtils.copyProperties(judi, indicator);
// judi.setAnalyzedElement(indicator.getAnalyzedElement());
adaptedUDI = judi;
JAVAUDIMAP.put(indicator, adaptedUDI);
}
}
}
return adaptedUDI;
}
Aggregations