01: /*
02: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25: package com.sun.tools.internal.ws.processor.modeler.wsdl;
26:
27: import com.sun.tools.internal.xjc.api.ClassNameAllocator;
28: import com.sun.tools.internal.ws.processor.util.ClassNameCollector;
29:
30: import java.util.Set;
31: import java.util.HashSet;
32: import java.util.Map;
33: import java.util.HashMap;
34:
35: /**
36: * @author Vivek Pandey
37: * <p/>
38: * Implementation of Callback interface that allows the driver of the XJC API to rename JAXB-generated classes/interfaces/enums.
39: */
40: public class ClassNameAllocatorImpl implements ClassNameAllocator {
41: public ClassNameAllocatorImpl(ClassNameCollector classNameCollector) {
42: this .classNameCollector = classNameCollector;
43: this .jaxbClasses = new HashSet<String>();
44: }
45:
46: public String assignClassName(String packageName, String className) {
47: if (packageName == null || className == null) {
48: //TODO: throw Exception
49: return className;
50: }
51:
52: //if either of the values are empty string return the default className
53: if (packageName.equals("") || className.equals(""))
54: return className;
55:
56: String fullClassName = packageName + "." + className;
57:
58: // Check if there is any conflict with jaxws generated classes
59: Set<String> seiClassNames = classNameCollector
60: .getSeiClassNames();
61: if (seiClassNames != null
62: && seiClassNames.contains(fullClassName)) {
63: className += TYPE_SUFFIX;
64: }
65:
66: jaxbClasses.add(packageName + "." + className);
67: return className;
68: }
69:
70: /**
71: *
72: * @return jaxbGenerated classNames
73: */
74: public Set<String> getJaxbGeneratedClasses() {
75: return jaxbClasses;
76: }
77:
78: private final static String TYPE_SUFFIX = "_Type";
79: private ClassNameCollector classNameCollector;
80: private Set<String> jaxbClasses;
81: }
|