KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > framework > Endpoint


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.jbi.framework;
18
19 import java.beans.PropertyChangeListener JavaDoc;
20
21 import javax.management.JMException JavaDoc;
22 import javax.management.MBeanAttributeInfo JavaDoc;
23 import javax.management.MBeanOperationInfo JavaDoc;
24 import javax.xml.namespace.QName JavaDoc;
25 import javax.xml.transform.TransformerException JavaDoc;
26
27 import org.apache.servicemix.jbi.management.AttributeInfoHelper;
28 import org.apache.servicemix.jbi.management.MBeanInfoProvider;
29 import org.apache.servicemix.jbi.management.OperationInfoHelper;
30 import org.apache.servicemix.jbi.servicedesc.AbstractServiceEndpoint;
31 import org.apache.servicemix.jbi.servicedesc.ExternalEndpoint;
32 import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
33 import org.apache.servicemix.jbi.servicedesc.LinkedEndpoint;
34 import org.apache.servicemix.jbi.util.DOMUtil;
35
36 public class Endpoint implements EndpointMBean, MBeanInfoProvider {
37
38     private AbstractServiceEndpoint endpoint;
39     private Registry registry;
40     
41     public Endpoint(AbstractServiceEndpoint endpoint, Registry registry) {
42         this.endpoint = endpoint;
43         this.registry = registry;
44     }
45
46     public String JavaDoc getEndpointName() {
47         return endpoint.getEndpointName();
48     }
49
50     public QName JavaDoc[] getInterfaces() {
51         return endpoint.getInterfaces();
52     }
53
54     public QName JavaDoc getServiceName() {
55         return endpoint.getServiceName();
56     }
57     
58     public String JavaDoc getReference() {
59         try {
60             return DOMUtil.asIndentedXML(endpoint.getAsReference(null));
61         } catch (TransformerException JavaDoc e) {
62             return null;
63         }
64     }
65     
66     public String JavaDoc getWSDL() {
67         try {
68             return DOMUtil.asXML(registry.getEndpointDescriptor(endpoint));
69         } catch (Exception JavaDoc e) {
70             return null;
71         }
72     }
73
74     public String JavaDoc getComponentName() {
75         if (endpoint.getComponentNameSpace() != null) {
76             return endpoint.getComponentNameSpace().getName();
77         } else {
78             return null;
79         }
80     }
81
82     public MBeanAttributeInfo JavaDoc[] getAttributeInfos() throws JMException JavaDoc {
83         AttributeInfoHelper helper = new AttributeInfoHelper();
84         helper.addAttribute(getObjectToManage(), "endpointName", "name of the endpoint");
85         helper.addAttribute(getObjectToManage(), "serviceName", "name of the service");
86         helper.addAttribute(getObjectToManage(), "componentName", "component name of the service unit");
87         helper.addAttribute(getObjectToManage(), "interfaces", "interfaces implemented by this endpoint");
88         return helper.getAttributeInfos();
89     }
90
91     public MBeanOperationInfo JavaDoc[] getOperationInfos() throws JMException JavaDoc {
92         OperationInfoHelper helper = new OperationInfoHelper();
93         helper.addOperation(getObjectToManage(), "getReference", "retrieve the endpoint reference");
94         helper.addOperation(getObjectToManage(), "getWSDL", "retrieve the wsdl description of this endpoint");
95         return helper.getOperationInfos();
96     }
97
98     public Object JavaDoc getObjectToManage() {
99         return this;
100     }
101
102     public String JavaDoc getName() {
103         return endpoint.getServiceName() + endpoint.getEndpointName();
104     }
105
106     public String JavaDoc getType() {
107         return "Endpoint";
108     }
109
110     public String JavaDoc getSubType() {
111         if (endpoint instanceof InternalEndpoint) {
112             return "Internal";
113         } else if (endpoint instanceof LinkedEndpoint) {
114             return "Linked";
115         } else if (endpoint instanceof ExternalEndpoint) {
116             return "External";
117         }
118         return null;
119     }
120
121     public String JavaDoc getDescription() {
122         return null;
123     }
124
125     public void setPropertyChangeListener(PropertyChangeListener JavaDoc l) {
126     }
127
128     protected AbstractServiceEndpoint getEndpoint() {
129         return endpoint;
130     }
131
132 }
133
Popular Tags