@Override
 public void run() {
   ClassLoader originalLoader = Classes.setTCCL(_loader);
   try {
     _session.getStateful().fireUntilHalt();
   } finally {
     try {
       _handler.disposeStatefulSession();
     } finally {
       Classes.setTCCL(originalLoader);
     }
   }
 }
  /**
   * Get the Java runtime class for the specified message type QName.
   *
   * @param name The message type {@link javax.xml.namespace.QName}.
   * @return The Java runtime class for the specified message type QName, otherwise null.
   */
  public static Class<?> toJavaMessageType(QName name) {
    if (!isJavaMessageType(name)) {
      throw new RuntimeException(
          "Invalid call.  Not a Java message type.  Use isJavaMessageType before calling this method.");
    }

    String className = name.getLocalPart().substring(JAVA_TYPE_PREFIX.length());
    if (!PRIMITIVES.contains(className) && className.contains("[]")) {
      className = className.substring(0, className.length() - 2);
      return Array.newInstance(Classes.forName(className), 0).getClass();
    }
    return Classes.forName(className);
  }
  private static Class getObjectFactory(Class<?> type) {
    if (type.getAnnotation(XmlType.class) != null) {
      // Get the ObjectFactory, if it exists...
      String objectFactoryName = type.getPackage().getName() + "." + "ObjectFactory";

      return Classes.forName(objectFactoryName, JAXBTransformerFactory.class);
    }

    return null;
  }
 /** {@inheritDoc} */
 @Override
 public void init(QName qname, BPMComponentImplementationModel model) {
   _processId = model.getProcessId();
   _messageContentInName = model.getMessageContentInName();
   if (_messageContentInName == null) {
     _messageContentInName = MESSAGE_CONTENT_IN;
   }
   _messageContentOutName = model.getMessageContentOutName();
   if (_messageContentOutName == null) {
     _messageContentOutName = MESSAGE_CONTENT_OUT;
   }
   ComponentModel cm = model.getComponent();
   _targetNamespace = cm != null ? cm.getTargetNamespace() : null;
   _taskHandlerModels.addAll(model.getTaskHandlers());
   ClassLoader loader = Classes.getClassLoader(getClass());
   ResourceType.install(loader);
   ComponentImplementationConfig cic = new ComponentImplementationConfig(model, loader);
   Map<String, Object> env = new HashMap<String, Object>();
   // env.put(EnvironmentName.ENTITY_MANAGER_FACTORY,
   // Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"));
   // env.put(EnvironmentName.TRANSACTION_MANAGER,
   // AS7TransactionManagerLookup.getTransactionManager());
   cic.setEnvironmentOverrides(env);
   Properties props = new Properties();
   // props.setProperty("drools.processInstanceManagerFactory",
   // JPAProcessInstanceManagerFactory.class.getName());
   // props.setProperty("drools.processSignalManagerFactory",
   // JPASignalManagerFactory.class.getName());
   cic.setPropertiesOverrides(props);
   Resource procDef = model.getProcessDefinition();
   if (procDef.getType() == null) {
     procDef = new SimpleResource(procDef.getLocation(), "BPMN2");
   }
   if (model.isAgent()) {
     _kagent = Agents.newAgent(cic, procDef);
     _kbase = _kagent.getKnowledgeBase();
   } else {
     _kbase = Bases.newBase(cic, procDef);
   }
   _ksessionConfig = Configs.getSessionConfiguration(cic);
   _environment = Environments.getEnvironment(cic);
   _audit = model.getAudit();
   for (ProcessActionModel pam : model.getProcessActions()) {
     _actionModels.put(pam.getName(), pam);
   }
 }
 /**
  * Will create a new ContextMapper based on the specifications of the passed in
  * ContextMapperModel, or if a class it not specified, will apply the rest of the model properties
  * on the default/fallback implementation.
  *
  * @param model contains the config details
  * @return the new ContextMapper instance
  */
 @SuppressWarnings("unchecked")
 public final ContextMapper<D> newContextMapper(ContextMapperModel model) {
   ContextMapper<D> contextMapper = null;
   ContextMapperFactory<D> contextMapperFactory =
       ContextMapperFactory.getContextMapperFactory(getBindingDataClass());
   if (model != null) {
     contextMapper =
         contextMapperFactory.newContextMapper(
             (Class<ContextMapper<D>>) Classes.forName(model.getClazz()));
     contextMapper.setModel(model);
     if (contextMapper instanceof RegexContextMapper) {
       RegexContextMapper<D> regexContextMapper = (RegexContextMapper<D>) contextMapper;
       regexContextMapper.setIncludes(model.getIncludes());
       regexContextMapper.setExcludes(model.getExcludes());
       regexContextMapper.setIncludeNamespaces(model.getIncludeNamespaces());
       regexContextMapper.setExcludeNamespaces(model.getExcludeNamespaces());
     }
   } else {
     contextMapper = contextMapperFactory.newContextMapperDefault();
   }
   return contextMapper;
 }
 /**
  * Overridable method for resolving a class which allows environments like OSGi to customize
  * resolution.
  */
 protected Class<?> getClass(String className) {
   return Classes.forName(className, TransformerUtil.class);
 }
 /**
  * Overridable method for resolving a class path resource which allows environments like OSGi to
  * customize resolution.
  */
 protected List<URL> getResources(String path) throws java.io.IOException {
   return Classes.getResources(path, getClass());
 }