You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/04/14 07:20:07 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/xml XmlMapper.java

craigmcc    00/04/13 22:20:07

  Modified:    src/share/org/apache/tomcat/util/xml XmlMapper.java
  Log:
  Modify the ObjectCreate class to operate in the manner that (I believe)
  was originally intended, based on which constructor you call.
  
  If the ObjectCreate(classN) constructor is called, an instance of the
  class specified by "classN" will always be instantiated.
  
  If the ObjectCreate(classN,attrib) constructor is called, the "classN"
  argument is considered to be the default class name.  If an attribute of
  the name specified by the "attrib" argument is present in the actual XML
  node being parsed, its value is considered to override the default class
  name.  (Previously, this triggered a null pointer exception if the
  attribute was missing).
  
  This approach is very useful in dynamically configuring new objects, but
  allowing the provision of a default class name that can be overridden
  instead of requiring it to be explicitly included on *every* XML element.
  
  Revision  Changes    Path
  1.13      +19 -5     jakarta-tomcat/src/share/org/apache/tomcat/util/xml/XmlMapper.java
  
  Index: XmlMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/xml/XmlMapper.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XmlMapper.java	2000/04/03 22:23:41	1.12
  +++ XmlMapper.java	2000/04/14 05:20:06	1.13
  @@ -422,19 +422,32 @@
   
   //-------------------- "Core" actions --------------------
   // XXX XXX XXX Need to move the "standard" actions in individual files
  -/** Create an object
  +/**
  + * Create an object of the specified or override Java class name.
    */
   class ObjectCreate extends XmlAction {
       String className;
       String attrib;
   
  +    /**
  +     * Create an object of the specified class name.
  +     *
  +     * @param classN Fully qualified name of the Java class to instantiate
  +     */
       public ObjectCreate(String classN) {
   	className=classN;
       }
   
  -    /** Create an object based on an attribute of the current
  -	tag
  -    */
  +    /**
  +     * Create an object of the specified default class name, unless an
  +     * attribute with the specified name is present, in which case the value
  +     * of this attribute overrides the default class name.
  +     *
  +     * @param classN Fully qualified name of the Java class to instantiate
  +     *  if the specified attribute name is not present
  +     * @param attrib Name of the attribute that may contain a fully qualified
  +     *  name of a Java class that overrides the default
  +     */
       public ObjectCreate(String classN, String attrib) {
   	className=classN;
   	this.attrib=attrib;
  @@ -448,7 +461,8 @@
   
   	if( attrib!=null) {
   	    AttributeList attributes = ctx.getAttributeList( top );
  -	    classN= attributes.getValue(attrib);
  +	    if (attributes.getValue(attrib) != null)
  +		classN= attributes.getValue(attrib);
   	}
   	Class c=Class.forName( classN );
   	Object o=c.newInstance();