KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > connector > MapElementNode


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 package com.sun.enterprise.deployment.node.runtime.connector;
24
25 import java.util.Map JavaDoc;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28
29 import com.sun.enterprise.deployment.node.XMLElement;
30 import com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode;
31 import com.sun.enterprise.deployment.runtime.connector.MapElement;
32 import com.sun.enterprise.deployment.runtime.connector.Principal;
33 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
34
35 /**
36  * This node handles the role-map runtime deployment descriptors
37  *
38  * @author Jerome Dochez
39  * @version
40  */

41 public class MapElementNode extends RuntimeDescriptorNode {
42     
43     public MapElementNode() {
44         registerElementHandler(new XMLElement(RuntimeTagNames.PRINCIPAL),
45                                PrincipalNode.class);
46         registerElementHandler(new XMLElement(RuntimeTagNames.BACKEND_PRINCIPAL),
47                                PrincipalNode.class);
48     }
49     
50     
51     /**
52      * Adds a new DOL descriptor instance to the descriptor instance associated with
53      * this XMLNode
54      *
55      * @param descriptor the new descriptor
56      */

57     public void addDescriptor(Object JavaDoc newDescriptor) {
58     MapElement descriptor = (MapElement) getDescriptor();
59     if (descriptor==null) {
60         throw new RuntimeException JavaDoc("Cannot set info on null descriptor");
61     }
62     if (newDescriptor instanceof Principal) {
63         Principal principal = (Principal) newDescriptor;
64         if (principal.getValue(Principal.CREDENTIAL)==null) {
65         descriptor.addPrincipal(principal);
66         } else {
67         descriptor.setBackendPrincipal(true);
68         descriptor.setAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.USER_NAME, principal.getValue(Principal.USER_NAME));
69         descriptor.setAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.PASSWORD, principal.getValue(Principal.PASSWORD));
70         descriptor.setAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.CREDENTIAL, principal.getValue(Principal.CREDENTIAL));
71         
72         }
73     }
74     }
75     
76     /**
77      * write the descriptor class to a DOM tree and return it
78      *
79      * @param parent node for the DOM tree
80      * @param node name for the descriptor
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, MapElement descriptor) {
85     Node JavaDoc mapElementNode = super.writeDescriptor(parent, nodeName, descriptor);
86     PrincipalNode pn = new PrincipalNode();
87     Principal[] principals = descriptor.getPrincipal();
88     for (int i=0;i<principals.length;i++) {
89         pn.writeDescriptor(mapElementNode, RuntimeTagNames.PRINCIPAL, principals[i]);
90     }
91     // backend-principal
92
if (descriptor.isBackendPrincipal()) {
93         Element JavaDoc backend = (Element JavaDoc) appendChild(mapElementNode, RuntimeTagNames.BACKEND_PRINCIPAL);
94         setAttribute(backend, RuntimeTagNames.USER_NAME,
95             (String JavaDoc) descriptor.getAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.USER_NAME));
96         setAttribute(backend, RuntimeTagNames.PASSWORD,
97             (String JavaDoc) descriptor.getAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.PASSWORD));
98         setAttribute(backend, RuntimeTagNames.CREDENTIAL,
99             (String JavaDoc) descriptor.getAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.CREDENTIAL));
100     }
101         
102     return mapElementNode;
103     }
104 }
105
Popular Tags