db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata AttributeDescriptorBase.java ClassDescriptor.java DescriptorBase.java DescriptorRepository.java FieldDescriptor.java
Date Fri, 11 Jul 2003 07:42:06 GMT
arminw      2003/07/11 00:42:05

  Modified:    src/java/org/apache/ojb/broker/metadata
                        AttributeDescriptorBase.java ClassDescriptor.java
                        DescriptorBase.java DescriptorRepository.java
                        FieldDescriptor.java
  Log:
  improve toString() method
  
  Revision  Changes    Path
  1.11      +14 -1     db-ojb/src/java/org/apache/ojb/broker/metadata/AttributeDescriptorBase.java
  
  Index: AttributeDescriptorBase.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/AttributeDescriptorBase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AttributeDescriptorBase.java	26 Mar 2003 10:37:56 -0000	1.10
  +++ AttributeDescriptorBase.java	11 Jul 2003 07:42:04 -0000	1.11
  @@ -120,4 +120,17 @@
       {
           m_ClassDescriptor = classDescriptor;
       }
  +
  +    public String toString()
  +    {
  +        StringBuffer buf = new StringBuffer();
  +        buf.append("superordinate class descriptor [");
  +        buf.append(m_ClassDescriptor.getClassNameOfObject() + "@" + Integer.toHexString(hashCode()));
  +        buf.append("]");
  +        buf.append(", persistent field [");
  +        buf.append(m_PersistentField);
  +        buf.append("]");
  +        buf.append(", "+super.toString());
  +        return buf.toString();
  +    }
   }
  
  
  
  1.64      +9 -8      db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- ClassDescriptor.java	2 Jul 2003 20:09:37 -0000	1.63
  +++ ClassDescriptor.java	11 Jul 2003 07:42:04 -0000	1.64
  @@ -71,6 +71,7 @@
   import java.util.Vector;
   
   import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.accesslayer.RowReader;
   import org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl;
  @@ -1012,7 +1013,7 @@
   
       /**
        * Get interfaces implemented by clazz
  -     * 
  +     *
        * @param clazz
        * @return
        */
  @@ -1020,7 +1021,7 @@
       {
           Class superClazz = clazz;
           Class[] interfaces = clazz.getInterfaces();
  -        
  +
           // clazz can be an interface itself and when getInterfaces()
           // is called on an interface it returns only the extending
           // interfaces, not the interface itself.
  @@ -1028,11 +1029,11 @@
           {
               Class[] tempInterfaces = new Class[interfaces.length + 1];
               tempInterfaces[0] = clazz;
  -        
  +
               System.arraycopy(interfaces, 0, tempInterfaces, 1, interfaces.length);
               interfaces = tempInterfaces;
           }
  -        
  +
           // add all interfaces implemented by superclasses to the interfaces array
           while ((superClazz = superClazz.getSuperclass()) != null)
           {
  @@ -1042,7 +1043,7 @@
               System.arraycopy(superInterfaces, 0, combInterfaces, interfaces.length, superInterfaces.length);
               interfaces = combInterfaces;
           }
  -        
  +
           /**
            * Must remove duplicate interfaces before calling Proxy.getProxyClass().
            * Duplicates can occur if a subclass re-declares that it implements
  @@ -1054,7 +1055,7 @@
               unique.put(interfaces[i].getName(), interfaces[i]);
           }
           interfaces = (Class[]) unique.values().toArray(new Class[unique.size()]);
  -        
  +
           return interfaces;
       }
       /**
  @@ -1602,7 +1603,7 @@
        */
       public String toString()
       {
  -        ToStringBuilder buf = new ToStringBuilder(this);
  +        ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
           return buf
               .append("classNameOfObject", getClassNameOfObject())
               .append("tableName", getTableName())
  
  
  
  1.4       +31 -22    db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java
  
  Index: DescriptorBase.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DescriptorBase.java	20 Jan 2003 16:13:33 -0000	1.3
  +++ DescriptorBase.java	11 Jul 2003 07:42:04 -0000	1.4
  @@ -54,9 +54,9 @@
    * <http://www.apache.org/>.
    */
   
  +import java.io.Serializable;
   import java.util.HashMap;
   import java.util.Map;
  -import java.io.Serializable;
   
   /**
    * base class for all Descriptors. It is used to implement the AttributeContainer
  @@ -65,8 +65,8 @@
    */
   class DescriptorBase implements AttributeContainer, Serializable
   {
  -	/** holds user defined attributes */
  -    private Map attributeList = null;
  +    /** holds user defined attributes */
  +    private Map attributeMap = null;
   
       /**
        * Constructor for DescriptorBase.
  @@ -75,35 +75,35 @@
       {
       }
   
  -	/**
  -	 * @see org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(String, String)
  -	 */
  -   public void addAttribute(String attributeName, String attributeValue)
  -   {
  +    /**
  +     * @see org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(String, String)
  +     */
  +    public void addAttribute(String attributeName, String attributeValue)
  +    {
           // Don't allow null attribute names.
  -        if (attributeName==null)
  +        if (attributeName == null)
           {
               return;
           }
           // Set up the attribute list
  -        if (attributeList==null)
  +        if (attributeMap == null)
           {
  -            attributeList=new HashMap();
  +            attributeMap = new HashMap();
           }
           // Add the entry.
  -        attributeList.put(attributeName,attributeValue);
  +        attributeMap.put(attributeName, attributeValue);
       }
   
  -	/**
  -	 * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(String, String)
  -	 */
  +    /**
  +     * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(String, String)
  +     */
       public String getAttribute(String attributeName, String defaultValue)
       {
           String result = defaultValue;
  -        if (attributeList!=null)
  +        if (attributeMap != null)
           {
  -            result = (String)attributeList.get(attributeName);
  -            if (result==null)
  +            result = (String) attributeMap.get(attributeName);
  +            if (result == null)
               {
                   result = defaultValue;
               }
  @@ -111,11 +111,20 @@
           return result;
       }
   
  -	/**
  -	 * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(String)
  -	 */
  +    /**
  +     * @see org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(String)
  +     */
       public String getAttribute(String attributeName)
       {
  -        return this.getAttribute(attributeName,null);
  +        return this.getAttribute(attributeName, null);
  +    }
  +
  +    public String toString()
  +    {
  +        StringBuffer buf = new StringBuffer();
  +        buf.append("custom attributes [");
  +        buf.append(attributeMap);
  +        buf.append("]");
  +        return buf.toString();
       }
   }
  
  
  
  1.37      +30 -34    db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- DescriptorRepository.java	8 Jul 2003 20:12:38 -0000	1.36
  +++ DescriptorRepository.java	11 Jul 2003 07:42:04 -0000	1.37
  @@ -54,6 +54,12 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.commons.lang.SystemUtils;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
  +import org.apache.ojb.broker.OJBRuntimeException;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.Enumeration;
  @@ -64,11 +70,6 @@
   import java.util.Map;
   import java.util.Vector;
   
  -import org.apache.commons.lang.SystemUtils;
  -import org.apache.commons.lang.builder.ToStringBuilder;
  -import org.apache.ojb.broker.OJBRuntimeException;
  -import org.apache.ojb.broker.PersistenceBrokerException;
  -
   /**
    * The repository containing all object mapping and manipulation information of
    * all used persistent objects.
  @@ -81,7 +82,7 @@
    * @version $Id$
    */
   public final class DescriptorRepository extends DescriptorBase
  -                                        implements Serializable, XmlCapable, IsolationLevels
  +        implements Serializable, XmlCapable, IsolationLevels
   {
       /**
        * The version identifier of the Repository.
  @@ -175,11 +176,6 @@
           return retval;
       }
   
  -
  -
  -
  -
  -
       /**
        * @return all field descriptors for a class that belongs to a set of classes mapped
        * to the same table, otherwise the select queries produced won't contain the necessary
  @@ -277,10 +273,10 @@
               if (!extentClassCld.isAbstract())
               {
                   concreteSubclasses.add(extentClass);
  -            } 
  -            // recurse   
  +            }
  +            // recurse
               concreteSubclasses.addAll(getConcreteSubclassesOf(extentClass));
  -            
  +
           }
           return concreteSubclasses;
       }
  @@ -299,7 +295,7 @@
        */
       public ClassDescriptor getDescriptorFor(String strClassName) throws ClassNotPersistenceCapableException
       {
  - 		ClassDescriptor result = discoverDescriptor(strClassName);
  +        ClassDescriptor result = discoverDescriptor(strClassName);
           if (result == null)
           {
               throw new ClassNotPersistenceCapableException(strClassName + " not found in
OJB Repository");
  @@ -383,7 +379,7 @@
       {
           Enumeration enum = descriptorTable.keys();
           Enumeration enum2 = descriptorTable.elements();
  -        ToStringBuilder buf = new ToStringBuilder(this);
  +        ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
           while (enum.hasMoreElements())
           {
               Object cl = enum.nextElement();
  @@ -439,24 +435,24 @@
           }
           return LITERAL_IL_READ_UNCOMMITTED;
       }
  -    
  +
       /**
  -       * Starts by looking to see if the <code>className</code> is
  -       * already mapped specifically to the descritpor repository.
  -       * If the <code>className</code> is not specifically mapped we
  -       * look at the <code>className</code>'s parent class for a mapping.
  -       * We do this until the parent class is of the type 
  -       * <code>java.lang.Object</code>.  If no mapping was found, 
  -       * <code>null</code> is returned.  Mappings successfuly discovered 
  -       * through inheritence are added to the internal table of
  -       * class descriptors to improve performance on subsequent requests  
  -       * for those classes.
  -       * 
  -       * @param className name of class whose descriptor we need to find.
  -       * @return ClassDescriptor for <code>className</code> or <code>null</code>
  -       * if no ClassDescriptor could be located.
  -       * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
  -       */
  +     * Starts by looking to see if the <code>className</code> is
  +     * already mapped specifically to the descritpor repository.
  +     * If the <code>className</code> is not specifically mapped we
  +     * look at the <code>className</code>'s parent class for a mapping.
  +     * We do this until the parent class is of the type
  +     * <code>java.lang.Object</code>.  If no mapping was found,
  +     * <code>null</code> is returned.  Mappings successfuly discovered
  +     * through inheritence are added to the internal table of
  +     * class descriptors to improve performance on subsequent requests
  +     * for those classes.
  +     *
  +     * @param className name of class whose descriptor we need to find.
  +     * @return ClassDescriptor for <code>className</code> or <code>null</code>
  +     * if no ClassDescriptor could be located.
  +     * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
  +     */
       protected ClassDescriptor discoverDescriptor(String className)
       {
           ClassDescriptor result = (ClassDescriptor) descriptorTable.get(className);
  
  
  
  1.27      +20 -14    db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
  
  Index: FieldDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- FieldDescriptor.java	8 May 2003 14:56:29 -0000	1.26
  +++ FieldDescriptor.java	11 Jul 2003 07:42:05 -0000	1.27
  @@ -54,18 +54,18 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.commons.lang.SerializationUtils;
  +import org.apache.commons.lang.SystemUtils;
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
  -import org.apache.commons.lang.SystemUtils;
  -import org.apache.commons.lang.SerializationUtils;
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl;
   import org.apache.ojb.broker.util.ClassHelper;
   
  +import java.io.Serializable;
   import java.sql.Types;
   import java.util.Comparator;
  -import java.io.Serializable;
   
   /**
    * A FieldDescriptor holds the mapping information for a specific member-variable
  @@ -275,9 +275,14 @@
       public String toString()
       {
           // here we got value of all fields
  -        String result = ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
  -        result = result + " --> belonging class was " + getClassDescriptor().getClassNameOfObject();
  -        return result;
  +        StringBuffer buf = new StringBuffer();
  +        buf.append("[");
  +        buf.append(ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE));
  +        buf.append(", " + super.toString());
  +        buf.append(SystemUtils.LINE_SEPARATOR + " --> belonging class was ");
  +        buf.append(getClassDescriptor().getClassNameOfObject());
  +        buf.append("]" + SystemUtils.LINE_SEPARATOR);
  +        return buf.toString();
       }
   
       /**
  @@ -317,7 +322,7 @@
           catch (Exception e)
           {
               throw new MetadataException(
  -                    "Could not instantiate FieldConversion class using default constructor",e);
  +                    "Could not instantiate FieldConversion class using default constructor",
e);
           }
       }
   
  @@ -487,12 +492,12 @@
   
       public void setAccess(String access)
       {
  -        if(access == null)
  +        if (access == null)
           {
               access = ACCESS_READWRITE;
           }
  -        
  -        if(ACCESS_ANONYMOUS.equals(access) ||
  +
  +        if (ACCESS_ANONYMOUS.equals(access) ||
                   ACCESS_READONLY.equals(access) ||
                   ACCESS_READWRITE.equals(access))
           {
  @@ -500,7 +505,7 @@
           }
           else
           {
  -            throw new OJBRuntimeException("Try to set unkown field 'access' value: "+access);
  +            throw new OJBRuntimeException("Try to set unkown field 'access' value: " +
access);
           }
       }
   
  @@ -518,7 +523,7 @@
           String eol = SystemUtils.LINE_SEPARATOR;
   
           //opening tag + attributes
  -        String result = "      " + tags.getOpeningTagNonClosingById(FIELD_DESCRIPTOR) +
" "+eol;
  +        String result = "      " + tags.getOpeningTagNonClosingById(FIELD_DESCRIPTOR) +
" " + eol;
   
   //        // id
   //        String id = new Integer(getColNo()).toString();
  @@ -601,7 +606,8 @@
           return result;
       }
   
  -    public Object clone() {
  +    public Object clone()
  +    {
           return SerializationUtils.deserialize(SerializationUtils.serialize(this));
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message