KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > runtime > common > PrincipalNameDescriptor


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.runtime.common;
25
26 import com.sun.enterprise.deployment.Descriptor;
27 import java.lang.reflect.Constructor JavaDoc;
28 import java.security.Principal JavaDoc;
29
30 /**
31  * This is an in memory representation of the principal-name with its name of
32  * the implementation class.
33  * @author deployment dev team
34  */

35 public class PrincipalNameDescriptor extends Descriptor {
36
37     private static final String JavaDoc defaultClassName =
38                 "com.sun.enterprise.deployment.PrincipalImpl";
39     private String JavaDoc principalName = null;
40     private String JavaDoc className = null;
41
42     public PrincipalNameDescriptor() {}
43
44     public String JavaDoc getName() {
45         return principalName;
46     }
47
48     public String JavaDoc getClassName() {
49         if (className == null) {
50             return defaultClassName;
51         }
52         return className;
53     }
54
55     public void setName(String JavaDoc name) {
56         principalName = name;
57     }
58
59     public void setClassName(String JavaDoc name) {
60         className = name;
61     }
62
63     public Principal JavaDoc getPrincipal() {
64         try {
65             Class JavaDoc clazz = Class.forName(getClassName());
66             Constructor JavaDoc constructor =
67                             clazz.getConstructor(new Class JavaDoc[]{String JavaDoc.class});
68             Object JavaDoc o = constructor.newInstance(new Object JavaDoc[]{principalName});
69             return (Principal JavaDoc) o;
70         } catch(Exception JavaDoc ex) {
71             RuntimeException JavaDoc e = new RuntimeException JavaDoc();
72             e.initCause(ex);
73             throw e;
74         }
75     }
76
77     public String JavaDoc toString() {
78         return "principal-name " + principalName + "; className " + getClassName();
79     }
80 }
81
Popular Tags