package org.jboss.ejb;
import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.ejb.plugins.local.BaseLocalProxyFactory;
import org.jboss.ejb.txtimer.EJBTimerService;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.InvocationKey;
import org.jboss.invocation.InvocationStatistics;
import org.jboss.invocation.InvocationType;
import org.jboss.invocation.MarshalledInvocation;
import org.jboss.logging.Logger;
import org.jboss.metadata.ApplicationMetaData;
import org.jboss.metadata.BeanMetaData;
import org.jboss.metadata.EjbLocalRefMetaData;
import org.jboss.metadata.EjbRefMetaData;
import org.jboss.metadata.EnvEntryMetaData;
import org.jboss.metadata.MessageDestinationMetaData;
import org.jboss.metadata.MessageDestinationRefMetaData;
import org.jboss.metadata.ResourceEnvRefMetaData;
import org.jboss.metadata.ResourceRefMetaData;
import org.jboss.mx.util.MBeanProxy;
import org.jboss.mx.util.ObjectNameConverter;
import org.jboss.mx.util.ObjectNameFactory;
import org.jboss.naming.ENCThreadLocalKey;
import org.jboss.naming.NonSerializableFactory;
import org.jboss.naming.Util;
import org.jboss.security.AuthenticationManager;
import org.jboss.security.RealmMapping;
import org.jboss.security.AnybodyPrincipal;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.util.NestedError;
import org.jboss.util.NestedRuntimeException;
import org.jboss.webservice.WebServiceClientHandler;
import org.omg.CORBA.ORB;
import javax.ejb.EJBException;
import javax.ejb.EJBObject;
import javax.ejb.TimerService;
import javax.ejb.Timer;
import javax.ejb.TimedObject;
import javax.ejb.spi.HandleDelegate;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.LinkRef;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.transaction.TransactionManager;
import javax.xml.soap.SOAPMessage;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.Policy;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
public abstract class Container
extends ServiceMBeanSupport
implements ContainerMBean, AllowedOperationsFlags
{
public final static String BASE_EJB_CONTAINER_NAME =
"jboss.j2ee:service=EJB";
public final static ObjectName ORB_NAME = ObjectNameFactory.create("jboss:service=CorbaORB");
public final static ObjectName EJB_CONTAINER_QUERY_NAME =
ObjectNameFactory.create(BASE_EJB_CONTAINER_NAME + ",*");
protected static final Method EJBOBJECT_REMOVE;
protected static final Method EJB_TIMEOUT;
protected EjbModule ejbModule;
protected ClassLoader localClassLoader;
protected ClassLoader classLoader;
protected ClassLoader webClassLoader;
private DeploymentInfo di;
protected BeanMetaData metaData;
protected Class beanClass;
protected Class homeInterface;
protected Class remoteInterface;
protected Class localHomeInterface;
protected Class localInterface;
protected TransactionManager tm;
protected AuthenticationManager sm;
protected RealmMapping rm;
protected Object securityProxy;
protected BeanLockManager lockManager;
protected LocalProxyFactory localProxyFactory =
new BaseLocalProxyFactory();
private HashMap methodPermissionsCache = new HashMap();
protected Map marshalledInvocationMapping = new HashMap();
private ObjectName jmxName;
protected HashMap proxyFactories = new HashMap();
private MBeanServerAction serverAction = new MBeanServerAction();
protected ThreadLocal proxyFactoryTL = new ThreadLocal();
protected long createCount;
protected long removeCount;
protected InvocationStatistics invokeStats = new InvocationStatistics();
protected String jaccContextID;
static
{
try
{
EJBOBJECT_REMOVE = EJBObject.class.getMethod("remove", new Class[0]);
EJB_TIMEOUT = TimedObject.class.getMethod("ejbTimeout", new Class[]{Timer.class});
}
catch (Throwable t)
{
throw new NestedRuntimeException(t);
}
}
public Class getLocalClass()
{
return localInterface;
}
public Class getLocalHomeClass()
{
return localHomeInterface;
}
public Class getRemoteClass()
{
return remoteInterface;
}
public Class getHomeClass()
{
return homeInterface;
}
public boolean isCallByValue()
{
if (ejbModule.isCallByValue())
return true;
return metaData.isCallByValue();
}
public void setTransactionManager(final TransactionManager tm)
{
this.tm = tm;
}
public TransactionManager getTransactionManager()
{
return tm;
}
public void setSecurityManager(AuthenticationManager sm)
{
this.sm = sm;
}
public AuthenticationManager getSecurityManager()
{
return sm;
}
public BeanLockManager getLockManager()
{
return lockManager;
}
public void setLockManager(final BeanLockManager lockManager)
{
this.lockManager = lockManager;
lockManager.setContainer(this);
}
public void addProxyFactory(String invokerBinding, EJBProxyFactory factory)
{
proxyFactories.put(invokerBinding, factory);
}
public void setRealmMapping(final RealmMapping rm)
{
this.rm = rm;
}
public RealmMapping getRealmMapping()
{
return rm;
}
public void setSecurityProxy(Object proxy)
{
this.securityProxy = proxy;
}
public Object getSecurityProxy()
{
return securityProxy;
}
public EJBProxyFactory getProxyFactory()
{
EJBProxyFactory factory = (EJBProxyFactory)proxyFactoryTL.get();
if (factory == null && remoteInterface != null)
{
Iterator i = proxyFactories.values().iterator();
if (i.hasNext())
factory = (EJBProxyFactory)i.next();
}
return factory;
}
public void setProxyFactory(Object factory)
{
proxyFactoryTL.set(factory);
}
public EJBProxyFactory lookupProxyFactory(String binding)
{
return (EJBProxyFactory)proxyFactories.get(binding);
}
public final DeploymentInfo getDeploymentInfo()
{
return di;
}
public final void setDeploymentInfo(DeploymentInfo di)
{
this.di = di;
}
public void setEjbModule(EjbModule app)
{
ejbModule = app;
}
public String getJaccContextID()
{
return jaccContextID;
}
public void setJaccContextID(String id)
{
jaccContextID = id;
}
public EjbModule getEjbModule()
{
return ejbModule;
}
public long getCreateCount()
{
return createCount;
}
public long getRemoveCount()
{
return removeCount;
}
public InvocationStatistics getInvokeStats()
{
return invokeStats;
}
public void setLocalClassLoader(ClassLoader cl)
{
this.localClassLoader = cl;
}
public ClassLoader getLocalClassLoader()
{
return localClassLoader;
}
public void setClassLoader(ClassLoader cl)
{
this.classLoader = cl;
}
public ClassLoader getClassLoader()
{
return classLoader;
}
public ClassLoader getWebClassLoader()
{
return webClassLoader;
}
public void setWebClassLoader(final ClassLoader webClassLoader)
{
this.webClassLoader = webClassLoader;
}
public void setBeanMetaData(final BeanMetaData metaData)
{
this.metaData = metaData;
}
public Context getEnvContext() throws NamingException
{
ClassLoader ccl = SecurityActions.getContextClassLoader();
try
{
SecurityActions.setContextClassLoader(classLoader);
return (Context)new InitialContext().lookup("java:comp/env");
}
finally
{
SecurityActions.setContextClassLoader(ccl);
}
}
public BeanMetaData getBeanMetaData()
{
return metaData;
}
public Set getMethodPermissions(Method m, InvocationType iface)
{
Set permissions;
if (methodPermissionsCache.containsKey(m))
{
permissions = (Set) methodPermissionsCache.get(m);
}
else if( m.equals(EJB_TIMEOUT) )
{
permissions = new HashSet();
permissions.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
methodPermissionsCache.put(m, permissions);
}
else
{
String name = m.getName();
Class[] sig = m.getParameterTypes();
permissions = getBeanMetaData().getMethodPermissions(name, sig, iface);
methodPermissionsCache.put(m, permissions);
}
return permissions;
}
public Class getBeanClass()
{
return beanClass;
}
public Object createBeanClassInstance() throws Exception
{
return getBeanClass().newInstance();
}
public ObjectName getJmxName()
{
if (jmxName == null)
{
BeanMetaData beanMetaData = getBeanMetaData();
if (beanMetaData == null)
{
throw new IllegalStateException("Container metaData is null");
}
String jndiName = beanMetaData.getContainerObjectNameJndiName();
if (jndiName == null)
{
throw new IllegalStateException("Container jndiName is null");
}
String name = BASE_EJB_CONTAINER_NAME + ",jndiName=" + jndiName;
try
{
jmxName = ObjectNameConverter.convert(name);
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException("Failed to create ObjectName, msg=" + e.getMessage());
}
}
return jmxName;
}
public TimerService getTimerService(Object pKey)
throws IllegalStateException
{
if (this instanceof StatefulSessionContainer)
throw new IllegalStateException("Statefull Session Beans are not allowed to access the TimerService");
TimerService timerService = null;
try
{
EJBTimerService service = (EJBTimerService)MBeanProxy.get(EJBTimerService.class, EJBTimerService.OBJECT_NAME, server);
timerService = service.createTimerService(getJmxName(), pKey, this);
}
catch (Exception e)
{
throw new EJBException("Could not create timer service", e);
}
return timerService;
}
public void removeTimerService(Object pKey)
throws IllegalStateException
{
try
{
EJBTimerService service = (EJBTimerService)MBeanProxy.get(EJBTimerService.class, EJBTimerService.OBJECT_NAME, server);
service.removeTimerService(getJmxName(), pKey);
}
catch (Exception e)
{
log.error("Could not remove timer service", e);
}
}
protected void createService() throws Exception
{
beanClass = classLoader.loadClass(metaData.getEjbClass());
if (metaData.getLocalHome() != null)
localHomeInterface = classLoader.loadClass(metaData.getLocalHome());
if (metaData.getLocal() != null)
localInterface = classLoader.loadClass(metaData.getLocal());
localProxyFactory.setContainer(this);
localProxyFactory.create();
if (localHomeInterface != null)
ejbModule.addLocalHome(this, localProxyFactory.getEJBLocalHome());
ejbModule.createMissingPermissions(this, metaData);
Policy.getPolicy().refresh();
}
protected void startService() throws Exception
{
setupEnvironment();
localProxyFactory.start();
}
protected void stopService() throws Exception
{
localProxyFactory.stop();
removeTimerService(null);
teardownEnvironment();
}
protected void destroyService() throws Exception
{
localProxyFactory.destroy();
ejbModule.removeLocalHome(this);
beanClass = null;
homeInterface = null;
remoteInterface = null;
localHomeInterface = null;
localInterface = null;
methodPermissionsCache.clear();
invokeStats.resetStats();
marshalledInvocationMapping.clear();
}
public abstract Object internalInvokeHome(Invocation mi)
throws Exception;
public abstract Object internalInvoke(Invocation mi)
throws Exception;
abstract Interceptor createContainerInterceptor();
public abstract void addInterceptor(Interceptor in);
public Object invoke(Invocation mi)
throws Exception
{
ClassLoader callerClassLoader = SecurityActions.getContextClassLoader();
long start = System.currentTimeMillis();
Method m = null;
boolean setCl = false;
Object type = null;
String contextID = getJaccContextID();
try
{
if (!callerClassLoader.equals(classLoader))
{
setCl = true;
SecurityActions.setContextClassLoader(this.classLoader);
}
mi.setValue(InvocationKey.JACC_CONTEXT_ID, contextID);
contextID = SecurityActions.setContextID(contextID);
if (mi.getType() != InvocationType.SERVICE_ENDPOINT)
{
EJBArgsPolicyContextHandler.setArgs(mi.getArguments());
}
else
{
SOAPMessage msg = (SOAPMessage)mi.getValue(InvocationKey.SOAP_MESSAGE);
SOAPMsgPolicyContextHandler.setMessage(msg);
}
BeanMetaDataPolicyContextHandler.setMetaData(this.getBeanMetaData());
type = mi.getType();
this.invokeStats.callIn();
if (type == InvocationType.REMOTE ||
type == InvocationType.LOCAL ||
type == InvocationType.SERVICE_ENDPOINT)
{
if (mi instanceof MarshalledInvocation)
{
((MarshalledInvocation)mi).setMethodMap(marshalledInvocationMapping);
if (log.isTraceEnabled())
{
log.trace("METHOD REMOTE INVOKE " +
mi.getObjectName() + "||" +
mi.getMethod().getName() + "||");
}
}
m = mi.getMethod();
Object obj = internalInvoke(mi);
return obj;
}
else if (type == InvocationType.HOME ||
type == InvocationType.LOCALHOME)
{
if (mi instanceof MarshalledInvocation)
{
((MarshalledInvocation)mi).setMethodMap(marshalledInvocationMapping);
if (log.isTraceEnabled())
{
log.trace("METHOD HOME INVOKE " +
mi.getObjectName() + "||" +
mi.getMethod().getName() + "||" +
mi.getArguments().toString());
}
}
m = mi.getMethod();
Object obj = internalInvokeHome(mi);
return obj;
}
else
{
throw new MBeanException(new IllegalArgumentException("Unknown invocation type: " + type));
}
}
finally
{
if (m != null)
{
long end = System.currentTimeMillis();
long elapsed = end - start;
this.invokeStats.updateStats(m, elapsed);
}
this.invokeStats.callOut();
if (setCl)
{
SecurityActions.setContextClassLoader(callerClassLoader);
}
contextID = SecurityActions.setContextID(contextID);
if (mi.getType() == InvocationType.SERVICE_ENDPOINT)
{
SOAPMsgPolicyContextHandler.setMessage(null);
}
}
}
private void setupEnvironment() throws Exception
{
boolean debug = log.isDebugEnabled();
BeanMetaData beanMetaData = getBeanMetaData();
if (debug)
{
log.debug("Begin java:comp/env for EJB: " + beanMetaData.getEjbName());
ClassLoader tcl = SecurityActions.getContextClassLoader();
log.debug("TCL: " + tcl);
}
ORB orb = null;
HandleDelegate hd = null;
try
{
orb = (ORB)server.getAttribute(ORB_NAME, "ORB");
hd = (HandleDelegate)server.getAttribute(ORB_NAME, "HandleDelegate");
}
catch (Throwable t)
{
log.debug("Unable to retrieve orb" + t.toString());
}
Context ctx = (Context)new InitialContext().lookup("java:comp");
if (orb != null)
{
NonSerializableFactory.rebind(ctx, "ORB", orb);
log.debug("Bound java:comp/ORB for EJB: " + getBeanMetaData().getEjbName());
NonSerializableFactory.rebind(ctx, "HandleDelegate", hd);
log.debug("Bound java:comp:/HandleDelegate for EJB: " + getBeanMetaData().getEjbName());
}
Context envCtx = ctx.createSubcontext("env");
{
Iterator enum = beanMetaData.getEnvironmentEntries();
while (enum.hasNext())
{
EnvEntryMetaData entry = (EnvEntryMetaData)enum.next();
if (debug)
{
log.debug("Binding env-entry: " + entry.getName() + " of type: " +
entry.getType() + " to value:" + entry.getValue());
}
EnvEntryMetaData.bindEnvEntry(envCtx, entry);
}
}
{
Iterator enum = beanMetaData.getEjbReferences();
while (enum.hasNext())
{
EjbRefMetaData ref = (EjbRefMetaData)enum.next();
if (debug)
log.debug("Binding an EJBReference " + ref.getName());
if (ref.getLink() != null)
{
String linkName = ref.getLink();
String jndiName = EjbUtil.findEjbLink(server, di, linkName);
if (debug)
{
log.debug("Binding " + ref.getName() +
" to ejb-link: " + linkName + " -> " + jndiName);
}
if (jndiName == null)
{
String msg = "Failed to resolve ejb-link: " + linkName
+ " make by ejb-name: " + ref.getName();
throw new DeploymentException(msg);
}
Util.bind(envCtx,
ref.getName(),
new LinkRef(jndiName));
}
else
{
Iterator it = beanMetaData.getInvokerBindings();
Reference reference = null;
while (it.hasNext())
{
String invokerBinding = (String)it.next();
String name = ref.getInvokerBinding(invokerBinding);
if (name == null)
name = ref.getJndiName();
if (name == null)
{
throw new DeploymentException
("ejb-ref " + ref.getName() +
", expected either ejb-link in ejb-jar.xml or " +
"jndi-name in jboss.xml");
}
StringRefAddr addr = new StringRefAddr(invokerBinding, name);
log.debug("adding " + invokerBinding + ":" + name +
" to Reference");
if (reference == null)
{
reference = new Reference("javax.naming.LinkRef",
ENCThreadLocalKey.class.getName(),
null);
}
reference.add(addr);
}
if (reference != null)
{
if (ref.getJndiName() != null)
{
StringRefAddr addr =
new StringRefAddr("default", ref.getJndiName());
reference.add(addr);
}
if (reference.size() == 1 && reference.get("default") == null)
{
StringRefAddr addr = (StringRefAddr)reference.get(0);
String target = (String)addr.getContent();
StringRefAddr addr1 = new StringRefAddr("default", target);
reference.add(addr1);
}
Util.bind(envCtx, ref.getName(), reference);
}
else
{
if (ref.getJndiName() == null)
{
throw new DeploymentException("ejb-ref " + ref.getName() +
", expected either ejb-link in ejb-jar.xml " +
"or jndi-name in jboss.xml");
}
Util.bind(envCtx,
ref.getName(),
new LinkRef(ref.getJndiName()));
}
}
}
}
{
Iterator enum = beanMetaData.getEjbLocalReferences();
while (enum.hasNext())
{
EjbLocalRefMetaData ref = (EjbLocalRefMetaData)enum.next();
String refName = ref.getName();
log.debug("Binding an EJBLocalReference " + ref.getName());
if (ref.getLink() != null)
{
log.debug("Binding " + refName + " to bean source: " + ref.getLink());
String jndiName = EjbUtil.findLocalEjbLink(server, di,
ref.getLink());
Util.bind(envCtx,
ref.getName(),
new LinkRef(jndiName));
}
else
{
if (ref.getJndiName() == null)
{
throw new DeploymentException("ejb-local-ref " + ref.getName() +
", expected either ejb-link in ejb-jar.xml " +
"or local-jndi-name in jboss.xml");
}
Util.bind(envCtx,
ref.getName(),
new LinkRef(ref.getJndiName()));
}
}
}
Iterator serviceRefs = metaData.getServiceReferences().values().iterator();
WebServiceClientHandler.setupServiceRefEnvironment(envCtx, serviceRefs, di);
{
Iterator enum = beanMetaData.getResourceReferences();
ApplicationMetaData application =
beanMetaData.getApplicationMetaData();
while (enum.hasNext())
{
ResourceRefMetaData ref = (ResourceRefMetaData)enum.next();
String resourceName = ref.getResourceName();
String finalName = application.getResourceByName(resourceName);
String resType = ref.getType();
if (finalName == null)
finalName = ref.getJndiName();
if (finalName == null && resType.equals("java.net.URL") == false)
{
if (ref.getType().equals("javax.sql.DataSource"))
{
Context dsCtx = new InitialContext();
try
{
dsCtx.lookup("java:/DefaultDS");
finalName = "java:/DefaultDS";
}
catch (Exception e)
{
if (debug)
log.debug("failed to lookup DefaultDS; ignoring", e);
}
finally
{
dsCtx.close();
}
}
if (finalName == null)
{
log.warn("No resource manager found for " +
ref.getResourceName());
continue;
}
}
if (resType.equals("java.net.URL"))
{
if (ref.getResURL() != null)
{
log.debug("Binding URL: " + ref.getRefName() +
" to JDNI ENC as: " + ref.getResURL());
URL resURL = new URL(ref.getResURL());
Util.bind(envCtx, ref.getRefName(), resURL);
}
else
{
log.debug("Binding URL: " + ref.getRefName() + " to: " + finalName);
Object bind = null;
if (ref.getJndiName() != null)
{
bind = new LinkRef(finalName);
}
else
{
bind = new URL(finalName);
}
Util.bind(envCtx, ref.getRefName(), bind);
}
}
else
{
if (debug)
{
log.debug("Binding resource manager: " + ref.getRefName() +
" to JDNI ENC as: " + finalName);
}
Util.bind(envCtx, ref.getRefName(), new LinkRef(finalName));
}
}
}
{
Iterator enum = beanMetaData.getResourceEnvReferences();
while (enum.hasNext())
{
ResourceEnvRefMetaData resRef =
(ResourceEnvRefMetaData)enum.next();
String encName = resRef.getRefName();
String jndiName = resRef.getJndiName();
if (debug)
{
log.debug("Binding env resource: " + encName +
" to JDNI ENC as: " + jndiName);
}
Util.bind(envCtx, encName, new LinkRef(jndiName));
}
}
{
Iterator enum = beanMetaData.getMessageDestinationReferences();
while (enum.hasNext())
{
MessageDestinationRefMetaData ref = (MessageDestinationRefMetaData)enum.next();
String refName = ref.getRefName();
String jndiName = ref.getJNDIName();
String link = ref.getLink();
if (link != null)
{
if (jndiName == null)
{
MessageDestinationMetaData messageDestination = getMessageDestination(link);
if (messageDestination == null)
throw new DeploymentException("message-destination-ref '" + refName +
"' message-destination-link '" + link + "' not found and no jndi-name in jboss.xml");
else
{
String linkJNDIName = messageDestination.getJNDIName();
if (linkJNDIName == null)
log.warn("message-destination '" + link + "' has no jndi-name in jboss.xml");
else
jndiName = linkJNDIName;
}
}
else
log.warn("message-destination-ref '" + refName +
"' ignoring message-destination-link '" + link + "' because it has a jndi-name in jboss.xml");
}
else if (jndiName == null)
throw new DeploymentException("message-destination-ref '" + refName +
"' has no message-destination-link in ejb-jar.xml and no jndi-name in jboss.xml");
Util.bind(envCtx, refName, new LinkRef(jndiName));
}
}
String securityDomain =
metaData.getContainerConfiguration().getSecurityDomain();
if (securityDomain == null)
securityDomain = metaData.getApplicationMetaData().getSecurityDomain();
if (securityDomain != null)
{
if (debug)
{
log.debug("Binding securityDomain: " + securityDomain +
" to JDNI ENC as: security/security-domain");
}
Util.bind(envCtx,
"security/security-domain",
new LinkRef(securityDomain));
Util.bind(envCtx,
"security/subject",
new LinkRef(securityDomain + "/subject"));
}
if (debug)
log.debug("End java:comp/env for EJB: " + beanMetaData.getEjbName());
}
public MessageDestinationMetaData getMessageDestination(String link)
{
return EjbUtil.findMessageDestination(server, di, link);
}
private void teardownEnvironment() throws Exception
{
Context ctx = (Context)new InitialContext().lookup("java:comp");
ctx.unbind("env");
log.debug("Removed bindings from java:comp/env for EJB: " + getBeanMetaData().getEjbName());
try
{
NonSerializableFactory.unbind("ORB");
log.debug("Unbound java:comp/ORB for EJB: " + getBeanMetaData().getEjbName());
NonSerializableFactory.unbind("HandleDelegate");
log.debug("Unbound java:comp/HandleDelegate for EJB: " + getBeanMetaData().getEjbName());
}
catch (NamingException ignored)
{
}
}
protected abstract class AbstractContainerInterceptor
implements Interceptor
{
protected final Logger log = Logger.getLogger(this.getClass());
public void setContainer(Container con)
{
}
public void setNext(Interceptor interceptor)
{
}
public Interceptor getNext()
{
return null;
}
public void create()
{
}
public void start()
{
}
public void stop()
{
}
public void destroy()
{
}
protected void rethrow(Exception e)
throws Exception
{
if (e instanceof IllegalAccessException)
{
throw new EJBException(e);
}
else if (e instanceof InvocationTargetException)
{
Throwable t = ((InvocationTargetException)e).getTargetException();
if (t instanceof EJBException)
{
throw (EJBException)t;
}
else if (t instanceof Exception)
{
throw (Exception)t;
}
else if (t instanceof Error)
{
throw (Error)t;
}
else
{
throw new NestedError("Unexpected Throwable", t);
}
}
throw e;
}
public void sample(Object s)
{
}
public Map retrieveStatistic()
{
return null;
}
public void resetStatistic()
{
}
}
class MBeanServerAction implements PrivilegedExceptionAction
{
private ObjectName target;
String method;
Object[] args;
String[] sig;
MBeanServerAction()
{
}
MBeanServerAction(ObjectName target, String method, Object[] args, String[] sig)
{
this.target = target;
this.method = method;
this.args = args;
this.sig = sig;
}
public Object run() throws Exception
{
Object rtnValue = server.invoke(target, method, args, sig);
return rtnValue;
}
Object invoke(ObjectName target, String method, Object[] args, String[] sig)
throws Exception
{
SecurityManager sm = System.getSecurityManager();
Object rtnValue = null;
if (sm == null)
{
rtnValue = server.invoke(target, method, args, sig);
}
else
{
try
{
MBeanServerAction action = new MBeanServerAction(target, method, args, sig);
rtnValue = AccessController.doPrivileged(action);
}
catch (PrivilegedActionException e)
{
Exception ex = e.getException();
throw ex;
}
}
return rtnValue;
}
}
}