/** * Loads a class using the class loader. * 1. The class loader of the current class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param className The name of the class to load. * @return The class or null if no class loader could load the class. */ public static Class<?> forName(String className) throws ClassNotFoundException { return ClassUtils.forName(ClassUtils.class, className); }
/** * Loads a class using the class loader. * 1. The class loader of the current class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param className The name of the class to load. * @return The class or null if no class loader could load the class. */ public static Class<?> forName(String className) throws ClassNotFoundException { return ClassUtils.forName(ClassUtils.class, className); }
/** * Loads a class using the class loader. * 1. The class loader of the context class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param classLoader The classloader to use. * @param className The name of the class to load * @return The class or null if no class loader could load the class. */ public static Class<?> forName(ClassLoader classLoader, String className) throws ClassNotFoundException { Class<?> c = null; if (classLoader != null) { c = forName(className, classLoader); } if (c == null && Thread.currentThread().getContextClassLoader() != null) { c = forName(className, Thread.currentThread().getContextClassLoader()); } if (c == null) { throw new ClassNotFoundException("Failed to load class" + className); } return c; }
/** * Loads a class using the class loader. * 1. The class loader of the context class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param classLoader The classloader to use. * @param className The name of the class to load * @return The class or null if no class loader could load the class. */ public static Class<?> forName(ClassLoader classLoader, String className) throws ClassNotFoundException { Class<?> c = null; if (classLoader != null) { c = forName(className, classLoader); } if (c == null && Thread.currentThread().getContextClassLoader() != null) { c = forName(className, Thread.currentThread().getContextClassLoader()); } if (c == null) { throw new ClassNotFoundException("Failed to load class" + className); } return c; }
static Class getClassProp(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; Class c = CLASS_CACHE.get(name); if (c != null) return c; try { c = ClassUtils.forName(name); CLASS_CACHE.put(name, c); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } return c; }
/** * Loads a class using the class loader. * 1. The class loader of the context class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param contextClass The name of a context class to use. * @param className The name of the class to load * @return The class or null if no class loader could load the class. */ public static Class<?> forName(Class<?> contextClass, String className) throws ClassNotFoundException { Class<?> c = null; if (contextClass.getClassLoader() != null) { c = forName(className, contextClass.getClassLoader()); } if (c == null && Thread.currentThread().getContextClassLoader() != null) { c = forName(className, Thread.currentThread().getContextClassLoader()); } if (c == null) { throw new ClassNotFoundException("Failed to load class" + className); } return c; }
/** * Loads a class using the class loader. * 1. The class loader of the context class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param contextClass The name of a context class to use. * @param className The name of the class to load * @return The class or null if no class loader could load the class. */ public static Class<?> forName(Class<?> contextClass, String className) throws ClassNotFoundException { Class<?> c = null; if (contextClass.getClassLoader() != null) { c = forName(className, contextClass.getClassLoader()); } if (c == null && Thread.currentThread().getContextClassLoader() != null) { c = forName(className, Thread.currentThread().getContextClassLoader()); } if (c == null) { throw new ClassNotFoundException("Failed to load class" + className); } return c; }
static Class getClassProp(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; Class c = CLASS_CACHE.get(name); if (c != null) return c; try { c = ClassUtils.forName(name); CLASS_CACHE.put(name, c); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } return c; }
@Override public Object newRecord(Object old, Schema schema) { try { Class c = ClassUtils.forName(SpecificData.getClassName(schema)); if (c == null) return newRecord(old, schema); // punt to generic if (c.isInstance(old)) return old; // reuse instance return c.getMethod("newBuilder").invoke(null); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public Object newRecord(Object old, Schema schema) { try { Class c = ClassUtils.forName(SpecificData.getClassName(schema)); if (c == null) return newRecord(old, schema); // punt to generic if (c.isInstance(old)) return old; // reuse instance return c.newInstance(); // create new instance } catch (Exception e) { throw new RuntimeException(e); } }
@Override protected Object createEnum(String symbol, Schema schema) { try { Class c = ClassUtils.forName(SpecificData.getClassName(schema)); if (c == null) return super.createEnum(symbol, schema); // punt to generic return Enum.valueOf(c, symbol); } catch (Exception e) { throw new AvroRuntimeException(e); } }
@Override protected Object createEnum(String symbol, Schema schema) { try { Class c = ClassUtils.forName(SpecificData.getClassName(schema)); if (c == null) return super.createEnum(symbol, schema); // punt to generic return ((ProtocolMessageEnum)Enum.valueOf(c, symbol)).getValueDescriptor(); } catch (Exception e) { throw new RuntimeException(e); } }
private Class getPropAsClass(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; try { return ClassUtils.forName(getData().getClassLoader(), name); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } }
private Class getPropAsClass(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; try { return ClassUtils.forName(getData().getClassLoader(), name); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } }
if (c == null) { try { c = ClassUtils.forName(getClassLoader(), getClassName(schema)); } catch (ClassNotFoundException e) { c = NO_CLASS;
/** * Loads a class using the class loader. * 1. The class loader of the current class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param className The name of the class to load. * @return The class or null if no class loader could load the class. */ public static Class<?> forName(String className) throws ClassNotFoundException { return ClassUtils.forName(ClassUtils.class, className); }
static Class getClassProp(Schema schema, String prop) { String name = schema.getProp(prop); if (name == null) return null; Class c = CLASS_CACHE.get(name); if (c != null) return c; try { c = ClassUtils.forName(name); CLASS_CACHE.put(name, c); } catch (ClassNotFoundException e) { throw new AvroRuntimeException(e); } return c; }
/** * Loads a class using the class loader. * 1. The class loader of the context class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param classLoader The classloader to use. * @param className The name of the class to load * @return The class or null if no class loader could load the class. */ public static Class<?> forName(ClassLoader classLoader, String className) throws ClassNotFoundException { Class<?> c = null; if (classLoader != null) { c = forName(className, classLoader); } if (c == null && Thread.currentThread().getContextClassLoader() != null) { c = forName(className, Thread.currentThread().getContextClassLoader()); } if (c == null) { throw new ClassNotFoundException("Failed to load class" + className); } return c; }
/** * Loads a class using the class loader. * 1. The class loader of the context class is being used. * 2. The thread context class loader is being used. * If both approaches fail, returns null. * * @param contextClass The name of a context class to use. * @param className The name of the class to load * @return The class or null if no class loader could load the class. */ public static Class<?> forName(Class<?> contextClass, String className) throws ClassNotFoundException { Class<?> c = null; if (contextClass.getClassLoader() != null) { c = forName(className, contextClass.getClassLoader()); } if (c == null && Thread.currentThread().getContextClassLoader() != null) { c = forName(className, Thread.currentThread().getContextClassLoader()); } if (c == null) { throw new ClassNotFoundException("Failed to load class" + className); } return c; }