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