Search in sources :

Example 1 with TalendURLClassLoader

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;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) URL(java.net.URL) TalendURLClassLoader(org.talend.utils.classloader.TalendURLClassLoader)

Example 2 with TalendURLClassLoader

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;
}
Also used : TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) ArrayList(java.util.ArrayList) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Indicator(org.talend.dataquality.indicators.Indicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) URL(java.net.URL) TalendURLClassLoader(org.talend.utils.classloader.TalendURLClassLoader)

Aggregations

URL (java.net.URL)2 IFile (org.eclipse.core.resources.IFile)2 TalendURLClassLoader (org.talend.utils.classloader.TalendURLClassLoader)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Indicator (org.talend.dataquality.indicators.Indicator)1 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)1 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)1