use of org.apache.openejb.jee.ResourceRef in project tomee by apache.
the class ApplicationClient$JAXB method _read.
public static final ApplicationClient _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
// Check for xsi:nil
if (reader.isXsiNil()) {
return null;
}
if (context == null) {
context = new RuntimeContext();
}
final ApplicationClient applicationClient = new ApplicationClient();
context.beforeUnmarshal(applicationClient, org.metatype.sxc.jaxb.LifecycleCallback.NONE);
ArrayList<Text> descriptions = null;
ArrayList<Text> displayNames = null;
LocalCollection<Icon> icon = null;
KeyedCollection<String, EnvEntry> envEntry = null;
KeyedCollection<String, EjbRef> ejbRef = null;
KeyedCollection<String, EjbLocalRef> ejbLocalRef = null;
KeyedCollection<String, ServiceRef> serviceRef = null;
KeyedCollection<String, ResourceRef> resourceRef = null;
KeyedCollection<String, ResourceEnvRef> resourceEnvRef = null;
KeyedCollection<String, MessageDestinationRef> messageDestinationRef = null;
KeyedCollection<String, PersistenceContextRef> persistenceContextRef = null;
KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef = null;
List<org.apache.openejb.jee.LifecycleCallback> postConstruct = null;
List<org.apache.openejb.jee.LifecycleCallback> preDestroy = null;
KeyedCollection<String, MessageDestination> messageDestination = null;
KeyedCollection<String, DataSource> dataSource = null;
// Check xsi:type
final QName xsiType = reader.getXsiType();
if (xsiType != null) {
if (("application-clientType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
return context.unexpectedXsiType(reader, ApplicationClient.class);
}
}
// Read attributes
for (final Attribute attribute : reader.getAttributes()) {
if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: id
final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
context.addXmlId(reader, id, applicationClient);
applicationClient.id = id;
} else if (("metadata-complete" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: metadataComplete
final Boolean metadataComplete = ("1".equals(attribute.getValue()) || "true".equals(attribute.getValue()));
applicationClient.metadataComplete = metadataComplete;
} else if (("version" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: version
applicationClient.version = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
} else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
context.unexpectedAttribute(attribute, new QName("", "id"), new QName("", "metadata-complete"), new QName("", "version"));
}
}
// Read elements
for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
if (("module-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: moduleName
final String moduleNameRaw = elementReader.getElementAsString();
final String moduleName;
try {
moduleName = Adapters.collapsedStringAdapterAdapter.unmarshal(moduleNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
continue;
}
applicationClient.moduleName = moduleName;
} else if (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: descriptions
final Text descriptionsItem = readText(elementReader, context);
if (descriptions == null) {
descriptions = new ArrayList<Text>();
}
descriptions.add(descriptionsItem);
} else if (("display-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: displayNames
final Text displayNamesItem = readText(elementReader, context);
if (displayNames == null) {
displayNames = new ArrayList<Text>();
}
displayNames.add(displayNamesItem);
} else if (("icon" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: icon
final Icon iconItem = readIcon(elementReader, context);
if (icon == null) {
icon = applicationClient.icon;
if (icon != null) {
icon.clear();
} else {
icon = new LocalCollection<Icon>();
}
}
icon.add(iconItem);
} else if (("env-entry" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: envEntry
final EnvEntry envEntryItem = readEnvEntry(elementReader, context);
if (envEntry == null) {
envEntry = applicationClient.envEntry;
if (envEntry != null) {
envEntry.clear();
} else {
envEntry = new KeyedCollection<String, EnvEntry>();
}
}
envEntry.add(envEntryItem);
} else if (("ejb-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: ejbRef
final EjbRef ejbRefItem = readEjbRef(elementReader, context);
if (ejbRef == null) {
ejbRef = applicationClient.ejbRef;
if (ejbRef != null) {
ejbRef.clear();
} else {
ejbRef = new KeyedCollection<String, EjbRef>();
}
}
ejbRef.add(ejbRefItem);
} else if (("ejb-local-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: ejbLocalRef
final EjbLocalRef ejbLocalRefItem = readEjbLocalRef(elementReader, context);
if (ejbLocalRef == null) {
ejbLocalRef = applicationClient.ejbLocalRef;
if (ejbLocalRef != null) {
ejbLocalRef.clear();
} else {
ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
}
}
ejbLocalRef.add(ejbLocalRefItem);
} else if (("service-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: serviceRef
final ServiceRef serviceRefItem = readServiceRef(elementReader, context);
if (serviceRef == null) {
serviceRef = applicationClient.serviceRef;
if (serviceRef != null) {
serviceRef.clear();
} else {
serviceRef = new KeyedCollection<String, ServiceRef>();
}
}
serviceRef.add(serviceRefItem);
} else if (("resource-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: resourceRef
final ResourceRef resourceRefItem = readResourceRef(elementReader, context);
if (resourceRef == null) {
resourceRef = applicationClient.resourceRef;
if (resourceRef != null) {
resourceRef.clear();
} else {
resourceRef = new KeyedCollection<String, ResourceRef>();
}
}
resourceRef.add(resourceRefItem);
} else if (("resource-env-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: resourceEnvRef
final ResourceEnvRef resourceEnvRefItem = readResourceEnvRef(elementReader, context);
if (resourceEnvRef == null) {
resourceEnvRef = applicationClient.resourceEnvRef;
if (resourceEnvRef != null) {
resourceEnvRef.clear();
} else {
resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
}
}
resourceEnvRef.add(resourceEnvRefItem);
} else if (("message-destination-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: messageDestinationRef
final MessageDestinationRef messageDestinationRefItem = readMessageDestinationRef(elementReader, context);
if (messageDestinationRef == null) {
messageDestinationRef = applicationClient.messageDestinationRef;
if (messageDestinationRef != null) {
messageDestinationRef.clear();
} else {
messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
}
}
messageDestinationRef.add(messageDestinationRefItem);
} else if (("persistence-context-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: persistenceContextRef
final PersistenceContextRef persistenceContextRefItem = readPersistenceContextRef(elementReader, context);
if (persistenceContextRef == null) {
persistenceContextRef = applicationClient.persistenceContextRef;
if (persistenceContextRef != null) {
persistenceContextRef.clear();
} else {
persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
}
}
persistenceContextRef.add(persistenceContextRefItem);
} else if (("persistence-unit-ref" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: persistenceUnitRef
final PersistenceUnitRef persistenceUnitRefItem = readPersistenceUnitRef(elementReader, context);
if (persistenceUnitRef == null) {
persistenceUnitRef = applicationClient.persistenceUnitRef;
if (persistenceUnitRef != null) {
persistenceUnitRef.clear();
} else {
persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
}
}
persistenceUnitRef.add(persistenceUnitRefItem);
} else if (("post-construct" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: postConstruct
final org.apache.openejb.jee.LifecycleCallback postConstructItem = readLifecycleCallback(elementReader, context);
if (postConstruct == null) {
postConstruct = applicationClient.postConstruct;
if (postConstruct != null) {
postConstruct.clear();
} else {
postConstruct = new ArrayList<org.apache.openejb.jee.LifecycleCallback>();
}
}
postConstruct.add(postConstructItem);
} else if (("pre-destroy" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: preDestroy
final org.apache.openejb.jee.LifecycleCallback preDestroyItem = readLifecycleCallback(elementReader, context);
if (preDestroy == null) {
preDestroy = applicationClient.preDestroy;
if (preDestroy != null) {
preDestroy.clear();
} else {
preDestroy = new ArrayList<org.apache.openejb.jee.LifecycleCallback>();
}
}
preDestroy.add(preDestroyItem);
} else if (("callback-handler" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: callbackHandler
final String callbackHandlerRaw = elementReader.getElementAsString();
final String callbackHandler;
try {
callbackHandler = Adapters.collapsedStringAdapterAdapter.unmarshal(callbackHandlerRaw);
} catch (final Exception e) {
context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
continue;
}
applicationClient.callbackHandler = callbackHandler;
} else if (("message-destination" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: messageDestination
final MessageDestination messageDestinationItem = readMessageDestination(elementReader, context);
if (messageDestination == null) {
messageDestination = applicationClient.messageDestination;
if (messageDestination != null) {
messageDestination.clear();
} else {
messageDestination = new KeyedCollection<String, MessageDestination>();
}
}
messageDestination.add(messageDestinationItem);
} else if (("data-source" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: dataSource
final DataSource dataSourceItem = readDataSource(elementReader, context);
if (dataSource == null) {
dataSource = applicationClient.dataSource;
if (dataSource != null) {
dataSource.clear();
} else {
dataSource = new KeyedCollection<String, DataSource>();
}
}
dataSource.add(dataSourceItem);
} else {
context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "module-name"), new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "display-name"), new QName("http://java.sun.com/xml/ns/javaee", "icon"), new QName("http://java.sun.com/xml/ns/javaee", "env-entry"), new QName("http://java.sun.com/xml/ns/javaee", "ejb-ref"), new QName("http://java.sun.com/xml/ns/javaee", "ejb-local-ref"), new QName("http://java.sun.com/xml/ns/javaee", "service-ref"), new QName("http://java.sun.com/xml/ns/javaee", "resource-ref"), new QName("http://java.sun.com/xml/ns/javaee", "resource-env-ref"), new QName("http://java.sun.com/xml/ns/javaee", "message-destination-ref"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-context-ref"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-unit-ref"), new QName("http://java.sun.com/xml/ns/javaee", "post-construct"), new QName("http://java.sun.com/xml/ns/javaee", "pre-destroy"), new QName("http://java.sun.com/xml/ns/javaee", "callback-handler"), new QName("http://java.sun.com/xml/ns/javaee", "message-destination"), new QName("http://java.sun.com/xml/ns/javaee", "data-source"));
}
}
if (descriptions != null) {
try {
applicationClient.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
} catch (final Exception e) {
context.setterError(reader, ApplicationClient.class, "setDescriptions", Text[].class, e);
}
}
if (displayNames != null) {
try {
applicationClient.setDisplayNames(displayNames.toArray(new Text[displayNames.size()]));
} catch (final Exception e) {
context.setterError(reader, ApplicationClient.class, "setDisplayNames", Text[].class, e);
}
}
if (icon != null) {
applicationClient.icon = icon;
}
if (envEntry != null) {
applicationClient.envEntry = envEntry;
}
if (ejbRef != null) {
applicationClient.ejbRef = ejbRef;
}
if (ejbLocalRef != null) {
applicationClient.ejbLocalRef = ejbLocalRef;
}
if (serviceRef != null) {
applicationClient.serviceRef = serviceRef;
}
if (resourceRef != null) {
applicationClient.resourceRef = resourceRef;
}
if (resourceEnvRef != null) {
applicationClient.resourceEnvRef = resourceEnvRef;
}
if (messageDestinationRef != null) {
applicationClient.messageDestinationRef = messageDestinationRef;
}
if (persistenceContextRef != null) {
applicationClient.persistenceContextRef = persistenceContextRef;
}
if (persistenceUnitRef != null) {
applicationClient.persistenceUnitRef = persistenceUnitRef;
}
if (postConstruct != null) {
applicationClient.postConstruct = postConstruct;
}
if (preDestroy != null) {
applicationClient.preDestroy = preDestroy;
}
if (messageDestination != null) {
applicationClient.messageDestination = messageDestination;
}
if (dataSource != null) {
applicationClient.dataSource = dataSource;
}
context.afterUnmarshal(applicationClient, org.metatype.sxc.jaxb.LifecycleCallback.NONE);
return applicationClient;
}
use of org.apache.openejb.jee.ResourceRef in project tomee by apache.
the class XmlOverridesTest method test.
public void test() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
lookupEntry.setLookupName("java:app/AppName");
bean.getEnvEntry().add(lookupEntry);
bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
app.getEjbModules().add(new EjbModule(ejbJar));
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final AppInfo appInfo = config.configureApplication(app);
final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
final JndiEncInfo enc = beanInfo.jndiEnc;
assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
// 10 + ComponentName
assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
assertEquals("Context.extended", false, context.extended);
assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
assertEquals("Context.properties.size()", 1, context.properties.size());
assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
use of org.apache.openejb.jee.ResourceRef in project tomee by apache.
the class AutoConfig method processJndiRefs.
private void processJndiRefs(final String moduleId, final JndiConsumer jndiConsumer, final AppResources appResources, final ClassLoader classLoader) throws OpenEJBException {
// Resource reference
for (final ResourceRef ref : jndiConsumer.getResourceRef()) {
// skip destinations with lookup name
if (ref.getLookupName() != null) {
continue;
}
// skip destinations with a global jndi name
final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
if (mappedName.startsWith("jndi:")) {
continue;
}
final String refType = getType(ref, classLoader);
// skip references such as URLs which are automatically handled by the server
if (isIgnoredReferenceType(refType, classLoader)) {
continue;
}
String destinationId = mappedName.length() == 0 ? ref.getName() : mappedName;
try {
destinationId = getResourceId(moduleId, destinationId, refType, appResources);
} catch (final OpenEJBException ex) {
if (!(ref instanceof ContextRef)) {
throw ex;
} else {
// let jaxrs provider manage it
continue;
}
}
ref.setMappedName(destinationId);
}
// Resource env reference
for (final JndiReference ref : jndiConsumer.getResourceEnvRef()) {
// skip destinations with lookup name
if (ref.getLookupName() != null) {
continue;
}
// skip destinations with a global jndi name
final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
if (mappedName.startsWith("jndi:")) {
continue;
}
final String refType = getType(ref, classLoader);
// skip references such as URLs which are automatically handled by the server
if (isIgnoredReferenceType(refType, classLoader)) {
continue;
}
String destinationId = mappedName.length() == 0 ? ref.getName() : mappedName;
destinationId = getResourceEnvId(moduleId, destinationId, refType, appResources);
ref.setMappedName(destinationId);
}
// Message destination reference
for (final MessageDestinationRef ref : jndiConsumer.getMessageDestinationRef()) {
// skip destinations with lookup name
if (ref.getLookupName() != null) {
continue;
}
// skip destinations with a global jndi name
final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
if (mappedName.startsWith("jndi:")) {
continue;
}
String destinationId = mappedName.length() == 0 ? ref.getName() : mappedName;
destinationId = getResourceEnvId(moduleId, destinationId, ref.getType(), appResources);
ref.setMappedName(destinationId);
}
}
use of org.apache.openejb.jee.ResourceRef in project tomee by apache.
the class AutoConfig method processApplicationResources.
private void processApplicationResources(final AppModule module) throws OpenEJBException {
final Collection<Resource> resources = module.getResources();
if (resources.size() == 0) {
return;
}
final List<JndiConsumer> jndiConsumers = new ArrayList<JndiConsumer>();
for (final WebModule webModule : module.getWebModules()) {
final JndiConsumer consumer = webModule.getWebApp();
jndiConsumers.add(consumer);
}
for (final EjbModule ejbModule : module.getEjbModules()) {
Collections.addAll(jndiConsumers, ejbModule.getEjbJar().getEnterpriseBeans());
}
List<ResourceInfo> resourceInfos = new ArrayList<ResourceInfo>();
final Map<ResourceInfo, Resource> resourcesMap = new HashMap<ResourceInfo, Resource>(resources.size());
for (final Resource resource : resources) {
final String originalId = PropertyPlaceHolderHelper.value(resource.getId());
final String modulePrefix = module.getModuleId() + "/";
if ("/".equals(modulePrefix) || originalId.startsWith("global") || originalId.startsWith("/global")) {
resource.setId(replaceJavaAndSlash(originalId));
} else {
resource.getProperties().setProperty(ORIGINAL_ID, originalId);
resource.setId(modulePrefix + replaceJavaAndSlash(originalId));
}
resource.setJndi(PropertyPlaceHolderHelper.value(resource.getJndi()));
final Thread thread = Thread.currentThread();
final ClassLoader oldCl = thread.getContextClassLoader();
thread.setContextClassLoader(module.getClassLoader());
try {
resource.getProperties().putAll(PropertyPlaceHolderHelper.holds(resource.getProperties()));
} finally {
thread.setContextClassLoader(oldCl);
}
final Collection<String> aliases = resource.getAliases();
if (!aliases.isEmpty()) {
final Collection<String> newAliases = new ArrayList<String>();
for (final String s : aliases) {
newAliases.add(module.getModuleId() + "/" + s);
}
resource.getAliases().clear();
resource.getAliases().addAll(newAliases);
}
final Properties properties = resource.getProperties();
if (DataSource.class.getName().equals(resource.getType()) || DataSource.class.getSimpleName().equals(resource.getType())) {
DataSourceFactory.trimNotSupportedDataSourceProperties(properties);
}
final boolean shouldGenerateJdbcUrl = DataSource.class.getName().equals(resource.getType()) && resource.getProperties().containsKey(ORIGIN_FLAG) && resource.getProperties().getProperty(ORIGIN_FLAG).equals(ORIGIN_ANNOTATION);
if (shouldGenerateJdbcUrl && properties.get("JdbcUrl") == null) {
final String url = getVendorUrl(properties);
if (url != null) {
properties.put("JdbcUrl", url);
}
}
final ResourceInfo resourceInfo = configFactory.configureService(resource, ResourceInfo.class);
resourceInfo.originAppName = module.getModuleId();
final ResourceRef resourceRef = new ResourceRef();
resourceRef.setResType(chooseType(module.getClassLoader(), resourceInfo, resource.getType()));
if (shouldGenerateJdbcUrl) {
properties.remove(ORIGIN_FLAG);
resourceRef.setResRefName(dataSourceLookupName(resource));
} else {
resourceRef.setResRefName(OPENEJB_RESOURCE_JNDI_PREFIX + resourceInfo.id);
}
resourceRef.setMappedName(resourceInfo.id);
final ResourceRef strictRef = new ResourceRef(OPENEJB_RESOURCE_JNDI_PREFIX + originalId, resourceRef.getResType(), resourceRef.getResAuth(), resourceRef.getResSharingScope());
strictRef.setMappedName(resourceInfo.id);
for (final JndiConsumer consumer : jndiConsumers) {
// for injections etc...
addResource(consumer, resourceRef);
if (!"/".equals(modulePrefix)) {
// for lookups (without prefix)
addResource(consumer, strictRef);
}
}
resourceInfos.add(resourceInfo);
resourcesMap.put(resourceInfo, resource);
}
resourceInfos = ConfigurationFactory.sort(resourceInfos, module.getModuleId() + "/");
for (final ResourceInfo resourceInfo : resourceInfos) {
final int originalSize = resourceInfo.aliases.size();
final String id = installResource(module.getModuleId(), resourceInfo);
final Resource resource = resourcesMap.remove(resourceInfo);
resource.setId(id);
if (resourceInfo.aliases.size() > originalSize) {
// an aliases is generally added to be able to bind in global jndi tree
resource.getAliases().add(resourceInfo.aliases.get(resourceInfo.aliases.size() - 1));
}
}
resourceInfos.clear();
// resources.clear(); // don't clear it since we want to keep this to be able to undeploy resources with the app
}
use of org.apache.openejb.jee.ResourceRef in project tomee by apache.
the class JndiEncInfoBuilder method buildResourceRefInfos.
private void buildResourceRefInfos(final JndiConsumer item, final JndiEncInfo moduleJndiEnc, final JndiEncInfo compJndiEnc) {
for (final ResourceRef res : item.getResourceRef()) {
final ResourceReferenceInfo info;
if (res instanceof ContextRef) {
info = new ContextReferenceInfo();
} else {
info = new ResourceReferenceInfo();
}
if (res.getResAuth() != null) {
info.referenceAuth = res.getResAuth().toString();
} else {
info.referenceAuth = ResAuth.CONTAINER.toString();
}
info.referenceName = res.getResRefName();
info.referenceType = res.getResType();
info.resourceID = res.getMappedName();
info.location = buildLocationInfo(res);
info.targets.addAll(buildInjectionInfos(res));
insert(info, appInfo.globalJndiEnc.resourceRefs, appInfo.appJndiEnc.resourceRefs, moduleJndiEnc.resourceRefs, compJndiEnc.resourceRefs);
}
}
Aggregations