List of usage examples for org.apache.commons.lang ClassUtils getClass
public static Class<?> getClass(String className) throws ClassNotFoundException
className
using the current thread's context class loader. From source file:org.apache.maven.plugins.help.EvaluateMojo.java
/** * @param xstreamObject not null/*w w w .j a v a 2 s . com*/ * @param jarFile not null * @param packageFilter a package name to filter. */ private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) { JarInputStream jarStream = null; try { jarStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry jarEntry = jarStream.getNextJarEntry(); while (jarEntry != null) { if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) { String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf(".")); name = name.replaceAll("/", "\\."); if (name.contains(packageFilter)) { try { Class<?> clazz = ClassUtils.getClass(name); String alias = StringUtils.lowercaseFirstLetter(ClassUtils.getShortClassName(clazz)); xstreamObject.alias(alias, clazz); if (!clazz.equals(Model.class)) { xstreamObject.omitField(clazz, "modelEncoding"); // unnecessary field } } catch (ClassNotFoundException e) { getLog().error(e); } } } jarStream.closeEntry(); jarEntry = jarStream.getNextJarEntry(); } } catch (IOException e) { if (getLog().isDebugEnabled()) { getLog().debug("IOException: " + e.getMessage(), e); } } finally { IOUtil.close(jarStream); } }
From source file:org.apache.wink.server.internal.DeploymentConfiguration.java
/** * Initializes the main handlers chain. Override in order to change the * chains.// w w w. ja v a2s . c o m */ @SuppressWarnings("unchecked") private void initHandlers() { String handlersFactoryClassName = properties.getProperty(HANDLERS_FACTORY_CLASS_PROP); if (handlersFactoryClassName != null) { try { logger.trace("Handlers Factory Class is: {}", handlersFactoryClassName); //$NON-NLS-1$ // use ClassUtils.getClass instead of Class.forName so we have // classloader visibility into the Web module in J2EE // environments Class<HandlersFactory> handlerFactoryClass = (Class<HandlersFactory>) ClassUtils .getClass(handlersFactoryClassName); HandlersFactory handlersFactory = handlerFactoryClass.newInstance(); if (requestUserHandlers == null) { requestUserHandlers = (List<RequestHandler>) handlersFactory.getRequestHandlers(); } if (responseUserHandlers == null) { responseUserHandlers = (List<ResponseHandler>) handlersFactory.getResponseHandlers(); } if (errorUserHandlers == null) { errorUserHandlers = (List<ResponseHandler>) handlersFactory.getErrorHandlers(); } } catch (ClassNotFoundException e) { logger.error(Messages.getMessage("isNotAClassWithMsgFormat", //$NON-NLS-1$ handlersFactoryClassName), e); } catch (InstantiationException e) { logger.error(Messages.getMessage("classInstantiationExceptionWithMsgFormat", //$NON-NLS-1$ handlersFactoryClassName), e); } catch (IllegalAccessException e) { logger.error(Messages.getMessage("classIllegalAccessWithMsgFormat", //$NON-NLS-1$ handlersFactoryClassName), e); } } if (requestUserHandlers == null) { requestUserHandlers = initRequestUserHandlers(); } if (responseUserHandlers == null) { responseUserHandlers = initResponseUserHandlers(); } if (errorUserHandlers == null) { errorUserHandlers = initErrorUserHandlers(); } }
From source file:org.chililog.server.engine.parsers.EntryParserFactory.java
/** * Instances the correct entry parser//from ww w .j ava 2 s. c o m * * @param repoInfo * Repository meta data * @param repoParserInfo * Parser meta data * @return Entry parser * @throws ChiliLogException */ public static EntryParser getParser(RepositoryConfigBO repoInfo, RepositoryParserConfigBO repoParserInfo) throws ChiliLogException { if (repoParserInfo == null) { throw new NullArgumentException("repoParserInfo"); } try { String className = repoParserInfo.getClassName(); if (className.equals(_delimitedEntryParserClassName)) { return new DelimitedEntryParser(repoInfo, repoParserInfo); } else if (className.equals(_regexEntryParserClassName)) { return new RegexEntryParser(repoInfo, repoParserInfo); } else if (className.equals(_jsonEntryParserClassName)) { return new JsonEntryParser(repoInfo, repoParserInfo); } // Use reflection to instance it Class<?> cls = ClassUtils.getClass(className); return (EntryParser) ConstructorUtils.invokeConstructor(cls, new Object[] { repoInfo, repoParserInfo }); } catch (Exception ex) { throw new ChiliLogException(ex, Strings.PARSER_FACTORY_ERROR, repoParserInfo.getName(), repoInfo.getName(), ex.getMessage()); } }
From source file:org.chililog.server.workbench.ApiRequestHandler.java
/** * <p>//from ww w. j av a 2 s . c om * Instance our API worker class using the name passed in on the URI. * </p> * <p> * If <code>/api/Authentication</code> is passed in, the class * <code>com.chililog.server.intefaces.management.workers.AuthenticationWorker</code> will be instanced. * </p> */ private ApiResult instanceApiWorker() throws Exception { // TODO - Invoke in another thread because we are mostly reading and writing to mongodb String className = null; try { String uri = _request.getUri(); String[] segments = uri.split("/"); String apiName = segments[2]; // Get rid of query string int qs = apiName.indexOf("?"); if (qs > 0) { apiName = apiName.substring(0, qs); } // Merge _ to camel case apiName = WordUtils.capitalizeFully(apiName, new char[] { '_' }); apiName = apiName.replace("_", ""); className = "org.chililog.server.workbench.workers." + apiName + "Worker"; _logger.debug("Instancing ApiWorker: %s", className); Class<?> apiClass = ClassUtils.getClass(className); _apiWorker = (Worker) ConstructorUtils.invokeConstructor(apiClass, _request); return _apiWorker.validate(); } catch (ClassNotFoundException ex) { return new ApiResult(HttpResponseStatus.NOT_FOUND, new ChiliLogException(ex, Strings.API_NOT_FOUND_ERROR, className, _request.getUri())); } }
From source file:org.cloudifysource.rest.doclet.RESTRequestExampleGenerator.java
@Override public String generateExample(final Type type) throws Exception { Class<?> clazz = ClassUtils.getClass(type.qualifiedTypeName()); Object requestBodyParam = getRequestExample(clazz); String jsonStr = new ObjectMapper().writeValueAsString(requestBodyParam); return jsonStr; }
From source file:org.cloudifysource.rest.doclet.RESTResposneExampleGenerator.java
private Object getExample(final Type type) throws InstantiationException, IllegalAccessException, ClassNotFoundException { Object example;//from ww w.j a va 2 s . co m Class<?> clazz = ClassUtils.getClass(type.qualifiedTypeName()); // create the example instance if (DeleteApplicationAttributeResponse.class.equals(clazz)) { example = new DeleteApplicationAttributeResponse(); ((DeleteApplicationAttributeResponse) example).setPreviousValue(RESTExamples.getAttribute()); } else if (DeleteServiceAttributeResponse.class.equals(clazz)) { example = new DeleteServiceAttributeResponse(); ((DeleteServiceAttributeResponse) example).setPreviousValue(RESTExamples.getAttribute()); } else if (DeleteServiceInstanceAttributeResponse.class.equals(clazz)) { example = new DeleteServiceInstanceAttributeResponse(); ((DeleteServiceInstanceAttributeResponse) example).setPreviousValue(RESTExamples.getAttribute()); } else if (GetApplicationAttributesResponse.class.equals(clazz)) { example = new GetApplicationAttributesResponse(); ((GetApplicationAttributesResponse) example).setAttributes(RESTExamples.getAttributes()); } else if (GetServiceAttributesResponse.class.equals(clazz)) { example = new GetServiceAttributesResponse(); ((GetServiceAttributesResponse) example).setAttributes(RESTExamples.getAttributes()); } else if (GetServiceInstanceAttributesResponse.class.equals(clazz)) { example = new GetServiceInstanceAttributesResponse(); ((GetServiceInstanceAttributesResponse) example).setAttributes(RESTExamples.getAttributes()); } else if (InstallApplicationResponse.class.equals(clazz)) { example = new InstallApplicationResponse(); ((InstallApplicationResponse) example).setDeploymentID(RESTExamples.getDeploymentID()); } else if (InstallServiceResponse.class.equals(clazz)) { example = new InstallServiceResponse(); ((InstallServiceResponse) example).setDeploymentID(RESTExamples.getDeploymentID()); } else if (ServiceInstanceMetricsResponse.class.equals(clazz)) { example = new ServiceInstanceMetricsResponse(); ((ServiceInstanceMetricsResponse) example).setAppName(RESTExamples.getAppName()); ((ServiceInstanceMetricsResponse) example) .setServiceInstanceMetricsData(RESTExamples.getServiceInstanceMetricsData()); ((ServiceInstanceMetricsResponse) example).setServiceName(RESTExamples.getServiceName()); } else if (ServiceMetricsResponse.class.equals(clazz)) { ServiceMetricsResponse serviceMetricsResponse = new ServiceMetricsResponse(); serviceMetricsResponse.setAppName(RESTExamples.getAppName()); serviceMetricsResponse.setServiceInstaceMetricsData(RESTExamples.getServiceInstanceMetricsDataList()); serviceMetricsResponse.setServiceName(RESTExamples.getServiceName()); example = serviceMetricsResponse; } else if (UninstallApplicationResponse.class.equals(clazz)) { example = new UninstallApplicationResponse(); ((UninstallApplicationResponse) example).setDeploymentID(RESTExamples.getDeploymentID()); } else if (UninstallServiceResponse.class.equals(clazz)) { example = new UninstallServiceResponse(); ((UninstallServiceResponse) example).setDeploymentID(RESTExamples.getDeploymentID()); } else if (UpdateApplicationAttributeResponse.class.equals(clazz)) { example = new UpdateApplicationAttributeResponse(); ((UpdateApplicationAttributeResponse) example).setPreviousValue(RESTExamples.getAttribute()); } else if (UploadResponse.class.equals(clazz)) { example = new UploadResponse(); ((UploadResponse) example).setUploadKey(RESTExamples.getUploadKey()); } else if (ServiceDetails.class.equals(clazz)) { ServiceDetails serviceDetails = new ServiceDetails(); serviceDetails.setApplicationName(RESTExamples.getAppName()); serviceDetails.setInstanceNames(RESTExamples.getInstanceNames()); serviceDetails.setName(RESTExamples.getServiceName()); serviceDetails.setNumberOfInstances(RESTExamples.getNumberOfInstances()); example = serviceDetails; } else if (DeploymentEvents.class.equals(clazz)) { example = new DeploymentEvents(); ((DeploymentEvents) example).setEvents(RESTExamples.getEvents()); } else if (ApplicationDescription.class.equals(clazz)) { ApplicationDescription applicationDescription = new ApplicationDescription(); applicationDescription.setApplicationName(RESTExamples.getAppName()); applicationDescription.setApplicationState(RESTExamples.getApplicationState()); applicationDescription.setAuthGroups(RESTExamples.getAuthGroups()); applicationDescription.setServicesDescription(RESTExamples.getServicesDescription()); example = applicationDescription; } else if (ServiceInstanceDetails.class.equals(clazz)) { ServiceInstanceDetails serviceInstanceDetails = new ServiceInstanceDetails(); String appName = RESTExamples.getAppName(); String serviceName = RESTExamples.getServiceName(); int instanceId = RESTExamples.getInstanceId(); serviceInstanceDetails.setApplicationName(appName); serviceInstanceDetails.setHardwareId(RESTExamples.getHardwareId()); serviceInstanceDetails.setImageId(RESTExamples.getImageId()); serviceInstanceDetails.setInstanceId(instanceId); serviceInstanceDetails.setMachineId(RESTExamples.getMachineId()); serviceInstanceDetails.setPrivateIp(RESTExamples.getPrivateIp()); serviceInstanceDetails.setProcessDetails(RESTExamples.getProcessDetails(instanceId)); serviceInstanceDetails.setPublicIp(RESTExamples.getPublicIp()); serviceInstanceDetails.setServiceInstanceName(RESTExamples.getInstanceName(serviceName, appName)); serviceInstanceDetails.setServiceName(serviceName); serviceInstanceDetails.setTemplateName(RESTExamples.getTemplateName()); example = serviceInstanceDetails; } else if (ServiceDescription.class.equals(clazz)) { example = RESTExamples.getServicesDescription(); } else if (clazz.isPrimitive()) { example = PrimitiveExampleValues.getValue(clazz); } else if (String.class.equals(clazz)) { example = "string"; } else if (ParameterizedType.class.isAssignableFrom(type.getClass())) { List<Object> list = new LinkedList<Object>(); if (List.class.isAssignableFrom(clazz)) { ParameterizedType parameterizedType = (ParameterizedType) type; Type paramType = parameterizedType.typeArguments()[0]; list.add(getExample(paramType)); list.add(getExample(paramType)); list.add(getExample(paramType)); } example = list; } else { String className = clazz.getName(); logger.warning("Missing custom instantiation of class " + className + " for generating response example, using newInstance instead."); try { return clazz.newInstance(); } catch (Exception e) { String errMsg = "failed to instantiate " + className; logger.warning(errMsg); throw new IllegalArgumentException(errMsg); } } return example; }
From source file:org.cloudifysource.restDoclet.exampleGenerators.DocDefaultExampleGenerator.java
private String generateJSON(final Type type) throws Exception { Class<?> clazz = ClassUtils.getClass(type.qualifiedTypeName()); if (MultipartFile.class.getName().equals(clazz.getName())) { return "\"file content\""; }/*from w w w .ja va 2 s.com*/ if (clazz.isInterface()) { throw new InstantiationException("the given class is an interface [" + clazz.getName() + "]."); } Object newInstance = null; if (clazz.isPrimitive()) { newInstance = PrimitiveExampleValues.getValue(clazz); } Class<?> classToInstantiate = clazz; if (newInstance == null) { newInstance = classToInstantiate.newInstance(); } return new ObjectMapper().writeValueAsString(newInstance); }
From source file:org.dbist.dml.AbstractDml.java
protected ValueGenerator getValueGenerator(String generator) { if (ValueUtils.isEmpty(generator)) return null; if (GenerationRule.UUID.equals(generator)) { try {//from ww w. j a v a 2s. co m return UuidGenerator.class.newInstance(); } catch (InstantiationException e) { throw new DbistRuntimeException(e); } catch (IllegalAccessException e) { throw new DbistRuntimeException(e); } } try { return (ValueGenerator) ClassUtils.getClass(generator).newInstance(); } catch (InstantiationException e) { throw new DbistRuntimeException(e); } catch (IllegalAccessException e) { throw new DbistRuntimeException(e); } catch (ClassNotFoundException e) { throw new DbistRuntimeException(e); } }
From source file:org.eclipse.reqcycle.ui.eattrpropseditor.EAttrPropsEditorPlugin.java
public static String getEditorType(final EClassifier eType) { if (eType instanceof EClass) { throw new UnsupportedOperationException("EClass not yet supported ..."); }/* w ww . ja v a2 s . c om*/ String editorType = eType.getInstanceClassName(); if (eType instanceof EEnum) { editorType = EEnum.class.getName(); } else { try { Class<?> javaClass = ClassUtils.getClass(editorType); if (javaClass.isPrimitive()) { javaClass = ClassUtils.primitiveToWrapper(javaClass); } editorType = javaClass.getName(); } catch (ClassNotFoundException e) { e.printStackTrace(System.err); // Change or remove return null; // Bad bad bad ... } } return editorType; }
From source file:org.jamwiki.parser.ParserUtil.java
/** * Utility method to retrieve an instance of the current system parser. * * @param parserInput A ParserInput object that contains parser configuration * information./* www . j a va 2s.co m*/ * @return An instance of the system parser. * @throws ParserException Thrown if a parser instance can not be instantiated. */ private static AbstractParser parserInstance(ParserInput parserInput) throws ParserException { String parserClass = Environment.getValue(Environment.PROP_PARSER_CLASS); logger.fine("Using parser: " + parserClass); try { Class clazz = ClassUtils.getClass(parserClass); Class[] parameterTypes = new Class[1]; parameterTypes[0] = ClassUtils.getClass("org.jamwiki.parser.ParserInput"); Constructor constructor = clazz.getConstructor(parameterTypes); Object[] initArgs = new Object[1]; initArgs[0] = parserInput; return (AbstractParser) constructor.newInstance(initArgs); } catch (ClassNotFoundException e) { throw new ParserException(e); } catch (NoSuchMethodException e) { throw new ParserException(e); } catch (IllegalAccessException e) { throw new ParserException(e); } catch (InstantiationException e) { throw new ParserException(e); } catch (InvocationTargetException e) { throw new ParserException(e); } }