Author: dblevins
Date: Tue May 26 03:46:24 2009
New Revision: 778557
URL: http://svn.apache.org/viewvc?rev=778557&view=rev
Log:
Quick addition as we have an api jar now... can start to add annotations to
replace the elements of the openejb-jar.xml file.
OPENEJB-1029: @EjbDeployment annotation as alternative to <ejb-deployment> in
openejb-jar.xml
Added:
openejb/trunk/openejb3/container/openejb-api/src/main/java/org/apache/openejb/api/EjbDeployment.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
Added:
openejb/trunk/openejb3/container/openejb-api/src/main/java/org/apache/openejb/api/EjbDeployment.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-api/src/main/java/org/apache/openejb/api/EjbDeployment.java?rev=778557&view=auto
==============================================================================
---
openejb/trunk/openejb3/container/openejb-api/src/main/java/org/apache/openejb/api/EjbDeployment.java
(added)
+++
openejb/trunk/openejb3/container/openejb-api/src/main/java/org/apache/openejb/api/EjbDeployment.java
Tue May 26 03:46:24 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.api;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Annotation that matches the <ejb-deployment> element in the openejb-jar.xml
file
+ */
+...@target(ElementType.TYPE)
+...@retention(RetentionPolicy.RUNTIME)
+public @interface EjbDeployment {
+
+ /**
+ * The Deployment ID for this bean
+ * @return
+ */
+ java.lang.String id() default "";
+
+ /**
+ * The Container ID where the bean should be deployed
+ * @return
+ */
+ java.lang.String container() default "";
+
+}
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=778557&r1=778556&r2=778557&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 May 26 03:46:24 2009
@@ -96,23 +96,40 @@
for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans())
{
+ StringTemplate template = deploymentIdTemplate;
+
+ org.apache.openejb.api.EjbDeployment annotation =
getEjbDeploymentAnnotation(ejbModule, bean);
+
EjbDeployment ejbDeployment =
openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
if (ejbDeployment == null) {
ejbDeployment = new EjbDeployment();
ejbDeployment.setEjbName(bean.getEjbName());
- ejbDeployment.setDeploymentId(autoAssignDeploymentId(bean,
contextData, deploymentIdTemplate));
- logger.info("Auto-deploying ejb " + bean.getEjbName() + ":
EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
+ if (annotation != null && isDefined(annotation.id())) {
+ template = new StringTemplate(annotation.id());
+ ejbDeployment.setDeploymentId(formatDeploymentId(bean,
contextData, template));
+ } else {
+ ejbDeployment.setDeploymentId(formatDeploymentId(bean,
contextData, template));
+ logger.info("Auto-deploying ejb " + bean.getEjbName() + ":
EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
+ }
+
openejbJar.getEjbDeployment().add(ejbDeployment);
- } else {
- if (ejbDeployment.getDeploymentId() == null) {
- ejbDeployment.setDeploymentId(autoAssignDeploymentId(bean,
contextData, deploymentIdTemplate));
+ } else if (ejbDeployment.getDeploymentId() == null) {
+ if (annotation != null && isDefined(annotation.id())) {
+ template = new StringTemplate(annotation.id());
+ ejbDeployment.setDeploymentId(formatDeploymentId(bean,
contextData, template));
+ } else {
+ ejbDeployment.setDeploymentId(formatDeploymentId(bean,
contextData, template));
logger.info("Auto-assigning deployment-id for ejb " +
bean.getEjbName() + ": EjbDeployment(deployment-id=" +
ejbDeployment.getDeploymentId() + ")");
}
}
+ if (ejbDeployment.getContainerId() == null && annotation != null
&& isDefined(annotation.container())) {
+ ejbDeployment.setContainerId(annotation.container());
+ }
+
if (isCmpEntity(bean)) {
EntityBean entity = (EntityBean) bean;
if (entity.getAbstractSchemaName() == null) {
@@ -136,12 +153,32 @@
return ejbModule;
}
+ private org.apache.openejb.api.EjbDeployment
getEjbDeploymentAnnotation(EjbModule ejbModule, EnterpriseBean bean) {
+ try {
+ Class<?> beanClass =
ejbModule.getClassLoader().loadClass(bean.getEjbClass());
+ return
beanClass.getAnnotation(org.apache.openejb.api.EjbDeployment.class);
+ } catch (ClassNotFoundException e) {
+ // this should never happen, the class has already been loaded a
ton of times by this point
+ // unfortunately we have some unit tests that prevent us from
throwing an exception just in case
+ // Those are OpenEjb2ConversionTest and SunCmpConversionTest
+ return null;
+ }
+ }
+
+ private String get(String s) {
+ return isDefined(s) ? s : null;
+ }
+
+ private boolean isDefined(String s) {
+ return s != null && !"".equals(s);
+ }
+
private static boolean isCmpEntity(EnterpriseBean bean) {
return bean instanceof EntityBean && ((EntityBean)
bean).getPersistenceType() == PersistenceType.CONTAINER;
}
- private String autoAssignDeploymentId(EnterpriseBean bean, Map<String,
String> contextData, StringTemplate template) {
+ private String formatDeploymentId(EnterpriseBean bean, Map<String, String>
contextData, StringTemplate template) {
contextData.put("ejbType", bean.getClass().getSimpleName());
contextData.put("ejbClass", bean.getClass().getName());
contextData.put("ejbClass.simpleName",
bean.getClass().getSimpleName());