KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > connector > AuthMechNode


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.connector;
25
26 import java.util.*;
27 import org.xml.sax.Attributes JavaDoc;
28 import com.sun.enterprise.deployment.Descriptor;
29 import com.sun.enterprise.deployment.OutboundResourceAdapter;
30 import com.sun.enterprise.deployment.AuthMechanism;
31 import com.sun.enterprise.deployment.SecurityPermission;
32 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
33 import com.sun.enterprise.deployment.xml.TagNames;
34 import com.sun.enterprise.deployment.EnvironmentProperty;
35 import com.sun.enterprise.deployment.node.DescriptorFactory;
36 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
37 import com.sun.enterprise.deployment.node.ConfigurableNode;
38 import com.sun.enterprise.deployment.node.XMLElement;
39
40 import com.sun.enterprise.deployment.ConnectorDescriptor;
41
42 import org.xml.sax.Attributes JavaDoc;
43 import org.w3c.dom.Node JavaDoc;
44
45 /**
46  * This node is responsible for handling the Connector DTD related auth-mechanism XML tag
47  *
48  * @author Sheetal Vartak
49  * @version
50  */

51 public class AuthMechNode extends DeploymentDescriptorNode {
52     
53     private AuthMechanism auth = null;
54     
55     /**
56      * all sub-implementation of this class can use a dispatch table to map xml element to
57      * method name on the descriptor class for setting the element value.
58      *
59      * @return the map with the element name as a key, the setter method as a value
60      */

61
62     protected Map getDispatchTable() {
63         Map table = super.getDispatchTable();
64         table.put(ConnectorTagNames.CREDENTIAL_INTF, "setCredentialInterface");
65         table.put(ConnectorTagNames.AUTH_MECH_TYPE, "setAuthMechVal");
66         return table;
67     }
68
69     /**
70     * @return the descriptor instance to associate with this XMLNode
71     */

72     public Object JavaDoc getDescriptor() {
73         if (auth == null) {
74             auth = (AuthMechanism) DescriptorFactory.getDescriptor(getXMLPath());
75         }
76         return auth;
77     }
78
79     /**
80      * write the descriptor class to a DOM tree and return it
81      *
82      * @param parent node for the DOM tree
83      * @param the descriptor to write
84      * @return the DOM tree top node
85      */

86     public Node writeDescriptor(Node parent, Descriptor descriptor) {
87
88         if (! (descriptor instanceof OutboundResourceAdapter) &&
89         ! (descriptor instanceof ConnectorDescriptor)) {
90             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
91         }
92
93     Iterator authMechs = null;
94
95     if (descriptor instanceof ConnectorDescriptor) {
96         authMechs = ((ConnectorDescriptor)descriptor).getAuthMechanisms().iterator();
97     } else if (descriptor instanceof OutboundResourceAdapter) {
98         authMechs = ((OutboundResourceAdapter)descriptor).getAuthMechanisms().iterator();
99     }
100
101     //auth mechanism info
102
for (;authMechs.hasNext();) {
103         AuthMechanism auth = (AuthMechanism) authMechs.next();
104         Node authNode = appendChild(parent, ConnectorTagNames.AUTH_MECHANISM);
105         appendTextChild(authNode, TagNames.DESCRIPTION, auth.getDescription());
106         appendTextChild(authNode, ConnectorTagNames.AUTH_MECH_TYPE, auth.getAuthMechType());
107         appendTextChild(authNode, ConnectorTagNames.CREDENTIAL_INTF, auth.getCredentialInterface());
108     }
109     return parent;
110     }
111 }
112
Popular Tags