1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.support.definition.support;
14
15 import com.eviware.soapui.impl.support.definition.DefinitionCache;
16 import com.eviware.soapui.impl.support.definition.InterfaceDefinitionPart;
17 import com.eviware.soapui.impl.wsdl.support.wsdl.AbstractWsdlDefinitionLoader;
18 import org.apache.xmlbeans.XmlException;
19 import org.apache.xmlbeans.XmlObject;
20 import org.apache.xmlbeans.XmlOptions;
21
22 import java.io.File;
23 import java.io.InputStream;
24 import java.util.List;
25
26 /***
27 * WsdlLoader for cached definitions
28 *
29 * @author ole.matzura
30 */
31
32 public class InterfaceCacheDefinitionLoader extends AbstractWsdlDefinitionLoader
33 {
34 private String rootInConfig = "";
35 private DefinitionCache config;
36
37 public InterfaceCacheDefinitionLoader( DefinitionCache config )
38 {
39 super( config.getRootPart().getUrl() );
40 this.config = config;
41 }
42
43 public InputStream load( String url ) throws Exception
44 {
45 XmlObject xmlObject = loadXmlObject( url, null );
46 return xmlObject == null ? null : xmlObject.newInputStream();
47 }
48
49 public XmlObject loadXmlObject( String url, XmlOptions options ) throws Exception
50 {
51
52 if( url.endsWith( config.getRootPart().getUrl() ))
53 {
54 rootInConfig = url.substring( 0, url.length() - config.getRootPart().getUrl().length() );
55 }
56
57 List<InterfaceDefinitionPart> partList = config.getDefinitionParts();
58 for( InterfaceDefinitionPart part : partList )
59 {
60 if( (rootInConfig + part.getUrl()).equalsIgnoreCase( url ) )
61 {
62 return getPartContent( part );
63 }
64 }
65
66
67 if( File.separatorChar == '/' )
68 {
69 url = url.replace( '/', '//' );
70
71 for( InterfaceDefinitionPart part : partList )
72 {
73 if( (rootInConfig + part.getUrl()).equalsIgnoreCase( url ) )
74 {
75 return getPartContent( part );
76 }
77 }
78 }
79
80 else if( File.separatorChar == '//' )
81 {
82 url = url.replace( '//', '/' );
83
84 for( InterfaceDefinitionPart part : partList )
85 {
86 if( (rootInConfig + part.getUrl()).equalsIgnoreCase( url ) )
87 {
88 return getPartContent( part );
89 }
90 }
91 }
92
93 return null;
94 }
95
96 public static XmlObject getPartContent( InterfaceDefinitionPart part ) throws XmlException
97 {
98 return XmlObject.Factory.parse( part.getContent(), new XmlOptions().setLoadLineNumbers() );
99 }
100
101 public void close()
102 {
103 }
104
105 public void setNewBaseURI(String uri)
106 {
107
108 }
109
110 public String getFirstNewURI()
111 {
112 return getBaseURI();
113 }
114 }