1 package org.andromda.core.translation.library;
2
3 import java.util.LinkedHashMap;
4 import java.util.Map;
5 import org.andromda.core.common.ExceptionUtils;
6 import org.apache.commons.lang.StringUtils;
7 import org.apache.commons.lang.builder.ToStringBuilder;
8
9
10
11
12
13
14
15 public class Fragment
16 {
17 private String name;
18 private String handlerMethod;
19
20
21
22
23 private Translation translation;
24
25
26
27
28 private Map<String, String> kinds = new LinkedHashMap<String, String>();
29
30
31
32
33
34
35
36 public Fragment()
37 {
38
39 }
40
41
42
43
44
45
46 public String getName()
47 {
48 return name;
49 }
50
51
52
53
54
55
56 public void setName(final String name)
57 {
58 this.name = StringUtils.trimToEmpty(name);
59 }
60
61
62
63
64
65
66 public Map<String, String> getKinds()
67 {
68 return this.kinds;
69 }
70
71
72
73
74
75
76
77 public String getKind(String name)
78 {
79
80 name = StringUtils.trimToEmpty(name);
81 ExceptionUtils.checkEmpty("name", name);
82 String kind = StringUtils.trimToEmpty(kinds.get(name));
83 if (kind == null)
84 {
85 throw new LibraryException(
86 "No kind '" + name + "' could be found for the translation fragment '" +
87 this.getName() + "' check the fragment '" + this.getName() + "' in translation template --> '" +
88 getTranslation().getLibraryTranslation().getTemplate() + '\'');
89 }
90 return kind;
91 }
92
93
94
95
96
97
98
99 public void addKind(
100 final String name,
101 final String body)
102 {
103 kinds.put(
104 StringUtils.trimToEmpty(name),
105 body);
106 }
107
108
109
110
111
112
113 public String getHandlerMethod()
114 {
115 return this.handlerMethod;
116 }
117
118
119
120
121
122
123
124
125 public void setHandlerMethod(final String handlerMethod)
126 {
127 this.handlerMethod = handlerMethod;
128 }
129
130
131
132
133
134
135 public Translation getTranslation()
136 {
137 final String methodName = "Fragment.getTranslation";
138
139
140 if (this.translation == null)
141 {
142 throw new LibraryException(methodName + " - translation can not be null");
143 }
144 return translation;
145 }
146
147
148
149
150
151
152 public void setTranslation(final Translation translation)
153 {
154 this.translation = translation;
155 }
156
157
158
159
160 public String toString()
161 {
162 return ToStringBuilder.reflectionToString(this);
163 }
164 }