01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.tools.common.model;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.cxf.tools.util.AnnotationUtil;
24:
25: public class JavaClass extends JavaInterface {
26:
27: private final List<JavaField> jfield = new ArrayList<JavaField>();
28:
29: public JavaClass() {
30: }
31:
32: public JavaClass(JavaModel model) {
33: super (model);
34: }
35:
36: public void addField(JavaField f) {
37: this .jfield.add(f);
38: }
39:
40: public List<JavaField> getFields() {
41: return this .jfield;
42: }
43:
44: public JavaMethod appendGetter(JavaField field) {
45: String getterName = "get"
46: + AnnotationUtil.capitalize(field.getName());
47: JavaMethod jMethod = new JavaMethod(this );
48: jMethod.setName(getterName);
49: jMethod.setReturn(new JavaReturn(field.getName(), field
50: .getType(), field.getTargetNamespace()));
51:
52: JavaCodeBlock block = new JavaCodeBlock();
53: JavaExpression exp = new JavaExpression();
54: exp.setValue("return this." + field.getName());
55: block.getExpressions().add(exp);
56:
57: jMethod.setJavaCodeBlock(block);
58:
59: addMethod(jMethod);
60: return jMethod;
61: }
62:
63: public JavaMethod appendSetter(JavaField field) {
64: String setterName = "set"
65: + AnnotationUtil.capitalize(field.getName());
66: JavaMethod jMethod = new JavaMethod(this );
67: jMethod.setReturn(new JavaReturn("return", "void", null));
68: String paramName = getSetterParamName(field.getName());
69: jMethod.addParameter(new JavaParameter(paramName, field
70: .getType(), field.getTargetNamespace()));
71: JavaCodeBlock block = new JavaCodeBlock();
72: JavaExpression exp = new JavaExpression();
73: exp.setValue("this." + field.getName() + " = " + paramName);
74: block.getExpressions().add(exp);
75:
76: jMethod.setJavaCodeBlock(block);
77:
78: jMethod.setName(setterName);
79: addMethod(jMethod);
80: return jMethod;
81: }
82:
83: private String getSetterParamName(String fieldName) {
84: return "new" + AnnotationUtil.capitalize(fieldName);
85: }
86:
87: }
|