jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ap/SchemaGenerator.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
20 * |
20 * |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
|
26 |
|
27 |
25 |
28 package com.sun.tools.internal.jxc.ap; |
26 package com.sun.tools.internal.jxc.ap; |
29 |
27 |
30 import com.sun.tools.internal.jxc.api.JXC; |
28 import com.sun.tools.internal.jxc.api.JXC; |
31 import com.sun.tools.internal.xjc.api.J2SJAXBModel; |
29 import com.sun.tools.internal.xjc.api.J2SJAXBModel; |
87 |
85 |
88 @Override |
86 @Override |
89 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
87 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
90 final ErrorReceiverImpl errorListener = new ErrorReceiverImpl(processingEnv); |
88 final ErrorReceiverImpl errorListener = new ErrorReceiverImpl(processingEnv); |
91 |
89 |
92 List<Reference> classes = new ArrayList<Reference>(); |
90 List<Reference> classesToBeBound = new ArrayList<Reference>(); |
93 // simply ignore all the interface definitions, |
91 // simply ignore all the interface definitions, |
94 // so that users won't have to manually exclude interfaces, which is silly. |
92 // so that users won't have to manually exclude interfaces, which is silly. |
95 filterClass(classes, roundEnv.getRootElements()); |
93 filterClass(classesToBeBound, roundEnv.getRootElements()); |
96 |
94 |
97 J2SJAXBModel model = JXC.createJavaCompiler().bind(classes, Collections.<QName, Reference>emptyMap(), null, processingEnv); |
95 J2SJAXBModel model = JXC.createJavaCompiler().bind(classesToBeBound, Collections.<QName, Reference>emptyMap(), null, processingEnv); |
98 if (model == null) |
96 if (model == null) |
99 return false; // error |
97 return false; // error |
100 |
98 |
101 try { |
99 try { |
102 model.generateSchema( |
100 model.generateSchema( |
131 errorListener.error(e.getMessage(), e); |
129 errorListener.error(e.getMessage(), e); |
132 } |
130 } |
133 return false; |
131 return false; |
134 } |
132 } |
135 |
133 |
136 private void filterClass(List<Reference> classes, Collection<? extends Element> elements) { |
134 /** |
|
135 * Filter classes (note that enum is kind of class) from elements tree |
|
136 * @param result list of found classes |
|
137 * @param elements tree to be filtered |
|
138 */ |
|
139 private void filterClass(List<Reference> result, Collection<? extends Element> elements) { |
137 for (Element element : elements) { |
140 for (Element element : elements) { |
138 if (element.getKind().equals(ElementKind.CLASS) || element.getKind().equals(ElementKind.ENUM)) { |
141 final ElementKind kind = element.getKind(); |
139 classes.add(new Reference((TypeElement) element, processingEnv)); |
142 if (ElementKind.CLASS.equals(kind) || ElementKind.ENUM.equals(kind)) { |
140 filterClass(classes, ElementFilter.typesIn(element.getEnclosedElements())); |
143 result.add(new Reference((TypeElement) element, processingEnv)); |
|
144 filterClass(result, ElementFilter.typesIn(element.getEnclosedElements())); |
141 } |
145 } |
142 } |
146 } |
143 } |
147 } |
144 |
148 |
145 @Override |
149 @Override |