Java Code Examples for org.activiti.engine.impl.util.ReflectUtil#loadClass()

The following examples show how to use org.activiti.engine.impl.util.ReflectUtil#loadClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CxfWSDLImporter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected static void _importFields(final JDefinedClass theClass, final AtomicInteger index, final SimpleStructureDefinition structure) {
    
  final JClass parentClass = theClass._extends();
  if (parentClass != null && parentClass instanceof JDefinedClass) {
    _importFields((JDefinedClass)parentClass, index, structure);
  }
  for (Entry<String, JFieldVar> entry : theClass.fields().entrySet()) {
    Class<?> fieldClass = ReflectUtil.loadClass(entry.getValue().type().boxify().erasure().fullName());

    String fieldName = entry.getKey();
    if (fieldName.startsWith("_")) {
      if (!JJavaName.isJavaIdentifier(fieldName.substring(1))) {
        fieldName = fieldName.substring(1); //it was prefixed with '_' so we should use the original name.
      }
    }

    structure.setFieldName(index.getAndIncrement(), fieldName, fieldClass);
  }
}
 
Example 2
Source File: JuelScriptEngine.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static void importFunctions(ScriptContext ctx, String namespace, Object obj) {
  Class<?> clazz = null;
  if (obj instanceof Class) {
    clazz = (Class<?>) obj;
  } else if (obj instanceof String) {
    try {
      clazz = ReflectUtil.loadClass((String) obj);
    } catch (ActivitiException ae) {
      throw new ELException(ae);
    }
  } else {
    throw new ELException("Class or class name is missing");
  }
  Method[] methods = clazz.getMethods();
  for (Method m : methods) {
    int mod = m.getModifiers();
    if (Modifier.isStatic(mod) && Modifier.isPublic(mod)) {
      String name = namespace + ":" + m.getName();
      ctx.setAttribute(name, m, ScriptContext.ENGINE_SCOPE);
    }
  }
}
 
Example 3
Source File: WebServiceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void createItemDefinitions(BpmnModel bpmnModel) {
  
  for (org.activiti.bpmn.model.ItemDefinition itemDefinitionElement : bpmnModel.getItemDefinitions().values()) {
  
    if (itemDefinitionMap.containsKey(itemDefinitionElement.getId()) == false) {
      StructureDefinition structure = null;
  
      try {
        // it is a class
        Class<?> classStructure = ReflectUtil.loadClass(itemDefinitionElement.getStructureRef());
        structure = new ClassStructureDefinition(classStructure);
      } catch (ActivitiException e) {
        // it is a reference to a different structure
        structure = structureDefinitionMap.get(itemDefinitionElement.getStructureRef());
      }
  
      ItemDefinition itemDefinition = new ItemDefinition(itemDefinitionElement.getId(), structure);
      if (StringUtils.isNotEmpty(itemDefinitionElement.getItemKind())) {
        itemDefinition.setItemKind(ItemKind.valueOf(itemDefinitionElement.getItemKind()));
      }
      
      itemDefinitionMap.put(itemDefinition.getId(), itemDefinition);
    }
  }
}
 
Example 4
Source File: JuelScriptEngine.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void importFunctions(ScriptContext ctx, String namespace, Object obj) {
    Class<?> clazz = null;
    if (obj instanceof Class) {
        clazz = (Class<?>) obj;
    } else if (obj instanceof String) {
        try {
            clazz = ReflectUtil.loadClass((String) obj);
        } catch (ActivitiException ae) {
            throw new ELException(ae);
        }
    } else {
        throw new ELException("Class or class name is missing");
    }
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
        int mod = m.getModifiers();
        if (Modifier.isStatic(mod) && Modifier.isPublic(mod)) {
            String name = namespace + ":" + m.getName();
            ctx.setAttribute(name, m, ScriptContext.ENGINE_SCOPE);
        }
    }
}
 
Example 5
Source File: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void importStructure(Mapping mapping) {
  QName qname = mapping.getElement();
  JDefinedClass theClass = (JDefinedClass) mapping.getType().getTypeClass();
  SimpleStructureDefinition structure = (SimpleStructureDefinition) this.structures.get(this.namespace + qname.getLocalPart());

  Map<String, JFieldVar> fields = theClass.fields();
  int index = 0;
  for (Entry<String, JFieldVar> entry : fields.entrySet()) {
    Class<?> fieldClass = ReflectUtil.loadClass(entry.getValue().type().boxify().fullName());
    structure.setFieldName(index, entry.getKey(), fieldClass);
    index++;
  }
}
 
Example 6
Source File: SerializableType.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ObjectInputStream createObjectInputStream(InputStream is) throws IOException {
  return new ObjectInputStream(is) {
    protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
      return ReflectUtil.loadClass(desc.getName());
    }
  };
}
 
Example 7
Source File: JPAEntityMappings.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Object getJPAEntity(String className, String idString) {
  Class<?> entityClass = null;
  entityClass = ReflectUtil.loadClass(className);

  EntityMetaData metaData = getEntityMetaData(entityClass);

  // Create primary key of right type
  Object primaryKey = createId(metaData, idString);
  return findEntity(entityClass, primaryKey);
}
 
