use of org.apache.tomcat.util.descriptor.web.ContextResourceLink in project tomcat by apache.
the class NamingResourcesImpl method removeResourceLink.
/**
* Remove any resource link with the specified name.
*
* @param name Name of the resource link to remove
*/
@Override
public void removeResourceLink(String name) {
entries.remove(name);
ContextResourceLink resourceLink = null;
synchronized (resourceLinks) {
resourceLink = resourceLinks.remove(name);
}
if (resourceLink != null) {
support.firePropertyChange("resourceLink", resourceLink, null);
// De-register with JMX
if (resourceRequireExplicitRegistration) {
try {
MBeanUtils.destroyMBean(resourceLink);
} catch (Exception e) {
log.warn(sm.getString("namingResources.mbeanDestroyFail", resourceLink.getName()), e);
}
}
resourceLink.setNamingResources(null);
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceLink in project tomcat by apache.
the class ContextResourceLinkMBean method getAttribute.
/**
* Obtain and return the value of a specific attribute of this MBean.
*
* @param name Name of the requested attribute
*
* @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 Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
// Validate the input parameters
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("mBean.nullName")), sm.getString("mBean.nullName"));
}
ContextResourceLink cl = doGetManagedResource();
String value = null;
if ("global".equals(name)) {
return cl.getGlobal();
} else if ("description".equals(name)) {
return cl.getDescription();
} else if ("name".equals(name)) {
return cl.getName();
} else if ("type".equals(name)) {
return cl.getType();
} else {
value = (String) cl.getProperty(name);
if (value == null) {
throw new AttributeNotFoundException(sm.getString("mBean.attributeNotFound", name));
}
}
return value;
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceLink in project tomcat 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);
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
if (nresources == null) {
return;
}
ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
if (resourceLink == null) {
throw new IllegalArgumentException(sm.getString("namingResourcesMBean.removeNotFound.resourceLink", resourceLinkName));
}
nresources.removeResourceLink(resourceLinkName);
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceLink in project tomcat by apache.
the class NamingResourcesMBean method getResourceLinks.
/**
* Return the MBean Names of all the defined resource link references for
* this application.
* @return an array of object names as strings
*/
public String[] getResourceLinks() {
ContextResourceLink[] resourceLinks = ((NamingResourcesImpl) this.resource).findResourceLinks();
List<String> results = new ArrayList<>();
for (ContextResourceLink resourceLink : resourceLinks) {
try {
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
results.add(oname.toString());
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException(sm.getString("namingResourcesMBean.createObjectNameError.resourceLink", resourceLink), e);
}
}
return results.toArray(new String[0]);
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceLink 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();
}
Aggregations