use of org.apache.tomcat.util.descriptor.web.ContextEjb 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]);
}
// 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.ContextEjb in project tomcat by apache.
the class NamingResourcesImpl method removeEjb.
/**
* Remove any EJB resource reference with the specified name.
*
* @param name Name of the EJB resource reference to remove
*/
public void removeEjb(String name) {
entries.remove(name);
ContextEjb ejb = null;
synchronized (ejbs) {
ejb = ejbs.remove(name);
}
if (ejb != null) {
support.firePropertyChange("ejb", ejb, null);
ejb.setNamingResources(null);
}
}
use of org.apache.tomcat.util.descriptor.web.ContextEjb in project tomee by apache.
the class TomcatJndiBuilder method mergeRef.
public void mergeRef(final NamingResourcesImpl naming, final EjbReferenceInfo ref) {
if (isLookupRef(naming, ref)) {
return;
}
ContextEjb ejb = naming.findEjb(ref.referenceName.replaceAll("^comp/env/", ""));
boolean addEntry = false;
if (ejb == null) {
ejb = new ContextEjb();
ejb.setName(ref.referenceName.replaceAll("^comp/env/", ""));
addEntry = true;
}
ejb.setProperty(Constants.FACTORY, EjbFactory.class.getName());
ejb.setProperty(NamingUtil.NAME, ref.referenceName.replaceAll("^comp/env/", ""));
ejb.setHome(ref.homeClassName);
ejb.setRemote(ref.interfaceClassName);
ejb.setLink(null);
ejb.setType(ref.interfaceClassName);
if (useCrossClassLoaderRef) {
ejb.setProperty(NamingUtil.EXTERNAL, Boolean.toString(ref.externalReference));
}
if (ref.ejbDeploymentId != null) {
ejb.setProperty(NamingUtil.DEPLOYMENT_ID, ref.ejbDeploymentId);
}
if (ref.location != null) {
ejb.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName);
ejb.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId);
}
if (addEntry) {
naming.addEjb(ejb);
}
if (replaceEntry) {
ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken());
if (!addEntry) {
namingContextListener.removeEjb(ejb.getName());
}
namingContextListener.addEjb(ejb);
ContextAccessController.setReadOnly(namingContextListener.getName());
}
}
Aggregations