Java Code Examples for org.apache.commons.lang.ClassUtils#getClass()

The following examples show how to use org.apache.commons.lang.ClassUtils#getClass() . 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: MCRFunctionCallJava.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object call(Context context, List args) throws FunctionCallException {
    try {
        String clazzName = (String) (args.get(0));
        String methodName = (String) (args.get(1));
        LOGGER.debug("XEditor extension function calling {} {}", clazzName, methodName);

        Class[] argTypes = new Class[args.size() - 2];
        Object[] params = new Object[args.size() - 2];
        for (int i = 0; i < argTypes.length; i++) {
            argTypes[i] = args.get(i + 2).getClass();
            params[i] = args.get(i + 2);
        }

        Class clazz = ClassUtils.getClass(clazzName);
        Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
        return method.invoke(null, params);
    } catch (Exception ex) {
        LOGGER.warn("Exception in call to external java method", ex);
        return ex.getMessage();
    }
}
 
Example 2
Source File: ReflectUtil.java    From sofa-acts with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param className
 * @return
 */
public static Class<?> getClassForName(String className) {
    try {
        return ClassUtils.getClass(className);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }

}
 
Example 3
Source File: StateHelper.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 加载状态枚举类
 *
 * @param stateClass
 * @return
 * @throws IllegalArgumentException
 */
public static Class<?> getSatetClass(String stateClass) throws IllegalArgumentException {
    Assert.notNull(stateClass, "[stateClass] not be null");

    Class<?> stateEnum;
    try {
        stateEnum = ClassUtils.getClass(stateClass);
        if (stateEnum.isEnum() && ClassUtils.isAssignable(stateEnum, StateSpec.class)) {
            return stateEnum;
        }
    } catch (ClassNotFoundException ignored) {
        throw new IllegalArgumentException("No class of state found: " + stateClass);
    }
    throw new IllegalArgumentException("Bad class of state found: " + stateEnum);
}
 
Example 4
Source File: MCRExternalValidator.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private Method findMethod(Class<?> argType) {
    try {
        Class<?> clazz = ClassUtils.getClass(className);
        Class<?>[] argTypes = { argType };
        return MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
    } catch (ClassNotFoundException ex) {
        throw new MCRConfigurationException("class configured for external validation not found: " + className);
    }
}
 
Example 5
Source File: ClassUtil.java    From qaf with MIT License 5 votes vote down vote up
public static Class<?> getClass(Type typeOfT) {
	if (typeOfT instanceof ParameterizedType) {
		return getClass(((ParameterizedType) typeOfT).getRawType());
	}
	if (typeOfT instanceof Class) {
		return (Class<?>) typeOfT;
	}
	try {
		return ClassUtils.getClass(typeOfT.getTypeName());
	} catch (ClassNotFoundException e) {
		return typeOfT.getClass();
	}

}
 
Example 6
Source File: KimAttributeDefinition.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public void completeValidation(Class rootObjectClass, Class otherObjectClass, ValidationTrace tracer) {
	super.completeValidation(rootObjectClass, otherObjectClass,tracer);
	if ( StringUtils.isNotBlank(lookupBoClass) ) {
       	try {
       		ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(), getLookupBoClass());
       	} catch (ClassNotFoundException e) {
               String currentValues[] = {"property = " + getName(), "class = " + rootObjectClass.getName(), "lookupBoClass = " + getLookupBoClass()};
               tracer.createError("lookupBoClass could not be found", currentValues);
       	}
       }
}
 
Example 7
Source File: ClassLoaderUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public static Class<?> getClass(String className) {
	if (StringUtils.isEmpty(className)) {
		return null;
	}
	try {
		return ClassUtils.getClass(getDefaultClassLoader(), className);
	} catch (ClassNotFoundException e) {
		throw new RiceRuntimeException(e);
	}
}
 
Example 8
Source File: AutoCreateMappingRulePolicyImpl.java    From bdf3 with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(ImporterSolution importerSolution) {
	try {
		Class<?> entityClass = ClassUtils.getClass(importerSolution.getEntityClassName());
		List<Field> fields = FieldUtils.getFields(entityClass);
		List<String> propertyNames = getPropertyNames(importerSolution);
		int col = propertyNames.size();

		for (Field field : fields) {
			Transient t = field.getAnnotation(Transient.class);
			String propertyName = field.getName();
			if (t != null 
					|| BeanUtils.getPropertyDescriptor(entityClass, propertyName) == null 
					|| !EntityUtils.isSimpleType(field.getType())
					|| contains(propertyNames, propertyName)) {
				continue;
			}
			MappingRule mappingRule = new MappingRule();
			mappingRule.setId(UUID.randomUUID().toString());
			mappingRule.setImporterSolutionId(importerSolution.getId());
			mappingRule.setName(propertyName);
			mappingRule.setPropertyName(propertyName);
			mappingRule.setExcelColumn(col);
			
			PropertyDef propertyDef = field.getAnnotation(PropertyDef.class);
			Column column = field.getAnnotation(Column.class);
			if (propertyDef != null) {
				mappingRule.setName(propertyDef.label());
			}
			if (column != null) {
				
			}
			JpaUtil.persist(mappingRule);
			col++;
		}
				
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	
}
 
Example 9
Source File: ClassLoaderUtils.java    From rice with Educational Community License v2.0 4 votes vote down vote up
public static <T> Class<? extends T> getClass(String className, Class<T> type) throws ClassNotFoundException {
	Class<?> theClass = ClassUtils.getClass(getDefaultClassLoader(), className);
	return theClass.asSubclass(type);
}