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.WebDDContextImpl;
21  import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.WebContext;
22  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
23  import org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenerationFault;
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   * <web-app> .....
33   * <servlet>
34   * <servlet-name>AxisServlet</servlet-name>
35   * <display-name>Apache-Axis Servlet</display-name>
36   * <servlet-class>
37   * org.apache.axis.transport.http.AxisServlet
38   * </servlet-class>
39   * </servlet>
40   * ...
41   * </web-app>
42   * Parse the web,xl file and get the servlet class corresponds to the given servlet
43   *
44   * @author hemapani
45   */
46  public class WebDDParser {
47      private J2EEWebServiceContext j2eewscontext;
48      private WebContext context;
49      private String servletClass = null;
50      private String servletName = null;
51  
52      public WebDDParser(J2EEWebServiceContext j2eewscontext) {
53          this.j2eewscontext = j2eewscontext;
54      }
55  
56      public void parse(InputStream inputStream) throws GenerationFault {
57          Document doc = Utils.createDocument(inputStream);
58          Element root = doc.getDocumentElement();
59          NodeList sevlele = root.getElementsByTagName("servlet");
60          
61          String j2eeLink = j2eewscontext.getMiscInfo().getJ2eeComponetLink();
62          int count = 0;
63          while (count < sevlele.getLength()) {
64              Element serv = (Element) sevlele.item(count);
65              servletName = Utils.getElementValue(serv.getElementsByTagName("servlet-name"));
66              if (servletName.equals(j2eeLink)) {
67                  servletClass = Utils.getElementValue(serv.getElementsByTagName("servlet-class"));
68                  context = new WebDDContextImpl(servletClass, servletName);
69                  return;
70              }
71              count++;
72          }
73          throw new UnrecoverableGenerationFault("J2EE link not found");
74      }
75  
76      /***
77       * @return
78       */
79      public String getServletClass() {
80          return servletClass;
81      }
82  
83      /***
84       * @param string
85       */
86      public void setServletClass(String string) {
87          servletClass = string;
88      }
89  
90      /***
91       * @return
92       */
93      public WebContext getContext() {
94          return context;
95      }
96  
97      /***
98       * @param context
99       */
100     public void setContext(WebContext context) {
101         this.context = context;
102     }
103 
104 }