/** * Factory method that performs validation. * * @param classToInstantiate the class to instantiate, not null * @param paramTypes the constructor parameter types * @param args the constructor arguments * @return a new instantiate factory */ public static Factory getInstance(Class classToInstantiate, Class[] paramTypes, Object[] args) { if (classToInstantiate == null) { throw new IllegalArgumentException("Class to instantiate must not be null"); } if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) { throw new IllegalArgumentException("Parameter types must match the arguments"); } if (paramTypes == null || paramTypes.length == 0) { return new InstantiateFactory(classToInstantiate); } else { paramTypes = (Class[]) paramTypes.clone(); args = (Object[]) args.clone(); return new InstantiateFactory(classToInstantiate, paramTypes, args); } }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate */ public InstantiateFactory(Class classToInstantiate) { super(); iClassToInstantiate = classToInstantiate; iParamTypes = null; iArgs = null; findConstructor(); }
/** * Creates a Factory that can create objects of a specific type using * a no-args constructor. * * @see org.apache.commons.collections.functors.InstantiateFactory * * @param classToInstantiate the Class to instantiate each time in the factory * @return the <code>reflection</code> factory * @throws IllegalArgumentException if the classToInstantiate is null */ public static Factory instantiateFactory(Class classToInstantiate) { return InstantiateFactory.getInstance(classToInstantiate, null, null); }
/** * Factory method that performs validation. * * @param classToInstantiate the class to instantiate, not null * @param paramTypes the constructor parameter types * @param args the constructor arguments * @return a new instantiate factory */ public static Factory getInstance(Class classToInstantiate, Class[] paramTypes, Object[] args) { if (classToInstantiate == null) { throw new IllegalArgumentException("Class to instantiate must not be null"); } if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) { throw new IllegalArgumentException("Parameter types must match the arguments"); } if (paramTypes == null || paramTypes.length == 0) { return new InstantiateFactory(classToInstantiate); } else { paramTypes = (Class[]) paramTypes.clone(); args = (Object[]) args.clone(); return new InstantiateFactory(classToInstantiate, paramTypes, args); } }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate * @param paramTypes the constructor parameter types, not cloned * @param args the constructor arguments, not cloned */ public InstantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { super(); iClassToInstantiate = classToInstantiate; iParamTypes = paramTypes; iArgs = args; findConstructor(); }
/** * Creates a Factory that can create objects of a specific type using * the arguments specified to this method. * * @see org.apache.commons.collections.functors.InstantiateFactory * * @param classToInstantiate the Class to instantiate each time in the factory * @param paramTypes parameter types for the constructor, can be null * @param args the arguments to pass to the constructor, can be null * @return the <code>reflection</code> factory * @throws IllegalArgumentException if the classToInstantiate is null * @throws IllegalArgumentException if the paramTypes and args don't match * @throws IllegalArgumentException if the constructor doesn't exist */ public static Factory instantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { return InstantiateFactory.getInstance(classToInstantiate, paramTypes, args); }
public Object makeObject() { return new InstantiateFactory(String.class); }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate */ public InstantiateFactory(Class classToInstantiate) { super(); iClassToInstantiate = classToInstantiate; iParamTypes = null; iArgs = null; findConstructor(); }
/** * Creates a Factory that can create objects of a specific type using * a no-args constructor. * * @see org.apache.commons.collections.functors.InstantiateFactory * * @param classToInstantiate the Class to instantiate each time in the factory * @return the <code>reflection</code> factory * @throws IllegalArgumentException if the classToInstantiate is null */ public static Factory instantiateFactory(Class classToInstantiate) { return InstantiateFactory.getInstance(classToInstantiate, null, null); }
try { prototype.getClass().getConstructor(new Class[] { prototype.getClass()}); return new InstantiateFactory( prototype.getClass(), new Class[] { prototype.getClass()},
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate * @param paramTypes the constructor parameter types, not cloned * @param args the constructor arguments, not cloned */ public InstantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { super(); iClassToInstantiate = classToInstantiate; iParamTypes = paramTypes; iArgs = args; findConstructor(); }
/** * Creates a Factory that can create objects of a specific type using * the arguments specified to this method. * * @see org.apache.commons.collections.functors.InstantiateFactory * * @param classToInstantiate the Class to instantiate each time in the factory * @param paramTypes parameter types for the constructor, can be null * @param args the arguments to pass to the constructor, can be null * @return the <code>reflection</code> factory * @throws IllegalArgumentException if the classToInstantiate is null * @throws IllegalArgumentException if the paramTypes and args don't match * @throws IllegalArgumentException if the constructor doesn't exist */ public static Factory instantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { return InstantiateFactory.getInstance(classToInstantiate, paramTypes, args); }
try { prototype.getClass().getConstructor(new Class[] { prototype.getClass()}); return new InstantiateFactory( prototype.getClass(), new Class[] { prototype.getClass()},
/** * Creates an object using the stored constructor. * * @return the new object */ public Object create() { // needed for post-serialization if (iConstructor == null) { findConstructor(); } try { return iConstructor.newInstance(iArgs); } catch (InstantiationException ex) { throw new FunctorException("InstantiateFactory: InstantiationException", ex); } catch (IllegalAccessException ex) { throw new FunctorException("InstantiateFactory: Constructor must be public", ex); } catch (InvocationTargetException ex) { throw new FunctorException("InstantiateFactory: Constructor threw an exception", ex); } }
/** * Creates a Factory that can create objects of a specific type using * a no-args constructor. * * @see org.apache.commons.collections.functors.InstantiateFactory * * @param classToInstantiate the Class to instantiate each time in the factory * @return the <code>reflection</code> factory * @throws IllegalArgumentException if the classToInstantiate is null */ public static Factory instantiateFactory(Class classToInstantiate) { return InstantiateFactory.getInstance(classToInstantiate, null, null); }
Map<Integer, Map<String, String>> arr = org.apache.commons.collections.map.LazyMap.decorate( new HashMap(), new InstantiateFactory(HashMap.class)); //$arr[0]['name'] = 'demo'; arr.get(0).put("name", "demo"); System.out.println(arr.get(0).get("name")); System.out.println(arr.get(1).get("name")); //yields null
/** * Creates an object using the stored constructor. * * @return the new object */ public Object create() { // needed for post-serialization if (iConstructor == null) { findConstructor(); } try { return iConstructor.newInstance(iArgs); } catch (InstantiationException ex) { throw new FunctorException("InstantiateFactory: InstantiationException", ex); } catch (IllegalAccessException ex) { throw new FunctorException("InstantiateFactory: Constructor must be public", ex); } catch (InvocationTargetException ex) { throw new FunctorException("InstantiateFactory: Constructor threw an exception", ex); } }
/** * Creates a Factory that can create objects of a specific type using * a no-args constructor. * * @see org.apache.commons.collections.functors.InstantiateFactory * * @param classToInstantiate the Class to instantiate each time in the factory * @return the <code>reflection</code> factory * @throws IllegalArgumentException if the classToInstantiate is null */ public static Factory instantiateFactory(Class classToInstantiate) { return InstantiateFactory.getInstance(classToInstantiate, null, null); }
/** * Factory method that performs validation. * * @param classToInstantiate the class to instantiate, not null * @param paramTypes the constructor parameter types * @param args the constructor arguments * @return a new instantiate factory */ public static Factory getInstance(Class classToInstantiate, Class[] paramTypes, Object[] args) { if (classToInstantiate == null) { throw new IllegalArgumentException("Class to instantiate must not be null"); } if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) { throw new IllegalArgumentException("Parameter types must match the arguments"); } if (paramTypes == null || paramTypes.length == 0) { return new InstantiateFactory(classToInstantiate); } else { paramTypes = (Class[]) paramTypes.clone(); args = (Object[]) args.clone(); return new InstantiateFactory(classToInstantiate, paramTypes, args); } }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate */ public InstantiateFactory(Class classToInstantiate) { super(); iClassToInstantiate = classToInstantiate; iParamTypes = null; iArgs = null; findConstructor(); }