01: /**
02: * Copyright 2004-2005 jManage.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package org.jmanage.core.services;
16:
17: import org.jmanage.core.services.ServiceContext;
18: import org.jmanage.core.auth.User;
19: import org.jmanage.core.config.ApplicationConfig;
20: import org.jmanage.core.management.ObjectName;
21: import org.jmanage.core.management.ServerConnection;
22: import org.jmanage.core.management.ServerConnector;
23: import org.jmanage.core.util.Loggers;
24: import java.util.logging.Logger;
25:
26: /**
27: *
28: * date: Jan 19, 2005
29: * @author Rakesh Kalra
30: * @author Shashank Bellary
31: */
32: public class ServiceContextImpl implements ServiceContext {
33:
34: private static final Logger logger = Loggers
35: .getLogger(ServiceContextImpl.class);
36:
37: private User user;
38: private String appName;
39: private String mbeanName;
40:
41: private transient ServerConnection serverConnection;
42:
43: public User getUser() {
44: return user;
45: }
46:
47: public void setUser(User user) {
48: this .user = user;
49: }
50:
51: /**
52: *
53: * @param user
54: */
55: public void _setUser(User user) {
56: }
57:
58: public ApplicationConfig getApplicationConfig() {
59: assert appName != null;
60: return ServiceUtils.getApplicationConfigByName(appName);
61: }
62:
63: public ObjectName getObjectName() {
64: assert mbeanName != null;
65: String mbeanName = ServiceUtils.resolveMBeanName(
66: getApplicationConfig(), this .mbeanName);
67: return new ObjectName(mbeanName);
68: }
69:
70: public ServerConnection getServerConnection() {
71: ApplicationConfig appConfig = getApplicationConfig();
72: assert appConfig != null;
73: assert !appConfig.isCluster() : "not supported for cluster";
74: if (serverConnection == null) {
75: serverConnection = ServerConnector
76: .getServerConnection(appConfig);
77: }
78: return serverConnection;
79: }
80:
81: /**
82: * @param appName configured application mame
83: */
84: public void setApplicationName(String appName) {
85: this .appName = appName;
86: }
87:
88: /**
89: * @param mbeanName configured mbean name or object name
90: */
91: public void setMBeanName(String mbeanName) {
92: this .mbeanName = mbeanName;
93: }
94:
95: public void releaseResources() {
96: ServiceUtils.close(serverConnection);
97: serverConnection = null;
98: }
99: }
|