use of org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef in project tomee by apache.
the class TomcatJndiBuilder method isLookupRef.
private boolean isLookupRef(final NamingResourcesImpl naming, final InjectableInfo ref) {
if (ref.location == null) {
return false;
}
if (ref.location.jndiName == null) {
return false;
}
if (!ref.location.jndiName.startsWith("java:")) {
return false;
}
final ContextResourceEnvRef lookup = new ContextResourceEnvRef();
lookup.setName(ref.referenceName.replaceAll("^comp/env/", ""));
lookup.setProperty(Constants.FACTORY, LookupFactory.class.getName());
lookup.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName);
lookup.setType(Object.class.getName());
lookup.setOverride(false);
naming.addResourceEnvRef(lookup);
return true;
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef in project tomee by apache.
the class OpenEJBNamingContextListener method processInitialNamingResources.
private void processInitialNamingResources() {
// Resource links
final ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
for (final ContextResourceLink resourceLink : resourceLinks) {
addResourceLink(resourceLink);
}
// Resources
final ContextResource[] resources = namingResources.findResources();
for (final ContextResource resource : resources) {
addResource(resource);
}
// Resources Env
final ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
for (final ContextResourceEnvRef resourceEnvRef : resourceEnvRefs) {
addResourceEnvRef(resourceEnvRef);
}
// Environment entries
final ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
for (final ContextEnvironment contextEnvironment : contextEnvironments) {
addEnvironment(contextEnvironment);
}
// EJB references
final ContextEjb[] ejbs = namingResources.findEjbs();
for (final ContextEjb ejb : ejbs) {
addEjb(ejb);
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef in project tomee by apache.
the class TomcatJndiBuilder method mergeRef.
public void mergeRef(final NamingResourcesImpl naming, final ResourceEnvReferenceInfo ref) {
if (isLookupRef(naming, ref)) {
return;
}
ContextResourceEnvRef resourceEnv = naming.findResourceEnvRef(ref.referenceName.replaceAll("^comp/env/", ""));
boolean addEntry = false;
if (resourceEnv == null) {
resourceEnv = new ContextResourceEnvRef();
resourceEnv.setName(ref.referenceName.replaceAll("^comp/env/", ""));
addEntry = true;
}
resourceEnv.setType(ref.resourceEnvRefType);
if (UserTransaction.class.getName().equals(ref.resourceEnvRefType)) {
resourceEnv.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName());
} else if (TransactionManager.class.getName().equals(ref.resourceEnvRefType)) {
resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName());
resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, TransactionManager.class.getName());
} else if (TransactionSynchronizationRegistry.class.getName().equals(ref.resourceEnvRefType)) {
resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName());
resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, TransactionSynchronizationRegistry.class.getName());
} else if ("org.omg.CORBA.ORB".equals(ref.resourceEnvRefType)) {
resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName());
resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, ref.resourceEnvRefType);
} else if (HandleDelegate.class.getName().equals(ref.resourceEnvRefType)) {
resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName());
resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, HandleDelegate.class.getName());
} else {
resourceEnv.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
resourceEnv.setProperty(NamingUtil.NAME, ref.referenceName.replaceAll("^comp/env/", ""));
if (ref.resourceID != null) {
resourceEnv.setProperty(NamingUtil.RESOURCE_ID, ref.resourceID);
}
if (ref.location != null) {
resourceEnv.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName);
resourceEnv.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId);
}
}
if (addEntry) {
naming.addResourceEnvRef(resourceEnv);
}
if (replaceEntry) {
ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken());
if (!addEntry) {
namingContextListener.removeResourceEnvRef(resourceEnv.getName());
}
namingContextListener.addResourceEnvRef(resourceEnv);
ContextAccessController.setReadOnly(namingContextListener.getName());
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef in project tomee by apache.
the class TomcatJndiBuilder method mergeRef.
public void mergeRef(final NamingResourcesImpl naming, final EnvEntryInfo ref) {
// if (!ref.referenceName.startsWith("comp/")) return;
if ("java.lang.Class".equals(ref.type)) {
final ContextResourceEnvRef resourceEnv = new ContextResourceEnvRef();
resourceEnv.setName(ref.referenceName.replaceAll("^comp/env/", ""));
resourceEnv.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
resourceEnv.setType(ref.type);
resourceEnv.setProperty(NamingUtil.RESOURCE_ID, ref.value);
resourceEnv.setOverride(false);
naming.addResourceEnvRef(resourceEnv);
return;
}
try {
final ClassLoader loader = this.standardContext.getLoader().getClassLoader();
final Class<?> type = loader.loadClass(ref.type);
if (Enum.class.isAssignableFrom(type)) {
final ContextResourceEnvRef enumRef = new ContextResourceEnvRef();
enumRef.setName(ref.referenceName.replaceAll("^comp/env/", ""));
enumRef.setProperty(Constants.FACTORY, EnumFactory.class.getName());
enumRef.setProperty(EnumFactory.ENUM_VALUE, ref.value);
enumRef.setType(ref.type);
enumRef.setOverride(false);
naming.addResourceEnvRef(enumRef);
return;
}
} catch (final Throwable e) {
// no-op
}
if (isLookupRef(naming, ref)) {
return;
}
ContextEnvironment environment = naming.findEnvironment(ref.referenceName.replaceAll("^comp/env/", ""));
boolean addEntry = false;
if (environment == null) {
environment = new ContextEnvironment();
environment.setName(ref.referenceName.replaceAll("^comp/env/", ""));
addEntry = true;
}
environment.setType(ref.type);
environment.setValue(ref.value);
environment.setOverride(false);
if (addEntry) {
naming.addEnvironment(environment);
}
if (replaceEntry) {
ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken());
if (!addEntry) {
namingContextListener.removeEnvironment(environment.getName());
}
namingContextListener.addEnvironment(environment);
ContextAccessController.setReadOnly(namingContextListener.getName());
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef 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());
}
Aggregations