use of org.apache.catalina.deploy.ContextService in project tomcat70 by apache.
the class WebAnnotationSet method addResource.
protected static void addResource(Context context, Resource annotation, String defaultName, Class<?> defaultType) {
String name = getName(annotation, defaultName);
String type = getType(annotation, defaultType);
if (type.equals("java.lang.String") || type.equals("java.lang.Character") || type.equals("java.lang.Integer") || type.equals("java.lang.Boolean") || type.equals("java.lang.Double") || type.equals("java.lang.Byte") || type.equals("java.lang.Short") || type.equals("java.lang.Long") || type.equals("java.lang.Float")) {
// env-ref element
ContextEnvironment resource = new ContextEnvironment();
resource.setName(name);
resource.setType(type);
resource.setDescription(annotation.description());
resource.setValue(annotation.mappedName());
resource.setLookupName(annotation.lookup());
context.getNamingResources().addEnvironment(resource);
} else if (type.equals("javax.xml.rpc.Service")) {
// service-ref element
ContextService service = new ContextService();
service.setName(name);
service.setWsdlfile(annotation.mappedName());
service.setType(type);
service.setDescription(annotation.description());
service.setLookupName(annotation.lookup());
context.getNamingResources().addService(service);
} else if (type.equals("javax.sql.DataSource") || type.equals("javax.jms.ConnectionFactory") || type.equals("javax.jms.QueueConnectionFactory") || type.equals("javax.jms.TopicConnectionFactory") || type.equals("javax.mail.Session") || type.equals("java.net.URL") || type.equals("javax.resource.cci.ConnectionFactory") || type.equals("org.omg.CORBA_2_3.ORB") || type.endsWith("ConnectionFactory")) {
// resource-ref element
ContextResource resource = new ContextResource();
resource.setName(name);
resource.setType(type);
if (annotation.authenticationType() == Resource.AuthenticationType.CONTAINER) {
resource.setAuth("Container");
} else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) {
resource.setAuth("Application");
}
resource.setScope(annotation.shareable() ? "Shareable" : "Unshareable");
resource.setProperty("mappedName", annotation.mappedName());
resource.setDescription(annotation.description());
resource.setLookupName(annotation.lookup());
context.getNamingResources().addResource(resource);
} else if (type.equals("javax.jms.Queue") || type.equals("javax.jms.Topic")) {
// message-destination-ref
MessageDestinationRef resource = new MessageDestinationRef();
resource.setName(name);
resource.setType(type);
resource.setUsage(annotation.mappedName());
resource.setDescription(annotation.description());
resource.setLookupName(annotation.lookup());
context.getNamingResources().addMessageDestinationRef(resource);
} else {
/*
* General case. Also used for:
* - javax.resource.cci.InteractionSpec
* - javax.transaction.UserTransaction
*/
// resource-env-ref
ContextResourceEnvRef resource = new ContextResourceEnvRef();
resource.setName(name);
resource.setType(type);
resource.setProperty("mappedName", annotation.mappedName());
resource.setDescription(annotation.description());
resource.setLookupName(annotation.lookup());
context.getNamingResources().addResourceEnvRef(resource);
}
}
use of org.apache.catalina.deploy.ContextService in project tomcat70 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 NamingResources();
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) {
logger.error(sm.getString("naming.bindFailed", e));
}
}
// Binding the resources directory context
if (container instanceof Context) {
try {
compCtx.bind("Resources", ((Container) container).getResources());
} catch (NamingException e) {
logger.error(sm.getString("naming.bindFailed", e));
}
}
}
Aggregations