Search in sources :

Example 1 with NamingResources

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

the class NamingResourcesMBean method addResourceLink.

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

Example 2 with NamingResources

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

the class ContextResourceLinkMBean method setAttribute.

/**
 * 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 {
    // Validate the input parameters
    if (attribute == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    ContextResourceLink crl = null;
    try {
        crl = (ContextResourceLink) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    if ("global".equals(name)) {
        crl.setGlobal((String) value);
    } else if ("description".equals(name)) {
        crl.setDescription((String) value);
    } else if ("name".equals(name)) {
        crl.setName((String) value);
    } else if ("type".equals(name)) {
        crl.setType((String) value);
    } else {
        crl.setProperty(name, "" + value);
    }
    // cannot use side-effects.  It's removed and added back each time
    // there is a modification in a resource.
    NamingResources nr = crl.getNamingResources();
    nr.removeResourceLink(crl.getName());
    nr.addResourceLink(crl);
}
Also used : ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) InstanceNotFoundException(javax.management.InstanceNotFoundException) NamingResources(org.apache.catalina.deploy.NamingResources) MBeanException(javax.management.MBeanException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 3 with NamingResources

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

the class ContextResourceMBean method setAttribute.

/**
 * 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 {
    // Validate the input parameters
    if (attribute == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    ContextResource cr = null;
    try {
        cr = (ContextResource) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    if ("auth".equals(name)) {
        cr.setAuth((String) value);
    } else if ("description".equals(name)) {
        cr.setDescription((String) value);
    } else if ("name".equals(name)) {
        cr.setName((String) value);
    } else if ("scope".equals(name)) {
        cr.setScope((String) value);
    } else if ("type".equals(name)) {
        cr.setType((String) value);
    } else {
        cr.setProperty(name, "" + value);
    }
    // cannot use side-effects.  It's removed and added back each time
    // there is a modification in a resource.
    NamingResources nr = cr.getNamingResources();
    nr.removeResource(cr.getName());
    nr.addResource(cr);
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) NamingResources(org.apache.catalina.deploy.NamingResources) MBeanException(javax.management.MBeanException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ContextResource(org.apache.catalina.deploy.ContextResource)

Example 4 with NamingResources

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

the class SetNextNamingRule method end.

// --------------------------------------------------------- Public Methods
/**
 * Process the end of this element.
 *
 * @param namespace the namespace URI of the matching element, or an
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {
    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    NamingResources namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResources) parent;
    }
    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName, child, paramType, digester.getClassLoader());
}
Also used : Context(org.apache.catalina.Context) NamingResources(org.apache.catalina.deploy.NamingResources)

Example 5 with NamingResources

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

the class StandardContext method addResource.

/**
 * Add a resource reference for this web application.
 *
 * @param resourceName New resource reference name
 */
public String addResource(String resourceName, String type) throws MalformedObjectNameException {
    NamingResources nresources = getNamingResources();
    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
    return createObjectName(resource).toString();
}
Also used : NamingResources(org.apache.catalina.deploy.NamingResources) ContextResource(org.apache.catalina.deploy.ContextResource)

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