KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * SecurityConstraintNode.java
26  *
27  * Created on March 1, 2002, 2:24 PM
28  */

29
30 package com.sun.enterprise.deployment.node.web;
31
32 import java.util.Enumeration JavaDoc;
33 import java.util.Map JavaDoc;
34 import org.w3c.dom.Node JavaDoc;
35
36 import com.sun.enterprise.deployment.SecurityConstraintImpl;
37 import com.sun.enterprise.deployment.WebResourceCollectionImpl;
38 import com.sun.enterprise.deployment.AuthorizationConstraintImpl;
39 import com.sun.enterprise.deployment.UserDataConstraintImpl;
40 import com.sun.enterprise.deployment.xml.WebTagNames;
41 import com.sun.enterprise.deployment.node.XMLElement;
42 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
43
44 /**
45  * This node handles the security-contraint xml tag
46  *
47  * @author Jerome Dochez
48  * @version
49  */

50 public class SecurityConstraintNode extends DeploymentDescriptorNode {
51
52     public SecurityConstraintNode() {
53         super();
54         registerElementHandler(new XMLElement(WebTagNames.USERDATA_CONSTRAINT),
55                     UserDataConstraintNode.class, "setUserDataConstraint");
56         registerElementHandler(new XMLElement(WebTagNames.AUTH_CONSTRAINT),
57                     AuthConstraintNode.class, "setAuthorizationConstraint");
58         registerElementHandler(new XMLElement(WebTagNames.WEB_RESOURCE_COLLECTION),
59                     WebResourceCollectionNode.class, "addWebResourceCollection");
60     }
61     
62     /**
63      * all sub-implementation of this class can use a dispatch table to map
64      * xml element to
65      * method name on the descriptor class for setting the element value.
66      *
67      * @return the map with the element name as a key, the setter method as a
68      * value
69      */

70     protected Map JavaDoc getDispatchTable() {
71         Map JavaDoc table = super.getDispatchTable();
72         table.put(WebTagNames.NAME, "setName");
73     return table;
74     }
75     
76     /**
77      * write the descriptor class to a DOM tree and return it
78      *
79      * @param parent node in the DOM tree
80      * @param node name for the root element of this xml fragment
81      * @param the descriptor to write
82      * @return the DOM tree top node
83      */

84     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, SecurityConstraintImpl descriptor) {
85         Node JavaDoc myNode = appendChild(parent, nodeName);
86         appendTextChild(myNode, WebTagNames.NAME, descriptor.getName());
87         
88         // web-resource-collection+
89
WebResourceCollectionNode wrcNode = new WebResourceCollectionNode();
90         for (Enumeration JavaDoc webResources = descriptor.getWebResourceCollections();
91             webResources.hasMoreElements();) {
92                 wrcNode.writeDescriptor(myNode, WebTagNames.WEB_RESOURCE_COLLECTION,
93                     (WebResourceCollectionImpl) webResources.nextElement());
94         }
95         
96         // auth-constaint?
97
AuthorizationConstraintImpl aci = (AuthorizationConstraintImpl) descriptor.getAuthorizationConstraint();
98         if (aci!=null) {
99             AuthConstraintNode acNode = new AuthConstraintNode();
100             acNode.writeDescriptor(myNode, WebTagNames.AUTH_CONSTRAINT, aci);
101         }
102         
103         // user-data-constraint?
104
UserDataConstraintImpl udci = (UserDataConstraintImpl) descriptor.getUserDataConstraint();
105         if (udci!=null) {
106             UserDataConstraintNode udcn = new UserDataConstraintNode();
107             udcn.writeDescriptor(myNode, WebTagNames.USERDATA_CONSTRAINT, udci);
108         }
109         return myNode;
110     }
111     
112 }
Popular Tags