Example usage for org.apache.commons.lang3 ClassUtils getClass

List of usage examples for org.apache.commons.lang3 ClassUtils getClass

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ClassUtils getClass.

Prototype

public static Class<?> getClass(final String className) throws ClassNotFoundException 

Source Link

Document

Returns the (initialized) class represented by className using the current thread's context class loader.

Usage

From source file:jp.terasoluna.fw.validation.FieldChecks.java

/**
 * ?????/*from   w w w . j av a  2  s  .co m*/
 *
 * @param va Validator????ValidatorAction
 * @return ?
 */
@SuppressWarnings("rawtypes")
protected Class[] getParamClass(ValidatorAction va) {

    StringTokenizer st = new StringTokenizer(va.getMethodParams(), ",");
    Class[] paramClass = new Class[st.countTokens()];

    for (int i = 0; st.hasMoreTokens(); i++) {
        try {
            String key = st.nextToken().trim();
            paramClass[i] = ClassUtils.getClass(key);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }
    return paramClass;
}

From source file:net.sourceforge.pmd.util.fxdesigner.util.beans.XmlInterfaceVersion1.java

private void parseSingleProperty(Element propertyElement, SimpleBeanModelNode owner) {
    String typeName = propertyElement.getAttribute(SCHEMA_PROPERTY_TYPE);
    String name = propertyElement.getAttribute(SCHEMA_PROPERTY_NAME);
    Class<?> type;// w ww  .  j a va 2  s  .  c om
    try {
        type = ClassUtils.getClass(typeName);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return;
    }

    ConvertUtils.convert(new Object());
    Object value = ConvertUtils.convert(propertyElement.getTextContent(), type);

    owner.addProperty(name, value, type);
}

From source file:org.apache.bval.jsr.ApacheValidationProvider.java

/**
 * {@inheritDoc}//from   w ww.j  a va2s .co  m
 * 
 * @throws javax.validation.ValidationException
 *             if the ValidatorFactory cannot be built
 */
public ValidatorFactory buildValidatorFactory(final ConfigurationState configuration) {
    final Class<? extends ValidatorFactory> validatorFactoryClass;
    try {
        final String validatorFactoryClassname = configuration.getProperties()
                .get(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME);

        if (validatorFactoryClassname == null) {
            validatorFactoryClass = ApacheValidatorFactory.class;
        } else {
            validatorFactoryClass = ClassUtils.getClass(validatorFactoryClassname)
                    .asSubclass(ValidatorFactory.class);
        }
    } catch (ValidationException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new ValidationException("error building ValidatorFactory", ex);
    }

    try {
        return validatorFactoryClass.getConstructor(ConfigurationState.class).newInstance(configuration);
    } catch (final Exception ex) {
        throw new ValidationException("Cannot instantiate : " + validatorFactoryClass, ex);
    }
}

From source file:org.apache.bval.jsr.ApacheValidatorFactory.java

/**
 * Return an object of the specified type to allow access to the
 * provider-specific API. If the Bean Validation provider implementation
 * does not support the specified class, the ValidationException is thrown.
 *
 * @param type the class of the object to be returned.
 * @return an instance of the specified class
 * @throws ValidationException if the provider does not support the call.
 *//*from ww  w. java2s  .c om*/
public <T> T unwrap(final Class<T> type) {
    if (type.isInstance(this)) {
        @SuppressWarnings("unchecked")
        final T result = (T) this;
        return result;
    }

    // FIXME 2011-03-27 jw:
    // This code is unsecure.
    // It should allow only a fixed set of classes.
    // Can't fix this because don't know which classes this method should support.

    if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
        return newInstance(type);
    }
    try {
        final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
        if (type.isAssignableFrom(cls)) {
            @SuppressWarnings("unchecked")
            T result = (T) newInstance(cls);
            return result;
        }
    } catch (ClassNotFoundException e) {
        // do nothing
    }
    throw new ValidationException("Type " + type + " not supported");
}

From source file:org.apache.bval.jsr.ClassValidator.java

/**
 * {@inheritDoc} Return an instance of the specified type allowing access to provider-specific APIs. If the Bean
 * Validation provider implementation does not support the specified class, <code>ValidationException</code> is
 * thrown.//from w  ww. j  ava2s . c om
 *
 * @param type the class of the object to be returned.
 * @return an instance of the specified class
 * @throws ValidationException if the provider does not support the call.
 */
