1 /*
2 * Copyright (c) 1997, 2013, 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
466
467 /*
468 * Creates a pseudo schema for the WSDL schema fragments that have the same
469 * targetNamespace.
470 *
471 * <xsd:schema targetNamespace="X">
472 * <xsd:include schemaLocation="Y1"/>
473 * <xsd:include schemaLocation="Y2"/>
474 * </xsd:schema>
475 *
476 * @param tns targetNamespace of the the schema documents
477 * @param docs collection of systemId for the schema documents that have the
478 * same tns, the collection must have more than one document
479 * @param psuedoSystemId for the created pseudo schema
480 * @return Source of pseudo schema that can be used multiple times
481 */
482 private @Nullable Source createSameTnsPseudoSchema(String tns, Collection<String> docs, String pseudoSystemId) {
483 assert docs.size() > 1;
484
485 final StringBuilder sb = new StringBuilder("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'");
486 if (!"".equals(tns)) {
487 sb.append(" targetNamespace='").append(tns).append("'");
488 }
489 sb.append(">\n");
490 for(String systemId : docs) {
491 sb.append("<xsd:include schemaLocation='").append(systemId).append("'/>\n");
492 }
493 sb.append("</xsd:schema>\n");
494 if (LOGGER.isLoggable(Level.FINE)) {
495 LOGGER.log(Level.FINE, "Pseudo Schema for the same tns={0}is {1}", new Object[]{tns, sb});
496 }
497
498 // override getReader() so that the same source can be used multiple times
499 return new StreamSource(pseudoSystemId) {
500 @Override
501 public Reader getReader() {
502 return new StringReader(sb.toString());
503 }
504 };
505 }
506
|
1 /*
2 * Copyright (c) 1997, 2017, 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
466
467 /*
468 * Creates a pseudo schema for the WSDL schema fragments that have the same
469 * targetNamespace.
470 *
471 * <xsd:schema targetNamespace="X">
472 * <xsd:include schemaLocation="Y1"/>
473 * <xsd:include schemaLocation="Y2"/>
474 * </xsd:schema>
475 *
476 * @param tns targetNamespace of the the schema documents
477 * @param docs collection of systemId for the schema documents that have the
478 * same tns, the collection must have more than one document
479 * @param psuedoSystemId for the created pseudo schema
480 * @return Source of pseudo schema that can be used multiple times
481 */
482 private @Nullable Source createSameTnsPseudoSchema(String tns, Collection<String> docs, String pseudoSystemId) {
483 assert docs.size() > 1;
484
485 final StringBuilder sb = new StringBuilder("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'");
486 if (tns != null && !("".equals(tns)) && !("null".equals(tns))) {
487 sb.append(" targetNamespace='").append(tns).append("'");
488 }
489 sb.append(">\n");
490 for(String systemId : docs) {
491 sb.append("<xsd:include schemaLocation='").append(systemId).append("'/>\n");
492 }
493 sb.append("</xsd:schema>\n");
494 if (LOGGER.isLoggable(Level.FINE)) {
495 LOGGER.log(Level.FINE, "Pseudo Schema for the same tns={0}is {1}", new Object[]{tns, sb});
496 }
497
498 // override getReader() so that the same source can be used multiple times
499 return new StreamSource(pseudoSystemId) {
500 @Override
501 public Reader getReader() {
502 return new StringReader(sb.toString());
503 }
504 };
505 }
506
|