ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.jbpm.pvm.internal.wire.descriptor;
 
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireException;
 
/** loads the class with the specified class name using the WireContext class loader.
 * 
 * @see WireContext#getClassLoader()
 *
 * @author Tom Baeyens
 * @author Guillaume Porcher (documentation)
 */
public class ClassDescriptor extends AbstractDescriptor {
 
  private static final long serialVersionUID = 1L;
 
  String text;
 
  /** loads the class from the class loader of the specified WireContext.
   * @throws WireException if the class could not be loaded.
   */
  public Object construct(WireContext wireContext) {
    try {
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      return Class.forName(text, true, classLoader);
    } catch (Exception e) {
      Throwable cause = (e.getCause()!=null ? e.getCause() : e);
      throw new WireException("couldn't load class '"+text+"': "+cause.getMessage(), cause);
    }
  }
 
  public void setClassName(String className) {
    this.text = className;
  }
 
  public void setClass(Class<?> clazz) {
    if (clazz==null) {
      text = null;
    } else {
      this.text = clazz.getName();
    }
  }
}