KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > core > JavaEEServiceEngineContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.jbi.serviceengine.core;
24 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
25 import com.sun.enterprise.jbi.serviceengine.config.ComponentConfiguration;
26 import com.sun.enterprise.jbi.serviceengine.work.WorkManagerImpl;
27 import com.sun.logging.LogDomains;
28 import java.util.Iterator JavaDoc;
29 import javax.jbi.JBIException;
30 import javax.jbi.component.ComponentContext;
31 import javax.jbi.messaging.DeliveryChannel;
32 import javax.jbi.messaging.MessagingException;
33 import javax.jbi.servicedesc.ServiceEndpoint;
34 import java.util.logging.Logger JavaDoc;
35 import java.util.logging.Level JavaDoc;
36
37 /**
38  * Wrapper for a JBI Context object, provides utility methods
39  * @author Manisha Umbarje
40  */

41 public class JavaEEServiceEngineContext {
42     
43     private ComponentContext jbiContext;
44     
45     private EndpointRegistry endpointRegistry;
46     
47     private DeliveryChannel seDeliveryChannel;
48     
49     private WorkManagerImpl workManager;
50     
51     private ComponentConfiguration config ;
52     
53     private Bridge bridge;
54     
55     private static JavaEEServiceEngineContext serviceEngineContext;
56     /**
57      * Internal handle to the logger instance
58      */

59     protected static final Logger JavaDoc logger =
60         LogDomains.getLogger(LogDomains.SERVER_LOGGER);
61
62             
63     /** Creates a new instance of JavaEEServiceEngineContext */
64     private JavaEEServiceEngineContext() {
65     }
66     
67     public static JavaEEServiceEngineContext getInstance() {
68         if (serviceEngineContext == null)
69             serviceEngineContext = new JavaEEServiceEngineContext();
70         return serviceEngineContext;
71     }
72     
73     public void initialize() throws ServiceEngineException {
74         endpointRegistry = EndpointRegistry.getInstance();
75         config = new ComponentConfiguration();
76         workManager = new WorkManagerImpl(config);
77         bridge = config.getBridge();
78         bridge.initialize();
79     }
80     /**
81      * Returns the context provided by the JBI environment to the
82      * service engine
83      */

84     public ComponentContext getJBIContext() {
85         return jbiContext;
86     }
87     
88     public DeliveryChannel getDeliveryChannel() {
89         return seDeliveryChannel;
90     }
91     
92     public WorkManagerImpl getWorkManager() {
93         return workManager;
94     }
95     
96     public Bridge getBridge() {
97         return bridge;
98     }
99     /**
100      *
101      */

102     public void setJBIContext(ComponentContext context)
103     throws MessagingException {
104         jbiContext = context;
105         seDeliveryChannel = jbiContext.getDeliveryChannel();
106         debug(Level.FINE, "Delivery Channel is : " + seDeliveryChannel);
107     }
108     
109     /**
110      * Gets the ServiceEndpoint Registry
111      */

112     public EndpointRegistry getRegistry() {
113         return endpointRegistry;
114     }
115     
116     /**
117      * Activates multiple end points in JBI
118      * @param endpoints list of end points to be activated in JBI
119      */

120     public void activateEndpoints(Iterator JavaDoc endpoints)
121     throws JBIException {
122         if (endpoints != null) {
123             while(endpoints.hasNext()) {
124                 ServiceEndpoint endpoint = (ServiceEndpoint)endpoints.next();
125                 jbiContext.activateEndpoint(
126                         endpoint.getServiceName(), endpoint.getEndpointName());
127             }
128         }
129         
130     }
131     
132     private void debug(Level JavaDoc logLevel, String JavaDoc msgID) {
133         logger.log(logLevel, msgID);
134     }
135
136 }
137
Popular Tags