use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.
the class NamingContextListener method createNamingContext.
/**
* Create and initialize the JNDI naming context.
*/
private void createNamingContext() throws NamingException {
// Creating the comp subcontext
if (container instanceof Server) {
compCtx = namingContext;
envCtx = namingContext;
} else {
compCtx = namingContext.createSubcontext("comp");
envCtx = compCtx.createSubcontext("env");
}
int i;
if (log.isDebugEnabled()) {
log.debug("Creating JNDI naming context");
}
if (namingResources == null) {
namingResources = new NamingResourcesImpl();
namingResources.setContainer(container);
}
// Resource links
ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
for (i = 0; i < resourceLinks.length; i++) {
addResourceLink(resourceLinks[i]);
}
// Resources
ContextResource[] resources = namingResources.findResources();
for (i = 0; i < resources.length; i++) {
addResource(resources[i]);
}
// Resources Env
ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
for (i = 0; i < resourceEnvRefs.length; i++) {
addResourceEnvRef(resourceEnvRefs[i]);
}
// Environment entries
ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
for (i = 0; i < contextEnvironments.length; i++) {
addEnvironment(contextEnvironments[i]);
}
// EJB references
ContextEjb[] ejbs = namingResources.findEjbs();
for (i = 0; i < ejbs.length; i++) {
addEjb(ejbs[i]);
}
// Message Destination References
MessageDestinationRef[] mdrs = namingResources.findMessageDestinationRefs();
for (i = 0; i < mdrs.length; i++) {
addMessageDestinationRef(mdrs[i]);
}
// WebServices references
ContextService[] services = namingResources.findServices();
for (i = 0; i < services.length; i++) {
addService(services[i]);
}
// Binding a User Transaction reference
if (container instanceof Context) {
try {
Reference ref = new TransactionRef();
compCtx.bind("UserTransaction", ref);
ContextTransaction transaction = namingResources.getTransaction();
if (transaction != null) {
Iterator<String> params = transaction.listProperties();
while (params.hasNext()) {
String paramName = params.next();
String paramValue = (String) transaction.getProperty(paramName);
StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
}
} catch (NameAlreadyBoundException e) {
// Ignore because UserTransaction was obviously
// added via ResourceLink
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
}
// Binding the resources directory context
if (container instanceof Context) {
try {
compCtx.bind("Resources", ((Context) container).getResources());
} catch (NamingException e) {
log.error(sm.getString("naming.bindFailed", e));
}
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat 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);
boolean context = false;
NamingResourcesImpl namingResources = null;
if (parent instanceof Context) {
namingResources = ((Context) parent).getNamingResources();
context = true;
} else {
namingResources = (NamingResourcesImpl) parent;
}
// Call the specified method
IntrospectionUtils.callMethod1(namingResources, methodName, child, paramType, digester.getClassLoader());
StringBuilder code = digester.getGeneratedCode();
if (code != null) {
if (context) {
code.append(digester.toVariableName(parent)).append(".getNamingResources()");
} else {
code.append(digester.toVariableName(namingResources));
}
code.append(".").append(methodName).append('(');
code.append(digester.toVariableName(child)).append(");");
code.append(System.lineSeparator());
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.
the class NamingResourcesMBean method addEnvironment.
// ------------------------------------------------------------- Operations
/**
* Add an environment entry for this web application.
*
* @param envName New environment entry name
* @param type The type of the new environment entry
* @param value The value of the new environment entry
* @return the object name of the new environment entry
* @throws MalformedObjectNameException if the object name was invalid
*/
public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException {
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
if (nresources == null) {
return null;
}
ContextEnvironment env = nresources.findEnvironment(envName);
if (env != null) {
throw new IllegalArgumentException(sm.getString("namingResourcesMBean.addAlreadyExists.environment", envName));
}
env = new ContextEnvironment();
env.setName(envName);
env.setType(type);
env.setValue(value);
nresources.addEnvironment(env);
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("ContextEnvironment");
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env);
return oname.toString();
}
use of org.apache.catalina.deploy.NamingResourcesImpl 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.catalina.deploy.NamingResourcesImpl 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]);
}
Aggregations