You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/08/29 06:31:52 UTC
svn commit: r570634 - in /openejb/trunk/openejb3:
container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/
container/openejb-core/src/main/java/org/apache/openejb/config/
container/openejb-core/src/main/java/org/apache/openejb/core/se...
Author: dblevins
Date: Tue Aug 28 21:31:49 2007
New Revision: 570634
URL: http://svn.apache.org/viewvc?rev=570634&view=rev
Log:
Added the ability for properties to be specified at the ejb-jar level. So far just extends to these properties:
openejb.jndiname.strategy.class
openejb.jndiname.format
openejb.deploymentId.format
Added:
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java
openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/OpenejbJar.java
openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Tue Aug 28 21:31:49 2007
@@ -514,7 +514,7 @@
} catch (Throwable t) {
try {
destroyApplication(appInfo);
- } catch (UndeployException e1) {
+ } catch (Exception e1) {
logger.debug("App failing deployment may not have undeployed cleanly: "+appInfo.jarPath, e1);
}
throw new OpenEJBException("Creating application failed: "+appInfo.jarPath, t);
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java Tue Aug 28 21:31:49 2007
@@ -18,8 +18,11 @@
import java.util.List;
import java.util.ArrayList;
+import java.util.Properties;
public class EjbJarInfo extends InfoObject {
+ public final Properties properties = new Properties();
+
public String moduleId;
public String jarPath;
public final List<EnterpriseBeanInfo> enterpriseBeans = new ArrayList<EnterpriseBeanInfo>();
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java Tue Aug 28 21:31:49 2007
@@ -39,6 +39,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Comparator;
+import java.lang.reflect.Constructor;
/**
@@ -48,31 +49,48 @@
public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, JndiBuilder.class.getPackage().getName());
- private JndiNameStrategy strategy = new LegacyAddedSuffixStrategy();
private final Context context;
+ private static final String JNDINAME_STRATEGY_CLASS = "openejb.jndiname.strategy.class";
public JndiBuilder(Context context) {
this.context = context;
+ }
+
+ public void build(EjbJarInfo ejbJar, HashMap<String, DeploymentInfo> deployments) {
+
+ JndiNameStrategy strategy = createStrategy(ejbJar, deployments);
+
+ for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
+ DeploymentInfo deploymentInfo = deployments.get(beanInfo.ejbDeploymentId);
+ bind(ejbJar, deploymentInfo, beanInfo, strategy);
+ }
+ }
- String strategyClass = SystemInstance.get().getProperty("openejb.jndiname.strategy.class", LegacyAddedSuffixStrategy.class.getName());
+ private JndiNameStrategy createStrategy(EjbJarInfo ejbJar, HashMap<String, DeploymentInfo> deployments) {
+ String strategyClassName = SystemInstance.get().getProperty(JNDINAME_STRATEGY_CLASS, TemplatedStrategy.class.getName());
+ strategyClassName = ejbJar.properties.getProperty(JNDINAME_STRATEGY_CLASS, strategyClassName);
+
+ logger.debug("Using " + JNDINAME_STRATEGY_CLASS + " '" + strategyClassName + "'");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
- strategy = (JndiNameStrategy) classLoader.loadClass(strategyClass).newInstance();
+ Class strategyClass = classLoader.loadClass(strategyClassName);
+
+ try {
+ Constructor constructor = strategyClass.getConstructor(EjbJarInfo.class, Map.class);
+ return (JndiNameStrategy) constructor.newInstance(ejbJar, deployments);
+ } catch (NoSuchMethodException e) {
+ }
+
+ Constructor constructor = strategyClass.getConstructor();
+ return (JndiNameStrategy) constructor.newInstance();
} catch (InstantiationException e) {
- throw new IllegalStateException("Could not instantiate JndiNameStrategy: "+strategyClass, e);
+ throw new IllegalStateException("Could not instantiate JndiNameStrategy: "+strategyClassName, e);
} catch (IllegalAccessException e) {
- throw new IllegalStateException("Could not access JndiNameStrategy: "+strategyClass, e);
+ throw new IllegalStateException("Could not access JndiNameStrategy: "+strategyClassName, e);
} catch (ClassNotFoundException e) {
- throw new IllegalStateException("Could not load JndiNameStrategy: "+strategyClass, e);
+ throw new IllegalStateException("Could not load JndiNameStrategy: "+strategyClassName, e);
} catch (Throwable t){
- throw new IllegalStateException("Could not create JndiNameStrategy: "+strategyClass, t);
- }
- }
-
- public void build(EjbJarInfo ejbJar, HashMap<String, DeploymentInfo> deployments) {
- for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
- DeploymentInfo deploymentInfo = deployments.get(beanInfo.ejbDeploymentId);
- bind(deploymentInfo, beanInfo);
+ throw new IllegalStateException("Could not create JndiNameStrategy: "+strategyClassName, t);
}
}
@@ -139,15 +157,20 @@
// TODO: put these into the classpath and get them with xbean-finder
public static class TemplatedStrategy implements JndiNameStrategy {
+ private static final String JNDINAME_FORMAT = "openejb.jndiname.format";
private org.codehaus.swizzle.stream.StringTemplate template;
- public TemplatedStrategy() {
- String format = SystemInstance.get().getProperty("openejb.jndiname.format", "{deploymentId}/{interfaceClass.simpleName}");
+ public TemplatedStrategy(EjbJarInfo ejbJarInfo, Map<String, DeploymentInfo> deployments) {
+ String format = SystemInstance.get().getProperty(JNDINAME_FORMAT, "{deploymentId}{interfaceType.openejbLegacyName}");
+ format = ejbJarInfo.properties.getProperty(JNDINAME_FORMAT, format);
+
+ logger.info("Using " + JNDINAME_FORMAT + " '" + format + "'");
+
this.template = new StringTemplate(format);
}
-
public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
+
Map<String,String> contextData = new HashMap<String,String>();
contextData.put("moduleId", deploymentInfo.getModuleID());
contextData.put("ejbType", deploymentInfo.getComponentType().name());
@@ -155,18 +178,18 @@
contextData.put("ejbClass.simpleName", deploymentInfo.getBeanClass().getSimpleName());
contextData.put("ejbName", deploymentInfo.getEjbName());
contextData.put("deploymentId", deploymentInfo.getDeploymentID().toString());
- contextData.put("interfaceType", type.annotatedName);
+ contextData.put("interfaceType", type.getAnnotatedName());
+ contextData.put("interfaceType.annotatedName", type.getAnnotatedName());
contextData.put("interfaceType.xmlName", type.getXmlName());
contextData.put("interfaceType.xmlNameCc", type.getXmlNameCc());
contextData.put("interfaceType.openejbLegacyName", type.getOpenejbLegacy());
contextData.put("interfaceClass", interfce.getName());
contextData.put("interfaceClass.simpleName", interfce.getSimpleName());
- return template.apply(contextData);
+ return this.template.apply(contextData);
}
}
public static class LegacyAddedSuffixStrategy implements JndiNameStrategy {
-
public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
String id = deploymentInfo.getDeploymentID() + "";
if (id.charAt(0) == '/') {
@@ -187,64 +210,7 @@
}
}
- public static class AddedSuffixStrategy implements JndiNameStrategy {
-
- public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
- String id = deploymentInfo.getDeploymentID() + "";
- if (id.charAt(0) == '/') {
- id = id.substring(1);
- }
-
- switch (type) {
- case REMOTE_HOME:
- return id + "Remote";
- case LOCAL_HOME:
- return id + "Local";
- case BUSINESS_LOCAL:
- return id + "BusinessLocal";
- case BUSINESS_REMOTE:
- return id + "BusinessRemote";
- }
- return id;
- }
- }
-
-
- public static class CommonPrefixStrategy implements JndiNameStrategy {
-
- public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
- String id = deploymentInfo.getDeploymentID() + "";
- if (id.charAt(0) == '/') {
- id = id.substring(1);
- }
-
- switch (type) {
- case REMOTE_HOME:
- return "component/remote/" + id;
- case LOCAL_HOME:
- return "component/local/" + id;
- case BUSINESS_REMOTE:
- return "business/remote/" + id;
- case BUSINESS_LOCAL:
- return "business/local/" + id;
- }
- return id;
- }
- }
-
- public static class InterfaceSimpleNameStrategy implements JndiNameStrategy {
-
- public String getName(DeploymentInfo deploymentInfo, Class interfce, Interface type) {
- return interfce.getSimpleName();
- }
- }
-
- public JndiNameStrategy getStrategy() {
- return strategy;
- }
-
- public void bind(DeploymentInfo deploymentInfo, EnterpriseBeanInfo beanInfo) {
- JndiNameStrategy strategy = getStrategy();
+ public void bind(EjbJarInfo ejbJarInfo, DeploymentInfo deploymentInfo, EnterpriseBeanInfo beanInfo, JndiNameStrategy strategy) {
CoreDeploymentInfo deployment = (CoreDeploymentInfo) deploymentInfo;
Bindings bindings = new Bindings();
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java Tue Aug 28 21:31:49 2007
@@ -129,6 +129,7 @@
ejbJar.moduleId = new File(ejbJar.jarPath).getName().replaceFirst(".jar$","");
}
+ ejbJar.properties.putAll(jar.getOpenejbJar().getProperties());
for (EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
EnterpriseBeanInfo beanInfo;
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java Tue Aug 28 21:31:49 2007
@@ -63,6 +63,14 @@
ejbModule.setOpenejbJar(openejbJar);
}
+ StringTemplate deploymentIdTemplate = this.deploymentIdTemplate;
+ if (openejbJar.getProperties().containsKey(DEPLOYMENT_ID_FORMAT)){
+ String format = openejbJar.getProperties().getProperty(DEPLOYMENT_ID_FORMAT);
+ logger.info("Using "+DEPLOYMENT_ID_FORMAT+" '"+format+"'");
+ deploymentIdTemplate = new StringTemplate(format);
+ }
+
+
for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
if (ejbDeployment == null) {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java Tue Aug 28 21:31:49 2007
@@ -101,23 +101,18 @@
}
public Object login(String realmName, String username, String password) throws LoginException {
- try {
- if (realmName == null){
- realmName = this.realmName;
- }
- LoginContext context = new LoginContext(realmName, new UsernamePasswordCallbackHandler(username, password));
- context.login();
+ if (realmName == null){
+ realmName = this.realmName;
+ }
+ LoginContext context = new LoginContext(realmName, new UsernamePasswordCallbackHandler(username, password));
+ context.login();
- Subject subject = context.getSubject();
+ Subject subject = context.getSubject();
- Identity identity = new Identity(subject);
- Serializable token = identity.getToken();
- identities.put(token, identity);
- return token;
- } catch (LoginException e) {
- e.printStackTrace();
- throw e;
- }
+ Identity identity = new Identity(subject);
+ Serializable token = identity.getToken();
+ identities.put(token, identity);
+ return token;
}
private final static class SecurityContext {
Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/OpenejbJar.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/OpenejbJar.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/OpenejbJar.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/OpenejbJar.java Tue Aug 28 21:31:49 2007
@@ -23,18 +23,23 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
+import java.util.Properties;
/**
*/
@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(propOrder = {"ejbDeployment"})
+@XmlType(propOrder = {"properties","ejbDeployment"})
@XmlRootElement(name = "openejb-jar")
public class OpenejbJar {
+ @XmlElement(name = "properties")
+ @XmlJavaTypeAdapter(PropertiesAdapter.class)
+ protected Properties properties;
@XmlElement(name = "ejb-deployment", required = true)
protected List<EjbDeployment> ejbDeployment;
@@ -73,4 +78,12 @@
public void removeEjbDeployment(EjbDeployment ejbDeployment) {
getEjbDeployment().remove(ejbDeployment);
}
+
+ public Properties getProperties() {
+ if (properties == null) {
+ properties = new Properties();
+ }
+ return properties;
+ }
+
}
Added: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java?rev=570634&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java (added)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java Tue Aug 28 21:31:49 2007
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.jee.oejb3;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import java.util.Properties;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertiesAdapter extends XmlAdapter<String, Properties> {
+ public Properties unmarshal(String s) throws Exception {
+ Properties properties = new Properties();
+ ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes());
+ properties.load(in);
+ return properties;
+ }
+
+ public String marshal(Properties properties) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ properties.store(out, null);
+ return new String(out.toByteArray());
+ }
+}
Modified: openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java (original)
+++ openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java Tue Aug 28 21:31:49 2007
@@ -137,6 +137,10 @@
return (T)components.get(type);
}
+ public <T> T removeComponent(Class<T> type) {
+ return (T)components.remove(type);
+ }
+
/**
* @param type the class type of the component required
*/
Modified: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml?rev=570634&r1=570633&r2=570634&view=diff
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml (original)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml Tue Aug 28 21:31:49 2007
@@ -17,6 +17,9 @@
limitations under the License.
-->
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
+ <properties>
+ openejb.jndiname.format = {deploymentId}{interfaceType.openejbLegacyName}
+ </properties>
<ejb-deployment ejb-name="BasicCmpBean" deployment-id="client/tests/entity/cmp/BasicCmpHome" container-id="Default CMP Container">
<resource-link res-ref-name="jdbc/basic/entityDatabase" res-id="Default JDBC Database"/>
<query>