Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
URLWSDLLocator.java
Go to the documentation of this file.
1 
2 package vmi1;
3 
4 import javax.wsdl.xml.WSDLLocator;
5 import org.xml.sax.InputSource;
6 
7 import java.util.Map;
8 import java.util.HashMap;
9 import java.util.Set;
10 import java.util.Iterator;
11 
12 import java.net.URL;
13 import java.net.MalformedURLException;
14 import java.net.URISyntaxException;
15 
16 import java.io.InputStream;
17 import java.io.IOException;
18 
19 public class URLWSDLLocator implements WSDLLocator {
20  protected URL url;
21  protected Map<String,URL> urlMap;
22  protected Map<String,InputStream> inputStreamMap;
23  protected URL lastImportedURL = null;
24 
25  public URLWSDLLocator(URL url) {
26  this.url = url;
27  this.urlMap = new HashMap<String,URL>();
28  this.inputStreamMap = new HashMap<String,InputStream>();
29  }
30 
31  public void close() {
32  Set<Map.Entry<String,InputStream>> isms = inputStreamMap.entrySet();
33  Iterator<Map.Entry<String,InputStream>> isi = isms.iterator();
34  while (isi.hasNext()) {
35  Map.Entry<String,InputStream> me = isi.next();
36  try {
37  me.getValue().close();
38  }
39  catch (Exception ex) { }
40  }
41 
42  inputStreamMap.clear();
43  urlMap.clear();
44  lastImportedURL = null;
45  }
46 
47  public InputSource getBaseInputSource() {
48  InputSource newInputSource = null;
49  InputStream is = inputStreamMap.get(url.toString());
50  if (is != null)
51  return new InputSource(is);
52  else {
53  try {
54  is = url.openStream();
55  }
56  catch (IOException ex) {
57  ex.printStackTrace();
58  return null;
59  }
60  newInputSource = new InputSource(is);
61  urlMap.put(url.toString(),url);
62  inputStreamMap.put(url.toString(),is);
63  return newInputSource;
64  }
65 
66  }
67 
68  public String getBaseURI() {
69  String uri = null;
70  try {
71  uri = url.toURI().toString();
72  }
73  catch (URISyntaxException ex) {
74  ex.printStackTrace();
75  }
76  return uri;
77  }
78 
79  public InputSource getImportInputSource(String parentLocation,
80  String importLocation) {
81  URL newImportedURL = null;
82  try {
83  URL parentLocationURL = new URL(parentLocation);
84 
85  newImportedURL = new URL(parentLocationURL,importLocation);
86  }
87  catch (MalformedURLException ex) {
88  ex.printStackTrace();
89  return null;
90  }
91 
92  InputStream newInputStream = inputStreamMap.get(newImportedURL.toString());
93  if (newInputStream != null) {
94  lastImportedURL = newImportedURL;
95  return new InputSource(newInputStream);
96  }
97  else {
98  try {
99  newInputStream = newImportedURL.openStream();
100  }
101  catch (IOException ex) {
102  ex.printStackTrace();
103  return null;
104  }
105  InputSource newInputSource = new InputSource(newInputStream);
106 
107  urlMap.put(newImportedURL.toString(),newImportedURL);
108  inputStreamMap.put(newImportedURL.toString(),newInputStream);
109 
110  lastImportedURL = newImportedURL;
111 
112  return newInputSource;
113  }
114  }
115 
116  public String getLatestImportURI() {
117  if (lastImportedURL != null)
118  return lastImportedURL.toString();
119  return null;
120  }
121 }
InputSource getImportInputSource(String parentLocation, String importLocation)
Map< String, InputStream > inputStreamMap
Map< String, URL > urlMap
InputSource getBaseInputSource()