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:org.apache.kylin.common.metrics.metrics2.CodahaleMetrics.java

/**
 * Initializes reporting using kylin.metric.codahale-metric-report-classes.
 *
 * @return whether initialization was successful or not
 *//*from w  ww .  j ava 2s .c o m*/
private boolean initCodahaleMetricsReporterClasses() {

    List<String> reporterClasses = Lists.newArrayList(Splitter.on(",").trimResults().omitEmptyStrings()
            .split(KylinConfig.getInstanceFromEnv().getCoadhaleMetricsReportClassesNames()));
    if (reporterClasses.isEmpty()) {
        return false;
    }

    for (String reporterClass : reporterClasses) {
        Class name = null;
        try {
            name = ClassUtils.getClass(reporterClass);
        } catch (ClassNotFoundException e) {
            LOGGER.error("Unable to instantiate metrics reporter class " + reporterClass
                    + " from conf kylin.metric.codahale-metric-report-classes", e);
            throw new IllegalArgumentException(e);
        }
        try {
            Constructor constructor = name.getConstructor(MetricRegistry.class, KylinConfig.class);
            CodahaleReporter reporter = (CodahaleReporter) constructor.newInstance(metricRegistry, conf);
            reporter.start();
            reporters.add(reporter);
        } catch (NoSuchMethodException | InstantiationException | IllegalAccessException
                | InvocationTargetException e) {
            LOGGER.error("Unable to instantiate using constructor(MetricRegistry, KylinConfig) for"
                    + " reporter " + reporterClass + " from conf kylin.metric.codahale-metric-report-classes",
                    e);
            throw new IllegalArgumentException(e);
        }
    }
    return true;
}

From source file:org.apache.kylin.common.metrics.perflog.PerfLoggerFactory.java

public static IPerfLogger getPerfLogger(boolean resetPerfLogger) {
    IPerfLogger result = perfLogger.get();
    if (resetPerfLogger || result == null) {
        try {/*  ww  w.  j  a  v a 2s.  c  om*/
            result = (IPerfLogger) ClassUtils
                    .getClass(KylinConfig.getInstanceFromEnv().getPerfLoggerClassName()).newInstance();
        } catch (ClassNotFoundException e) {
            LOG.error("Performance Logger Class not found:" + e.getMessage());
            result = new SimplePerfLogger();
        } catch (IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }
        perfLogger.set(result);
    }
    return result;
}

From source file:org.apache.olingo.client.core.edm.EdmTermImpl.java

@Override
public List<Class<?>> getAppliesTo() {
    if (appliesTo == null) {
        appliesTo = new ArrayList<Class<?>>();
        for (String element : term.getAppliesTo()) {
            try {
                appliesTo.add(ClassUtils.getClass(EdmTerm.class.getPackage().getName() + ".Edm" + element));
            } catch (ClassNotFoundException e) {
                LOG.error("Could not load Edm class for {}", element, e);
            }/*from   ww w  .j a va 2  s .  c  om*/
        }
    }
    return appliesTo;
}

From source file:org.apache.olingo.client.core.edm.xml.annotation.DynamicAnnotationExpressionDeserializer.java

private AbstractElementOrAttributeExpression getElementOrAttributeExpressio(final String simpleClassName)
        throws JsonParseException {

    try {/*from  w  ww  .ja  v  a2s  .co  m*/
        @SuppressWarnings("unchecked")
        Class<? extends AbstractElementOrAttributeExpression> elOrAttrClass = (Class<? extends AbstractElementOrAttributeExpression>) ClassUtils
                .getClass(getClass().getPackage().getName() + "." + simpleClassName + "Impl");
        return elOrAttrClass.newInstance();
    } catch (Exception e) {
        throw new JsonParseException("Could not instantiate " + simpleClassName, JsonLocation.NA, e);
    }
}

From source file:org.apache.olingo.commons.core.edm.EdmTermImpl.java

@Override
public List<Class<?>> getAppliesTo() {
    if (appliesTo == null) {
        final List<Class<?>> appliesToLocal = new ArrayList<Class<?>>();
        for (String element : term.getAppliesTo()) {
            try {
                appliesToLocal//from  ww w . jav  a  2 s. com
                        .add(ClassUtils.getClass(EdmTerm.class.getPackage().getName() + ".Edm" + element));
            } catch (ClassNotFoundException e) {
                LOG.error("Could not load Edm class for {}", element, e);
            }
        }

        appliesTo = appliesToLocal;
    }
    return appliesTo;
}

From source file:org.apache.syncope.client.console.SyncopeConsoleApplication.java

@SuppressWarnings("unchecked")
protected void populatePageClasses(final Properties props) {
    Enumeration<String> propNames = (Enumeration<String>) props.propertyNames();
    while (propNames.hasMoreElements()) {
        String name = propNames.nextElement();
        if (name.startsWith("page.")) {
            try {
                Class<?> clazz = ClassUtils.getClass(props.getProperty(name));
                if (BasePage.class.isAssignableFrom(clazz)) {
                    pageClasses.put(StringUtils.substringAfter("page.", name),
                            (Class<? extends BasePage>) clazz);
                } else {
                    LOG.warn("{} does not extend {}, ignoring...", clazz.getName(), BasePage.class.getName());
                }/*  ww  w  . ja  v a  2s .c om*/
            } catch (ClassNotFoundException e) {
                LOG.error("While looking for class identified by property '{}'", name, e);
            }
        }
    }
}

