KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > web > ServletMappingNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.node.web;
25
26 import com.sun.enterprise.deployment.xml.WebTagNames;
27 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
28 import com.sun.enterprise.deployment.node.XMLNode;
29 import com.sun.enterprise.deployment.node.XMLElement;
30 import com.sun.enterprise.deployment.WebBundleDescriptor;
31
32
33 import com.sun.enterprise.deployment.util.DOLUtils;
34 import com.sun.enterprise.util.web.URLPattern;
35 import com.sun.enterprise.util.LocalStringManagerImpl;
36 import java.util.logging.Level JavaDoc;
37
38 /**
39  * This node is responsible for handling servlet-mapping subtree node
40  *
41  * @author Jerome Dochez
42  * @version
43  */

44 public class ServletMappingNode extends DeploymentDescriptorNode {
45
46     private String JavaDoc servletName;
47     private String JavaDoc urlPattern;
48
49     private static LocalStringManagerImpl localStrings =
50             new LocalStringManagerImpl(ServletMappingNode.class);
51
52     /**
53      * receives notiification of the value for a particular tag
54      *
55      * @param element the xml element
56      * @param value it's associated value
57      */

58     public void setElementValue(XMLElement element, String JavaDoc value) {
59         if (WebTagNames.SERVLET_NAME.equals(element.getQName())) {
60             servletName = value;
61         }
62         if (WebTagNames.URL_PATTERN.equals(element.getQName())) {
63             // If URL Pattern does not start with "/" then
64
// prepend it (for Servlet2.2 Web apps)
65
Object JavaDoc parent = getParentNode().getDescriptor();
66             if (parent instanceof WebBundleDescriptor &&
67                 ((WebBundleDescriptor) parent).getSpecVersion().equals("2.2"))
68             {
69                 if(!value.startsWith("/") && !value.startsWith("*.")) {
70                     value = "/" + value;
71                 }
72             }
73             urlPattern = value;
74             if (!URLPattern.isValid(urlPattern)) {
75                 throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
76                 "enterprise.deployment.invalidurlpattern",
77                 "Invalid URL Pattern: [{0}]",
78                 new Object JavaDoc[] {urlPattern}));
79             }
80
81             XMLNode parentNode = getParentNode();
82             if (parentNode instanceof WebBundleNode) {
83                 ((WebBundleNode) parentNode).addServletMapping(servletName,
84                 urlPattern);
85             } else {
86                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
87                     new Object JavaDoc[]{getXMLRootTag() , "servlet-mapping"});
88             }
89
90         }
91     }
92     
93         
94    /**
95     * @return the descriptor instance to associate with this XMLNode
96     */

97     public Object JavaDoc getDescriptor() {
98         return null;
99     }
100 }
101
Popular Tags