1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
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
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 import java.text.ParseException;
37
38 import javax.xml.xpath.XPath;
39 import javax.xml.xpath.XPathConstants;
40 import javax.xml.xpath.XPathExpressionException;
41 import javax.xml.xpath.XPathFactory;
42
43 import com.sun.istack.internal.SAXParseException2;
44 import com.sun.istack.internal.NotNull;
45 import com.sun.istack.internal.Nullable;
46 import com.sun.tools.internal.xjc.ErrorReceiver;
47 import com.sun.tools.internal.xjc.reader.Const;
48 import com.sun.tools.internal.xjc.util.DOMUtils;
49 import com.sun.xml.internal.bind.v2.util.EditDistance;
50 import com.sun.xml.internal.xsom.SCD;
51 import java.io.File;
52 import java.io.IOException;
53 import java.util.logging.Level;
54 import java.util.logging.Logger;
55 import javax.xml.XMLConstants;
56
57 import org.w3c.dom.Attr;
58 import org.w3c.dom.Document;
59 import org.w3c.dom.Element;
60 import org.w3c.dom.NamedNodeMap;
61 import org.w3c.dom.Node;
62 import org.w3c.dom.NodeList;
63 import org.xml.sax.SAXParseException;
64
65 /**
66 * Internalizes external binding declarations.
67 *
68 * <p>
69 * The {@link #transform(DOMForest,boolean)} method is the entry point.
70 *
71 * @author
72 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
73 */
74 class Internalizer {
75
76 private static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
77
78 private static final XPathFactory xpf = XPathFactory.newInstance();
79
80 private final XPath xpath = xpf.newXPath();
81
82 /**
83 * Internalize all <jaxb:bindings> customizations in the given forest.
84 *
85 * @return
86 * if the SCD support is enabled, the return bindings need to be applied
87 * after schema components are parsed.
88 * If disabled, the returned binding set will be empty.
89 * SCDs are only for XML Schema, and doesn't make any sense for other
90 * schema languages.
91 */
92 static SCDBasedBindingSet transform( DOMForest forest, boolean enableSCD ) {
93 return new Internalizer( forest, enableSCD ).transform();
94 }
95
96
97 private Internalizer( DOMForest forest, boolean enableSCD ) {
98 this.errorHandler = forest.getErrorHandler();
99 this.forest = forest;
100 this.enableSCD = enableSCD;
101 }
102
103 /**
104 * DOMForest object currently being processed.
105 */
106 private final DOMForest forest;
107
108 /**
109 * All errors found during the transformation is sent to this object.
110 */
111 private ErrorReceiver errorHandler;
112
113 /**
114 * If true, the SCD-based target selection is supported.
115 */
116 private boolean enableSCD;
117
118
119 private SCDBasedBindingSet transform() {
120
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
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
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 import java.text.ParseException;
37
38 import javax.xml.xpath.XPath;
39 import javax.xml.xpath.XPathConstants;
40 import javax.xml.xpath.XPathExpressionException;
41 import javax.xml.xpath.XPathFactory;
42
43 import com.sun.istack.internal.SAXParseException2;
44 import com.sun.istack.internal.NotNull;
45 import com.sun.istack.internal.Nullable;
46 import com.sun.tools.internal.xjc.ErrorReceiver;
47 import com.sun.tools.internal.xjc.reader.Const;
48 import com.sun.tools.internal.xjc.util.DOMUtils;
49 import com.sun.xml.internal.bind.v2.util.EditDistance;
50 import com.sun.xml.internal.bind.v2.util.XmlFactory;
51 import com.sun.xml.internal.xsom.SCD;
52 import java.io.File;
53 import java.io.IOException;
54 import java.util.logging.Level;
55 import java.util.logging.Logger;
56 import javax.xml.XMLConstants;
57
58 import org.w3c.dom.Attr;
59 import org.w3c.dom.Document;
60 import org.w3c.dom.Element;
61 import org.w3c.dom.NamedNodeMap;
62 import org.w3c.dom.Node;
63 import org.w3c.dom.NodeList;
64 import org.xml.sax.SAXParseException;
65
66 /**
67 * Internalizes external binding declarations.
68 *
69 * <p>
70 * The {@link #transform(DOMForest,boolean)} method is the entry point.
71 *
72 * @author
73 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
74 */
75 class Internalizer {
76
77 private static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
78
79 private static XPathFactory xpf = null;
80
81 private final XPath xpath;
82
83 /**
84 * Internalize all <jaxb:bindings> customizations in the given forest.
85 *
86 * @return
87 * if the SCD support is enabled, the return bindings need to be applied
88 * after schema components are parsed.
89 * If disabled, the returned binding set will be empty.
90 * SCDs are only for XML Schema, and doesn't make any sense for other
91 * schema languages.
92 */
93 static SCDBasedBindingSet transform( DOMForest forest, boolean enableSCD, boolean disableSecureProcessing ) {
94 return new Internalizer(forest, enableSCD, disableSecureProcessing).transform();
95 }
96
97
98 private Internalizer(DOMForest forest, boolean enableSCD, boolean disableSecureProcessing) {
99 this.errorHandler = forest.getErrorHandler();
100 this.forest = forest;
101 this.enableSCD = enableSCD;
102 synchronized (this) {
103 if (xpf == null) {
104 xpf = XmlFactory.createXPathFactory(disableSecureProcessing);
105 }
106 }
107 xpath = xpf.newXPath();
108 }
109
110 /**
111 * DOMForest object currently being processed.
112 */
113 private final DOMForest forest;
114
115 /**
116 * All errors found during the transformation is sent to this object.
117 */
118 private ErrorReceiver errorHandler;
119
120 /**
121 * If true, the SCD-based target selection is supported.
122 */
123 private boolean enableSCD;
124
125
126 private SCDBasedBindingSet transform() {
127
|