/** * Factory method for this class * * @return Never <code>null</code>. */ @Nonnull public static <DATATYPE> IdentityEncoder <DATATYPE> create () { return GenericReflection.<IdentityEncoder <Object>, IdentityEncoder <DATATYPE>> uncheckedCast (s_aInstance); } }
@Nullable public static <RETURNTYPE> RETURNTYPE invokeStaticMethod (@Nonnull final Class <?> aClass, @Nonnull final String sMethodName, @Nullable final Object... aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { return GenericReflection.<RETURNTYPE> invokeStaticMethod (aClass, sMethodName, getClassArray (aArgs), aArgs); }
@Nullable public IAggregator <SRCTYPE, DSTTYPE> create () { // Can never return null (hopefully) return GenericReflection.uncheckedCast (GenericReflection.newInstance (m_aClass)); }
@Nullable public static <RETURNTYPE> RETURNTYPE invokeStaticMethod (@Nonnull final String sClassName, @Nonnull final String sMethodName, @Nullable final Class <?> [] aArgClasses, @Nullable final Object [] aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { return GenericReflection.<RETURNTYPE> invokeStaticMethod (getClassFromName (sClassName), sMethodName, aArgClasses, aArgs); }
@Nullable public static <RETURNTYPE> RETURNTYPE invokeMethod (@Nonnull final Object aSrcObj, @Nonnull final String sMethodName, @Nullable final Class <?> [] aArgClasses, @Nullable final Object [] aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { final Method aMethod = aSrcObj.getClass ().getDeclaredMethod (sMethodName, aArgClasses); final Object aReturn = aMethod.invoke (aSrcObj, aArgs); return GenericReflection.<Object, RETURNTYPE> uncheckedCast (aReturn); }
return GenericReflection.<DATATYPE, ICloneable <DATATYPE>> uncheckedCast (aObject).getClone (); return GenericReflection.<DATATYPE> invokeMethod (aObject, "clone"); final Constructor <DATATYPE> aCtor = GenericReflection.findConstructor (aObject, aObject.getClass ()); if (aCtor != null) return aCtor.newInstance (aObject);
/** * Get the class of the given name * * @param <DATATYPE> * The return type * @param sName * The name to be resolved. * @return <code>null</code> if the class could not be resolved */ @Nullable public static <DATATYPE> Class <DATATYPE> getClassFromNameSafe (@Nonnull final String sName) { try { return getClassFromName (sName); } catch (final ClassNotFoundException e) { return null; } }
@Nullable public DATATYPE create () { return GenericReflection.newInstance (m_aClass); }
private EXMLParserProperty (@Nonnull final EXMLParserPropertyType ePropertyType, @Nonnull @Nonempty final String sName, @Nonnull @Nonempty final String sValueClassName) { m_ePropertyType = ePropertyType; m_sName = sName; // May be null m_aValueClass = GenericReflection.getClassFromNameSafe (sValueClassName); m_sValueClassName = sValueClassName; }
/** * Create a new instance of the class identified by the passed object. The * default constructor will be invoked. * * @param <DATATYPE> * The type of object to be created. * @param aObj * The object from which the class should be used. * @return A new instance of the object or an exception is thrown. * @throws IllegalAccessException * Reflection exception * @throws NoSuchMethodException * Reflection exception * @throws InvocationTargetException * Reflection exception * @throws InstantiationException * Reflection exception */ @Nonnull public static <DATATYPE> DATATYPE newInstance (@Nonnull final DATATYPE aObj) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException { return findConstructor (aObj).newInstance (); }
@Nullable public static <DATATYPE> DATATYPE newInstance (@Nullable final String sClassName, @Nullable final Class <DATATYPE> aDesiredType) { if (sClassName != null && aDesiredType != null) try { return aDesiredType.cast (getClassFromName (sClassName).newInstance ()); } catch (final Throwable t) { /* * Catch all exceptions because any exception thrown from the * constructor (indirectly invoked by newInstance) may also end up in * this catch block */ s_aLogger.error ("Failed to instantiate '" + sClassName + "'", t); } return null; }
s_aModifiers.put (sClassName, GenericReflection.newInstance (aModifierClass));
@Override @Nullable @IsLocked (ELockType.WRITE) public JAXBContext getValueToCache (@Nullable final Package aPackage) { if (aPackage == null) return null; if (GlobalDebug.isDebugMode ()) s_aLogger.info ("Creating JAXB context for package " + aPackage.getName ()); try { // When using "-npa" on JAXB no package-info class is created! if (aPackage.getAnnotation (XmlSchema.class) == null && GenericReflection.getClassFromNameSafe (aPackage.getName () + ".ObjectFactory") == null) s_aLogger.warn ("The package " + aPackage.getName () + " does not seem to be JAXB generated!"); return JAXBContext.newInstance (aPackage.getName ()); } catch (final JAXBException ex) { final String sMsg = "Failed to create JAXB context for package " + aPackage.getName (); s_aLogger.error (sMsg); throw new IllegalArgumentException (sMsg, ex); } }
@Nonnull protected final IMPLTYPE thisAsT () { // Avoid the unchecked cast warning in all places return GenericReflection.<AbstractTabBox <IMPLTYPE>, IMPLTYPE> uncheckedCast (this); }
public Enum <?> convert (@Nonnull final Object aSource) { // Split class name and enum value name final List <String> aParts = StringHelper.getExploded (':', (String) aSource, 2); try { // Resolve any enum class // Note: The explicit EChange is just here, because an explicit enum // type is needed. It must of course not only be EChange :) final Class <EChange> aClass = GenericReflection.getClassFromName (aParts.get (0)); // And look up the element by name return Enum.valueOf (aClass, aParts.get (1)); } catch (final ClassNotFoundException ex) { return null; } } });
@Nonnull protected final THISTYPE thisAsT () { // Avoid the unchecked cast warning in all places return GenericReflection.<AbstractHCHasChildrenMutable <THISTYPE, CHILDTYPE>, THISTYPE> uncheckedCast (this); }
if (StringHelper.hasNoTextAfterTrim (sClass)) throw new IllegalStateException ("Persistence file " + aURL + ": class name is missing!"); GenericReflection.getClassFromName (sClass.trim ());
@Nonnull protected final THISTYPE thisAsT () { // Avoid the unchecked cast warning in all places return GenericReflection.<AbstractHCElement <THISTYPE>, THISTYPE> uncheckedCast (this); }
@Nonnull public static <ELEMENTTYPE> IIterableIterator <ELEMENTTYPE> createEmpty () { return GenericReflection.<IterableIterator <Object>, IterableIterator <ELEMENTTYPE>> uncheckedCast (s_aEmpty); }
@Nonnull public static <ELEMENTTYPE> SortedSet <ELEMENTTYPE> getInstance () { return GenericReflection.<EmptySortedSet, SortedSet <ELEMENTTYPE>> uncheckedCast (INSTANCE); } }