KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.jbi.JBIException;
20 import javax.management.JMException JavaDoc;
21 import javax.management.MBeanOperationInfo JavaDoc;
22 import javax.naming.NamingException JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.servicemix.client.DefaultServiceMixClient;
27 import org.apache.servicemix.client.ServiceMixClient;
28 import org.apache.servicemix.jbi.management.BaseSystemService;
29 import org.apache.servicemix.jbi.management.OperationInfoHelper;
30
31 /**
32  * @author <a HREF="mailto:gnodet [at] apache.org">Guillaume Nodet</a>
33  */

34 public class ClientFactory extends BaseSystemService implements ClientFactoryMBean {
35
36     private static final Log logger = LogFactory.getLog(ClientFactory.class);
37     
38     private String JavaDoc jndiName = DEFAULT_JNDI_NAME;
39     
40     public ClientFactory() {
41     }
42     
43     /**
44      * @return the jndiName
45      */

46     public String JavaDoc getJndiName() {
47         return jndiName;
48     }
49
50     /**
51      * @param jndiName the jndiName to set
52      */

53     public void setJndiName(String JavaDoc jndiName) {
54         this.jndiName = jndiName;
55     }
56
57     public ServiceMixClient createClient() throws JBIException {
58         return new DefaultServiceMixClient(getContainer());
59     }
60
61     protected Class JavaDoc getServiceMBean() {
62         return ClientFactoryMBean.class;
63     }
64
65     public String JavaDoc getDescription() {
66         return "Client Factory Service";
67     }
68
69     public MBeanOperationInfo JavaDoc[] getOperationInfos() throws JMException JavaDoc {
70         OperationInfoHelper helper = new OperationInfoHelper();
71         helper.addOperation(getObjectToManage(), "createClient", 0, "create a new client");
72         return OperationInfoHelper.join(super.getOperationInfos(), helper.getOperationInfos());
73     }
74
75     /**
76      * Start the item.
77      *
78      * @exception javax.jbi.JBIException if the item fails to start.
79      */

80     public void start() throws javax.jbi.JBIException {
81         try {
82             getContainer().getNamingContext().bind(jndiName, this);
83             super.start();
84         } catch (NamingException JavaDoc e) {
85             logger.error("Cound not start ClientFactory: " + e);
86             if (logger.isDebugEnabled()) {
87                 logger.debug("Could not start ClientFactory", e);
88             }
89         }
90     }
91
92     /**
93      * Stop the item. This suspends current messaging activities.
94      *
95      * @exception javax.jbi.JBIException if the item fails to stop.
96      */

97     public void stop() throws javax.jbi.JBIException {
98         try {
99             super.stop();
100             getContainer().getNamingContext().unbind(jndiName);
101         } catch (NamingException JavaDoc e) {
102             logger.error("Cound not stop ClientFactory: " + e);
103             if (logger.isDebugEnabled()) {
104                 logger.debug("Could not stop ClientFactory", e);
105             }
106         }
107     }
108
109 }
110
Popular Tags