You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/09/09 06:12:11 UTC

cvs commit: jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/util ObjectFactory.java

dgraham     2003/09/08 21:12:11

  Modified:    mapper/src/share/org/apache/commons/mapper/util
                        ObjectFactory.java
  Log:
  javadoc and formatting changes only.
  
  Revision  Changes    Path
  1.3       +44 -31    jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/util/ObjectFactory.java
  
  Index: ObjectFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/util/ObjectFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectFactory.java	10 Jun 2003 02:39:35 -0000	1.2
  +++ ObjectFactory.java	9 Sep 2003 04:12:11 -0000	1.3
  @@ -67,21 +67,27 @@
   
   /**
    * <p>
  - * ObjectFactory maps string names to classes to be instantiated.  Given a name it 
  - * will construct a new object of the mapped type using reflection.  Pass in a map 
  - * with entries in the form "logical name"="fully qualified class name".  Both key and 
  - * value must be Strings.
  + * ObjectFactory maps string names to classes to be instantiated.  Given a 
  + * name it will construct a new object of the mapped type using reflection.  
  + * Pass in a <code>Map</code> with entries in the form 
  + * "logical name"="fully qualified class name".  Both key and value must be 
  + * Strings.
    * </p>
  + * 
    * <p>
  - * For quick instantiation from a String, use the class method construct(String).
  + * For quick instantiation from a String, use the class method 
  + * <code>ObjectFactory.construct(String)</code>.
    * </p>  
  + * 
    * <p>
    * The classes to be constructed must have a public no-arg constructor.  An 
    * Exception thrown during the loading of a Class or creation of an Object is 
  - * considered a programmer error and is converted to an IllegalArgumentException.  
  - * This greatly simplifies client code and indicates a misconfiguration of the Map 
  - * passed to this factory. This class is thread-safe.
  + * considered a programmer error and is converted to an 
  + * <code>IllegalArgumentException</code>.  
  + * This greatly simplifies client code and indicates a misconfiguration of the 
  + * <code>Map</code> passed to this factory. This class is thread-safe.
    * </p>
  + * 
    * <p>
    * Example:
    * <code>
  @@ -93,14 +99,16 @@
    * Set mySet = (Set) factory.construct("set");
    * </code>
    * </p>
  + * 
    * <p>
    * Using ObjectFactory without a map:
    * <code>Set mySet = (Set) ObjectFactory.construct("java.util.HashSet");</code>
    * </p>
  + * 
    * <p>
  - * This class is useful as a backing class for higher level factory classes.  The higher
  - * level class can use ObjectFactory to do the mapping and creation work while it 
  - * implements factory specific semantics and caching.
  + * This class is useful as a backing class for higher level factory classes.  
  + * The higher level class can use ObjectFactory to do the mapping and creation 
  + * work while it implements factory specific semantics and caching.
    * </p>
    * 
    * @author David Graham
  @@ -118,8 +126,8 @@
   	protected Map classMap = new HashMap();
   
   	/**
  -	 * Create an ObjectFactory with the given mapping of names to fully qualified 
  -	 * class names. 
  +	 * Create an ObjectFactory with the given mapping of names to fully 
  +	 * qualified class names. 
   	 * @param map A map of logical names to fully qualified class names.
   	 */
   	public ObjectFactory(Map map) {
  @@ -129,9 +137,10 @@
   
   	/**
   	 * Convenience method that creates an object of the class given as a string.  
  -	 * @param className The fully qualified class name of the object to be created.
  -	 * @throws IllegalArgumentException if the Class for the given name could not be
  -	 * found.
  +	 * @param className The fully qualified class name of the object to be 
  +	 * created.
  +	 * @throws IllegalArgumentException if the Class for the given name could 
  +	 * not be found.
   	 */
   	public static Object construct(String className) {
   		return newInstance(loadClass(className));
  @@ -140,8 +149,8 @@
   	/**
   	 * Returns an object of the class associated with the given command.
   	 * @throws IllegalArgumentException if given name was not found in the map, 
  -	 * the Class for the name could not be found, or the Class is missing a no-arg
  -	 * constructor.
  +	 * the Class for the name could not be found, or the Class is missing a 
  +	 * no-arg constructor.
   	 */
   	public Object create(String name) {
   		return newInstance(this.getNamedClass(name));
  @@ -149,9 +158,9 @@
   
   	/**
   	 * Calls c.newInstance() and converts exceptions.
  -	 * @throws IllegalArgumentException if there is an error instantiating an object 
  -     * of the class.  This usually indicates the class is missing a public no-arg 
  -     * constructor.
  +	 * @throws IllegalArgumentException if there is an error instantiating an 
  +	 * object of the class.  This usually indicates the class is missing a 
  +	 * public no-arg constructor.
   	 */
   	protected static Object newInstance(Class c) {
   		try {
  @@ -175,8 +184,8 @@
   	/**
   	 * Returns the Class object mapped to the given name.  If not found in the 
   	 * cache, the Class object is stored there for quick retrieval.
  -	 * @throws IllegalArgumentException if the given name is not mapped to a class
  -	 * name or the Class could not be found.
  +	 * @throws IllegalArgumentException if the given name is not mapped to a 
  +	 * class name or the Class could not be found.
   	 */
   	protected Class getNamedClass(String logicalName) {
   
  @@ -201,8 +210,8 @@
   	 * Attempts to load the Class object for the given class name.
   	 * @param className The fully qualified class name to load.
   	 * @return The Class object for the class name.
  -	 * @throws IllegalArgumentException if the Class is not found for the given 
  -	 * name.
  +	 * @throws IllegalArgumentException if the Class is not found for the 
  +     * given name.
   	 */
   	protected static Class loadClass(String className) {
   		try {
  @@ -210,12 +219,16 @@
   
   		} catch (ClassNotFoundException e) {
   			throw new IllegalArgumentException(
  -				"Class '" + className + "' could not be found: " + e.getMessage());
  +				"Class '"
  +					+ className
  +					+ "' could not be found: "
  +					+ e.getMessage());
   		}
   	}
   
   	/**
  -	 * Gets a copy of the map this factory is using to construct instances of classes.  
  +	 * Gets a copy of the map this factory is using to construct instances of 
  +	 * classes.  
   	 */
   	public Map getMap() {
   		return new HashMap(this.nameMap);
  @@ -258,7 +271,7 @@
   	 * ObjectFactory's hashcode is based on its underlying Map's hashcodes.
   	 */
   	public int hashCode() {
  -		return this.nameMap.hashCode() *176543;
  +		return this.nameMap.hashCode() * 176543;
   	}
   
   }