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  /*
20  import javax.xml.bind.JAXBContext;
21  import javax.xml.bind.JAXBException;
22  import javax.xml.bind.Marshaller;
23  import javax.xml.bind.PropertyException; */
24  
25  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
26  import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.EJBContext;
27  import org.apache.geronimo.ews.ws4j2ee.toWs.AbstractWriter;
28  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationConstants;
29  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
30  
31  /***
32   * We plan to use the JAXB to genarate and parse the
33   * ejb-jar.xml file. This code is here just to get a simple
34   * DD created
35   *
36   * @author Srinath Perera(hemapani@opensource.lk)
37   */
38  public class EJBDDWriter extends AbstractWriter {
39      protected EJBContext ejbcontext;
40  
41      /***
42       * @param j2eewscontext
43       * @throws GenerationFault
44       */
45      public EJBDDWriter(J2EEWebServiceContext j2eewscontext, EJBContext ejbcontext)
46              throws GenerationFault {
47          super(j2eewscontext, j2eewscontext.getMiscInfo().getOutPutPath() + "/META-INF/ejb-jar.xml");
48          this.ejbcontext = ejbcontext;
49      }
50  
51      public void writeCode() throws GenerationFault {
52          if (out != null)
53              writeSessionDD();
54      }
55  
56      public void writeSessionDD() throws GenerationFault {
57          String ejbname = j2eewscontext.getWSCFContext().getWscfport().getServiceImplBean().getEjblink();
58          if (ejbname == null || ejbname.equals("")) {
59          	throw new GenerationFault("Error reading ejbname from webservices.xml.");
60          }
61          String version = GenerationConstants.J2EE_VERSION_1_4;
62          out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
63          out.write("<ejb-jar xmlns=\"http://java.sun.com/xml/ns/j2ee\"\n");
64          out.write("		 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
65          out.write("		 xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee\n");
66          out.write("		 http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd\"\n");
67          out.write("		 version=\"2.1\">\n");
68  
69          out.write("\t<enterprise-beans>\n");
70          out.write("\t\t<session>\n");
71          out.write("\t\t\t<display-name>" + j2eewscontext.getWSCFContext().getDisplayName() + "</display-name>\n");
72          out.write("\t\t\t<ejb-name>" + ejbname + "</ejb-name>\n");
73          String implStyle = j2eewscontext.getMiscInfo().getImplStyle();
74          if (GenerationConstants.USE_LOCAL_AND_REMOTE.equals(implStyle)
75                  || GenerationConstants.USE_REMOTE.equals(implStyle)
76                  || GenerationConstants.USE_INTERNALS.equals(implStyle)) {
77              out.write("\t\t\t<home>" + ejbcontext.getEjbhomeInterface() + "</home>\n");
78              out.write("\t\t\t<remote>" + ejbcontext.getEjbRemoteInterface() + "</remote>\n");
79          }
80          if (GenerationConstants.USE_LOCAL_AND_REMOTE.equals(implStyle)
81                  || GenerationConstants.USE_LOCAL.equals(implStyle)) {
82              out.write("\t\t\t<local-home>" + ejbcontext.getEjbLocalHomeInterfce() + "</local-home>\n");
83              out.write("\t\t\t<local>" + ejbcontext.getEjbLocalInterface() + "</local>\n");
84          }
85          out.write("\t\t\t<ejb-class>" + ejbcontext.getImplBean() + "</ejb-class>\n");
86          out.write("\t\t\t<session-type>Stateless</session-type>\n");
87          out.write("\t\t\t<transaction-type>Bean</transaction-type>\n");
88          out.write("\t\t\t<security-identity>\n");
89          out.write("\t\t\t\t<description></description>\n");
90          out.write("\t\t\t\t<use-caller-identity></use-caller-identity>\n");
91          out.write("\t\t\t</security-identity>\n");
92          out.write("\t\t</session>\n");
93          out.write("\t</enterprise-beans>\n");
94          out.write("\t<assembly-descriptor>\n");
95          out.write("\t    <method-permission>\n");
96          out.write("\t        <unchecked/>\n");
97          out.write("\t        <method>\n");
98          out.write("\t		     <ejb-name>" + ejbname + "</ejb-name>\n");
99          out.write("\t			 <method-name>*</method-name>\n");
100         out.write("\t		</method>\n");
101         out.write("\t     </method-permission>\n");
102         out.write("\t</assembly-descriptor>\n");
103         out.write("</ejb-jar>\n");
104     }
105 }