01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.assembler.classic;
18:
19: import org.apache.openejb.Container;
20: import org.apache.openejb.DeploymentInfo;
21: import org.apache.openejb.OpenEJBException;
22: import org.apache.openejb.core.CoreDeploymentInfo;
23: import org.apache.openejb.util.Messages;
24:
25: import java.util.ArrayList;
26: import java.util.HashMap;
27: import java.util.Properties;
28:
29: /**
30: * @version $Revision: 604114 $ $Date: 2007-12-13 22:47:37 -0800 $
31: */
32: public class EjbJarBuilder {
33: protected static final Messages messages = new Messages(
34: "org.apache.openejb.util.resources");
35:
36: private final ClassLoader classLoader;
37: private final Properties props;
38:
39: public EjbJarBuilder(Properties props, ClassLoader classLoader) {
40: this .props = props;
41: this .classLoader = classLoader;
42: }
43:
44: public HashMap<String, DeploymentInfo> build(EjbJarInfo ejbJar)
45: throws OpenEJBException {
46: HashMap<String, DeploymentInfo> deployments = new HashMap<String, DeploymentInfo>();
47:
48: InterceptorBindingBuilder interceptorBindingBuilder = new InterceptorBindingBuilder(
49: classLoader, ejbJar);
50:
51: for (EnterpriseBeanInfo ejbInfo : ejbJar.enterpriseBeans) {
52: try {
53: EnterpriseBeanBuilder deploymentBuilder = new EnterpriseBeanBuilder(
54: classLoader, ejbInfo, ejbJar.moduleId,
55: new ArrayList<String>());
56: CoreDeploymentInfo deployment = (CoreDeploymentInfo) deploymentBuilder
57: .build();
58:
59: interceptorBindingBuilder.build(deployment, ejbInfo);
60:
61: deployment.setJarPath(ejbJar.jarPath);
62: deployments.put(ejbInfo.ejbDeploymentId, deployment);
63:
64: Container container = (Container) props
65: .get(ejbInfo.containerId);
66: if (container == null)
67: throw new IllegalStateException(
68: "Container does not exist: "
69: + ejbInfo.containerId
70: + ". Referenced by deployment: "
71: + deployment.getDeploymentID());
72: // Don't deploy to the container, yet. That will be done by deploy() once Assembler as finished configuring the DeploymentInfo
73: deployment.setContainer(container);
74: } catch (Throwable e) {
75: throw new OpenEJBException("Error building bean '"
76: + ejbInfo.ejbName + "'. Exception: "
77: + e.getClass() + ": " + e.getMessage(), e);
78: }
79: }
80: return deployments;
81: }
82:
83: public void deploy(HashMap<String, DeploymentInfo> deployments)
84: throws OpenEJBException {
85: for (DeploymentInfo deployment : deployments.values()) {
86: try {
87: deployment.getContainer().deploy(deployment);
88: } catch (Throwable t) {
89: throw new OpenEJBException("Error deploying '"
90: + deployment.getEjbName() + "'. Exception: "
91: + t.getClass() + ": " + t.getMessage(), t);
92: }
93: }
94: }
95: }
|