|
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 |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.util; |
|
27 |
|
28 import com.sun.istack.internal.NotNull; |
|
29 import com.sun.xml.internal.ws.api.server.SDDocument; |
|
30 import com.sun.xml.internal.ws.wsdl.SDDocumentResolver; |
|
31 |
|
32 import java.util.*; |
|
33 |
|
34 /** |
|
35 * WSDL, schema document metadata utility class. |
|
36 * |
|
37 * @author Jitendra Kotamraju |
|
38 */ |
|
39 public class MetadataUtil { |
|
40 |
|
41 /** |
|
42 * Gets closure of all the referenced documents from the primary document(typically |
|
43 * the service WSDL). It traverses the WSDL and schema imports and builds a closure |
|
44 * set of documents. |
|
45 * |
|
46 * @param systemId primary wsdl or the any root document |
|
47 * @param resolver used to get SDDocumentImpl for a document |
|
48 * @param onlyTopLevelSchemas if true, the imported schemas from a schema would be ignored |
|
49 * @return all the documents |
|
50 */ |
|
51 public static Map<String, SDDocument> getMetadataClosure(@NotNull String systemId, |
|
52 @NotNull SDDocumentResolver resolver, boolean onlyTopLevelSchemas) { |
|
53 Map <String, SDDocument> closureDocs = new HashMap<String, SDDocument>(); |
|
54 Set<String> remaining = new HashSet<String>(); |
|
55 remaining.add(systemId); |
|
56 |
|
57 while(!remaining.isEmpty()) { |
|
58 Iterator<String> it = remaining.iterator(); |
|
59 String current = it.next(); |
|
60 remaining.remove(current); |
|
61 |
|
62 SDDocument currentDoc = resolver.resolve(current); |
|
63 SDDocument old = closureDocs.put(currentDoc.getURL().toExternalForm(), currentDoc); |
|
64 assert old == null; |
|
65 |
|
66 Set<String> imports = currentDoc.getImports(); |
|
67 if (!currentDoc.isSchema() || !onlyTopLevelSchemas) { |
|
68 for(String importedDoc : imports) { |
|
69 if (closureDocs.get(importedDoc) == null) { |
|
70 remaining.add(importedDoc); |
|
71 } |
|
72 } |
|
73 } |
|
74 } |
|
75 |
|
76 return closureDocs; |
|
77 } |
|
78 |
|
79 } |