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());
}
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);
}
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);
}
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());
}
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();
}
Aggregations