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.InjectionTarget;
21: import org.apache.openejb.jee.JndiReference;
22:
23: import java.util.ArrayList;
24: import java.util.List;
25:
26: /**
27: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
28: */
29: public class CheckInjectionTargets extends ValidationBase {
30: public void validate(EjbModule ejbModule) {
31:
32: for (EnterpriseBean bean : ejbModule.getEjbJar()
33: .getEnterpriseBeans()) {
34: List<JndiReference> entries = new ArrayList<JndiReference>();
35: entries.addAll(bean.getEjbLocalRef());
36: entries.addAll(bean.getEjbRef());
37: entries.addAll(bean.getEnvEntry());
38: entries.addAll(bean.getMessageDestinationRef());
39: entries.addAll(bean.getPersistenceContextRef());
40: entries.addAll(bean.getPersistenceUnitRef());
41: entries.addAll(bean.getResourceEnvRef());
42: entries.addAll(bean.getResourceRef());
43: entries.addAll(bean.getServiceRef());
44:
45: for (JndiReference reference : entries) {
46: // check injection target
47: for (InjectionTarget target : reference
48: .getInjectionTarget()) {
49: boolean classPrefix = false;
50:
51: String name = target.getInjectionTargetName();
52: if (name.startsWith(target
53: .getInjectionTargetClass()
54: + "/")) {
55: classPrefix = true;
56: name = name
57: .substring(target
58: .getInjectionTargetClass()
59: .length() + 1);
60: }
61:
62: String shortNameInvalid = name;
63:
64: if (name.startsWith("set") && name.length() >= 4
65: && Character.isUpperCase(name.charAt(3))) {
66: StringBuffer correctName = new StringBuffer(
67: name);
68: correctName.delete(0, 3);
69: correctName.setCharAt(0, Character
70: .toLowerCase(correctName.charAt(0)));
71: String shortNameCorrect = correctName
72: .toString();
73: if (classPrefix)
74: correctName.insert(0, target
75: .getInjectionTargetClass()
76: + "/");
77:
78: warn(bean, "injectionTarget.nameContainsSet",
79: target.getInjectionTargetName(),
80: shortNameInvalid, shortNameCorrect,
81: correctName, reference.getName(),
82: reference.getClass().getSimpleName());
83: target.setInjectionTargetName(correctName
84: .toString());
85: }
86: }
87: }
88: }
89: }
90:
91: }
|