KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > sca > assembly > impl > JbiBindingImpl


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.sca.assembly.impl;
18
19 import java.util.List JavaDoc;
20
21 import javax.wsdl.Definition;
22 import javax.wsdl.Port;
23 import javax.wsdl.PortType;
24 import javax.wsdl.Service;
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.apache.servicemix.sca.assembly.JbiBinding;
28 import org.apache.tuscany.model.assembly.AssemblyModelContext;
29 import org.apache.tuscany.model.assembly.impl.BindingImpl;
30
31 /**
32  * An implementation of the model object '<em><b>Web Service Binding</b></em>'.
33  */

34 public class JbiBindingImpl extends BindingImpl implements JbiBinding {
35
36     private String JavaDoc portURI;
37     private QName JavaDoc serviceName;
38     private String JavaDoc endpointName;
39     private QName JavaDoc interfaceName;
40     private Definition definition;
41     private Service service;
42     private PortType portType;
43     private Port port;
44
45
46     /**
47      * Constructor
48      */

49     protected JbiBindingImpl() {
50     }
51
52     /* (non-Javadoc)
53      * @see org.apache.servicemix.sca.assembly.JbiBinding#getPortURI()
54      */

55     public String JavaDoc getPortURI() {
56         return portURI;
57     }
58
59     /* (non-Javadoc)
60      * @see org.apache.servicemix.sca.assembly.JbiBinding#setPortURI(java.lang.String)
61      */

62     public void setPortURI(String JavaDoc portURI) {
63         this.portURI = portURI;
64     }
65
66     /* (non-Javadoc)
67      * @see org.apache.servicemix.sca.assembly.JbiBinding#getServiceName()
68      */

69     public QName JavaDoc getServiceName() {
70         return serviceName;
71     }
72
73     /* (non-Javadoc)
74      * @see org.apache.servicemix.sca.assembly.JbiBinding#getEndpointName()
75      */

76     public String JavaDoc getEndpointName() {
77         return endpointName;
78     }
79
80     /* (non-Javadoc)
81      * @see org.apache.servicemix.sca.assembly.JbiBinding#getInterfaceName()
82      */

83     public QName JavaDoc getInterfaceName() {
84         return interfaceName;
85     }
86
87     /* (non-Javadoc)
88      * @see org.apache.servicemix.sca.assembly.JbiBinding#getDefinition()
89      */

90     public Definition getDefinition() {
91         return definition;
92     }
93
94     /* (non-Javadoc)
95      * @see org.apache.servicemix.sca.assembly.JbiBinding#getService()
96      */

97     public Service getService() {
98         return service;
99     }
100
101     /* (non-Javadoc)
102      * @see org.apache.servicemix.sca.assembly.JbiBinding#getPort()
103      */

104     public Port getPort() {
105         return port;
106     }
107
108     /* (non-Javadoc)
109      * @see org.apache.servicemix.sca.assembly.JbiBinding#getPortType()
110      */

111     public PortType getPortType() {
112         return portType;
113     }
114
115     /**
116      * @see org.apache.tuscany.model.assembly.impl.BindingImpl#initialize(org.apache.tuscany.model.assembly.AssemblyModelContext)
117      */

118     public void initialize(AssemblyModelContext modelContext) {
119         if (isInitialized())
120             return;
121         super.initialize(modelContext);
122
123         // Get the service name and endpoint name
124
String JavaDoc[] parts = split(portURI);
125         serviceName = new QName JavaDoc(parts[0], parts[1]);
126         endpointName = parts[2];
127         
128         // Load the WSDL definitions for the given namespace
129
List JavaDoc<Definition> definitions = modelContext.getAssemblyLoader().loadDefinitions(parts[0]);
130         if (definitions != null) {
131             for (Definition definition : definitions) {
132                 Service service = definition.getService(serviceName);
133                 if (service != null) {
134                     Port port = service.getPort(endpointName);
135                     if (port != null) {
136                         this.service = service;
137                         this.port = port;
138                         this.portType = port.getBinding().getPortType();
139                         this.interfaceName = portType.getQName();
140                         this.definition = definition;
141                         return;
142                     }
143                 }
144             }
145         }
146     }
147
148     protected String JavaDoc[] split(String JavaDoc uri) {
149         char sep;
150         uri = uri.trim();
151         if (uri.indexOf('/') > 0) {
152             sep = '/';
153         } else {
154             sep = ':';
155         }
156         int idx1 = uri.lastIndexOf(sep);
157         int idx2 = uri.lastIndexOf(sep, idx1 - 1);
158         String JavaDoc epName = uri.substring(idx1 + 1);
159         String JavaDoc svcName = uri.substring(idx2 + 1, idx1);
160         String JavaDoc nsUri = uri.substring(0, idx2);
161         return new String JavaDoc[] { nsUri, svcName, epName };
162     }
163     
164 }
165
Popular Tags