Search in sources :

Example 16 with NamingResources

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

the class NamingResourcesMBean method removeResource.

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

Example 17 with NamingResources

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

the class NamingResourcesMBean method getEnvironments.

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

Example 18 with NamingResources

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

the class NamingResourcesMBean method getResources.

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

Example 19 with NamingResources

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

the class ContextEnvironmentMBean method setAttribute.

// ----------------------------------------------------- Instance Variables
// ------------------------------------------------------------- Attributes
/**
 * Set the value of a specific attribute of this MBean.
 *
 * @param attribute The identification of the attribute to be set
 *  and the new value
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    super.setAttribute(attribute);
    ContextEnvironment ce = null;
    try {
        ce = (ContextEnvironment) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    // cannot use side-effects.  It's removed and added back each time
    // there is a modification in a resource.
    NamingResources nr = ce.getNamingResources();
    nr.removeEnvironment(ce.getName());
    nr.addEnvironment(ce);
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) InstanceNotFoundException(javax.management.InstanceNotFoundException) NamingResources(org.apache.catalina.deploy.NamingResources) MBeanException(javax.management.MBeanException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException)

Example 20 with NamingResources

use of org.apache.catalina.deploy.NamingResources in project Payara by payara.

the class StandardContext method setNamingResources.

/**
 * Set the naming resources for this web application.
 *
 * @param namingResources The new naming resources
 */
@Override
public void setNamingResources(NamingResources namingResources) {
    // Process the property setting change
    NamingResources oldNamingResources = this.namingResources;
    this.namingResources = namingResources;
    support.firePropertyChange("namingResources", oldNamingResources, this.namingResources);
}
Also used : NamingResources(org.apache.catalina.deploy.NamingResources)

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