You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/09/10 10:23:26 UTC
svn commit: r1382689 - in /openejb/trunk/openejb/container/openejb-core/src:
main/java/org/apache/openejb/config/ main/java/org/apache/openejb/config/sys/
main/java/org/apache/openejb/junit/ test/java/org/apache/openejb/config/sys/
Author: rmannibucau
Date: Mon Sep 10 08:23:25 2012
New Revision: 1382689
URL: http://svn.apache.org/viewvc?rev=1382689&view=rev
Log:
more consistency in the way the 'new file config' is handled
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/AppResource.java (contents, props changed)
- copied, changed from r1382650, openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppContextConfigDeployer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/BeanProperties.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EnvEntriesPropertiesDeployer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/sys/ParseAppCtxXmlTest.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Mon Sep 10 08:23:25 2012
@@ -313,19 +313,12 @@ public class AnnotationDeployer implemen
private final MBeanDeployer mBeanDeployer;
private final BuiltInEnvironmentEntries builtInEnvironmentEntries;
private final MergeWebappJndiContext mergeWebappJndiContext;
- private final DynamicDeployer preJndiBindingDeployer;
- // TODO: explode it in Configuration factory to be able to add other deployer easily between phases
public AnnotationDeployer() {
- this(null);
- }
-
- public AnnotationDeployer(final DynamicDeployer postDiscoverDeployer) {
discoverAnnotatedBeans = new DiscoverAnnotatedBeans();
processAnnotatedBeans = new ProcessAnnotatedBeans();
builtInEnvironmentEntries = new BuiltInEnvironmentEntries();
envEntriesPropertiesDeployer = new EnvEntriesPropertiesDeployer();
- preJndiBindingDeployer = postDiscoverDeployer;
mBeanDeployer = new MBeanDeployer();
mergeWebappJndiContext = new MergeWebappJndiContext();
}
@@ -337,9 +330,6 @@ public class AnnotationDeployer implemen
try {
appModule = discoverAnnotatedBeans.deploy(appModule);
appModule = envEntriesPropertiesDeployer.deploy(appModule);
- if (preJndiBindingDeployer != null) {
- appModule = preJndiBindingDeployer.deploy(appModule);
- }
appModule = mergeWebappJndiContext.deploy(appModule);
appModule = builtInEnvironmentEntries.deploy(appModule);
appModule = processAnnotatedBeans.deploy(appModule);
@@ -347,6 +337,7 @@ public class AnnotationDeployer implemen
appModule = mBeanDeployer.deploy(appModule);
return appModule;
} finally {
+ envEntriesPropertiesDeployer.resetAdditionalEnvEntries();
Thread.currentThread().setContextClassLoader(classLoader);
removeModule();
}
@@ -368,6 +359,7 @@ public class AnnotationDeployer implemen
webModule = processAnnotatedBeans.deploy(webModule);
return webModule;
} finally {
+ envEntriesPropertiesDeployer.resetAdditionalEnvEntries();
Thread.currentThread().setContextClassLoader(classLoader);
removeModule();
}
@@ -5188,4 +5180,10 @@ public class AnnotationDeployer implemen
}
return classes;
}
+
+ public EnvEntriesPropertiesDeployer getEnvEntriesPropertiesDeployer() {
+ return envEntriesPropertiesDeployer;
+ }
+
+
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppContextConfigDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppContextConfigDeployer.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppContextConfigDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppContextConfigDeployer.java Mon Sep 10 08:23:25 2012
@@ -34,11 +34,12 @@ import java.util.Set;
public class AppContextConfigDeployer implements DynamicDeployer {
private static final String CONFIG_NAME = "app-ctx.xml";
- private SaxAppCtxConfig.Phase currentPhase = SaxAppCtxConfig.Phase.BEFORE_SCANNING;
+ private final EnvEntriesPropertiesDeployer envEntriesDeployer;
+ private final BeanProperties beanPropertiesDeployer;
- public AppContextConfigDeployer currentPhase(final SaxAppCtxConfig.Phase currentPhase) {
- this.currentPhase = currentPhase;
- return this;
+ public AppContextConfigDeployer(final EnvEntriesPropertiesDeployer envEntriesPropertiesDeployer, BeanProperties beanProperties) {
+ envEntriesDeployer = envEntriesPropertiesDeployer;
+ beanPropertiesDeployer = beanProperties;
}
@Override
@@ -70,7 +71,7 @@ public class AppContextConfigDeployer im
InputStream is = null;
try {
is = IO.read(url);
- SaxAppCtxConfig.parse(appModule, new InputSource(is), currentPhase); // work directly on the module, avoid temp objects
+ SaxAppCtxConfig.parse(appModule, new InputSource(is), envEntriesDeployer, beanPropertiesDeployer); // work directly on the module/deployer, avoid temp objects
} catch (SAXException e) {
throw new OpenEJBException("can't parse " + url.toExternalForm(), e);
} catch (ParserConfigurationException e) {
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/BeanProperties.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/BeanProperties.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/BeanProperties.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/BeanProperties.java Mon Sep 10 08:23:25 2012
@@ -25,6 +25,7 @@ import org.apache.openejb.util.LogCatego
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.SuperProperties;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -35,6 +36,9 @@ public class BeanProperties implements D
private static final Logger log = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, ModuleProperties.class);
+ private final Map<String, Properties> additionalProperties = new HashMap<String, Properties>();
+ private final Properties globalProperties = new Properties();
+
@Override
public AppModule deploy(AppModule appModule) throws OpenEJBException {
@@ -57,6 +61,15 @@ public class BeanProperties implements D
for (EnterpriseBean bean : module.getEjbJar().getEnterpriseBeans()) {
final SuperProperties properties = new SuperProperties().caseInsensitive(true);
+ properties.putAll(globalProperties);
+
+ final String additionalKey = bean.getEjbName();
+ if (additionalProperties.containsKey(additionalKey)) {
+ for (Map.Entry<Object, Object> entry : additionalProperties.get(additionalKey).entrySet()) {
+ properties.put(entry.getKey().toString(), entry.getValue().toString());
+ }
+ }
+
final EjbDeployment deployment = deploymentMap.get(bean.getEjbName());
if (deployment != null) {
properties.putAll(deployment.getProperties());
@@ -92,7 +105,22 @@ public class BeanProperties implements D
}
}
+ // cleanup
+ additionalProperties.clear();
+ globalProperties.clear();
+
return appModule;
}
+ public void addProperties(final String id, final Properties properties) {
+ if (additionalProperties.containsKey(id)) {
+ additionalProperties.get(id).putAll(properties);
+ } else {
+ additionalProperties.put(id, properties);
+ }
+ }
+
+ public void addGlobalProperties(final Properties properties) {
+ globalProperties.putAll(properties);
+ }
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Mon Sep 10 08:23:25 2012
@@ -161,7 +161,11 @@ public class ConfigurationFactory implem
}
}
- final AppContextConfigDeployer appContextConfigDeployer = new AppContextConfigDeployer();
+ // annotation deployer encapsulate some logic, to be able to push to it some config
+ // we give the ability here to get the internal deployer to push the config values
+ final AnnotationDeployer annotationDeployer = new AnnotationDeployer();
+ final BeanProperties beanProperties = new BeanProperties();
+ final AppContextConfigDeployer appContextConfigDeployer = new AppContextConfigDeployer(annotationDeployer.getEnvEntriesPropertiesDeployer(), beanProperties);
final Chain chain = new Chain();
@@ -171,7 +175,7 @@ public class ConfigurationFactory implem
chain.add(new ReadDescriptors());
- chain.add(appContextConfigDeployer.currentPhase(SaxAppCtxConfig.Phase.BEFORE_SCANNING));
+ chain.add(appContextConfigDeployer);
chain.add(new ApplicationProperties());
@@ -179,9 +183,9 @@ public class ConfigurationFactory implem
chain.add(new LegacyProcessor());
- chain.add(new AnnotationDeployer(appContextConfigDeployer.currentPhase(SaxAppCtxConfig.Phase.AFTER_SACNNING)));
+ chain.add(annotationDeployer);
- chain.add(new BeanProperties());
+ chain.add(beanProperties);
chain.add(new ProxyBeanClassUpdate());
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EnvEntriesPropertiesDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EnvEntriesPropertiesDeployer.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EnvEntriesPropertiesDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EnvEntriesPropertiesDeployer.java Mon Sep 10 08:23:25 2012
@@ -45,6 +45,7 @@ public class EnvEntriesPropertiesDeploye
public static final String ENV_ENTRY_PROPERTIES = "env-entries.properties";
private final String descriptorName;
+ private final Map<String, String> additionalEnvEntries = new HashMap<String, String>();
public EnvEntriesPropertiesDeployer() {
this(ENV_ENTRY_PROPERTIES);
@@ -141,12 +142,20 @@ public class EnvEntriesPropertiesDeploye
}
if (propsUrl == null) return Collections.emptyMap();
try {
- Properties envEntriesProps = IO.readProperties(propsUrl);
-
+ final Properties envEntriesProps = IO.readProperties(propsUrl);
+ envEntriesProps.putAll(additionalEnvEntries);
return new HashMap(envEntriesProps);
} catch (IOException e) {
log.error("envprops.notLoaded", e, module.getModuleId(), propsUrl.toExternalForm());
return Collections.emptyMap();
}
}
+
+ public void addEnvEntries(final String key, final String value) {
+ additionalEnvEntries.put(key, value);
+ }
+
+ public void resetAdditionalEnvEntries() {
+ additionalEnvEntries.clear();
+ }
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/sys/SaxAppCtxConfig.java Mon Sep 10 08:23:25 2012
@@ -16,14 +16,15 @@
*/
package org.apache.openejb.config.sys;
-import org.apache.openejb.OpenEJBException;
import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.BeanProperties;
import org.apache.openejb.config.EjbModule;
import org.apache.openejb.config.EnvEntriesPropertiesDeployer;
import org.apache.openejb.config.PojoConfiguration;
import org.apache.openejb.jee.EnterpriseBean;
import org.apache.openejb.jee.oejb3.EjbDeployment;
import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.Saxs;
@@ -40,7 +41,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -48,14 +48,12 @@ import java.util.Properties;
public class SaxAppCtxConfig {
private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, SaxAppContextConfig.class);
- public enum Phase {
- BEFORE_SCANNING, AFTER_SACNNING
- }
-
- public static void parse(final AppModule appModule, final InputSource source, final Phase phase) throws SAXException, ParserConfigurationException, IOException {
+ public static void parse(final AppModule appModule, final InputSource source,
+ final EnvEntriesPropertiesDeployer envEntriesDeployer, final BeanProperties beanProperties)
+ throws SAXException, ParserConfigurationException, IOException {
Saxs.factory()
.newSAXParser()
- .parse(source, new SaxAppContextConfig(appModule, phase));
+ .parse(source, new SaxAppContextConfig(appModule, envEntriesDeployer, beanProperties));
}
private static class SaxAppContextConfig extends StackHandler {
@@ -73,11 +71,13 @@ public class SaxAppCtxConfig {
private static final Collection<String> ENV_ENTRY_ALIASES = Arrays.asList("enventry", "env-entry");
private final AppModule module;
- private final Phase phase;
+ private final EnvEntriesPropertiesDeployer envEntriesDeployer;
+ private final BeanProperties beanPropertiesDeployer;
- public SaxAppContextConfig(final AppModule appModule, Phase phase) {
+ public SaxAppContextConfig(final AppModule appModule, final EnvEntriesPropertiesDeployer envEntriesDeployer, final BeanProperties beanProperties) {
this.module = appModule;
- this.phase = phase;
+ this.envEntriesDeployer = envEntriesDeployer;
+ this.beanPropertiesDeployer = beanProperties;
}
@Override
@@ -88,11 +88,13 @@ public class SaxAppCtxConfig {
private class Document extends DefaultHandler {
@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException {
- if (APPLICATION_ALIASES.contains(localName.toLowerCase())) {
- push(new Root());
- } else {
+ // by default don't care about root tag
+ if (!APPLICATION_ALIASES.contains(localName.toLowerCase())
+ && SystemInstance.get().getOptions().get("openejb.configuration.strict-tags", false)) {
throw new IllegalStateException("Unsupported Element: " + localName);
+
}
+ push(new Root());
}
}
@@ -122,7 +124,7 @@ public class SaxAppCtxConfig {
final File file = new File(path);
if (file.exists()) {
try {
- parse(module, new InputSource(new FileInputStream(file)), phase);
+ parse(module, new InputSource(new FileInputStream(file)), envEntriesDeployer, beanPropertiesDeployer);
} catch (ParserConfigurationException e) {
throw new SAXException(e);
} catch (IOException e) {
@@ -134,7 +136,7 @@ public class SaxAppCtxConfig {
final InputStream is = cl.getResourceAsStream(path);
if (is != null) {
try {
- parse(module, new InputSource(is), phase);
+ parse(module, new InputSource(is), envEntriesDeployer, beanPropertiesDeployer);
} catch (ParserConfigurationException e) {
throw new SAXException(e);
} catch (IOException e) {
@@ -167,10 +169,6 @@ public class SaxAppCtxConfig {
@Override
public void setValue(final String text) {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
try {
for (Map.Entry<Object, Object> entry : new PropertiesAdapter().unmarshal(text).entrySet()) {
properties.put(prefix + entry.getKey(), entry.getValue());
@@ -218,10 +216,6 @@ public class SaxAppCtxConfig {
@Override
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
for (PojoConfig generic : genericConfigs) {
for (PojoConfiguration config : module.getPojoConfigurations().values()) {
for (String key : generic.getProperties().stringPropertyNames()) {
@@ -254,41 +248,9 @@ public class SaxAppCtxConfig {
@Override
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
for (PojoConfig generic : genericConfigs) { // BeanContextConfig
- if (!generic.hasProperties()) {
- continue;
- }
-
- for (EjbModule ejbModule : module.getEjbModules()) {
- if (acceptModule(id, ejbModule)) {
- continue;
- }
-
- for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
- final String name = bean.getEjbName();
-
- OpenejbJar openEjbJar = ejbModule.getOpenejbJar();
- if (openEjbJar == null) {
- openEjbJar = new OpenejbJar();
- ejbModule.setOpenejbJar(openEjbJar);
- }
-
- final Map<String, EjbDeployment> openejbJarDeployment = openEjbJar.getDeploymentsByEjbName();
- EjbDeployment deployment = openejbJarDeployment.get(name);
- if (deployment == null) {
- deployment = openEjbJar.addEjbDeployment(bean);
- }
-
- for (String key : generic.getProperties().stringPropertyNames()) {
- if (!deployment.getProperties().containsKey(key)) {
- deployment.getProperties().put(key, generic.getProperties().get(key));
- }
- }
- }
+ if (generic.hasProperties()) {
+ beanPropertiesDeployer.addGlobalProperties(generic.getProperties());
}
}
}
@@ -314,10 +276,6 @@ public class SaxAppCtxConfig {
@Override
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
module.getPojoConfigurations().put(id, new PojoConfiguration(pojoConfig.getProperties()));
}
}
@@ -332,35 +290,13 @@ public class SaxAppCtxConfig {
@Override
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
for (EjbModule ejbModule : module.getEjbModules()) {
if (!acceptModule(moduleId, ejbModule)) {
continue;
}
- final EnterpriseBean bean = ejbModule.getEjbJar().getEnterpriseBeansByEjbName().get(id);
- if (bean == null) {
- continue;
- }
-
- final String name = bean.getEjbName();
-
if (pojoConfig.hasProperties()) {
- OpenejbJar openEjbJar = ejbModule.getOpenejbJar();
- if (openEjbJar == null) {
- openEjbJar = new OpenejbJar();
- ejbModule.setOpenejbJar(openEjbJar);
- }
-
- final Map<String, EjbDeployment> openejbJarDeployment = openEjbJar.getDeploymentsByEjbName();
- EjbDeployment deployment = openejbJarDeployment.get(name);
- if (deployment == null) {
- deployment = openEjbJar.addEjbDeployment(bean);
- }
- deployment.getProperties().putAll(pojoConfig.getProperties());
+ beanPropertiesDeployer.addProperties(id, pojoConfig.getProperties());
}
}
}
@@ -382,54 +318,20 @@ public class SaxAppCtxConfig {
}
private class EnvEntries extends DefaultHandler {
- protected final String ENV_ENTRY_KEY = EnvEntries.class.getName();
-
- private final Map<String, String> values = new HashMap<String, String>();
-
@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException {
if (ENV_ENTRY_ALIASES.contains(localName.toLowerCase())) {
- push(new EnvEntry(values));
+ push(new EnvEntry());
get().startElement(uri, localName, qName, attributes);
} else {
throw new IllegalStateException("Unsupported Element: " + localName);
}
}
-
- @Override
- public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
- if (values.size() == 0) {
- return;
- }
-
- for (EjbModule ejbModule : module.getEjbModules()) {
- ejbModule.getAltDDs().put(ENV_ENTRY_KEY, values);
- }
- try {
- new EnvEntriesPropertiesDeployer(ENV_ENTRY_KEY).deploy(module);
- } catch (OpenEJBException e) {
- LOGGER.error("can't manage app-ctx.xml env-entries", e);
- }
- for (EjbModule ejbModule : module.getEjbModules()) {
- ejbModule.getAltDDs().remove(ENV_ENTRY_KEY);
- }
- values.clear();
- }
}
private class EnvEntry extends Content {
- private final Map<String, String> storage;
-
private String key;
- public EnvEntry(final Map<String, String> values) {
- storage = values;
- }
-
@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) {
if (ENV_ENTRY_ALIASES.contains(localName.toLowerCase())) {
@@ -441,11 +343,7 @@ public class SaxAppCtxConfig {
@Override
public void setValue(final String text) {
- if (!phase.equals(Phase.AFTER_SACNNING)) {
- return;
- }
-
- storage.put(key, text);
+ envEntriesDeployer.addEnvEntries(key, text);
}
}
}
Copied: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/AppResource.java (from r1382650, openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/AppResource.java?p2=openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/AppResource.java&p1=openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java&r1=1382650&r2=1382689&rev=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/AppResource.java Mon Sep 10 08:23:25 2012
@@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-@Target(ElementType.METHOD)
+@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface Module {
+public @interface AppResource {
}
Propchange: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/AppResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java Mon Sep 10 08:23:25 2012
@@ -55,11 +55,14 @@ import org.apache.xbean.finder.Annotatio
import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.rules.MethodRule;
import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkField;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.junit.runners.model.TestClass;
+import javax.naming.Context;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -105,7 +108,7 @@ public class ApplicationComposer extends
int appModules = 0;
int modules = 0;
- Class[] moduleTypes = { WebModule.class, EjbModule.class, EjbJar.class, EnterpriseBean.class, Persistence.class, PersistenceUnit.class, Connector.class, Beans.class, Application.class, Class[].class};
+ Class[] moduleTypes = { AppModule.class, WebModule.class, EjbModule.class, EjbJar.class, EnterpriseBean.class, Persistence.class, PersistenceUnit.class, Connector.class, Beans.class, Application.class, Class[].class};
for (FrameworkMethod method : testClass.getAnnotatedMethods(Module.class)) {
modules++;
@@ -256,6 +259,21 @@ public class ApplicationComposer extends
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(bean)).link());
ejbModule.setBeans(new Beans());
appModule.getEjbModules().add(ejbModule);
+ } else if (obj instanceof AppModule) {
+
+ // we can probably go further here
+ final AppModule module = (AppModule) obj;
+ appModule.getEjbModules().addAll(module.getEjbModules());
+ appModule.getPersistenceModules().addAll(module.getPersistenceModules());
+ appModule.getAdditionalLibMbeans().addAll(module.getAdditionalLibMbeans());
+ appModule.getWebModules().addAll(module.getWebModules());
+ appModule.getConnectorModules().addAll(module.getConnectorModules());
+ appModule.getResources().addAll(module.getResources());
+ appModule.getServices().addAll(module.getServices());
+ appModule.getPojoConfigurations().putAll(module.getPojoConfigurations());
+ appModule.getAdditionalLibraries().addAll(module.getAdditionalLibraries());
+ appModule.getAltDDs().putAll(module.getAltDDs());
+ appModule.getProperties().putAll(module.getProperties());
}
}
@@ -353,6 +371,23 @@ public class ApplicationComposer extends
System.getProperties().put(OPENEJB_APPLICATION_COMPOSER_CONTEXT, appContext.getGlobalJndiContext());
+ // test injections
+ final List<FrameworkField> fields = testClass.getAnnotatedFields(AppResource.class);
+ for (FrameworkField field : fields) {
+ final Class<?> type = field.getType();
+ if (AppModule.class.isAssignableFrom(type)) {
+ final Field jField = field.getField();
+ jField.setAccessible(true);
+ jField.set(testInstance, appModule);
+ } else if (Context.class.isAssignableFrom(type)) {
+ final Field jField = field.getField();
+ jField.setAccessible(true);
+ jField.set(testInstance, appContext.getGlobalJndiContext());
+ } else {
+ throw new IllegalArgumentException("can't find value for type " + type.getName());
+ }
+ }
+
final ThreadContext previous = ThreadContext.enter(new ThreadContext(context, null, Operation.BUSINESS));
try {
next.evaluate();
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/sys/ParseAppCtxXmlTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/sys/ParseAppCtxXmlTest.java?rev=1382689&r1=1382688&r2=1382689&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/sys/ParseAppCtxXmlTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/sys/ParseAppCtxXmlTest.java Mon Sep 10 08:23:25 2012
@@ -17,30 +17,39 @@
package org.apache.openejb.config.sys;
import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.config.AppContextConfigDeployer;
import org.apache.openejb.config.AppModule;
import org.apache.openejb.config.EjbModule;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.SingletonBean;
import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.junit.AppResource;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Module;
import org.junit.Test;
+import org.junit.runner.RunWith;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
+@RunWith(ApplicationComposer.class)
public class ParseAppCtxXmlTest {
+ @AppResource
+ private AppModule module;
+
+ @Module
+ public AppModule module() {
+ final AppModule app = new AppModule(ParseAppCtxXmlTest.class.getClassLoader(), "");
+ app.getAltDDs().put("app-ctx.xml", ParseAppCtxXmlTest.class.getClassLoader().getResource("complete-app-ctx.xml"));
+ app.getEjbModules().add(ejbModule("1"));
+ app.getEjbModules().iterator().next().getEjbJar().addEnterpriseBean(new SingletonBean("CalculatorBean", CalculatorConfigured.class.getName()));
+ app.getEjbModules().add(ejbModule("2"));
+ app.getEjbModules().get(1).getEjbJar().addEnterpriseBean(new SingletonBean("BeanInAModule", CalculatorConfigured2.class.getName()));
+ return app;
+ }
+
@Test
public void parse() throws IOException, OpenEJBException {
- final AppModule module = new AppModule(ParseAppCtxXmlTest.class.getClassLoader(), "");
- module.getAltDDs().put("app-ctx.xml", ParseAppCtxXmlTest.class.getClassLoader().getResource("complete-app-ctx.xml"));
- new AppContextConfigDeployer().currentPhase(SaxAppCtxConfig.Phase.BEFORE_SCANNING).deploy(module);
- module.getEjbModules().add(ejbModule("1"));
- module.getEjbModules().iterator().next().getEjbJar().addEnterpriseBean(new SingletonBean("CalculatorBean", "CalculatorBean"));
- module.getEjbModules().add(ejbModule("2"));
- module.getEjbModules().get(1).getEjbJar().addEnterpriseBean(new SingletonBean("BeanInAModule", "BeanInAModule"));
- new AppContextConfigDeployer().currentPhase(SaxAppCtxConfig.Phase.AFTER_SACNNING).deploy(module);
-
// Properties
assertEquals("dummy", module.getProperties().getProperty("foo.bar"));
assertEquals("10", module.getProperties().getProperty("AsynchronousPool.CorePoolSize"));
@@ -55,12 +64,12 @@ public class ParseAppCtxXmlTest {
assertEquals("true", module.getProperties().getProperty("i.m.imported"));
// BeanContext
- final EjbDeployment calculator = module.getEjbModules().iterator().next().getOpenejbJar().getDeploymentsByEjbName().get("CalculatorBean");
+ final EjbDeployment calculator = module.getEjbModules().get(1).getOpenejbJar().getDeploymentsByEjbName().get("CalculatorBean");
assertEquals("ok", calculator.getProperties().getProperty("no.root"));
assertEquals("wss4j", calculator.getProperties().getProperty("cxf.jaxws.in-interceptors"));
// ModuleContext
- final EjbDeployment beanInAModule = module.getEjbModules().get(1).getOpenejbJar().getDeploymentsByEjbName().get("BeanInAModule");
+ final EjbDeployment beanInAModule = module.getEjbModules().get(2).getOpenejbJar().getDeploymentsByEjbName().get("BeanInAModule");
assertEquals("mId", beanInAModule.getProperties().getProperty("module.id"));
// Pojo
@@ -76,4 +85,14 @@ public class ParseAppCtxXmlTest {
module.setModuleId(id);
return module;
}
+
+ // just some class to be able to deploy "fake" ejbs
+
+ public static class CalculatorConfigured {
+
+ }
+
+ public static class CalculatorConfigured2 {
+
+ }
}