Example usage for com.liferay.portal.kernel.util AggregateClassLoader getAggregateClassLoader

List of usage examples for com.liferay.portal.kernel.util AggregateClassLoader getAggregateClassLoader

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util AggregateClassLoader getAggregateClassLoader.

Prototype

public static ClassLoader getAggregateClassLoader(ClassLoader parentClassLoader, ClassLoader... classLoaders) 

Source Link

Usage

From source file:com.liferay.rtl.scripting.ruby.RubyExecutor.java

License:Open Source License

protected Map<String, Object> doEval(Set<String> allowedClasses, Map<String, Object> inputObjects,
        Set<String> outputNames, File scriptFile, String script, ClassLoader... classLoaders)
        throws ScriptingException {

    if (allowedClasses != null) {
        throw new ExecutionException("Constrained execution not supported for Ruby");
    }//from  ww w. j  ava2 s.c  o m

    try {
        LocalContextProvider localContextProvider = _scriptingContainer.getProvider();

        RubyInstanceConfig rubyInstanceConfig = localContextProvider.getRubyInstanceConfig();

        rubyInstanceConfig.setCurrentDirectory(_basePath);

        if (ArrayUtil.isNotEmpty(classLoaders)) {
            ClassLoader aggregateClassLoader = AggregateClassLoader
                    .getAggregateClassLoader(PortalClassLoaderUtil.getClassLoader(), classLoaders);

            rubyInstanceConfig.setLoader(aggregateClassLoader);
        }

        rubyInstanceConfig.setLoadPaths(_loadPaths);

        for (Map.Entry<String, Object> entry : inputObjects.entrySet()) {
            String inputName = entry.getKey();
            Object inputObject = entry.getValue();

            if (!inputName.startsWith(StringPool.DOLLAR)) {
                inputName = StringPool.DOLLAR + inputName;
            }

            _scriptingContainer.put(inputName, inputObject);
        }

        if (scriptFile != null) {
            _scriptingContainer.runScriptlet(new FileInputStream(scriptFile), scriptFile.toString());
        } else {
            _scriptingContainer.runScriptlet(script);
        }

        if (outputNames == null) {
            return null;
        }

        Map<String, Object> outputObjects = new HashMap<String, Object>();

        for (String outputName : outputNames) {
            outputObjects.put(outputName, _scriptingContainer.get(outputName));
        }

        return outputObjects;
    } catch (RaiseException re) {
        throw new ScriptingException(re.getException().message.asJavaString() + "\n\n", re);
    } catch (FileNotFoundException fnfe) {
        throw new ScriptingException(fnfe);
    } finally {
        try {
            _globalRuntimeField.set(null, null);
        } catch (Exception e) {
            _log.error(e, e);
        }
    }
}

From source file:com.liferay.xstream.configurator.XStreamConfiguratorRegistryUtil.java

License:Open Source License

public static ClassLoader getConfiguratorsClassLoader(ClassLoader masterClassLoader) {

    Set<ClassLoader> classLoaders = new HashSet<>();

    Set<XStreamConfigurator> xStreamConfigurators = _xStreamConfigurators;

    for (XStreamConfigurator xStreamConfigurator : xStreamConfigurators) {
        Class<?> clazz = xStreamConfigurator.getClass();

        classLoaders.add(clazz.getClassLoader());
    }/*from   w  w  w . j  a  va2s  .  c o  m*/

    // Temporary code to fetch class loaders from the old framework too

    Map<Class<?>, String> aliases = XStreamAliasRegistryUtil.getAliases();

    if (!aliases.isEmpty()) {
        for (Class<?> clazz : aliases.keySet()) {
            classLoaders.add(clazz.getClassLoader());
        }
    }

    return AggregateClassLoader.getAggregateClassLoader(masterClassLoader,
            classLoaders.toArray(new ClassLoader[classLoaders.size()]));
}