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 public IdentityMemberAndAccessorFactory(final JavaNaming naming) {
23 super(naming);
24 }
25
26
27
28
29
30
31
32 public JMethod[] createAccessMethods(final FieldInfo fieldInfo) {
33 String mname = fieldInfo.getMethodSuffix();
34 JType jType = new XMLInfoNature(fieldInfo).getSchemaType().getJType();
35
36 JMethod[] methods = new JMethod[3];
37 methods[0] = makeGetMethod(fieldInfo, mname, jType);
38 methods[1] = makeSetMethod(fieldInfo, mname, jType);
39 methods[2] = makeGetReferenceIdMethod(fieldInfo);
40
41
42 return methods;
43 }
44
45
46
47
48
49
50
51
52
53 private JMethod makeGetMethod(final FieldInfo fieldInfo,
54 final String mname, final JType jType) {
55 JMethod method = new JMethod("get" + mname, jType,
56 "the value of field '" + mname + "'.");
57 JSourceCode jsc = method.getSourceCode();
58 jsc.add("return this.");
59 jsc.append(fieldInfo.getName());
60 jsc.append(";");
61 return method;
62 }
63
64
65
66
67
68
69
70
71
72 private JMethod makeSetMethod(final FieldInfo fieldInfo,
73 final String mname, final JType jType) {
74 JMethod method = new JMethod("set" + mname);
75 method.addParameter(new JParameter(jType, fieldInfo.getName()));
76 JSourceCode jsc = method.getSourceCode();
77 jsc.add("this.");
78 jsc.append(fieldInfo.getName());
79 jsc.append(" = ");
80 jsc.append(fieldInfo.getName());
81 jsc.append(";");
82
83
84
85
86
87
88
89
90
91 return method;
92 }
93
94
95
96
97
98
99 private JMethod makeGetReferenceIdMethod(final FieldInfo fieldInfo) {
100 JMethod method = new JMethod("getReferenceId", SGTypes.STRING,
101 "the reference ID");
102 JSourceCode jsc = method.getSourceCode();
103 jsc.add("return this.");
104 jsc.append(fieldInfo.getName());
105 jsc.append(";");
106 return method;
107 }
108
109
110 }