View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.geronimo.ews.ws4j2ee.toWs.ejb;
18  
19  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
20  import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.EJBContext;
21  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationConstants;
22  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
23  import org.apache.geronimo.ews.ws4j2ee.toWs.Generator;
24  import org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenerationFault;
25  import org.apache.geronimo.ews.ws4j2ee.toWs.Writer;
26  import org.apache.geronimo.ews.ws4j2ee.toWs.Ws4J2eeFactory;
27  
28  /***
29   * <p>This class crete the nessacsaary EJB artifacts</p>
30   *
31   * @author Srinath Perera(hemapani@opensource.lk)
32   */
33  public class EJBGenerator implements Generator {
34      private J2EEWebServiceContext context;
35      private Writer homewriter;
36      private Writer remotewriter;
37      private Writer beanwriter;
38      private Writer ddwriter;
39      private Writer localwriter;
40      private Writer localhomewriter;
41      protected EJBContext ejbcontext;
42      private Ws4J2eeFactory factory;
43  
44      public EJBGenerator(J2EEWebServiceContext context) throws GenerationFault {
45          this.context = context;
46          ejbcontext = context.getEJBDDContext();
47          if (ejbcontext == null) {
48              throw new UnrecoverableGenerationFault("for ejbbased Impl" +
49                      " the EJBDDContext must not be null");
50          }
51          factory = context.getFactory();
52          String implStyle = context.getMiscInfo().getImplStyle();
53          if (GenerationConstants.USE_LOCAL_AND_REMOTE.equals(implStyle)
54                  || GenerationConstants.USE_REMOTE.equals(implStyle)) {
55              homewriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_HOME_INTERFACE_WRITER);
56              remotewriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_REMOTE_INTERFACE_WRITER);
57          } else if (GenerationConstants.USE_LOCAL_AND_REMOTE.equals(implStyle)
58                  || GenerationConstants.USE_LOCAL.equals(implStyle)) {
59              localhomewriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_LOCAL_HOME_INTERFACE_WRITER);
60              localwriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_LOCAL_INTERFACE_WRITER);
61          } else if (GenerationConstants.USE_INTERNALS.equals(implStyle)) {
62              homewriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_HOME_INTERFACE_WRITER);
63              remotewriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_REMOTE_INTERFACE_WRITER);
64          }
65          if (!context.getMiscInfo().isImplAvalible()) {
66              beanwriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_IMPLEMENTATION_BEAN_WRITER);
67          }
68          ddwriter = factory.getGenerationFactory().createEJBWriter(context, ejbcontext, GenerationConstants.EJB_DD_WRITER);
69      }
70  
71      public void generate() throws GenerationFault {
72          if (homewriter != null)
73              homewriter.write();
74          if (remotewriter != null)
75              remotewriter.write();
76          if (beanwriter != null)
77              beanwriter.write();
78          if (ddwriter != null)
79              ddwriter.write();
80          if (localwriter != null) {
81              localwriter.write();
82          }
83          if (localhomewriter != null) {
84              localhomewriter.write();
85          }
86      }
87  
88  }