KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > services > ServiceContextImpl


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 package org.jmanage.core.services;
17
18 import org.jmanage.core.services.ServiceContext;
19 import org.jmanage.core.auth.User;
20 import org.jmanage.core.config.ApplicationConfig;
21 import org.jmanage.core.management.ObjectName;
22 import org.jmanage.core.management.ServerConnection;
23 import org.jmanage.core.management.ServerConnector;
24 import org.jmanage.core.util.Loggers;
25 import java.util.logging.Logger JavaDoc;
26
27 /**
28  *
29  * date: Jan 19, 2005
30  * @author Rakesh Kalra
31  * @author Shashank Bellary
32  */

33 public class ServiceContextImpl implements ServiceContext {
34
35     private static final Logger JavaDoc logger =
36             Loggers.getLogger(ServiceContextImpl.class);
37
38     private User user;
39     private String JavaDoc appName;
40     private String JavaDoc mbeanName;
41
42     private transient ServerConnection serverConnection;
43
44     public User getUser(){
45         return user;
46     }
47
48     public void setUser(User user){
49         this.user = user;
50     }
51
52     /**
53      *
54      * @param user
55      */

56     public void _setUser(User user) {
57     }
58
59     public ApplicationConfig getApplicationConfig() {
60         assert appName != null;
61         return ServiceUtils.getApplicationConfigByName(appName);
62     }
63
64     public ObjectName getObjectName() {
65         assert mbeanName != null;
66         String JavaDoc mbeanName =
67                 ServiceUtils.resolveMBeanName(getApplicationConfig(),
68                         this.mbeanName);
69         return new ObjectName(mbeanName);
70     }
71
72     public ServerConnection getServerConnection() {
73         ApplicationConfig appConfig = getApplicationConfig();
74         assert appConfig != null;
75         assert !appConfig.isCluster():"not supported for cluster";
76         if (serverConnection == null) {
77             serverConnection =
78                     ServerConnector.getServerConnection(appConfig);
79         }
80         return serverConnection;
81     }
82
83     /**
84      * @param appName configured application mame
85      */

86     public void setApplicationName(String JavaDoc appName) {
87         this.appName = appName;
88     }
89
90     /**
91      * @param mbeanName configured mbean name or object name
92      */

93     public void setMBeanName(String JavaDoc mbeanName){
94         this.mbeanName = mbeanName;
95     }
96
97     public void releaseResources() {
98         ServiceUtils.close(serverConnection);
99         serverConnection = null;
100     }
101 }
102
Popular Tags