01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.config.rules;
17:
18: import org.apache.openejb.config.EjbModule;
19: import org.apache.openejb.jee.EnterpriseBean;
20: import org.apache.openejb.jee.PersistenceContextRef;
21: import org.apache.openejb.jee.SessionBean;
22: import org.apache.openejb.jee.SessionType;
23: import org.apache.openejb.jee.PersistenceContextType;
24: import org.apache.openejb.jee.MessageDrivenBean;
25: import org.apache.openejb.jee.EntityBean;
26: import org.apache.openejb.BeanType;
27:
28: /**
29: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
30: */
31: public class CheckPersistenceRefs extends ValidationBase {
32: public void validate(EjbModule ejbModule) {
33:
34: for (EnterpriseBean bean : ejbModule.getEjbJar()
35: .getEnterpriseBeans()) {
36:
37: String beanType = getType(bean);
38: if (beanType.equals("Stateful"))
39: continue; // skip statefuls
40:
41: for (PersistenceContextRef ref : bean
42: .getPersistenceContextRef()) {
43: if (isExtented(ref)) {
44: String refName = ref.getName();
45: String prefix = bean.getEjbClass() + "/";
46: if (refName.startsWith(prefix)) {
47: refName = refName.substring(prefix.length());
48: }
49: fail(bean,
50: "persistenceContextExtented.nonStateful",
51: refName, beanType);
52: }
53:
54: }
55: }
56: }
57:
58: private boolean isExtented(PersistenceContextRef ref) {
59: PersistenceContextType type = ref.getPersistenceContextType();
60: return type != null
61: && type.equals(PersistenceContextType.EXTENDED);
62: }
63:
64: private String getType(EnterpriseBean bean) {
65: if (bean instanceof SessionBean) {
66: SessionBean sessionBean = (SessionBean) bean;
67: switch (sessionBean.getSessionType()) {
68: case STATEFUL:
69: return "Stateful";
70: case STATELESS:
71: return "Stateless";
72: default:
73: throw new IllegalArgumentException(
74: "Uknown SessionBean type " + bean.getClass());
75: }
76: } else if (bean instanceof MessageDrivenBean)
77: return "MessageDriven";
78: else if (bean instanceof EntityBean)
79: return "EJB 2.1 Entity";
80: else
81: throw new IllegalArgumentException("Uknown bean type "
82: + bean.getClass());
83: }
84: }
|