1 /*
2 * Copyright 2003 - 2013 The eFaps Team
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 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.update;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.apache.commons.lang3.builder.ToStringBuilder;
27 import org.efaps.db.Instance;
28
29 /**
30 * TODO description!
31 *
32 * @author The eFaps Team
33 * @version $Id$
34 *
35 */
36 public class LinkInstance
37 {
38 /**
39 * Mapping for the values.
40 */
41 private final Map<String, String> valuesMap = new HashMap<String, String>();
42
43 /**
44 * Map of Names of a attribute to the values of this attribute.
45 */
46 private final Map<String, String> keyAttr2Value = new HashMap<String, String>();
47
48 /**
49 * Instance of the object the link links to.
50 */
51 private Instance childInstance;
52
53 /**
54 * Instance of the object the link links to.
55 */
56 private Instance instance;
57
58 /**
59 * Constructor not setting nothing. Careful the keyAttrputs must be set!
60 */
61 public LinkInstance()
62 {
63 }
64
65 /**
66 * Constructor setting the only keyfield to "Name" and the value of this
67 * keyfield to the given parameter.
68 * @param _name key for the keyfield "Name"
69 */
70 public LinkInstance(final String _name)
71 {
72 this.keyAttr2Value.put("Name", _name);
73 }
74
75 /**
76 * Constructor setting the only keyfield to "Name" and the value of this
77 * keyfield to the given parameter.
78 * @param _name key for the keyfield "Name"
79 * @param _values valuue
80 */
81 public LinkInstance(final String _name,
82 final String... _values)
83 {
84 this.keyAttr2Value.put("Name", _name);
85 for (int i = 0; i < _values.length; i += 2) {
86 this.valuesMap.put(_values[i], _values[i + 1]);
87 }
88 }
89
90 /**
91 * Getter method for instance variable {@link #keyAttr2Value}.
92 *
93 * @return value of instance variable {@link #keyAttr2Value}
94 */
95 public Map<String, String> getKeyAttr2Value()
96 {
97 return this.keyAttr2Value;
98 }
99
100 /**
101 * This is the getter method for the instance variable {@link #valuesMap}.
102 *
103 * @return value of instance variable {@link #valuesMap}
104 */
105 public Map<String, String> getValuesMap()
106 {
107 return this.valuesMap;
108 }
109
110 /**
111 * @param _values values to set
112 */
113 public void setValues(final Map<String, String> _values)
114 {
115 this.valuesMap.clear();
116 this.valuesMap.putAll(_values);
117 }
118
119 /**
120 * Setter method for the instance variable {@link #childInstance}.
121 *
122 * @param _instance Instance to set
123 */
124 public void setChildInstance(final Instance _instance)
125 {
126 this.childInstance = _instance;
127 }
128
129 /**
130 * Getter method for the instance variable {@link #childInstance}.
131 *
132 * @return value of instance variable {@link #childInstance}
133 */
134 public Instance getChildInstance()
135 {
136 return this.childInstance;
137 }
138
139 /**
140 * Getter method for the instance variable {@link #instance}.
141 *
142 * @return value of instance variable {@link #instance}
143 */
144 public Instance getInstance()
145 {
146 return this.instance;
147 }
148
149 /**
150 * Setter method for instance variable {@link #instance}.
151 *
152 * @param _instance value for instance variable {@link #instance}
153 */
154 public void setInstance(final Instance _instance)
155 {
156 this.instance = _instance;
157 }
158
159 @Override
160 public String toString()
161 {
162 return ToStringBuilder.reflectionToString(this);
163 }
164
165 }