From source file:org.apache.syncope.client.console.wicket.markup.html.list.ConnConfPropertyListView.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void populateItem(final ListItem<ConnConfProperty> item) {
    final ConnConfProperty property = item.getModelObject();

    final String label = StringUtils.isBlank(property.getSchema().getDisplayName())
            ? property.getSchema().getName()
            : property.getSchema().getDisplayName();

    final FieldPanel<? extends Serializable> field;
    boolean required = false;
    boolean isArray = false;

    if (property.getSchema().isConfidential()
            || Constants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
            || Constants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {

        field = new AjaxPasswordFieldPanel("panel", label, new Model<>(), false);
        ((PasswordTextField) field.getField()).setResetPassword(false);

        required = property.getSchema().isRequired();
    } else {/*from  ww w. j  a  v  a2  s. c om*/
        Class<?> propertySchemaClass;
        try {
            propertySchemaClass = ClassUtils.getClass(property.getSchema().getType());
            if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
                propertySchemaClass = org.apache.commons.lang3.ClassUtils
                        .primitiveToWrapper(propertySchemaClass);
            }
        } catch (ClassNotFoundException e) {
            LOG.error("Error parsing attribute type", e);
            propertySchemaClass = String.class;
        }

        if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
            @SuppressWarnings("unchecked")
            Class<Number> numberClass = (Class<Number>) propertySchemaClass;
            field = new AjaxSpinnerFieldPanel.Builder<>().build("panel", label, numberClass, new Model<>());
            required = property.getSchema().isRequired();
        } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
            field = new AjaxCheckBoxPanel("panel", label, new Model<>());
        } else {
            field = new AjaxTextFieldPanel("panel", label, new Model<>());
            required = property.getSchema().isRequired();
        }

        if (propertySchemaClass.isArray()) {
            isArray = true;
        }
    }

    field.setIndex(item.getIndex());
    field.setTitle(property.getSchema().getHelpMessage(), true);

    final AbstractFieldPanel<? extends Serializable> fieldPanel;
    if (isArray) {
        final MultiFieldPanel multiFieldPanel = new MultiFieldPanel.Builder(
                new PropertyModel<>(property, "values")).setEventTemplate(true).build("panel", label, field);
        item.add(multiFieldPanel);
        fieldPanel = multiFieldPanel;
    } else {
        setNewFieldModel(field, property.getValues());
        item.add(field);
        fieldPanel = field;
    }

    if (required) {
        fieldPanel.addRequiredLabel();
    }

    if (withOverridable) {
        fieldPanel.showExternAction(addCheckboxToggle(property));
    }
}

From source file:org.apache.syncope.core.misc.utils.MappingUtils.java

public static List<MappingItemTransformer> getMappingItemTransformers(final MappingItem mappingItem) {
    List<MappingItemTransformer> result = new ArrayList<>();

    for (String className : mappingItem.getMappingItemTransformerClassNames()) {
        try {//from www. j av  a2 s .  co m
            Class<?> transformerClass = ClassUtils.getClass(className);

            result.add((MappingItemTransformer) ApplicationContextProvider.getBeanFactory()
                    .createBean(transformerClass, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false));
        } catch (Exception e) {
            LOG.error("Could not instantiate {}, ignoring...", className, e);
        }
    }

    return result;
}

From source file:org.apache.syncope.core.persistence.jpa.validation.entity.SchedTaskValidator.java

@Override
public boolean isValid(final SchedTask task, final ConstraintValidatorContext context) {
    boolean isValid = true;

    if (!(task instanceof ProvisioningTask)) {
        Class<?> jobDelegateClass = null;
        try {/*w  ww  . jav a  2  s  .  com*/
            jobDelegateClass = ClassUtils.getClass(task.getJobDelegateClassName());
            isValid = SchedTaskJobDelegate.class.isAssignableFrom(jobDelegateClass);
        } catch (Exception e) {
            LOG.error("Invalid JobDelegate class specified", e);
            isValid = false;
        }
        if (jobDelegateClass == null || !isValid) {
            isValid = false;

            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate(
                    getTemplate(EntityViolationType.InvalidSchedTask, "Invalid job delegate class name"))
                    .addPropertyNode("jobDelegateClassName").addConstraintViolation();
        }
    }

    if (isValid && task.getCronExpression() != null) {
        try {
            new CronExpression(task.getCronExpression());
        } catch (ParseException e) {
            LOG.error("Invalid cron expression '" + task.getCronExpression() + "'", e);
            isValid = false;

            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate(
                    getTemplate(EntityViolationType.InvalidSchedTask, "Invalid cron expression"))
                    .addPropertyNode("cronExpression").addConstraintViolation();
        }
    }

    return isValid;
}

From source file:org.apache.syncope.core.provisioning.java.job.TaskJob.java

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
    super.execute(context);

    try {//from   ww  w.  j  av  a2 s  .c om
        AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY),
                new AuthContextUtils.Executable<Void>() {

                    @Override
                    public Void exec() {
                        try {
                            Class<?> delegateClass = ClassUtils
                                    .getClass(context.getMergedJobDataMap().getString(DELEGATE_CLASS_KEY));

                            ((SchedTaskJobDelegate) ApplicationContextProvider.getBeanFactory()
                                    .createBean(delegateClass, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false))
                                            .execute(taskKey, context.getMergedJobDataMap()
                                                    .getBoolean(DRY_RUN_JOBDETAIL_KEY), context);
                        } catch (Exception e) {
                            LOG.error("While executing task {}", taskKey, e);
                            throw new RuntimeException(e);
                        }

                        return null;
                    }
                });
    } catch (RuntimeException e) {
        LOG.error("While executing task {}", taskKey, e);
        throw new JobExecutionException("While executing task " + taskKey, e);
    }
}