commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/util ObjectFactory.java
Date Sun, 21 Sep 2003 23:27:18 GMT
dgraham     2003/09/21 16:27:18

  Modified:    mapper/src/share/org/apache/commons/mapper/util
                        ObjectFactory.java
  Log:
  Made protected members private because they exposed too
  much implementation details to potential subclasses.
  
  Revision  Changes    Path
  1.4       +23 -21    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ObjectFactory.java	9 Sep 2003 04:12:11 -0000	1.3
  +++ ObjectFactory.java	21 Sep 2003 23:27:18 -0000	1.4
  @@ -67,9 +67,9 @@
   
   /**
    * <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 <code>Map</code> with entries in the form 
  + * <code>ObjectFactory</code> 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>
  @@ -90,25 +90,26 @@
    * 
    * <p>
    * Example:
  - * <code>
  + * <pre>
    * Map map = new HashMap();
    * map.put("list", "java.util.ArrayList");
    * map.put("set", "java.util.HashSet");
    * 
    * ObjectFactory factory = new ObjectFactory(map);
    * Set mySet = (Set) factory.construct("set");
  - * </code>
  + * </pre>
    * </p>
    * 
    * <p>
    * Using ObjectFactory without a map:
  + * <br/>
    * <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.
  + * The higher level class can use <code>ObjectFactory</code> to do the mapping

  + * and creation work while it implements factory specific semantics and caching.
    * </p>
    * 
    * @author David Graham
  @@ -121,9 +122,10 @@
   	protected Map nameMap = new HashMap();
   
   	/** 
  -	 * Stores "name"=Class.  Caches Class objects for quick lookup.
  +	 * Stores "name"=Class.  Caches Class objects for quick lookup.  These Class
  +     * objects act as prototypes to create new instances from.
   	 */
  -	protected Map classMap = new HashMap();
  +	private Map prototypes = new HashMap();
   
   	/**
   	 * Create an ObjectFactory with the given mapping of names to fully 
  @@ -153,7 +155,7 @@
   	 * no-arg constructor.
   	 */
   	public Object create(String name) {
  -		return newInstance(this.getNamedClass(name));
  +		return newInstance(this.getPrototype(name));
   	}
   
   	/**
  @@ -162,7 +164,7 @@
   	 * object of the class.  This usually indicates the class is missing a 
   	 * public no-arg constructor.
   	 */
  -	protected static Object newInstance(Class c) {
  +	private static Object newInstance(Class c) {
   		try {
   			return c.newInstance();
   
  @@ -187,9 +189,9 @@
   	 * @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) {
  +	private Class getPrototype(String logicalName) {
   
  -		Class c = (Class) this.classMap.get(logicalName);
  +		Class c = (Class) this.prototypes.get(logicalName);
   		if (c == null) {
   			String className = (String) this.nameMap.get(logicalName);
   
  @@ -200,7 +202,7 @@
   
   			c = loadClass(className);
   
  -			this.classMap.put(logicalName, c);
  +			this.prototypes.put(logicalName, c);
   		}
   
   		return c;
  @@ -213,7 +215,7 @@
   	 * @throws IllegalArgumentException if the Class is not found for the 
        * given name.
   	 */
  -	protected static Class loadClass(String className) {
  +	private static Class loadClass(String className) {
   		try {
   			return Class.forName(className);
   
  @@ -227,8 +229,8 @@
   	}
   
   	/**
  -	 * Gets a copy of the map this factory is using to construct instances of 
  -	 * classes.  
  +	 * Gets a copy of the <code>Map</code> this factory is using to 
  +     * construct instances of classes.  
   	 */
   	public Map getMap() {
   		return new HashMap(this.nameMap);
  @@ -261,7 +263,7 @@
   			// Object does support clone
   		}
   
  -		of.classMap = new HashMap(this.classMap);
  +		of.prototypes = new HashMap(this.prototypes);
   		of.nameMap = new HashMap(this.nameMap);
   
   		return of;
  
  
  

Mime
View raw message