/** * Sets explicitely the factory to be used for the specified class * (see {@link #getInstance}). * * @param factory the factory to use. * @param forClass the associated class. * @see #getInstance(Class) */ public static <T> void setInstance(ObjectFactory <T> factory, Class <T> forClass) { Reflection.getInstance().setField(factory, forClass, ObjectFactory.class); }
/** * Defines the default XML format bound to the specified class. * If the specified class is <code>null</code> then the format is unbound * (unbound formats are used by custom {@link XMLBinding binding} instances). * The static binding is unique and can only be overriden by custom * {@link XMLBinding}. For example:[code] * // Overrides default binding for java.util.Collection. * class MyBinding extends XMLBinding { * XMLFormat<Collection> collectionXML = new XMLFormat<Collection>(null) { ... }; // Unbound. * public XMLFormat getFormat(Class cls) { * if (Collection.isAssignableFrom(cls)) { * return collectionXML; // Overrides default XML format. * } else { * return super.getFormat(cls); * } * } * }[/code] * * @param forClass the root class/interface to associate to this XML format * or <code>null</code> if this format is not bound. * @throws IllegalArgumentException if a XMLFormat is already bound to * the specified class. */ protected XMLFormat(Class <T> forClass) { _class = forClass; if (forClass == null) return; // Dynamic format. Reflection.getInstance().setField(this, forClass, XMLFormat.class); }
/** * Defines the static format bound to the specified class. * * @param forClass the class to which the format is bound or <code>null</code> * if the format is not bound to any class. * @throws IllegalArgumentException if the specified class is already * bound to another format. */ protected TextFormat(Class <T> forClass) { if (forClass == null) return; // Dynamic format. Reflection.getInstance().setField(new LocalReference(this), forClass, LocalReference.class); }