use of org.apache.catalina.Container in project tomcat by apache.
the class MBeanFactory method createValve.
/**
* Create a new Valve and associate it with a {@link Container}.
*
* @param className The fully qualified class name of the {@link Valve} to
* create
* @param parent The MBean name of the associated parent
* {@link Container}.
*
* @return The MBean name of the {@link Valve} that was created or
* <code>null</code> if the {@link Valve} does not implement
* {@link JmxEnabled}.
* @exception Exception if an MBean cannot be created or registered
*/
public String createValve(String className, String parent) throws Exception {
// Look for the parent
ObjectName parentName = new ObjectName(parent);
Container container = getParentContainerFromParent(parentName);
if (container == null) {
// TODO
throw new IllegalArgumentException();
}
Valve valve = (Valve) Class.forName(className).newInstance();
container.getPipeline().addValve(valve);
if (valve instanceof JmxEnabled) {
return ((JmxEnabled) valve).getObjectName().toString();
} else {
return null;
}
}
use of org.apache.catalina.Container in project tomcat by apache.
the class MBeanFactory method removeValve.
/**
* Remove an existing Valve.
*
* @param name MBean Name of the component to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeValve(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
Container container = getParentContainerFromChild(oname);
Valve[] valves = container.getPipeline().getValves();
for (int i = 0; i < valves.length; i++) {
ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
if (voname.equals(oname)) {
container.getPipeline().removeValve(valves[i]);
}
}
}
use of org.apache.catalina.Container in project tomcat by apache.
the class MBeanFactory method removeLoader.
/**
* Remove an existing Loader.
*
* @param name MBean Name of the component to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeLoader(String name) throws Exception {
ObjectName oname = new ObjectName(name);
// Acquire a reference to the component to be removed
Container container = getParentContainerFromChild(oname);
if (container instanceof Context) {
((Context) container).setLoader(null);
}
}
use of org.apache.catalina.Container in project tomcat by apache.
the class MBeanFactory method getParentContainerFromChild.
/**
* Get Parent ContainerBase to add its child component
* from child component's ObjectName as a String
*/
private Container getParentContainerFromChild(ObjectName oname) throws Exception {
String hostName = oname.getKeyProperty("host");
String path = oname.getKeyProperty("path");
Service service = getService(oname);
Container engine = service.getContainer();
if (hostName == null) {
// child's container is Engine
return engine;
} else if (path == null) {
// child's container is Host
Container host = engine.findChild(hostName);
return host;
} else {
// child's container is Context
Container host = engine.findChild(hostName);
path = getPathStr(path);
Container context = host.findChild(path);
return context;
}
}
use of org.apache.catalina.Container in project tomcat by apache.
the class MBeanFactory method getParentContainerFromParent.
/**
* Get Parent Container to add its child component
* from parent's ObjectName
*/
private Container getParentContainerFromParent(ObjectName pname) throws Exception {
String type = pname.getKeyProperty("type");
String j2eeType = pname.getKeyProperty("j2eeType");
Service service = getService(pname);
StandardEngine engine = (StandardEngine) service.getContainer();
if ((j2eeType != null) && (j2eeType.equals("WebModule"))) {
String name = pname.getKeyProperty("name");
name = name.substring(2);
int i = name.indexOf('/');
String hostName = name.substring(0, i);
String path = name.substring(i);
Container host = engine.findChild(hostName);
String pathStr = getPathStr(path);
Container context = host.findChild(pathStr);
return context;
} else if (type != null) {
if (type.equals("Engine")) {
return engine;
} else if (type.equals("Host")) {
String hostName = pname.getKeyProperty("host");
Container host = engine.findChild(hostName);
return host;
}
}
return null;
}
Aggregations