author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.internal.xjc.api.impl.s2j; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Collection; |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
||
34 |
import javax.xml.namespace.QName; |
|
35 |
||
36 |
import com.sun.codemodel.internal.JCodeModel; |
|
37 |
import com.sun.codemodel.internal.JClass; |
|
38 |
import com.sun.tools.internal.xjc.Plugin; |
|
39 |
import com.sun.tools.internal.xjc.api.ErrorListener; |
|
40 |
import com.sun.tools.internal.xjc.api.JAXBModel; |
|
41 |
import com.sun.tools.internal.xjc.api.Mapping; |
|
42 |
import com.sun.tools.internal.xjc.api.S2JJAXBModel; |
|
43 |
import com.sun.tools.internal.xjc.api.TypeAndAnnotation; |
|
44 |
import com.sun.tools.internal.xjc.model.CClassInfo; |
|
45 |
import com.sun.tools.internal.xjc.model.CElementInfo; |
|
46 |
import com.sun.tools.internal.xjc.model.Model; |
|
47 |
import com.sun.tools.internal.xjc.model.TypeUse; |
|
48 |
import com.sun.tools.internal.xjc.outline.Outline; |
|
49 |
import com.sun.tools.internal.xjc.outline.PackageOutline; |
|
50 |
||
51 |
/** |
|
52 |
* {@link JAXBModel} implementation. |
|
53 |
* |
|
54 |
* @author |
|
55 |
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
|
56 |
*/ |
|
57 |
final class JAXBModelImpl implements S2JJAXBModel { |
|
58 |
/*package*/ final Outline outline; |
|
59 |
||
60 |
/** |
|
61 |
* All the known classes. |
|
62 |
*/ |
|
63 |
private final Model model; |
|
64 |
||
65 |
private final Map<QName,Mapping> byXmlName = new HashMap<QName,Mapping>(); |
|
66 |
||
67 |
JAXBModelImpl(Outline outline) { |
|
68 |
this.model = outline.getModel(); |
|
69 |
this.outline = outline; |
|
70 |
||
71 |
for (CClassInfo ci : model.beans().values()) { |
|
72 |
if(!ci.isElement()) |
|
73 |
continue; |
|
74 |
byXmlName.put(ci.getElementName(),new BeanMappingImpl(this,ci)); |
|
75 |
} |
|
76 |
for (CElementInfo ei : model.getElementMappings(null).values()) { |
|
77 |
byXmlName.put(ei.getElementName(),new ElementMappingImpl(this,ei)); |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
public JCodeModel generateCode(Plugin[] extensions,ErrorListener errorListener) { |
|
82 |
// we no longer do any code generation |
|
83 |
return outline.getCodeModel(); |
|
84 |
} |
|
85 |
||
86 |
public List<JClass> getAllObjectFactories() { |
|
87 |
List<JClass> r = new ArrayList<JClass>(); |
|
88 |
for (PackageOutline pkg : outline.getAllPackageContexts()) { |
|
89 |
r.add(pkg.objectFactory()); |
|
90 |
} |
|
91 |
return r; |
|
92 |
} |
|
93 |
||
94 |
public final Mapping get(QName elementName) { |
|
95 |
return byXmlName.get(elementName); |
|
96 |
} |
|
97 |
||
98 |
public final Collection<? extends Mapping> getMappings() { |
|
99 |
return byXmlName.values(); |
|
100 |
} |
|
101 |
||
102 |
public TypeAndAnnotation getJavaType(QName xmlTypeName) { |
|
103 |
// TODO: primitive type handling? |
|
104 |
TypeUse use = model.typeUses().get(xmlTypeName); |
|
105 |
if(use==null) return null; |
|
106 |
||
107 |
return new TypeAndAnnotationImpl(outline,use); |
|
108 |
} |
|
109 |
||
110 |
public final List<String> getClassList() { |
|
111 |
List<String> classList = new ArrayList<String>(); |
|
112 |
||
113 |
// list up root classes |
|
114 |
for( PackageOutline p : outline.getAllPackageContexts() ) |
|
115 |
classList.add( p.objectFactory().fullName() ); |
|
116 |
return classList; |
|
117 |
} |
|
118 |
} |