public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) { // default behavior like before https://jira.jboss.org/jira/browse/JBPM-1148 return new ProcessClassLoader(ClassLoaderUtil.getClassLoader(), processDefinition); } }
protected Class findClass(String className) throws ClassNotFoundException { ProcessDefinition processDefinition = getProcessDefinition(); FileDefinition fileDefinition; if (processDefinition == null || (fileDefinition = processDefinition.getFileDefinition()) == null) { throw new ClassNotFoundException(className); } // look in the classes directory of the file module definition String fileName = "classes/" + className.replace('.', '/') + ".class"; byte[] classBytes = fileDefinition.getBytes(fileName); if (classBytes == null) throw new ClassNotFoundException(className); // if the class is in a package int packageIndex = className.lastIndexOf('.'); if (packageIndex != -1) { // check whether this class loader (or any ancestor) defined the package already String packageName = className.substring(0, packageIndex); if (getPackage(packageName) == null) { // define the package prior to defining the class // see https://jira.jboss.org/jira/browse/JBPM-1404 definePackage(packageName, null, null, null, processDefinition.getName(), Integer.toString(processDefinition.getVersion()), null, null); } } return defineClass(className, classBytes, 0, classBytes.length); } }
public InputStream getInputStream() throws IOException { connect(); /* * ideally, the connection would fetch the process definition and assign it to a class * field on connect(); however, that strategy "leaks" a detached process definition */ ProcessDefinition processDefinition = getProcessDefinition(); if (processDefinition == null) throw new IOException("no active jbpm context"); // having established a "connection", check whether the file exists String fileName = url.getPath(); FileDefinition fileDefinition = processDefinition.getFileDefinition(); if (fileDefinition == null || !fileDefinition.hasFile(fileName)) { throw new FileNotFoundException(fileName); } // retrieve file content byte[] fileContent = fileDefinition.getBytes(fileName); return new ByteArrayInputStream(fileContent); } }
public InputStream getInputStream() throws IOException { connect(); /* * ideally, the connection would fetch the process definition and assign it to a class * field on connect(); however, that strategy "leaks" a detached process definition */ ProcessDefinition processDefinition = getProcessDefinition(); if (processDefinition == null) throw new IOException("no active jbpm context"); // having established a "connection", check whether the file exists String fileName = url.getPath(); FileDefinition fileDefinition = processDefinition.getFileDefinition(); if (fileDefinition == null || !fileDefinition.hasFile(fileName)) { throw new FileNotFoundException(fileName); } // retrieve file content byte[] fileContent = fileDefinition.getBytes(fileName); return new ByteArrayInputStream(fileContent); } }
protected Class findClass(String className) throws ClassNotFoundException { ProcessDefinition processDefinition = getProcessDefinition(); FileDefinition fileDefinition; if (processDefinition == null || (fileDefinition = processDefinition.getFileDefinition()) == null) { throw new ClassNotFoundException(className); } // look in the classes directory of the file module definition String fileName = "classes/" + className.replace('.', '/') + ".class"; byte[] classBytes = fileDefinition.getBytes(fileName); if (classBytes == null) throw new ClassNotFoundException(className); // if the class is in a package int packageIndex = className.lastIndexOf('.'); if (packageIndex != -1) { // check whether this class loader (or any ancestor) defined the package already String packageName = className.substring(0, packageIndex); if (getPackage(packageName) == null) { // define the package prior to defining the class // see https://jira.jboss.org/jira/browse/JBPM-1404 definePackage(packageName, null, null, null, processDefinition.getName(), Integer.toString(processDefinition.getVersion()), null, null); } } return defineClass(className, classBytes, 0, classBytes.length); } }
public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) { // default behavior like before https://jira.jboss.org/jira/browse/JBPM-1148 return new ProcessClassLoader(ClassLoaderUtil.getClassLoader(), processDefinition); } }
protected URL findResource(String name) { ProcessDefinition processDefinition = getProcessDefinition(); FileDefinition fileDefinition; if (processDefinition == null || (fileDefinition = processDefinition.getFileDefinition()) == null) return null; // skip leading slashes int off = 0; for (int len = name.length(); off < len && name.charAt(off) == '/'; off++) /* just increase offset */; // if the resource name is absolute, that is, starts with one or more slashes if (off > 0) { // then search from the root of the process archive name = name.substring(off); } else { // otherwise, if the resource is relative, search from the classes directory name = "classes/" + name; } if (!fileDefinition.hasFile(name)) return null; try { return new URL("jbpm", null, -1, name, urlStreamHandler); } catch (MalformedURLException e) { throw new JbpmException("could not create url", e); } }
public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) { // use database identifier as key to lookup cached class loader long id = processDefinition.getId(); // if process definition is transient, use hash code as key Long key = new Long(id == 0L ? processDefinition.hashCode() : id); // consider that the context class loader changes among applications ClassLoader parentClassLoader = ClassLoaderUtil.getClassLoader(); synchronized (classLoaderRefs) { // lookup cached class loader ClassLoader processClassLoader = getProcessClassLoader(key, parentClassLoader); // if class loader is not cached, if (processClassLoader == null) { // (re-)create class loader processClassLoader = new ProcessClassLoader(parentClassLoader, processDefinition, jbpmConfiguration); // add class loader to cache putProcessClassLoader(key, processClassLoader); } return processClassLoader; } }
protected URL findResource(String name) { ProcessDefinition processDefinition = getProcessDefinition(); FileDefinition fileDefinition; if (processDefinition == null || (fileDefinition = processDefinition.getFileDefinition()) == null) return null; // skip leading slashes int off = 0; for (int len = name.length(); off < len && name.charAt(off) == '/'; off++) /* just increase offset */; // if the resource name is absolute, that is, starts with one or more slashes if (off > 0) { // then search from the root of the process archive name = name.substring(off); } else { // otherwise, if the resource is relative, search from the classes directory name = "classes/" + name; } if (!fileDefinition.hasFile(name)) return null; try { return new URL("jbpm", null, -1, name, urlStreamHandler); } catch (MalformedURLException e) { throw new JbpmException("could not create url", e); } }
public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) { // use database identifier as key to lookup cached class loader long id = processDefinition.getId(); // if process definition is transient, use hash code as key Long key = new Long(id == 0L ? processDefinition.hashCode() : id); // consider that the context class loader changes among applications ClassLoader parentClassLoader = ClassLoaderUtil.getClassLoader(); synchronized (classLoaderRefs) { // lookup cached class loader ClassLoader processClassLoader = getProcessClassLoader(key, parentClassLoader); // if class loader is not cached, if (processClassLoader == null) { // (re-)create class loader processClassLoader = new ProcessClassLoader(parentClassLoader, processDefinition, jbpmConfiguration); // add class loader to cache putProcessClassLoader(key, processClassLoader); } return processClassLoader; } }