KickJava   Java API By Example, From Geeks To Geeks.

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


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>Implements a Java method.</p>
23  *
24  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
25  */

26 public class JavaMethod extends AbstractJavaMethod {
27   private boolean isSynchronized;
28
29   /** <p>Creates a new JavaMethod with the given name, return
30    * type and protection.</p>
31    */

32   JavaMethod(String JavaDoc pName, JavaQName pType, JavaSource.Protection pProtection) {
33     super(pName, pType, pProtection);
34   }
35
36   /** <p>Sets whether this method is synchronized.</p>
37    */

38   public void setSynchronized(boolean pSynchronized) {
39     isSynchronized = pSynchronized;
40   }
41
42   /** <p>Returns whether this method is synchronized.</p>
43     */

44   public boolean isSynchronized() {
45     return isSynchronized;
46   }
47
48   /** <p>Adds a header line.</p>
49    */

50   protected void writeHeader(IndentationTarget pTarget) throws IOException JavaDoc {
51     pTarget.indent(0);
52     JavaSource.Protection protection = getProtection();
53     if (protection != null && !protection.equals(JavaSource.DEFAULT_PROTECTION)) {
54       pTarget.write(getProtection().toString());
55       pTarget.write(" ");
56     }
57     if (isStatic()) {
58       pTarget.write("static ");
59     }
60     if (isFinal()) {
61       pTarget.write("final ");
62     }
63     if (isAbstract()) {
64       pTarget.write("abstract ");
65     }
66     if (isSynchronized() && !pTarget.isInterface()) {
67         pTarget.write("synchronized ");
68     }
69      pTarget.write(pTarget.asString(getType()));
70     pTarget.write(" ");
71     pTarget.write(getName());
72     pTarget.write("(");
73     Parameter[] params = getParams();
74     for (int i = 0; i < params.length; i++) {
75       if (i > 0) {
76         pTarget.write(", ");
77       }
78       Parameter p = params[i];
79       pTarget.write(pTarget.asString(p.getType()) );
80       pTarget.write(" ");
81       pTarget.write(p.getName());
82     }
83     pTarget.write(")");
84     JavaQName[] exceptions = getExceptions();
85     for (int i = 0; i < exceptions.length; i++) {
86         if (i > 0) {
87           pTarget.write(", ");
88         } else {
89           pTarget.write(" throws ");
90         }
91       pTarget.write(pTarget.asString(exceptions[i]));
92     }
93     if (pTarget.isInterface() || isAbstract()) {
94       pTarget.write(";");
95     } else {
96       pTarget.write(" {");
97     }
98     pTarget.write();
99   }
100
101   /** <p>Returns the abbreviated method signature: The method name, followed
102    * by the parameter types. This is typically used in logging statements.</p>
103    */

104   public String JavaDoc getLoggingSignature() {
105     StringBuffer JavaDoc result = new StringBuffer JavaDoc(getName());
106     Parameter[] params = getParams();
107     if (params.length > 0) {
108       result.append('(');
109       for (int i = 0; i < params.length; i++) {
110         if (i > 0) { result.append(','); }
111         result.append(params[i].getType().getClassName());
112       }
113       result.append(')');
114     }
115     return result.toString();
116   }
117
118   /** <p>Returns whether the JavaMethod is void.</p>
119    */

120   public boolean isVoid() {
121     return getType().equals(JavaQNameImpl.VOID);
122   }
123 }
124
Popular Tags