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.EjbModule;
020: import org.apache.openejb.jee.AssemblyDescriptor;
021: import org.apache.openejb.jee.ContainerTransaction;
022: import org.apache.openejb.jee.EnterpriseBean;
023: import org.apache.openejb.jee.InterceptorBinding;
024: import org.apache.openejb.jee.Method;
025: import org.apache.openejb.jee.MethodPermission;
026: import org.apache.openejb.util.Join;
027:
028: import java.util.Map;
029: import java.util.List;
030:
031: /**
032: * @version $Rev: 638255 $ $Date: 2008-03-18 01:02:11 -0700 $
033: */
034: public class CheckAssemblyBindings extends ValidationBase {
035: public void validate(EjbModule ejbModule) {
036:
037: Map<String, EnterpriseBean> ejbsByName = ejbModule.getEjbJar()
038: .getEnterpriseBeansByEjbName();
039:
040: AssemblyDescriptor assembly = ejbModule.getEjbJar()
041: .getAssemblyDescriptor();
042:
043: if (assembly == null)
044: return;
045:
046: for (InterceptorBinding binding : assembly
047: .getInterceptorBinding()) {
048: List<String> interceptorClasses = binding
049: .getInterceptorClass();
050: if (binding.getInterceptorOrder() != null) {
051: interceptorClasses.addAll(binding.getInterceptorOrder()
052: .getInterceptorClass());
053: }
054:
055: if (binding.getEjbName() != null
056: && !binding.getEjbName().equals("*")
057: && !ejbsByName.containsKey(binding.getEjbName())) {
058: fail("InterceptorBinding",
059: "interceptorBinding.noSuchEjbName", binding
060: .getEjbName(), join(",",
061: interceptorClasses));
062: }
063:
064: if (binding.getMethod() != null) {
065: if (binding.getEjbName() == null) {
066: fail(
067: "InterceptorBinding",
068: "interceptorBinding.ejbNameRequiredWithMethod",
069: binding.getMethod().getMethodName(), join(
070: ",", interceptorClasses));
071: }
072: }
073: }
074:
075: for (MethodPermission permission : assembly
076: .getMethodPermission()) {
077: for (Method method : permission.getMethod()) {
078: if (method.getEjbName() == null) {
079: fail("MethodPermission",
080: "methodPermission.ejbNameRequired", method
081: .getMethodName(), join(",",
082: permission.getRoleName()));
083: } else if (method.getEjbName().equals("*")) {
084: } else if (!ejbsByName.containsKey(method.getEjbName())) {
085: fail("MethodPermission",
086: "methodPermission.noSuchEjbName", method
087: .getEjbName(), method
088: .getMethodName(), join(",",
089: permission.getRoleName()));
090: }
091: }
092: }
093:
094: for (ContainerTransaction transaction : assembly
095: .getContainerTransaction()) {
096: for (Method method : transaction.getMethod()) {
097: if (method.getEjbName() == null) {
098: fail("ContainerTransaction",
099: "containerTransaction.ejbNameRequired",
100: method.getMethodName(), transaction
101: .getTransAttribute());
102: } else if (method.getEjbName().equals("*")) {
103: } else if (!ejbsByName.containsKey(method.getEjbName())) {
104: fail("ContainerTransaction",
105: "containerTransaction.noSuchEjbName",
106: method.getEjbName(),
107: method.getMethodName(), transaction
108: .getTransAttribute());
109: }
110: }
111: }
112: }
113:
114: }
|