/** * Returns the (initialized) class represented by {@code className} using the given class loader. * * @throws NestedClassNotFoundException if the class is not found */ public static Class<?> forName(ClassLoader classLoader, String className) throws NestedClassNotFoundException { return forName(classLoader, className, true); }
protected Class<?> forName(String className) { return Classes.forName(className); }
/** * Returns the (initialized) class represented by {@code className} using the given class loader. * * <p/> * * returns {@code null} if the class is not found */ public static Class<?> tryForName(ClassLoader classLoader, String className) { try { return forName(classLoader, className, true); } catch (NestedClassNotFoundException e) { return null; } }
private synchronized void initializeDriver() throws SQLException { if (!driverInitialized) { if(Strings.isEmpty(driverClassName)){ throw new SQLException("'driverClassName' must not be empty"); } try { Classes.forName(driverClassName); } catch (Exception e) { throw new SQLException("Error setting driver on UnpooledDataSource. Cause: " + e); } driverInitialized = true; } }
@Override public boolean convertFrom(Object value, Class<?> targetType, Type genericType, Out<Object> out, ConvertContext context) throws Throwable { out.set(Classes.forName(value.toString())); return true; }
/** * Returns the (initialized) class represented by {@code className} using the current thread's context class loader. * * @throws NestedClassNotFoundException if the class is not found */ public static Class<?> forName(String className) throws NestedClassNotFoundException { return forName(getClassLoader(),className,true); }
/** * Returns the (initialized) class represented by {@code className} using the given class's loader. * * @throws NestedClassNotFoundException if the class is not found */ public static Class<?> forName(Class<?> loaderClass,String className) throws NestedClassNotFoundException { return forName(getClassLoader(loaderClass),className); }
/** * Returns the (initialized) class represented by {@code className} using the current thread's context class loader. * * <p/> * * returns {@code null} if the class is not found */ public static Class<?> tryForName(String className) { try { return forName(getClassLoader(),className,true); } catch (NestedClassNotFoundException e) { return null; } }
private Member resolveMember() { ClassLoader loader = clazz.getClassLoader(); Class<?>[] classes = new Class<?>[args.length]; // resolve args for (int i = 0; i < args.length; i++) { classes[i] = Classes.forName(loader, args[i].getClassName()); } try { if (CONSTRUCTOR.equals(name)) { return clazz.getDeclaredConstructor(classes); } return clazz.getDeclaredMethod(name, classes); } catch (NoSuchMethodException ex) { throw new IllegalStateException("Method [" + name + "] was discovered in the .class file but cannot be resolved in the class object", ex); } }
public static Map<String,Object> getAnnotationValues(AnnotationNode a) { Map<String,Object> map = new LinkedHashMap<>(); if(null != a.values) { for(int i=0;i<a.values.size();i++) { String name = (String)a.values.get(i); Object value = a.values.get(i+1); if(value instanceof String[]) { //enum value String[] array = (String[])value; Class<? extends Enum> enumType = (Class<? extends Enum>)Classes.forName(Type.getType(array[0]).getClassName()); map.put(name, Enums.nameOf(enumType, array[1])); }else{ map.put(name, value); } i+=1; } } return map; }
return forName(classLoader, className.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR_CHAR + className.substring(lastDotIndex + 1), initialize); } catch (NestedClassNotFoundException ex2) { // NOPMD
@Override public void init(ServletConfig config) throws ServletException { String servletClassName = config.getInitParameter(INIT_PARAM_SERVLET_CLASS); if(Strings.isEmpty(servletClassName)) { throw new ServletException("The init param '" + INIT_PARAM_SERVLET_CLASS + "' must be configured"); } Class<? extends Servlet> servletClass = (Class<? extends Servlet>)Classes.forName(servletClassName); AppContext context = AppContext.get(config.getServletContext()); if(null == context) { throw new ServletException("AppContext must be initialized!"); } this.config = config; servlet = context.getBeanFactory().getOrCreateBean(servletClass); servlet.init(config); }
private void init(Map<String, BeanInfo> beans, String type, String types) { for(Resource resource : Resources.scan("classpath*:META-INF/jmms." + types)) { String url = resource.getURLString(); Map<String, String> nameAndValues = Props.load(resource).toMap(); nameAndValues.forEach((beanName, className) -> { BeanInfo exists = beans.get(beanName); if(null != exists) { throw new IllegalStateException("Found duplicated " + type + " '" + beanName + "' at [ " + exists.url + " , " + url + " ]"); } if(Strings.isEmpty(className)) { throw new IllegalStateException("The class of '" + beanName + "' must not be empty, " + url); } try { Class<?> cls = Classes.forName(className); BeanInfo info = new BeanInfo(); info.cls = cls; info.url = url; beans.put(beanName, info); }catch (Exception e) { throw new IllegalStateException("Invalid class '" + className + "' , " + e.getMessage() + ", " + url); } }); } }
protected Class<?> tryGetDriverClass(DataSourceProps conf) throws NestedClassNotFoundException { if(!Strings.isEmpty(conf.getDriverClassName())){ return Classes.forName(conf.getDriverClassName()); } return null; }
static CompositeData convertToCompositeData(Object bean, CompositeType ct) throws OpenDataException{ BeanType bt = BeanType.of(bean.getClass()); Map<String,Object> map = new LinkedHashMap<>(); for(String name : ct.keySet()) { OpenType type = ct.getType(name); Object value = bt.getProperty(name).getValue(bean); Object converted = convert(value, type); if(type instanceof ArrayType) { List list = (List)converted; Class<?> elementType = Classes.forName(((ArrayType) type).getElementOpenType().getClassName()); converted = list.toArray((Object[])Array.newInstance(elementType, list.size())); } map.put(name, converted); } return new CompositeDataSupport(ct, map); }
public static Class<?> getClassType(Type type) { switch (type.getSort()) { case Type.BOOLEAN: return Boolean.TYPE; case Type.CHAR: return Character.TYPE; case Type.BYTE: return Byte.TYPE; case Type.SHORT: return Short.TYPE; case Type.INT: return Integer.TYPE; case Type.FLOAT: return Float.TYPE; case Type.LONG: return Long.TYPE; case Type.DOUBLE: return Double.TYPE; case Type.VOID: return Void.TYPE; } String cn = type.getInternalName(); cn = cn != null ? cn.replace('/', '.') : type.getClassName(); return Classes.forName(cn); }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected DataSource createDataSourceByClass(PoolProperties props) { String className = props.getDataSourceClassName(); DataSource ds = (DataSource)Reflection.newInstance(Classes.forName(className)); Properties dataSourceProperties = props.getDataSourceProperties(); if(null != dataSourceProperties && !dataSourceProperties.isEmpty()) { Beans.setPropertiesNestable(BeanType.of(ds.getClass()), ds, (Map)Props.toMap(dataSourceProperties)); } return ds; }
protected Class<?> javaTypeAttribute(XmlReader reader, String name) { String className = reader.getAttribute(name); if (Strings.isEmpty(className)) { return null; } try { return Classes.forName(className); } catch (ObjectNotFoundException e) { throw new BeanDefinitionException("invalid java type '" + className + "', must be a fully qualified class name, source : " + reader.getSource()); } }
@Override public Object newInstance(ConvertContext context, Class<?> type, Type genericType, Map<String, Object> map) { JsonType jsonType = type.getAnnotation(JsonType.class); if(null == jsonType) { return null; } String propertyName = Strings.firstNotEmpty(jsonType.property(), jsonType.meta().getDefaultPropertyName()); Object propertyValue = map.get(propertyName); if(null == propertyValue) { return null; } String name = (String)propertyValue; if(jsonType.meta() == JsonType.MetaType.CLASS_NAME) { return Reflection.newInstance(Classes.forName(name)); }else { for(JsonType.SubType subType : jsonType.types()) { if(subType.name().equals(name)) { return Reflection.newInstance(subType.type()); } } } return null; }
protected void createModels(ApiMetadataContext context, ApiMetadataBuilder m) { ApiConfig config = context.getConfig(); config.getResourceTypes().values().forEach((t) -> { if(null == m.tryGetModel(t)) { //create model for resource type. context.getMTypeContainer().getMType(t); } }); config.getModelConfigs().forEach((c)-> { if(!Strings.isEmpty(c.getClassName()) && null == m.tryGetModelByClassName(c.getClassName())) { context.getMTypeContainer().getMType(Classes.forName(c.getClassName())); } }); config.getModels().forEach(model -> { m.addModel(model); }); config.getComplexTypes().forEach(ct -> { tryAddModel(context, m, ct); }); context.getMTypeContainer().getComplexTypes().forEach((type, ct) -> { tryAddModel(context, m, ct); }); }