use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomcat by apache.
the class NamingResourcesSF method storeChildren.
/**
* Store the specified NamingResources properties.
*
* @param aWriter
* PrintWriter to which we are storing
* @param indent
* Number of spaces to indent this element
* @param aElement
* Object whose properties are being stored
* @param elementDesc
* element descriptor
*
* @exception Exception
* if an exception occurs while storing
*
* @see org.apache.catalina.storeconfig.StoreFactoryBase#storeChildren(java.io.PrintWriter,
* int, java.lang.Object, StoreDescription)
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aElement, StoreDescription elementDesc) throws Exception {
if (aElement instanceof NamingResourcesImpl) {
NamingResourcesImpl resources = (NamingResourcesImpl) aElement;
// Store nested <Ejb> elements
ContextEjb[] ejbs = resources.findEjbs();
storeElementArray(aWriter, indent, ejbs);
// Store nested <Environment> elements
ContextEnvironment[] envs = resources.findEnvironments();
storeElementArray(aWriter, indent, envs);
// Store nested <LocalEjb> elements
ContextLocalEjb[] lejbs = resources.findLocalEjbs();
storeElementArray(aWriter, indent, lejbs);
// Store nested <Resource> elements
ContextResource[] dresources = resources.findResources();
storeElementArray(aWriter, indent, dresources);
// Store nested <ResourceEnvRef> elements
ContextResourceEnvRef[] resEnv = resources.findResourceEnvRefs();
storeElementArray(aWriter, indent, resEnv);
// Store nested <ResourceLink> elements
ContextResourceLink[] resourceLinks = resources.findResourceLinks();
storeElementArray(aWriter, indent, resourceLinks);
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomcat by apache.
the class NamingContextListener method containerEvent.
// ---------------------------------------------- ContainerListener Methods
/**
* Acknowledge the occurrence of the specified event.
* Note: Will never be called when the listener is associated to a Server,
* since it is not a Container.
*
* @param event ContainerEvent that has occurred
*/
@Override
public void containerEvent(ContainerEvent event) {
if (!initialized)
return;
// Setting the context in read/write mode
ContextAccessController.setWritable(getName(), token);
String type = event.getType();
if (type.equals("addEjb")) {
String ejbName = (String) event.getData();
if (ejbName != null) {
ContextEjb ejb = namingResources.findEjb(ejbName);
addEjb(ejb);
}
} else if (type.equals("addEnvironment")) {
String environmentName = (String) event.getData();
if (environmentName != null) {
ContextEnvironment env = namingResources.findEnvironment(environmentName);
addEnvironment(env);
}
} else if (type.equals("addLocalEjb")) {
String localEjbName = (String) event.getData();
if (localEjbName != null) {
ContextLocalEjb localEjb = namingResources.findLocalEjb(localEjbName);
addLocalEjb(localEjb);
}
} else if (type.equals("addResource")) {
String resourceName = (String) event.getData();
if (resourceName != null) {
ContextResource resource = namingResources.findResource(resourceName);
addResource(resource);
}
} else if (type.equals("addResourceLink")) {
String resourceLinkName = (String) event.getData();
if (resourceLinkName != null) {
ContextResourceLink resourceLink = namingResources.findResourceLink(resourceLinkName);
addResourceLink(resourceLink);
}
} else if (type.equals("addResourceEnvRef")) {
String resourceEnvRefName = (String) event.getData();
if (resourceEnvRefName != null) {
ContextResourceEnvRef resourceEnvRef = namingResources.findResourceEnvRef(resourceEnvRefName);
addResourceEnvRef(resourceEnvRef);
}
} else if (type.equals("addService")) {
String serviceName = (String) event.getData();
if (serviceName != null) {
ContextService service = namingResources.findService(serviceName);
addService(service);
}
} else if (type.equals("removeEjb")) {
String ejbName = (String) event.getData();
if (ejbName != null) {
removeEjb(ejbName);
}
} else if (type.equals("removeEnvironment")) {
String environmentName = (String) event.getData();
if (environmentName != null) {
removeEnvironment(environmentName);
}
} else if (type.equals("removeLocalEjb")) {
String localEjbName = (String) event.getData();
if (localEjbName != null) {
removeLocalEjb(localEjbName);
}
} else if (type.equals("removeResource")) {
String resourceName = (String) event.getData();
if (resourceName != null) {
removeResource(resourceName);
}
} else if (type.equals("removeResourceLink")) {
String resourceLinkName = (String) event.getData();
if (resourceLinkName != null) {
removeResourceLink(resourceLinkName);
}
} else if (type.equals("removeResourceEnvRef")) {
String resourceEnvRefName = (String) event.getData();
if (resourceEnvRefName != null) {
removeResourceEnvRef(resourceEnvRefName);
}
} else if (type.equals("removeService")) {
String serviceName = (String) event.getData();
if (serviceName != null) {
removeService(serviceName);
}
}
// Setting the context in read only mode
ContextAccessController.setReadOnly(getName());
}
use of org.apache.tomcat.util.descriptor.web.ContextResource 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.tomcat.util.descriptor.web.ContextResource in project tomcat by apache.
the class NamingResourcesImpl method cleanUp.
/**
* Close those resources that an explicit close may help clean-up faster.
*/
private void cleanUp() {
if (resources.size() == 0) {
return;
}
javax.naming.Context ctxt;
try {
if (container instanceof Server) {
ctxt = ((Server) container).getGlobalNamingContext();
} else {
ctxt = ContextBindings.getClassLoader();
ctxt = (javax.naming.Context) ctxt.lookup("comp/env");
}
} catch (NamingException e) {
log.warn(sm.getString("namingResources.cleanupNoContext", container), e);
return;
}
for (ContextResource cr : resources.values()) {
if (cr.getSingleton()) {
String closeMethod = cr.getCloseMethod();
if (closeMethod != null && closeMethod.length() > 0) {
String name = cr.getName();
Object resource;
try {
resource = ctxt.lookup(name);
} catch (NamingException e) {
log.warn(sm.getString("namingResources.cleanupNoResource", cr.getName(), container), e);
continue;
}
cleanUp(resource, name, closeMethod);
}
}
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomcat by apache.
the class NamingResourcesImpl method initInternal.
// ------------------------------------------------------- Lifecycle methods
@Override
protected void initInternal() throws LifecycleException {
super.initInternal();
// Set this before we register currently known naming resources to avoid
// timing issues. Duplication registration is not an issue.
resourceRequireExplicitRegistration = true;
for (ContextResource cr : resources.values()) {
try {
MBeanUtils.createMBean(cr);
} catch (Exception e) {
log.warn(sm.getString("namingResources.mbeanCreateFail", cr.getName()), e);
}
}
for (ContextEnvironment ce : envs.values()) {
try {
MBeanUtils.createMBean(ce);
} catch (Exception e) {
log.warn(sm.getString("namingResources.mbeanCreateFail", ce.getName()), e);
}
}
for (ContextResourceLink crl : resourceLinks.values()) {
try {
MBeanUtils.createMBean(crl);
} catch (Exception e) {
log.warn(sm.getString("namingResources.mbeanCreateFail", crl.getName()), e);
}
}
}
Aggregations