01: /*
02: * Copyright 2006-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.ws.wsdl.wsdl11;
18:
19: import java.io.IOException;
20: import javax.xml.transform.Source;
21: import javax.xml.transform.sax.SAXSource;
22:
23: import org.springframework.beans.factory.InitializingBean;
24: import org.springframework.core.io.Resource;
25: import org.springframework.util.Assert;
26: import org.springframework.ws.wsdl.WsdlDefinitionException;
27: import org.springframework.xml.sax.SaxUtils;
28:
29: /**
30: * The default {@link Wsdl11Definition} implementation.
31: * <p/>
32: * <p>Allows a WSDL to be set by the {@link #setWsdl wsdl} property, or directly in the {@link
33: * #SimpleWsdl11Definition(org.springframework.core.io.Resource) constructor}.
34: *
35: * @author Arjen Poutsma
36: * @since 1.0.0
37: */
38: public class SimpleWsdl11Definition implements Wsdl11Definition,
39: InitializingBean {
40:
41: private Resource wsdlResource;
42:
43: /**
44: * Create a new instance of the <code>SimpleWsdl11Definition</code> class. <p>A subsequent call to the {@link
45: * #setWsdl(org.springframework.core.io.Resource)} method is required.
46: */
47: public SimpleWsdl11Definition() {
48: }
49:
50: /**
51: * Create a new instance of the <code>SimpleWsdl11Definition</code> class.
52: *
53: * @param wsdlResource the WSDL resource; must not be <code>null</code>
54: * @throws IllegalArgumentException if the supplied <code>wsdlResource</code> is <code>null</code>
55: */
56: public SimpleWsdl11Definition(Resource wsdlResource) {
57: Assert.notNull(wsdlResource, "wsdlResource must not be null");
58: this .wsdlResource = wsdlResource;
59: }
60:
61: public void afterPropertiesSet() throws Exception {
62: Assert.notNull(this .wsdlResource, "wsdl is required");
63: Assert.isTrue(this .wsdlResource.exists(), "wsdl '"
64: + this .wsdlResource + "' does not exit");
65: }
66:
67: public Source getSource() {
68: try {
69: return new SAXSource(SaxUtils
70: .createInputSource(this .wsdlResource));
71: } catch (IOException ex) {
72: throw new WsdlDefinitionException(
73: "Could not create source from " + this .wsdlResource,
74: ex);
75: }
76: }
77:
78: /**
79: * Set the WSDL resource to be exposed by calls to this instances' {@link #getSource()} method.
80: *
81: * @param wsdlResource the WSDL resource
82: */
83: public void setWsdl(Resource wsdlResource) {
84: this.wsdlResource = wsdlResource;
85: }
86:
87: }
|