mpoeschl    02/01/22 06:23:11

  Modified:    src/java/org/apache/stratum/xo Mapper.java
  Log:
  make javadocs readable
  
  Revision  Changes    Path
  1.13      +63 -63    
jakarta-turbine-stratum/src/java/org/apache/stratum/xo/Mapper.java
  
  Index: Mapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/xo/Mapper.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Mapper.java       18 Jan 2002 22:19:59 -0000      1.12
  +++ Mapper.java       22 Jan 2002 14:23:11 -0000      1.13
  @@ -75,25 +75,25 @@
   import org.apache.stratum.introspection.Introspector;
   
   /**
  - * <p>
    * Map an XML document to a JavaBean. The XML document is
    * assumed to be in a common format:
    *
    * <p>
  - * <person>
  - *   <firstName>Jason</firstName>
  - *   <lastName>van Zyl</lastName>
  - *   <hobbies>
  - *     <hobby>somnambulism</hobby>
  - *     <hobby>squash</hobby>
  - *   </hobbies>
  - *   <address>
  - *     <street>50 King</street>
  - *     <city>Guelph</city>
  - *     <country>Canada</country>
  - *   </address>
  - * </person>
  - *
  + * <pre>
  + * &lt;person&gt;
  + *   &lt;firstName&gt;Jason&lt;/firstName&gt;
  + *   &lt;lastName&gt;van Zyl&lt;/lastName&gt;
  + *   &lt;hobbies&gt;
  + *     &lt;hobby&gt;somnambulism&lt;/hobby&gt;
  + *     &lt;hobby&gt;squash&lt;/hobby&gt;
  + *   &lt;/hobbies&gt;
  + *   &lt;address&gt;
  + *     &lt;street&gt;50 King&lt;/street&gt;
  + *     &lt;city&gt;Guelph&lt;/city&gt;
  + *     &lt;country&gt;Canada&lt;/country&gt;
  + *   &lt;/address&gt;
  + * &lt;/person&gt;
  + * </pre>
    * <p>
    * These are some of the assumptions employed to
    * make mapping the object simpler:
  @@ -109,7 +109,7 @@
    * </ul>
    *
    * Processing Rules:
  - *
  + * <pre>
    * Does Element refers to a noun plural?
    *
    * Yes:
  @@ -120,7 +120,7 @@
    *       Create object and attach to parent,
    *       have to look for inclusion rules as we might need
    *       to create an object from another XML file.
  - *             
  + *
    *       Is the parent Element a plural noun?
    *         Yes:
    *           We have a collection:
  @@ -134,13 +134,13 @@
    *           Create object from an XML file and attach
    *         No:
    *           Simple String value to attach
  - *
  + * </pre>
    * <p>
    * This class is not thread safe.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
  - * @version $Id: Mapper.java,v 1.12 2002/01/18 22:19:59 jvanzyl Exp $
  + * @version $Id: Mapper.java,v 1.13 2002/01/22 14:23:11 mpoeschl Exp $
    */
   
   // How to use the resources package to pull in the
  @@ -173,9 +173,9 @@
        */
       protected static final String EID = "id";
   
  -    /** 
  -     * dom4j object model representation of a xml document. Note: 
  -     * We use the interface(!) not its implementation 
  +    /**
  +     * dom4j object model representation of a xml document. Note:
  +     * We use the interface(!) not its implementation
        */
       private Document document;
   
  @@ -185,7 +185,7 @@
        * will be included from an external source.
        */
       private Map inclusionRules;
  -    
  +
       /**
        * Base directory where the initial XML file is read
        * from if files are being used.
  @@ -218,7 +218,7 @@
           inclusionRules = new HashMap();
           introspector = new Introspector();
       }
  -    
  +
       /**
        * Reset the mapper so that it can be reused.
        */
  @@ -274,13 +274,13 @@
           throws Exception
       {
           InputStream xmlStream = findXmlStream(xmlInput);
  -        
  +
           // Get the base directory
           basePath = FileUtils.dirname(xmlInput);
   
           return map(xmlStream, beanClass);
       }
  -    
  +
       /**
        * Loads a XML document (first trying the classpath, then the file
        * system), maps it to a live instance of the JavaBean
  @@ -315,7 +315,7 @@
               // Couldn't load from the classpath -- try the file system.
               xmlStream = new FileInputStream(xmlInput);
           }
  -        
  +
           return xmlStream;
       }
   
  @@ -337,7 +337,7 @@
       {
           return map(xmlInput,bean,null);
       }
  -    
  +
       /**
        * Loads a XML document from <code>xmlInput</code>, maps it to an
        * instance of the JavaBean <code>beanClass</code>, and returns
  @@ -356,7 +356,7 @@
       {
           return map(xmlInput,null,beanClass);
       }
  -    
  +
       /**
        * Loads a XML document from <code>xmlInput</code>, maps it to
        * a newly created object if <code>bean</code> is <code>null</null>,
  @@ -371,18 +371,18 @@
        * @exception DocumentException If the build process fails.
        */
       protected Object map(InputStream xmlInput, Object bean, String beanClass)
  -        throws Exception 
  +        throws Exception
       {
           SAXReader xmlReader = new SAXReader();
           document = xmlReader.read(xmlInput);
   
           // Create the parent bean.
           Element rootElement = document.getRootElement();
  -        
  +
           if (bean == null)
           {
               bean = createInstance(rootElement, beanClass);
  -        }            
  +        }
   
           // Assure we have the fully qualified class of the bean.
           if (beanClass == null)
  @@ -412,7 +412,7 @@
       public void setDebug(boolean debug)
       {
           this.debug = debug;
  -    }        
  +    }
   
       /**
        * Walk down a Element node processing the children.
  @@ -424,13 +424,13 @@
       private Object treeWalk(Element element, Object bean)
           throws Exception
       {
  -        for ( int i = 0, size = element.nodeCount(); i < size; i++ ) 
  +        for ( int i = 0, size = element.nodeCount(); i < size; i++ )
           {
               Node node = element.node(i);
  -            if ( node instanceof Element ) 
  +            if ( node instanceof Element )
               {
                   String name = node.getName();
  -                
  +
                   // If the element refers to a noun plural than we
                   // have something like <items> or <hobbies> and we
                   // want to process the child elements.
  @@ -466,12 +466,12 @@
                           // and object from an external XML file if that's
                           // the case.
                           Object o = inclusion((Element) node);
  -                        
  +
                           if (o == null)
                           {
                               o = createInstance((Element) node, null);
  -                        }                            
  -                        
  +                        }
  +
                           // Now we have to attach the newly created object
                           // to its parent object.
                           if (isPlural(node.getParent().getName()))
  @@ -488,9 +488,9 @@
                               // to set the simple property.
                               setProperty(bean,name,o);
                           }
  -                        
  +
                           debug("Attached " + o + " to parent " + bean);
  -                        
  +
                           // Now we walk the tree so that (2), (3), and (4)
                           // above are assigned to the newly attached object.
                           treeWalk((Element) node, o);
  @@ -515,10 +515,10 @@
                               // Now we are dealing with elements that refer
                               // to a noun singular and these elements have
                               // no children.
  -                        
  +
                               o = inclusion((Element) node);
                               Class type = null;
  -                        
  +
                               if (o == null)
                               {
                                   type = PropertyUtils.getPropertyType(bean,name);
  @@ -556,11 +556,11 @@
                               // properties.
                               setProperty(bean,name,o);
                           }
  -                    }                        
  +                    }
                   }
               }
           }
  -    
  +
           return bean;
       }
   
  @@ -574,7 +574,7 @@
       public void setInclusionRule(String elementName, String rule)
       {
           inclusionRules.put(elementName, rule);
  -    }    
  +    }
   
       /**
        * Returns an instance of the class represented by
  @@ -655,7 +655,7 @@
       {
           return (((Element) node).nodeCount() > 1);
       }
  -    
  +
       /**
        * Build up and object by pulling in an external XML
        * document.
  @@ -711,20 +711,20 @@
               Object[] args = new Object[] { value };
               String methodName = makeMethodName("add", elementName);
               Method m = introspector.getMethod(bean.getClass(), methodName, args);
  -            
  +
               if (m == null)
               {
                   debugMethod(bean, elementName, "add", value);
                   return;
  -            }                
  -        
  +            }
  +
               m.invoke(bean,args);
           }
           catch (Exception e)
           {
           }
       }
  -    
  +
       /**
        * Set a standard simple bean property.
        *
  @@ -756,16 +756,16 @@
        * @param methodType
        * @param value
        */
  -    private void  debugMethod(Object bean, 
  -                              String elementName, 
  -                              String methodType, 
  +    private void  debugMethod(Object bean,
  +                              String elementName,
  +                              String methodType,
                                 Object value)
       {
  -        String methodName = bean.getClass().getName() + "." + 
  +        String methodName = bean.getClass().getName() + "." +
               makeMethodName(methodType, elementName);
  -    
  +
           debug("ERROR: " + methodName + "(" + value.getClass().getName() + ") not 
found!");
  -    }            
  +    }
   
       /**
        * A very simple plural stemmer to determine whether
  @@ -778,22 +778,22 @@
        */
       private boolean isPlural(String name)
       {
  -        if (name.endsWith("ies") && 
  +        if (name.endsWith("ies") &&
               (!name.endsWith("eies") || !name.endsWith("aies")))
           {
               return true;
           }
  -        else if (name.endsWith("es") && 
  +        else if (name.endsWith("es") &&
               (!name.endsWith("aes") && !name.endsWith("ees") &&
                   !name.endsWith("oes")))
           {
               return true;
           }
  -        else if (name.endsWith("s") && 
  +        else if (name.endsWith("s") &&
               (!name.endsWith("us") && !name.endsWith("ss")))
           {
               return true;
  -        }            
  +        }
   
           // None of the tests detected a plural
           return false;
  @@ -811,7 +811,7 @@
           return (text == null ? null : prefix +
                   text.substring(0, 1).toUpperCase() + text.substring(1));
       }
  -  
  +
       /**
        * Simple debug printer.
        */
  @@ -820,6 +820,6 @@
           if (debug)
           {
               System.out.println(message);
  -        }            
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to