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.parsers;
18  
19  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
20  import org.apache.geronimo.ews.ws4j2ee.context.impl.EJBDDContextImpl;
21  import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.EJBContext;
22  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
23  import org.apache.geronimo.ews.ws4j2ee.utils.Utils;
24  import org.w3c.dom.Document;
25  import org.w3c.dom.Element;
26  import org.w3c.dom.NodeList;
27  
28  import java.io.InputStream;
29  
30  /***
31   * Parse the ejb-jar.xml file and get the name of the EJB
32   *
33   * @author Srinath Perera(hemapani@opensource.lk)
34   */
35  public class DomEJBDDParser {
36      private J2EEWebServiceContext j2eewscontext;
37      private String ejbName = null;
38      private EJBContext context;
39  
40      public DomEJBDDParser(J2EEWebServiceContext j2eewscontext) {
41          this.j2eewscontext = j2eewscontext;
42      }
43  
44      public void parse(InputStream inputStream) throws GenerationFault {
45          try {
46              Document doc = Utils.createDocument(inputStream);
47              Element root = doc.getDocumentElement();
48              NodeList beaneles = root.getElementsByTagName("enterprise-beans");
49              if (beaneles.getLength() > 0) {
50                  Element beanele = (Element) beaneles.item(0);
51                  NodeList sessionList = beanele.getElementsByTagName("session");
52                  if (sessionList.getLength() > 0) {
53                      Element session = (Element) sessionList.item(0);
54                      String ejbName = Utils.getElementValue(session.getElementsByTagName("ejb-name"));
55                      String home = Utils.getElementValue(session.getElementsByTagName("home"));
56                      String remote = Utils.getElementValue(session.getElementsByTagName("remote"));
57                      String ejbClass = Utils.getElementValue(session.getElementsByTagName("ejb-class"));
58                      context = new EJBDDContextImpl(ejbName,
59                              ejbClass,
60                              home, remote, null, null);
61                  } else {
62                      throw new GenerationFault("session tag not found");
63                  }
64              } else {
65                  throw new GenerationFault("enterprise-beans tag not found");
66              }
67          } catch (Exception e) {
68              e.printStackTrace();
69              throw GenerationFault.createGenerationFault(e);
70          }
71      }
72  
73      /***
74       * @return
75       */
76      public EJBContext getContext() {
77          return context;
78      }
79  
80      /***
81       * @param context
82       */
83      public void setContext(EJBContext context) {
84          this.context = context;
85      }
86  
87  }