Search in sources :

Example 16 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project jbpm by kiegroup.

the class ObjectDataType method getXStream.

private XStream getXStream() {
    XStream xstream = createXStream();
    if (classLoader != null) {
        xstream.setClassLoader(classLoader);
        if (classLoader instanceof ProjectClassLoader) {
            Map<String, byte[]> store = ((ProjectClassLoader) classLoader).getStore();
            if (store != null) {
                String[] classes = store.keySet().stream().map(s -> s.replace('/', '.')).map(s -> s.endsWith(".class") ? s.substring(0, s.length() - ".class".length()) : s).toArray(String[]::new);
                xstream.addPermission(new ExplicitTypePermission(classes));
            }
        }
    }
    return xstream;
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createXStream(org.kie.soup.commons.xstream.XStreamUtils.createXStream) DataType(org.jbpm.process.core.datatype.DataType) ObjectOutput(java.io.ObjectOutput) Map(java.util.Map) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) IOException(java.io.IOException) ObjectInput(java.io.ObjectInput) ExplicitTypePermission(com.thoughtworks.xstream.security.ExplicitTypePermission) XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createXStream(org.kie.soup.commons.xstream.XStreamUtils.createXStream) ExplicitTypePermission(com.thoughtworks.xstream.security.ExplicitTypePermission)

Example 17 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project jbpm by kiegroup.

the class KModuleDeploymentService method processClassloader.

/**
 * This processes the deployment dependencies, which are made available by the {@link KieContainer} {@link ClassLoader}.
 *
 * @param kieContainer The {@link KieContainer}, used to get the {@link ClassLoader}
 * @param deployedUnit The {@link DeployedUnitImpl}, used to store the classes loaded
 */
protected void processClassloader(KieContainer kieContainer, DeployedUnitImpl deployedUnit) {
    if (kieContainer.getClassLoader() instanceof ProjectClassLoader) {
        ClassLoader parentCl = kieContainer.getClassLoader().getParent();
        if (parentCl instanceof URLClassLoader) {
            URL[] urls = ((URLClassLoader) parentCl).getURLs();
            if (urls == null || urls.length == 0) {
                return;
            }
            ConfigurationBuilder builder = new ConfigurationBuilder();
            builder.addUrls(urls);
            builder.addClassLoader(kieContainer.getClassLoader());
            Reflections reflections = new Reflections(builder);
            Set<Class<?>> xmlRootElemClasses = reflections.getTypesAnnotatedWith(XmlRootElement.class);
            Set<Class<?>> xmlTypeClasses = reflections.getTypesAnnotatedWith(XmlType.class);
            Set<Class<?>> remoteableClasses = reflections.getTypesAnnotatedWith(Remotable.class);
            Set<Class<?>> allClasses = new HashSet<Class<?>>();
            for (Set<Class<?>> classesToAdd : new Set[] { xmlRootElemClasses, xmlTypeClasses, remoteableClasses }) {
                if (classesToAdd != null) {
                    allClasses.addAll(classesToAdd);
                }
            }
            for (Class<?> clazz : allClasses) {
                filterClassesAddedToDeployedUnit(deployedUnit, clazz);
            }
        }
    }
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Set(java.util.Set) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) URL(java.net.URL) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Aggregations

ProjectClassLoader (org.drools.core.common.ProjectClassLoader)17 ArrayList (java.util.ArrayList)3 JavaDialectRuntimeData (org.drools.core.rule.JavaDialectRuntimeData)3 Before (org.junit.Before)3 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)2 ByteString (com.google.protobuf.ByteString)1 JCodeModel (com.sun.codemodel.JCodeModel)1 BadCommandLineException (com.sun.tools.xjc.BadCommandLineException)1 ErrorReceiver (com.sun.tools.xjc.ErrorReceiver)1 Model (com.sun.tools.xjc.model.Model)1 XStream (com.thoughtworks.xstream.XStream)1 ExplicitTypePermission (com.thoughtworks.xstream.security.ExplicitTypePermission)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1