/** * Return the class for the given string, correctly handling * primitive types. If the given class loader is null, the context * loader of the current thread will be used. * * @throws RuntimeException on load error * @author Abe White, taken from the Serp project */ public static Class toClass(String str, ClassLoader loader) { return toClass(str, false, loader); }
/** * Return the class for the given string, correctly handling * primitive types. If the given class loader is null, the context * loader of the current thread will be used. * * @throws RuntimeException on load error * @author Abe White, taken from the Serp project */ public static Class toClass(String str, ClassLoader loader) { return toClass(str, false, loader); }
/** * Return the {@link Class} representation of the class(es) named in the * given metadatas. */ public Class<?>[] parseTypes(MetaDataIterator itr) { String[] names = parseTypeNames(itr); Class<?>[] objs = new Class[names.length]; for (int i = 0; i < names.length; i++) objs[i] = ClassUtil.toClass(names[i], _loader); return objs; }
/** * Return the {@link Class} representation of the class(es) named in the * given metadatas. */ public Class<?>[] parseTypes(MetaDataIterator itr) { String[] names = parseTypeNames(itr); Class<?>[] objs = new Class[names.length]; for (int i = 0; i < names.length; i++) objs[i] = ClassUtil.toClass(names[i], _loader); return objs; }
/** * Return the {@link Class} representation of the class(es) named in the * given arg. * * @param arg a class name, .java file, .class file, or metadata * file naming the type(s) to act on */ public Class<?>[] parseTypes(String arg) { String[] names = parseTypeNames(arg); Class<?>[] objs = new Class[names.length]; for (int i = 0; i < names.length; i++) objs[i] = ClassUtil.toClass(names[i], _loader); return objs; }
/** * Return the {@link Class} representation of the class(es) named in the * given arg. * * @param arg a class name, .java file, .class file, or metadata * file naming the type(s) to act on */ public Class<?>[] parseTypes(String arg) { String[] names = parseTypeNames(arg); Class<?>[] objs = new Class[names.length]; for (int i = 0; i < names.length; i++) objs[i] = ClassUtil.toClass(names[i], _loader); return objs; }
/** * Return a mapping of each metadata resource to an array of its * contained classes. */ public Map<Object, Class<?>[]> mapTypes(MetaDataIterator itr) { Map<Object, String[]> map = mapTypeNames(itr); Map<Object, Class<?>[]> rval = new HashMap<Object, Class<?>[]>(); Map.Entry<Object, String[]> entry; String[] names; Class<?>[] objs; for (Iterator<Map.Entry<Object, String[]>> i = map.entrySet().iterator(); i.hasNext();) { entry = i.next(); names = entry.getValue(); objs = new Class[names.length]; for (int j = 0; j < names.length; j++) { objs[j] = ClassUtil.toClass(names[j], _loader); } rval.put(entry.getKey(), objs); } return rval; }
/** * Return a mapping of each metadata resource to an array of its * contained classes. */ public Map<Object, Class<?>[]> mapTypes(MetaDataIterator itr) { Map<Object, String[]> map = mapTypeNames(itr); Map<Object, Class<?>[]> rval = new HashMap<Object, Class<?>[]>(); Map.Entry<Object, String[]> entry; String[] names; Class<?>[] objs; for (Iterator<Map.Entry<Object, String[]>> i = map.entrySet().iterator(); i.hasNext();) { entry = i.next(); names = entry.getValue(); objs = new Class[names.length]; for (int j = 0; j < names.length; j++) { objs[j] = ClassUtil.toClass(names[j], _loader); } rval.put(entry.getKey(), objs); } return rval; }
try { if (fullName || noPackage) return ClassUtil.toClass(name, resolve, loader); return ClassUtil.toClass(pkg + "." + name, resolve, loader); } catch (RuntimeException re) { return ClassUtil.toClass(name, resolve, loader); } catch (RuntimeException re) { for (int i = 0; i < PACKAGES.length; i++) { try { return ClassUtil.toClass(PACKAGES[i] + name, resolve, loader); } catch (RuntimeException re) {
try { if (fullName || noPackage) return ClassUtil.toClass(name, resolve, loader); return ClassUtil.toClass(pkg + "." + name, resolve, loader); } catch (RuntimeException re) { return ClassUtil.toClass(name, resolve, loader); } catch (RuntimeException re) { for (int i = 0; i < PACKAGES.length; i++) { try { return ClassUtil.toClass(PACKAGES[i] + name, resolve, loader); } catch (RuntimeException re) {
public Object newInstance(String clsName, Class type, Configuration conf, boolean fatal) { // since the MappingRepository takes a JDBConfiguration constructor, // we need to manually perform the instantiation try { Class cls = ClassUtil.toClass(clsName, AccessController.doPrivileged( J2DoPrivHelper.getClassLoaderAction(type))); return cls.getConstructor(new Class[]{ JDBCConfiguration.class }). newInstance(new Object[]{ conf }); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof RuntimeException) throw(RuntimeException) e.getTargetException(); // fall back to default behavior for better error reporting return super.newInstance(clsName, type, conf, fatal); } catch (Exception e) { // fall back to default behavior for better error reporting return super.newInstance(clsName, type, conf, fatal); } } }
public Object newInstance(String clsName, Class type, Configuration conf, boolean fatal) { // since the MappingRepository takes a JDBConfiguration constructor, // we need to manually perform the instantiation try { Class cls = ClassUtil.toClass(clsName, AccessController.doPrivileged( J2DoPrivHelper.getClassLoaderAction(type))); return cls.getConstructor(new Class[]{ JDBCConfiguration.class }). newInstance(new Object[]{ conf }); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof RuntimeException) throw(RuntimeException) e.getTargetException(); // fall back to default behavior for better error reporting return super.newInstance(clsName, type, conf, fatal); } catch (Exception e) { // fall back to default behavior for better error reporting return super.newInstance(clsName, type, conf, fatal); } } }
public void customize(FieldMapping field) { String type = getProperty(field.getFullName(false) + ".type"); if (type != null) field.setDeclaredType(ClassUtil.toClass(type, null)); }
public void customize(FieldMapping field) { String type = getProperty(field.getFullName(false) + ".type"); if (type != null) field.setDeclaredType(ClassUtil.toClass(type, null)); }
/** * Loads the given class name by the given loader. * For efficiency, a cache per class loader is maintained of classes already loader. * @param clsName * @param loader */ static Class<?> loadClass(String clsName, ClassLoader loader) { Class<?> cls = null; Object key = loader == null ? NULL_LOADER : loader; Map<String,Class<?>> loaderCache = (Map<String,Class<?>>) _loaders.get(key); if (loaderCache == null) { // We don't have a cache for this loader. //OPENJPA-2636: Changed to HARD/WEAK to avoid Classloader leak: loaderCache = new ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.HARD, ConcurrentReferenceHashMap.WEAK); _loaders.put(key, loaderCache); } else { // We have a cache for this loader. cls = (Class<?>) loaderCache.get(clsName); } if (cls == null) { try { cls = ClassUtil.toClass(clsName, loader); loaderCache.put(clsName, cls); } catch (RuntimeException re) { // TODO, empty block is never good } } return cls; }
/** * Loads the given class name by the given loader. * For efficiency, a cache per class loader is maintained of classes already loader. * @param clsName * @param loader */ static Class<?> loadClass(String clsName, ClassLoader loader) { Class<?> cls = null; Object key = loader == null ? NULL_LOADER : loader; Map<String,Class<?>> loaderCache = (Map<String,Class<?>>) _loaders.get(key); if (loaderCache == null) { // We don't have a cache for this loader. //OPENJPA-2636: Changed to HARD/WEAK to avoid Classloader leak: loaderCache = new ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.HARD, ConcurrentReferenceHashMap.WEAK); _loaders.put(key, loaderCache); } else { // We have a cache for this loader. cls = (Class<?>) loaderCache.get(clsName); } if (cls == null) { try { cls = ClassUtil.toClass(clsName, loader); loaderCache.put(clsName, cls); } catch (RuntimeException re) { // TODO, empty block is never good } } return cls; }
/** * Return the {@link Class} for the given name, or null if name not valid. */ private Class toClass(String name) { if (_loader == null) _loader = _broker.getConfiguration().getClassResolverInstance(). getClassLoader(_class, _broker.getClassLoader()); try { return ClassUtil.toClass(name, _loader); } catch (RuntimeException re) { } catch (NoClassDefFoundError ncdfe) { } return null; }
/** * Return the {@link Class} for the given name, or null if name not valid. */ private Class toClass(String name) { if (_loader == null) _loader = _broker.getConfiguration().getClassResolverInstance(). getClassLoader(_class, _broker.getClassLoader()); try { return ClassUtil.toClass(name, _loader); } catch (RuntimeException re) { } catch (NoClassDefFoundError ncdfe) { } return null; }
type = ClassUtil.toClass(typeSpec, _conf. getClassResolverInstance().getClassLoader (ReverseMappingTool.class, null));
type = ClassUtil.toClass(typeSpec, _conf. getClassResolverInstance().getClassLoader (ReverseMappingTool.class, null));