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: */
19: package org.apache.axis2.description.java2wsdl;
20:
21: import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
22:
23: /**
24: * This class provides the default implementatoin for mapping java classes to namespaces
25: *
26: */
27: public class DefaultNamespaceGenerator implements NamespaceGenerator {
28: public static final String HTTP = "http://";
29: public static final char PACKAGE_CLASS_DELIMITER = '.';
30: public static final String SCHEMA_NAMESPACE_EXTN = "/xsd";
31:
32: /* (non-Javadoc)
33: * @see org.apache.axis2.description.java2wsdl.NamespaceGenerator#namespaceFromPackageName(java.lang.String)
34: */
35: public StringBuffer namespaceFromPackageName(String packageName) {
36:
37: StringBuffer strBuf = new StringBuffer();
38: int prevIndex = packageName.length();
39: int currentIndex = packageName
40: .lastIndexOf(PACKAGE_CLASS_DELIMITER);
41: if (currentIndex > 0) {
42: strBuf.append(HTTP);
43: } else if (prevIndex > 0) {
44: strBuf.append(HTTP);
45: strBuf.append(packageName);
46: return strBuf;
47: } else if (currentIndex == -1) {
48: // strBuf.append(HTTP);
49: // strBuf.append(packageName);
50: return strBuf;
51: }
52: while (currentIndex != -1) {
53: strBuf.append(packageName.substring(currentIndex + 1,
54: prevIndex));
55: prevIndex = currentIndex;
56: currentIndex = packageName.lastIndexOf(
57: PACKAGE_CLASS_DELIMITER, prevIndex - 1);
58: strBuf.append(PACKAGE_CLASS_DELIMITER);
59:
60: if (currentIndex == -1) {
61: strBuf.append(packageName.substring(0, prevIndex));
62: }
63: }
64: return strBuf;
65: }
66:
67: /* (non-Javadoc)
68: * @see org.apache.axis2.description.java2wsdl.NamespaceGenerator#schemaNamespaceFromPackageName(java.lang.String)
69: */
70: public StringBuffer schemaNamespaceFromPackageName(
71: String packageName) {
72: if (packageName.length() > 0) {
73: return namespaceFromPackageName(packageName).append(
74: SCHEMA_NAMESPACE_EXTN);
75: } else {
76: StringBuffer buffer = new StringBuffer();
77: buffer.append(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
78: buffer.append(SCHEMA_NAMESPACE_EXTN);
79: return buffer;
80: }
81: }
82:
83: }
|