View Javadoc

1   /*
2    * Copyright 2007-2011 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.exceptions.report.message;
17  
18  import java.io.Serializable;
19  
20  import de.smartics.exceptions.i18n.message.MessageType;
21  
22  /**
23   * Information about a place holder.
24   *
25   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
26   * @version $Revision:591 $
27   */
28  public final class PlaceHolderDesc implements Serializable
29  {
30    // ********************************* Fields *********************************
31  
32    // --- constants ------------------------------------------------------------
33  
34    /**
35     * The class version identifier.
36     */
37    private static final long serialVersionUID = 1L;
38  
39    // --- members --------------------------------------------------------------
40  
41    /**
42     * The ID of the place holder.
43     *
44     * @serial
45     */
46    private final PlaceHolderDescId placeHolderId;
47  
48    /**
49     * The descriptive name of the place holder. This is the name of the field
50     * that holds the value. The value may be a complex type where the OGNL path
51     * points to the value of the variable that will substitute the place holder.
52     *
53     * @serial
54     */
55    private final String paramName;
56  
57    /**
58     * The path to the value that substitutes the place holder.
59     *
60     * @serial
61     */
62    private final String ognlPath;
63  
64    /**
65     * The description of the place holder.
66     *
67     * @serial
68     */
69    private final String description;
70  
71    // ****************************** Initializer *******************************
72  
73    // ****************************** Constructors ******************************
74  
75    /**
76     * Copy constructor with a new message type.
77     *
78     * @param desc the description to copy except its message type.
79     * @param messageType the new messae type.
80     */
81    public PlaceHolderDesc(final PlaceHolderDesc desc,
82        final MessageType messageType)
83    {
84      this(new PlaceHolderDescId(desc.getPlaceHolderIndex(), messageType), desc
85          .getParamName(), desc.getOgnlPath(), desc.getDescription());
86    }
87  
88    /**
89     * Default constructor.
90     *
91     * @param placehHolderId the ID of the place holder.
92     * @param paramName the descriptive name of the place holder.
93     * @param ognlPath the path to the value that substitutes the place holder.
94     * @param description the description of the place holder.
95     */
96    public PlaceHolderDesc(final PlaceHolderDescId placehHolderId,
97        final String paramName, final String ognlPath, final String description)
98    {
99      this.placeHolderId = placehHolderId;
100     this.paramName = paramName;
101     this.ognlPath = ognlPath;
102     this.description = description;
103   }
104 
105   // ****************************** Inner Classes *****************************
106 
107   // ********************************* Methods ********************************
108 
109   // --- init -----------------------------------------------------------------
110 
111   // --- get&set --------------------------------------------------------------
112   /**
113    * Returns the ID of the place holder.
114    *
115    * @return the ID of the place holder.
116    */
117   public PlaceHolderDescId getPlaceHolderId()
118   {
119     return placeHolderId;
120   }
121 
122   /**
123    * Returns the index of the place holder within a message of the given message
124    * type.
125    *
126    * @return the index of the place holder within a message of the given message
127    *         type.
128    */
129   public int getPlaceHolderIndex()
130   {
131     return placeHolderId.getPlaceHolderIndex();
132   }
133 
134   /**
135    * Returns the type of the indexed message.
136    *
137    * @return the type of the indexed message.
138    */
139   public MessageType getPlaceHolderMessageType()
140   {
141     return placeHolderId.getMessageType();
142   }
143 
144   /**
145    * Returns the descriptive name of the place holder. This is the name of the
146    * field that holds the value. The value may be a complex type where the OGNL
147    * path points to the value of the variable that will substitute the place
148    * holder.
149    *
150    * @return the descriptive name of the place holder.
151    */
152   public String getParamName()
153   {
154     return paramName;
155   }
156 
157   /**
158    * Returns the path to the value that substitutes the place holder.
159    *
160    * @return the path to the value that substitutes the place holder.
161    */
162   public String getOgnlPath()
163   {
164     return ognlPath;
165   }
166 
167   /**
168    * Returns the description of the place holder.
169    *
170    * @return the description of the place holder.
171    */
172   public String getDescription()
173   {
174     return description;
175   }
176 
177   // --- business -------------------------------------------------------------
178 
179   // --- object basics --------------------------------------------------------
180 
181   /**
182    * Returns the string representation of the object.
183    *
184    * @return the string representation of the object.
185    */
186   @Override
187   public String toString()
188   {
189     return placeHolderId + ": " + paramName + ':' + ognlPath + ": "
190            + description;
191   }
192 }