KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > js > JavaConstructor


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
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  */

17 package org.apache.ws.jaxme.js;
18
19 import java.io.IOException JavaDoc;
20
21
22 /** <p>An implementation of a Java constructor.</p>
23  *
24  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
25  */

26 public class JavaConstructor extends AbstractJavaMethod {
27   /** Creates a new JavaConstructor with the given protection */
28   JavaConstructor(String JavaDoc pName, JavaSource.Protection pProtection) {
29     super(pName, null, pProtection);
30   }
31
32   public String JavaDoc getName() {
33      String JavaDoc name = super.getName();
34      int offset = name.lastIndexOf('$');
35      if (offset > -1) {
36         return name.substring(offset+1);
37      } else {
38         return name;
39      }
40   }
41
42   protected void writeHeader(IndentationTarget pTarget) throws IOException JavaDoc {
43     if (pTarget.isInterface()) {
44       return;
45     }
46     pTarget.indent(0);
47     JavaSource.Protection protection = getProtection();
48     if (protection != null && !protection.equals(JavaSource.DEFAULT_PROTECTION)) {
49       pTarget.write(getProtection().toString());
50       pTarget.write(" ");
51     }
52     pTarget.write(getName());
53     pTarget.write("(");
54     Parameter[] params = getParams();
55     for (int i = 0; i < params.length; i++) {
56       if (i > 0) {
57         pTarget.write(", ");
58       }
59       Parameter p = params[i];
60       pTarget.write(pTarget.asString(p.getType()));
61       pTarget.write(" ");
62       pTarget.write(p.getName());
63     }
64     pTarget.write(")");
65     JavaQName[] exceptions = getExceptions();
66     for (int i = 0; i < exceptions.length; i++) {
67         if (i > 0) {
68           pTarget.write(", ");
69         } else {
70           pTarget.write(" throws ");
71         }
72       pTarget.write(pTarget.asString(exceptions[i]));
73     }
74     pTarget.write(" {");
75     pTarget.write();
76   }
77 }
78
Popular Tags