View Javadoc

1   /*
2    * EDI-Knight Integration and Transformation Platform
3    * Copyright (C) 2006-2007 Holger Joest <hjoest@users.sourceforge.net>
4    *
5    * This program is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package net.sf.ediknight.common.edi.directory;
21  
22  import net.sf.ediknight.edi.directory.Element;
23  
24  
25  /***
26   * @author Holger Joest
27   */
28  public class ElementImpl
29  implements Element {
30  
31      private static final long serialVersionUID = 6418131247929435657L;
32  
33      private String id;
34  
35      private String name;
36  
37      private String description;
38  
39      private String mode;
40  
41      private boolean deprecated;
42  
43  
44      /***
45       * Constructor.
46       */
47      protected ElementImpl() {
48      }
49  
50  
51      /***
52       * @return the id
53       */
54      public final String getId() {
55          return id;
56      }
57  
58  
59      /***
60       * @param id The id to set.
61       */
62      public final void setId(String id) {
63          if (id == null) {
64              throw new IllegalArgumentException();
65          }
66          this.id = id;
67      }
68  
69  
70      /***
71       * @return the name
72       */
73      public final String getName() {
74          if (name == null) {
75              name = Names.toElementName(this);
76          }
77          return name;
78      }
79  
80  
81      /***
82       * @return the description
83       */
84      public final String getDescription() {
85          return description;
86      }
87  
88  
89      /***
90       * @param description The description to set.
91       */
92      public final void setDescription(String description) {
93          if (description == null) {
94              throw new IllegalArgumentException();
95          }
96          description =
97              Character.toUpperCase(description.charAt(0))
98              + description.substring(1).toLowerCase();
99          this.description = description;
100         name = null;
101     }
102 
103 
104     /***
105      * @param description The description to set.
106      */
107     public final void appendDescription(String description) {
108         if (description == null) {
109             throw new IllegalArgumentException();
110         }
111         if (this.description == null) {
112             this.description = description;
113         } else {
114             this.description += " " + description;
115         }
116         name = null;
117     }
118 
119 
120     /***
121      * @return true if this is an interactive element
122      */
123     public final boolean isInteractiveMode() {
124         return "I".equals(mode);
125     }
126 
127 
128     /***
129      * @return true if this is a batch mode element
130      */
131     public final boolean isBatchMode() {
132         return !"I".equals(mode);
133     }
134 
135 
136     /***
137      * @return the element mode
138      */
139     public final String getMode() {
140         return mode;
141     }
142 
143 
144     /***
145      * @param mode the element mode (BATCH or INTERACTIVE)
146      */
147     public final void setMode(String mode) {
148         this.mode = mode;
149     }
150 
151 
152     /***
153      * @return true if this element is deprecated
154      */
155     public final boolean isDeprecated() {
156         return deprecated;
157     }
158 
159 
160     /***
161      * @param deprecated true if this element is deprecated
162      */
163     public final void setDeprecated(boolean deprecated) {
164         this.deprecated = deprecated;
165     }
166 
167 
168     /***
169      * Throws an {@link IllegalStateException} if the element is not completely
170      * defined.
171      */
172     public void checkCompleteness() {
173         if (getId() == null) {
174             throw new IllegalStateException("Element has no id");
175         }
176         if (getDescription() == null) {
177             throw new IllegalStateException("Element has no description");
178         }
179         if (mode == null) {
180             throw new IllegalStateException("Invalid mode");
181         }
182     }
183 
184 
185     /***
186      * {@inheritDoc}
187      * @see java.lang.Comparable#compareTo(java.lang.Object)
188      */
189     public final int compareTo(Element other) {
190         return getId().compareTo(other.getId());
191     }
192 
193 }
194