1 /***
2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.codestreet.messageforge;
19
20 /***
21 * This class is used to implement the field name mapping within the framework. Fields in a
22 * messages can be associated with named groups. Each named group is a collection of field
23 * names from one or more messages. The idea is that each field in a named group has the
24 * same business semantics.
25 * @author Jawaid Hakim.
26 */
27 public class RFldMap implements RFldMapInterface
28 {
29 /***
30 * Ctor.
31 */
32 private RFldMap()
33 {
34 }
35
36 /***
37 * Get singleton instance.
38 * @return Singleton instance.
39 */
40 public static RFldMap getInstance()
41 {
42 return instance_;
43 }
44
45 /***
46 * Add a mapping of a message/field to a field group.
47 * @param fldGrpName Field group name.
48 * @param msgName Message name.
49 * @param fldName Field name.
50 */
51 public void add(String fldGrpName, String msgName, String fldName)
52 {
53 java.util.Map fldGrp = (java.util.Map)fldGrps_.get(fldGrpName);
54 if (fldGrp == null)
55 {
56 fldGrp = new java.util.HashMap();
57 fldGrps_.put(fldGrpName, fldGrp);
58 }
59 fldGrp.put(msgName, fldName);
60 }
61
62 /***
63 * Map a field group and a target message to the corresponding field name in
64 * that message.
65 * @param fldGrpName Name of the field group.
66 * @param msgName Name of the target message.
67 * @return Name of the target field. Returns <tt>null</tt> if the target
68 * field is not found.
69 */
70 public String map(String fldGrpName, String msgName)
71 {
72 java.util.Map fldGrp = (java.util.Map)fldGrps_.get(fldGrpName);
73 return (fldGrp != null) ? (String)fldGrp.get(msgName) : null;
74 }
75
76 /***
77 * Check if a mapping exists for a field group and a target message.
78 * @param fldGrpName Name of the field group.
79 * @param msgName Name of the target message.
80 * @return Returns <tt>true</tt> if the mapping exists. Otherwise, returns
81 * <tt>false</tt>.
82 */
83 public boolean hasMapping(String fldGrpName, String msgName)
84 {
85 String map = map(fldGrpName, msgName);
86 return (map != null);
87 }
88
89 private static RFldMap instance_ = new RFldMap();
90 private java.util.Map fldGrps_ = new java.util.HashMap();
91 }
This page was automatically generated by Maven