Example 8
Source File: ErrorPropagation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected static String findMatchingExceptionMapping(Exception e, List<MapExceptionEntry> exceptionMap) {
  String defaultExceptionMapping = null;

  for (MapExceptionEntry me : exceptionMap) {
    String exceptionClass = me.getClassName();
    String errorCode = me.getErrorCode();

    // save the first mapping with no exception class as default map
    if (StringUtils.isNotEmpty(errorCode) && StringUtils.isEmpty(exceptionClass) && defaultExceptionMapping == null) {
      defaultExceptionMapping = errorCode;
      continue;
    }

    // ignore if error code or class are not defined
    if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(exceptionClass)) {
      continue;
    }

    if (e.getClass().getName().equals(exceptionClass)) {
      return errorCode;
    }
    if (me.isAndChildren()) {
      Class<?> exceptionClassClass = ReflectUtil.loadClass(exceptionClass);
      if (exceptionClassClass.isAssignableFrom(e.getClass())) {
        return errorCode;
      }
    }
  }

  return defaultExceptionMapping;
}
 
Example 9
Source File: ProcessEngines.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected static void initProcessEngineFromSpringResource(URL resource) {
  try {
    Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.activiti.spring.SpringConfigurationHelper");
    Method method = springConfigurationHelperClass.getDeclaredMethod("buildProcessEngine", new Class<?>[] { URL.class });
    ProcessEngine processEngine = (ProcessEngine) method.invoke(null, new Object[] { resource });

    String processEngineName = processEngine.getName();
    ProcessEngineInfo processEngineInfo = new ProcessEngineInfoImpl(processEngineName, resource.toString(), null);
    processEngineInfosByName.put(processEngineName, processEngineInfo);
    processEngineInfosByResourceUrl.put(resource.toString(), processEngineInfo);

  } catch (Exception e) {
    throw new ActivitiException("couldn't initialize process engine from spring configuration resource " + resource.toString() + ": " + e.getMessage(), e);
  }
}
 
Example 10
Source File: SerializableType.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ObjectInputStream createObjectInputStream(InputStream is) throws IOException {
    return new ObjectInputStream(is) {
        @Override
        protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
            return ReflectUtil.loadClass(desc.getName());
        }
    };
}
 
Example 11
Source File: JPAEntityMappings.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public Object getJPAEntity(String className, String idString) {
    Class<?> entityClass = null;
    entityClass = ReflectUtil.loadClass(className);

    EntityMetaData metaData = getEntityMetaData(entityClass);
    if (metaData == null) {
        throw new ActivitiIllegalArgumentException("Class is not a JPA-entity: " + className);
    }

    // Create primary key of right type
    Object primaryKey = createId(metaData, idString);
    return findEntity(entityClass, primaryKey);
}
 
Example 12
Source File: ProcessEngines.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void initProcessEngineFromSpringResource(URL resource) {
    try {
        Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.activiti.spring.SpringConfigurationHelper");
        Method method = springConfigurationHelperClass.getDeclaredMethod("buildProcessEngine", new Class<?>[]{URL.class});
        ProcessEngine processEngine = (ProcessEngine) method.invoke(null, new Object[]{resource});

        String processEngineName = processEngine.getName();
        ProcessEngineInfo processEngineInfo = new ProcessEngineInfoImpl(processEngineName, resource.toString(), null);
        processEngineInfosByName.put(processEngineName, processEngineInfo);
        processEngineInfosByResourceUrl.put(resource.toString(), processEngineInfo);

    } catch (Exception e) {
        throw new ActivitiException("couldn't initialize process engine from spring configuration resource " + resource + ": " + e.getMessage(), e);
    }
}
 
Example 13
Source File: ErrorPropagation.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public static boolean mapException(Exception e, ActivityExecution execution, List<MapExceptionEntry> exceptionMap, boolean wrapped) {
    if (exceptionMap == null) {
        return false;
    }

    if (wrapped && e instanceof ActivitiActivityExecutionException) {
        e = (Exception) e.getCause();
    }

    String defaultMap = null;

    for (MapExceptionEntry me : exceptionMap) {
        String exceptionClass = me.getClassName();
        String errorCode = me.getErrorCode();
        String rootCause = me.getRootCause();

        // save the first mapping with no exception class as default map
        if (StringUtils.isNotEmpty(errorCode) && StringUtils.isEmpty(exceptionClass) && defaultMap == null) {
            // if rootCause is set, check if it matches the exception
            if (StringUtils.isNotEmpty(rootCause)) {
                if (ExceptionUtils.getRootCause(e).getClass().getName().equals(rootCause)) {
                    defaultMap = errorCode;
                    continue;
                }
            } else {
                defaultMap = errorCode;
                continue;
            }
        }

        // ignore if error code or class are not defined
        if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(exceptionClass))
            continue;

        if (e.getClass().getName().equals(exceptionClass)) {
            if (StringUtils.isNotEmpty(rootCause)) {
                if (ExceptionUtils.getRootCause(e).getClass().getName().equals(rootCause)) {
                    propagateError(errorCode, execution);
                }
                continue;
            }
            propagateError(errorCode, execution);
            return true;
        }
        if (me.isAndChildren()) {
            Class<?> exceptionClassClass = ReflectUtil.loadClass(exceptionClass);
            if (exceptionClassClass.isAssignableFrom(e.getClass())) {
                if (StringUtils.isNotEmpty(rootCause)) {
                    if (ExceptionUtils.getRootCause(e).getClass().getName().equals(rootCause)) {
                        propagateError(errorCode, execution);
                        return true;
                    }
                } else {
                    propagateError(errorCode, execution);
                    return true;
                }
            }
        }
    }
    if (defaultMap != null) {
        propagateError(defaultMap, execution);
        return true;
    }

    return false;
}