KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > wsm > model > jsr181 > Jsr181ParameterMetadataImpl


1 package org.apache.beehive.wsm.model.jsr181;
2
3 /*
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Header:$
19  */

20
21 import java.lang.annotation.Annotation JavaDoc;
22 import java.util.Collection JavaDoc;
23
24 import javax.jws.WebParam;
25
26 import javax.xml.namespace.QName JavaDoc; // todo (mmerz@apache.org, 01/25/05): this needs to go...
27

28 import org.apache.beehive.wsm.model.BeehiveWsParameterMetadata;
29 import org.apache.beehive.wsm.model.ValidationException;
30 import org.apache.beehive.wsm.model.java.JavaParameterInfo;
31
32 public class Jsr181ParameterMetadataImpl implements BeehiveWsParameterMetadata, java.io.Serializable JavaDoc {
33     
34     private static final long serialVersionUID = 1L;
35
36     private String JavaDoc wpName;
37     private String JavaDoc wpTargetNamespace;
38     private WebParam.Mode wpMode;
39     private boolean wpHeader;
40     private Class JavaDoc javaType;
41     private QName JavaDoc mXMLType;
42
43
44     public void validate() throws ValidationException {
45         return; // no validation required
46
}
47
48     public Jsr181ParameterMetadataImpl() {
49     }
50
51     // defaultName is argument name in the source file. It can be null if the
52
// name is not known.
53
public Jsr181ParameterMetadataImpl(JavaParameterInfo jp) {
54
55         // check input params
56
if (null == jp) {
57             jp.logError("illegal java parameter info: <null>");
58             return;
59         }
60         
61         javaType = jp.getType();
62         
63         // set default values
64
setWpName(jp.getName());
65         setWpMode(WebParam.Mode.IN);
66         
67         // set optional annotations
68
Collection JavaDoc<Annotation JavaDoc> annotations = jp.getAnnotations();
69         if (null != annotations) {
70             for (Annotation JavaDoc a : annotations) {
71                 if (a.annotationType() == WebParam.class) {
72                     initFromAnnotation((WebParam) a);
73                 }
74                 else {
75                     // todo: warning -- unknown annotation
76
}
77             }
78         }
79     }
80
81     public boolean isWpHeader() {
82         return wpHeader;
83     }
84
85     public void setWpHeader(boolean wpHeader) {
86         this.wpHeader = wpHeader;
87     }
88
89     public WebParam.Mode getWpMode() {
90         return wpMode;
91     }
92
93     public void setWpMode(WebParam.Mode wpMode) {
94         this.wpMode = wpMode;
95     }
96
97     public String JavaDoc getWpName() {
98         return wpName;
99     }
100
101     public void setWpName(String JavaDoc wpName) {
102         this.wpName = wpName;
103     }
104
105     public String JavaDoc getWpTargetNamespace() {
106          return wpTargetNamespace;
107     }
108
109     public void setWpTargetNamespace(String JavaDoc wpTargetNamespace) {
110         this.wpTargetNamespace = wpTargetNamespace;
111     }
112
113     public Class JavaDoc getJavaType() {
114         return javaType;
115     }
116
117     public void setJavaType(Class JavaDoc javaType) {
118         this.javaType = javaType;
119     }
120
121     private void initFromAnnotation(WebParam annotation) {
122         if (null != annotation) {
123             if (0 < annotation.name().length()) {
124                 setWpName(annotation.name());
125             }
126             setWpTargetNamespace(annotation.targetNamespace());
127             setWpMode(annotation.mode());
128             setWpHeader(annotation.header());
129         }
130     }
131
132     /* (non-Javadoc)
133      * @see org.apache.beehive.wsm.jsr181.model.Jsr181ParameterMetadata#getJavaTypeFullName()
134      *
135      * NOTE THIS METHOD AND SUPPORTING METHOD SHOULD BE MOVED OUT TO A ELEMENT CLASS
136      * THAT ENCAPSULATES QNAME AND CLASS
137      */

138     public String JavaDoc getJavaTypeFullName() {
139         return getClassName(getJavaType());
140
141     }
142     private String JavaDoc getClassName(Class JavaDoc cls) {
143             if (cls.isArray()) {
144                 return getClassName(cls.getComponentType()) + "[]";
145             }
146             else {
147                 return cls.getName().replace('$', '.');
148             }
149     }
150     
151     public QName JavaDoc getXmlType() {
152         return mXMLType;
153     }
154
155     public void setXmlType(QName JavaDoc xmlType) {
156         mXMLType = xmlType;
157     }
158 }
159
Popular Tags