Search in sources :

Example 11 with NamingResources

use of org.apache.catalina.deploy.NamingResources in project tomcat70 by apache.

the class NamingResourcesMBean method removeResourceLink.

/**
 * Remove any resource link reference with the specified name.
 *
 * @param resourceLinkName Name of the resource link reference to remove
 */
public void removeResourceLink(String resourceLinkName) {
    resourceLinkName = ObjectName.unquote(resourceLinkName);
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink == null) {
        throw new IllegalArgumentException("Invalid resource Link name '" + resourceLinkName + "'");
    }
    nresources.removeResourceLink(resourceLinkName);
}
Also used : ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) NamingResources(org.apache.catalina.deploy.NamingResources)

Example 12 with NamingResources

use of org.apache.catalina.deploy.NamingResources in project tomcat70 by apache.

the class NamingResourcesMBean method removeEnvironment.

/**
 * Remove any environment entry with the specified name.
 *
 * @param envName Name of the environment entry to remove
 */
public void removeEnvironment(String envName) {
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return;
    }
    ContextEnvironment env = nresources.findEnvironment(envName);
    if (env == null) {
        throw new IllegalArgumentException("Invalid environment name '" + envName + "'");
    }
    nresources.removeEnvironment(envName);
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) NamingResources(org.apache.catalina.deploy.NamingResources)

Example 13 with NamingResources

use of org.apache.catalina.deploy.NamingResources in project tomcat70 by apache.

the class NamingResourcesMBean method addResource.

/**
 * Add a resource reference for this web application.
 *
 * @param resourceName New resource reference name
 * @param type New resource reference type
 */
public String addResource(String resourceName, String type) throws MalformedObjectNameException {
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return null;
    }
    ContextResource resource = nresources.findResource(resourceName);
    if (resource != null) {
        throw new IllegalArgumentException("Invalid resource name - already exists'" + resourceName + "'");
    }
    resource = new ContextResource();
    resource.setName(resourceName);
    resource.setType(type);
    nresources.addResource(resource);
    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("ContextResource");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resource);
    return (oname.toString());
}
Also used : NamingResources(org.apache.catalina.deploy.NamingResources) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) ContextResource(org.apache.catalina.deploy.ContextResource) ObjectName(javax.management.ObjectName)

Example 14 with NamingResources

use of org.apache.catalina.deploy.NamingResources in project tomcat70 by apache.

the class NamingResourcesMBean method getResourceLinks.

/**
 * Return the MBean Names of all the defined resource link references for
 * this application.
 */
public String[] getResourceLinks() {
    ContextResourceLink[] resourceLinks = ((NamingResources) this.resource).findResourceLinks();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < resourceLinks.length; i++) {
        try {
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for resource " + resourceLinks[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) NamingResources(org.apache.catalina.deploy.NamingResources) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Example 15 with NamingResources

use of org.apache.catalina.deploy.NamingResources in project tomcat70 by apache.

the class NamingResourcesMBean method addEnvironment.

// ------------------------------------------------------------- Operations
/**
 * Add an environment entry for this web application.
 *
 * @param envName New environment entry name
 * @param type The type of the new environment entry
 * @param value The value of the new environment entry
 */
public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException {
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return null;
    }
    ContextEnvironment env = nresources.findEnvironment(envName);
    if (env != null) {
        throw new IllegalArgumentException("Invalid environment name - already exists '" + envName + "'");
    }
    env = new ContextEnvironment();
    env.setName(envName);
    env.setType(type);
    env.setValue(value);
    nresources.addEnvironment(env);
    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("ContextEnvironment");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env);
    return (oname.toString());
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) NamingResources(org.apache.catalina.deploy.NamingResources) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) ObjectName(javax.management.ObjectName)

Aggregations

NamingResources (org.apache.catalina.deploy.NamingResources)22 ObjectName (javax.management.ObjectName)6 ContextEnvironment (org.apache.catalina.deploy.ContextEnvironment)6 ContextResource (org.apache.catalina.deploy.ContextResource)6 ContextResourceLink (org.apache.catalina.deploy.ContextResourceLink)6 ArrayList (java.util.ArrayList)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 MBeanException (javax.management.MBeanException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)3 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)3 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 NamingException (javax.naming.NamingException)2 Context (org.apache.catalina.Context)2 LifecycleException (org.apache.catalina.LifecycleException)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1