// @Override - not allowed in 1.5 for Interface methods
public <T> T unwrap(Class<T> type) {
    // FIXME 2011-03-27 jw:
    // This code is unsecure.
    // It should allow only a fixed set of classes.
    // Can't fix this because don't know which classes this method should support.

    if (type.isAssignableFrom(getClass())) {
        @SuppressWarnings("unchecked")
        final T result = (T) this;
        return result;
    }
    if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
        return newInstance(type);
    }
    try {
        final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
        if (type.isAssignableFrom(cls)) {
            @SuppressWarnings("unchecked")
            final Class<? extends T> implClass = (Class<? extends T>) cls;
            return newInstance(implClass);
        }
    } catch (ClassNotFoundException e) {
    }
    throw new ValidationException("Type " + type + " not supported");
}

From source file:org.apache.bval.MetaBeanBuilder.java

/**
 * Find the named class.//w  ww. j  a v a  2 s.co m
 * 
 * @param className
 * @return Class found or null
 */
protected Class<?> findLocalClass(String className) {
    if (className != null) {
        try {
            return ClassUtils.getClass(className);
        } catch (ClassNotFoundException e) {
            log.log(Level.FINE, String.format("Class not found: %s", className), e);
        }
    }
    return null;
}

From source file:org.apache.bval.xml.XMLMetaBeanInfos.java

private void initValidationLookup() throws Exception {
    final HashMap<String, XMLMetaValidator> map = new HashMap<String, XMLMetaValidator>(validators.size());
    for (XMLMetaValidator xv : validators) {
        if (xv.getJava() != null) {
            Validation validation = (Validation) ClassUtils.getClass(xv.getJava()).newInstance();
            xv.setValidation(validation);
            map.put(xv.getId(), xv);//from   w  w  w  .  j a  va2s.c  o m
        }
    }
    validationLookup = new ConcurrentHashMap<String, XMLMetaValidator>(map);
}

From source file:org.apache.bval.xml.XMLMetaElement.java

public void mergeInto(MetaProperty prop) throws ClassNotFoundException {
    mergeFeaturesInto(prop);//from   ww  w  .  j a va  2 s  .  co  m
    if (getType() != null && getType().length() > 0) {
        prop.setType(ClassUtils.getClass(getType())); // enhancement: or use getGenericType() ?
    }
    if (getHidden() != null) {
        prop.putFeature(HIDDEN, getHidden().booleanValue());
    }
    if (getMandatory() != null) {
        prop.putFeature(MANDATORY, getMandatory().equals("true"));
    }
    if (getMaxLength() != null) {
        prop.putFeature(MAX_LENGTH, getMaxLength());
    }
    if (getMinLength() != null) {
        prop.putFeature(MIN_LENGTH, getMinLength());
    }
    if (getReadonly() != null) {
        prop.putFeature(READONLY, getReadonly());
    }
    if (getDenied() != null) {
        prop.putFeature(DENIED, getDenied());
    }
}

From source file:org.apache.jorphan.reflect.ClassTools.java

/**
 * Call no-args constructor for a class.
 *
 * @param className name of the class to be constructed
 * @return an instance of the class/* ww w . j a v  a 2s.  c  o  m*/
 * @throws JMeterException if class cannot be created
 */
public static Object construct(String className) throws JMeterException {
    Object instance = null;
    try {
        instance = ClassUtils.getClass(className).newInstance();
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
        throw new JMeterException(e);
    }
    return instance;
}

From source file:org.apache.jorphan.reflect.ClassTools.java

/**
 * Call a class constructor with an integer parameter
 * @param className name of the class to be constructed
 * @param parameter the value to be used in the constructor
 * @return an instance of the class/*from   w  w  w.  java2s  .  co m*/
 * @throws JMeterException if class cannot be created
 */
public static Object construct(String className, int parameter) throws JMeterException {
    Object instance = null;
    try {
        Class<?> clazz = ClassUtils.getClass(className);
        Constructor<?> constructor = clazz.getConstructor(Integer.TYPE);
        instance = constructor.newInstance(Integer.valueOf(parameter));
    } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException
            | NoSuchMethodException | SecurityException | IllegalAccessException | InstantiationException e) {
        throw new JMeterException(e);
    }
    return instance;
}