001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.config.rules;
017:
018: import static org.apache.openejb.util.Join.join;
019: import org.apache.openejb.config.ValidationRule;
020: import org.apache.openejb.config.AppModule;
021: import org.apache.openejb.config.EjbModule;
022: import org.apache.openejb.config.ClientModule;
023: import org.apache.openejb.config.ValidationContext;
024: import org.apache.openejb.config.DeploymentModule;
025: import org.apache.openejb.jee.EnterpriseBean;
026: import org.apache.openejb.jee.EntityBean;
027: import org.apache.openejb.jee.PersistenceType;
028: import org.apache.openejb.OpenEJBException;
029: import org.apache.openejb.util.SafeToolkit;
030: import org.apache.openejb.util.Join;
031:
032: import java.lang.reflect.Method;
033: import java.util.List;
034:
035: /**
036: * @version $Rev: 636688 $ $Date: 2008-03-13 02:58:53 -0700 $
037: */
038: public abstract class ValidationBase implements ValidationRule {
039: DeploymentModule module;
040:
041: public void validate(AppModule appModule) {
042: for (EjbModule ejbModule : appModule.getEjbModules()) {
043: module = ejbModule;
044: validate(ejbModule);
045: }
046: for (ClientModule clientModule : appModule.getClientModules()) {
047: module = clientModule;
048: validate(clientModule);
049: }
050: }
051:
052: public void validate(ClientModule appModule) {
053: }
054:
055: public void validate(EjbModule appModule) {
056: }
057:
058: public void error(EnterpriseBean bean, String key,
059: Object... details) {
060: error(bean.getEjbName(), key, details);
061: }
062:
063: private void error(String componentName, String key,
064: Object... details) {
065: module.getValidation().error(componentName, key, details);
066: }
067:
068: public void fail(EnterpriseBean bean, String key, Object... details) {
069: fail(bean.getEjbName(), key, details);
070: }
071:
072: public void fail(String component, String key, Object... details) {
073: module.getValidation().fail(component, key, details);
074: }
075:
076: public void warn(EnterpriseBean bean, String key, Object... details) {
077: warn(bean.getEjbName(), key, details);
078: }
079:
080: private void warn(String componentName, String key,
081: Object... details) {
082: module.getValidation().warn(componentName, key, details);
083: }
084:
085: public void missingMethod(ValidationContext set,
086: EnterpriseBean bean, String key, String methodName,
087: Class returnType, Class... paramTypes) {
088: fail(bean, key, methodName, returnType.getName(),
089: getParameters(paramTypes));
090: }
091:
092: public static boolean paramsMatch(Method methodA, Method methodB) {
093: if (methodA.getParameterTypes().length != methodB
094: .getParameterTypes().length) {
095: return false;
096: }
097:
098: for (int i = 0; i < methodA.getParameterTypes().length; i++) {
099: Class<?> a = methodA.getParameterTypes()[i];
100: Class<?> b = methodB.getParameterTypes()[i];
101: if (!a.equals(b))
102: return false;
103: }
104: return true;
105: }
106:
107: public String getParameters(Method method) {
108: Class[] params = method.getParameterTypes();
109: return getParameters(params);
110: }
111:
112: public String getParameters(Class... params) {
113: StringBuffer paramString = new StringBuffer(512);
114:
115: if (params.length > 0) {
116: paramString.append(params[0].getName());
117: }
118:
119: for (int i = 1; i < params.length; i++) {
120: paramString.append(", ");
121: paramString.append(params[i]);
122: }
123:
124: return paramString.toString();
125: }
126:
127: protected Class loadClass(String clazz) throws OpenEJBException {
128: ClassLoader cl = module.getClassLoader();
129: try {
130: return cl.loadClass(clazz);
131: } catch (ClassNotFoundException cnfe) {
132: throw new OpenEJBException(SafeToolkit.messages.format(
133: "cl0007", clazz, module.getJarLocation()), cnfe);
134: }
135: }
136:
137: public boolean isCmp(EnterpriseBean b) {
138:
139: if (b instanceof EntityBean) {
140: EntityBean entityBean = (EntityBean) b;
141: PersistenceType persistenceType = entityBean
142: .getPersistenceType();
143: return persistenceType == PersistenceType.CONTAINER;
144: }
145: return false;
146: }
147: }
|