1 package org.exolab.castor.builder.factory;
2
3 import org.castor.xml.JavaNaming;
4 import org.exolab.castor.builder.SGTypes;
5 import org.exolab.castor.builder.info.FieldInfo;
6 import org.exolab.castor.builder.info.nature.XMLInfoNature;
7 import org.exolab.javasource.JMethod;
8 import org.exolab.javasource.JParameter;
9 import org.exolab.javasource.JSourceCode;
10 import org.exolab.javasource.JType;
11
12
13
14
15
16 public class IdentityMemberAndAccessorFactory extends FieldMemberAndAccessorFactory {
17
18
19
20
21
22
23 public IdentityMemberAndAccessorFactory(final JavaNaming naming) {
24 super(naming);
25 }
26
27
28
29
30
31
32
33 public JMethod[] createAccessMethods(final FieldInfo fieldInfo) {
34 String mname = fieldInfo.getMethodSuffix();
35 JType jType = new XMLInfoNature(fieldInfo).getSchemaType().getJType();
36
37 JMethod[] methods = new JMethod[3];
38 methods[0] = makeGetMethod(fieldInfo, mname, jType);
39 methods[1] = makeSetMethod(fieldInfo, mname, jType);
40 methods[2] = makeGetReferenceIdMethod(fieldInfo);
41
42
43 return methods;
44 }
45
46
47
48
49
50
51
52
53
54 private JMethod makeGetMethod(final FieldInfo fieldInfo, final String mname, final JType jType) {
55 JMethod method = new JMethod("get" + mname, jType, "the value of field '" + mname + "'.");
56 JSourceCode jsc = method.getSourceCode();
57 jsc.add("return this.");
58 jsc.append(fieldInfo.getName());
59 jsc.append(";");
60 return method;
61 }
62
63
64
65
66
67
68
69
70
71 private JMethod makeSetMethod(final FieldInfo fieldInfo, final String mname, final JType jType) {
72 JMethod method = new JMethod("set" + mname);
73 method.addParameter(new JParameter(jType, fieldInfo.getName()));
74 JSourceCode jsc = method.getSourceCode();
75 jsc.add("this.");
76 jsc.append(fieldInfo.getName());
77 jsc.append(" = ");
78 jsc.append(fieldInfo.getName());
79 jsc.append(";");
80
81
82
83
84
85
86
87
88
89 return method;
90 }
91
92
93
94
95
96
97
98 private JMethod makeGetReferenceIdMethod(final FieldInfo fieldInfo) {
99 JMethod method = new JMethod("getReferenceId", SGTypes.STRING, "the reference ID");
100 JSourceCode jsc = method.getSourceCode();
101 jsc.add("return this.");
102 jsc.append(fieldInfo.getName());
103 jsc.append(";");
104 return method;
105 }
106
107
108 }