List of usage examples for org.apache.commons.lang3 ClassUtils getClass
public static Class<?> getClass(final String className) throws ClassNotFoundException
From source file:com.github.haixing_hu.bean.TypeAliasXmlAdapter.java
@Override public Class<?> unmarshal(final String name) throws Exception { Class<?> type = TypeAliasRegistry.getType(name); if (type == null) { type = ClassUtils.getClass(name); }/*from www. jav a2s .c om*/ return type; }
From source file:com.tuplejump.stargate.lucene.AnalyzerFactory.java
public static Analyzer getAnalyzer(String analyzerName) { try {/* w ww. j a v a2 s . com*/ Analyzers analyzer = Analyzers.valueOf(analyzerName); switch (analyzer) { case SimpleAnalyzer: { return new SimpleAnalyzer(); } case StandardAnalyzer: { return new StandardAnalyzer(); } case StopAnalyzer: { return new StopAnalyzer(); } case WhitespaceAnalyzer: { return new WhitespaceAnalyzer(); } case KeywordAnalyzer: { return new CaseInsensitiveKeywordAnalyzer(); } default: { return new StandardAnalyzer(); } } } catch (IllegalArgumentException e) { try { Class clazz = ClassUtils.getClass(analyzerName); return (Analyzer) clazz.newInstance(); } catch (ClassNotFoundException e1) { throw new IllegalArgumentException("No analyzer class found with name [" + analyzerName + "]"); } catch (InstantiationException e1) { throw new IllegalArgumentException("Could not construct an object of analyzer class with name [" + analyzerName + "]. " + "Unable to find no-args constructor"); } catch (IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
From source file:com.google.code.jconfig.factory.ConfigurationPluginFactory.java
/** * <p>/*from w w w . j a v a2s. co m*/ * Returns a plugin instance of type <em>classname</em>. * </p> * * <p> * If the implementation class use the {@link Cacheable} annotation, it * will be cached for future reuse otherwise a new instance will be * created at every request. * </p> * * @param classname the full name of an instance of * {@link IConfigurationPlugin}. * @return the plugin instance. * @throws PluginInstantiationException */ public static IConfigurationPlugin<?> getPlugin(final String classname) throws PluginInstantiationException { try { if (ClassUtils.getClass(classname).getAnnotation(Cacheable.class) == null) { logger.debug("Plugin <" + classname + "> is not cacheable. Creating a new one."); return (IConfigurationPlugin<?>) Class.forName(classname).newInstance(); } } catch (Exception e) { throw new PluginInstantiationException(e.getMessage(), e); } // cacheable plugin FutureTask<IConfigurationPlugin<?>> theTask = cache.get(classname); if (theTask == null) { logger.debug("No plugin of class <" + classname + "> available. Creatine a new one."); Callable<IConfigurationPlugin<?>> eval = new Callable<IConfigurationPlugin<?>>() { public IConfigurationPlugin<?> call() throws Exception { IConfigurationPlugin<?> plugin = (IConfigurationPlugin<?>) Class.forName(classname) .newInstance(); return plugin; } }; FutureTask<IConfigurationPlugin<?>> thePluginExec = new FutureTask<IConfigurationPlugin<?>>(eval); theTask = cache.putIfAbsent(classname, thePluginExec); if (theTask == null) { theTask = thePluginExec; theTask.run(); } logger.debug("New plugin of class <" + classname + "> ready to be used and cached."); } else { logger.debug("Plugin of class <" + classname + "> available in cache. Using the cached one."); } try { return theTask.get(); } catch (Exception e) { throw new PluginInstantiationException(e.getMessage(), e); } finally { logger.debug("plugin cache size: " + cache.size() + " - cache detail: " + cache); } }
From source file:com.esri.geoevent.test.performance.provision.DefaultProvisionerFactory.java
@Override public Provisioner createProvisioner(ProvisionerConfig config) throws ProvisionException { if (config == null) { return null; }// w w w . ja v a 2s. c o m String className = config.getClassName(); if (StringUtils.isEmpty(className)) { throw new ProvisionException( "Failed to create a valid Provisioner. The attribute \"ClassName\" is missing in the \"ProvisionerConfig\"!"); } try { Class<?> clazz = ClassUtils.getClass(className); Provisioner provisioner = (Provisioner) clazz.newInstance(); provisioner.init(config); return provisioner; } catch (ClassNotFoundException error) { throw new ProvisionException( "Failed to create a valid Provisioner. The className \"" + className + "\" was not found!", error); } catch (IllegalAccessException | InstantiationException error) { throw new ProvisionException("Failed to instatiate a valid Provisioner. The className \"" + className + "\" must have a parameter-less constructor!", error); } }
From source file:com.github.jknack.handlebars.js.HandlebarsJs.java
/** * Creates a {@link HandlebarsJs} object. * * @param helperRegistry The helperRegistry object. Required. * @return A new {@link HandlebarsJs} object. *//*from ww w .j av a2 s. co m*/ public static HandlebarsJs create(final HelperRegistry helperRegistry) { try { ClassUtils.getClass("org.mozilla.javascript.Context"); return new RhinoHandlebars(helperRegistry); } catch (final Exception ex) { return new HandlebarsJs(helperRegistry) { @Override public void registerHelpers(final String filename, final String source) throws Exception { throw new IllegalStateException("Rhino isn't on the classpath", ex); } }; } }
From source file:alfio.config.SpringBootLauncher.java
private static void launchHsqlGUI() { Class<?> cls;/* w w w . j av a2 s .co m*/ try { cls = ClassUtils.getClass("org.hsqldb.util.DatabaseManagerSwing"); MethodUtils.invokeStaticMethod(cls, "main", new Object[] { new String[] { "--url", "jdbc:hsqldb:mem:alfio", "--noexit" } }); } catch (ReflectiveOperationException e) { log.warn("error starting db manager", e); } }
From source file:com.feilong.core.lang.ClassUtilTest.java
/** * Test get class./* w ww. jav a2 s . c om*/ * * @throws ClassNotFoundException * the class not found exception */ @Test public void testGetClass() throws ClassNotFoundException { assertSame(FeiLongVersion.class, ClassUtil.getClass(FeiLongVersion.class.getName())); assertSame(FeiLongVersion.class, ClassUtils.getClass(FeiLongVersion.class.getName())); }
From source file:com.strider.datadefender.requirement.Parameter.java
private Object getArrayForValues(final List<Object> list, final String type) throws ClassNotFoundException { String dataType = type;//from w w w. j av a 2 s . c om if ("String".equals(dataType)) { dataType = "java.lang.String"; } final Class<?> c = ClassUtils.getClass(dataType); if (c.isPrimitive()) { final Class<?> w = ClassUtils.primitiveToWrapper(c); Object array = Array.newInstance(w, list.size()); array = list.toArray((Object[]) array); if (c == boolean.class) { return ArrayUtils.toPrimitive((Boolean[]) array); } else if (c == byte.class) { return ArrayUtils.toPrimitive((Byte[]) array); } else if (c == short.class) { return ArrayUtils.toPrimitive((Short[]) array); } else if (c == char.class) { return ArrayUtils.toPrimitive((Character[]) array); } else if (c == int.class) { return ArrayUtils.toPrimitive((Integer[]) array); } else if (c == long.class) { return ArrayUtils.toPrimitive((Long[]) array); } else if (c == float.class) { return ArrayUtils.toPrimitive((Float[]) array); } else if (c == double.class) { return ArrayUtils.toPrimitive((Double[]) array); } throw new IllegalArgumentException("Unhandled primitive type: " + c.getName()); } final Object array = Array.newInstance(c, list.size()); return list.toArray((Object[]) array); }
From source file:com.msopentech.odatajclient.engine.metadata.edm.v4.annotation.DynExprConstructDeserializer.java
private AbstractElOrAttrConstruct getElOrAttrInstance(final String simpleClassName) throws JsonParseException { try {/*from www. j av a2s . c o m*/ @SuppressWarnings("unchecked") Class<? extends AbstractElOrAttrConstruct> elOrAttrClass = (Class<? extends AbstractElOrAttrConstruct>) ClassUtils .getClass(getClass().getPackage().getName() + "." + simpleClassName); return elOrAttrClass.newInstance(); } catch (Exception e) { throw new JsonParseException("Could not instantiate " + simpleClassName, JsonLocation.NA, e); } }
From source file:com.norconex.jefmon.JEFMonApplication.java
private void initJobActions() { List<String> classes = ClassFinder.findSubTypes(IJobAction.class); for (String className : classes) { IJobAction action;//from w w w . j ava 2s . com try { action = (IJobAction) ClassUtils.getClass(className).newInstance(); allJobsActions.add(action); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { LOG.error("Cannot instantiate job action: " + className, e); } } }