Search in sources :

Example 21 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.

the class NamingResourcesMBean method getResources.

/**
 * Return the MBean Names of all the defined resource references for this
 * application.
 * @return an array of object names as strings
 */
public String[] getResources() {
    ContextResource[] resources = ((NamingResourcesImpl) this.resource).findResources();
    List<String> results = new ArrayList<>();
    for (ContextResource contextResource : resources) {
        try {
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), contextResource);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException(sm.getString("namingResourcesMBean.createObjectNameError.resource", contextResource), e);
        }
    }
    return results.toArray(new String[0]);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ArrayList(java.util.ArrayList) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) ObjectName(javax.management.ObjectName)

Example 22 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat 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
 * @return the object name of the new resource link
 * @throws MalformedObjectNameException if the object name was invalid
 */
public String addResourceLink(String resourceLinkName, String type) throws MalformedObjectNameException {
    NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
    if (nresources == null) {
        return null;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink != null) {
        throw new IllegalArgumentException(sm.getString("namingResourcesMBean.addAlreadyExists.resourceLink", 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.tomcat.util.descriptor.web.ContextResourceLink) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) ObjectName(javax.management.ObjectName)

Example 23 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.

the class NamingResourcesMBean method getEnvironments.

// ------------------------------------------------------------- Attributes
/**
 * Return the MBean Names of the set of defined environment entries for
 * this web application
 * @return an array of object names as strings
 */
public String[] getEnvironments() {
    ContextEnvironment[] envs = ((NamingResourcesImpl) this.resource).findEnvironments();
    List<String> results = new ArrayList<>();
    for (ContextEnvironment env : envs) {
        try {
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException(sm.getString("namingResourcesMBean.createObjectNameError.environment", env), e);
        }
    }
    return results.toArray(new String[0]);
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) MalformedObjectNameException(javax.management.MalformedObjectNameException) ArrayList(java.util.ArrayList) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ObjectName(javax.management.ObjectName)

Example 24 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat 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
 * @return the object name of the new resource
 * @throws MalformedObjectNameException if the object name was invalid
 */
public String addResource(String resourceName, String type) throws MalformedObjectNameException {
    NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
    if (nresources == null) {
        return null;
    }
    ContextResource resource = nresources.findResource(resourceName);
    if (resource != null) {
        throw new IllegalArgumentException(sm.getString("namingResourcesMBean.addAlreadyExists.resource", 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 : NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) ObjectName(javax.management.ObjectName)

Aggregations

NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)24 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)10 ObjectName (javax.management.ObjectName)6 ContextEnvironment (org.apache.tomcat.util.descriptor.web.ContextEnvironment)6 ContextResourceLink (org.apache.tomcat.util.descriptor.web.ContextResourceLink)6 ArrayList (java.util.ArrayList)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)3 Context (org.apache.catalina.Context)2 LifecycleListener (org.apache.catalina.LifecycleListener)2 StandardContext (org.apache.catalina.core.StandardContext)2 StandardServer (org.apache.catalina.core.StandardServer)2 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)2 ContextEjb (org.apache.tomcat.util.descriptor.web.ContextEjb)2 ContextResourceEnvRef (org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)2 ContextTransaction (org.apache.tomcat.util.descriptor.web.ContextTransaction)2 File (java.io.File)1 URI (java.net.URI)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1