View Javadoc

1   // -- FILE ------------------------------------------------------------------
2   // name       : ValidationInfoImpl.java
3   // project    : Panter: LI
4   // created    : lep - 2007.02.07
5   // language   : java
6   // environment: JDK 1.5.0
7   // copyright  : (c) 2006 by Panter llc, Switzerland
8   // license    : this is free software licensed under the GPL. see COPYING
9   // --------------------------------------------------------------------------
10  package ch.panter.li.bi.asn.api;
11  
12  import ch.panter.li.bi.util.ShieldableArrayList;
13  import ch.panter.li.bi.util.ReadOnlyCollection;
14  import ch.panter.li.bi.util.CompareTool;
15  import ch.panter.li.bi.util.HashCodeTool;
16  
17  import java.util.Stack;
18  
19  
20  public final class ValidationInfoImpl implements ValidationInfo
21  {
22  
23    public ValidationInfoImpl()
24    {
25    } // ValidationInfoImpl
26  
27    public final ReadOnlyCollection<ValidationItem> getItems()
28    {
29      return items;
30    } // getItems
31  
32    public final void pushContext( final String context )
33    {
34      contextStack.push( context );
35    } // pushContext
36  
37    public final String getContext()
38    {
39      final StringBuffer ctx = new StringBuffer();
40      for ( final String subContext : contextStack ) {
41        if ( ctx.length() > 0 ) {
42          ctx.append( ": " );
43        }
44        ctx.append( subContext );
45      }
46      return ctx.toString();
47    } // getContext
48  
49    public final void popContext()
50    {
51      if ( !contextStack.isEmpty() ) {
52        contextStack.pop();
53      }
54    } // popContext
55  
56    public final void add( final String item )
57    {
58      items.add( new ValidationItemImpl( getContext() + ": " + item ) );
59    } // add
60  
61    public boolean equals( final Object compare )
62    {
63      if ( this == compare ) {
64        return true;
65      } else if ( compare == null || getClass() != compare.getClass() ) {
66        return false;
67      }
68      final ValidationInfoImpl comp = (ValidationInfoImpl)compare;
69      return CompareTool.areEqual( this.items, comp.items );
70    } // equals
71  
72    public int hashCode()
73    {
74      int hash = getClass().hashCode();
75      hash = HashCodeTool.addHashCode( hash, items );
76      return hash;
77    } // hashCode
78  
79    public String toString()
80    {
81      return items.toString();
82    } // toString
83  
84    // members
85    private final Stack<String> contextStack = new Stack<String>();
86    private final ShieldableArrayList<ValidationItem> items = new ShieldableArrayList<ValidationItem>();
87  
88  } // class ValidationInfoImpl
89  
90  // -- EOF -------------------------------------------------------------------