1 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 ; 26 27 33 public class ServiceContextImpl implements ServiceContext { 34 35 private static final Logger logger = 36 Loggers.getLogger(ServiceContextImpl.class); 37 38 private User user; 39 private String appName; 40 private String 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 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 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 86 public void setApplicationName(String appName) { 87 this.appName = appName; 88 } 89 90 93 public void setMBeanName(String mbeanName){ 94 this.mbeanName = mbeanName; 95 } 96 97 public void releaseResources() { 98 ServiceUtils.close(serverConnection); 99 serverConnection = null; 100 } 101 } 102 | Popular Tags |