KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > deploy > Principal


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.security.deploy;
18
19 import java.beans.PropertyEditorManager JavaDoc;
20 import java.io.Serializable JavaDoc;
21
22 import org.apache.geronimo.common.propertyeditor.PropertyEditorException;
23 import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport;
24
25
26 /**
27  * @version $Rev: 154957 $ $Date: 2005-02-22 21:07:36 -0800 (Tue, 22 Feb 2005) $
28  */

29 public class Principal implements Serializable JavaDoc {
30
31     static {
32         PropertyEditorManager.registerEditor(Principal.class, PrincipalEditor.class);
33     }
34
35     private String JavaDoc className;
36     private String JavaDoc principalName;
37     private boolean designatedRunAs;
38
39     public String JavaDoc getClassName() {
40         return className;
41     }
42
43     public void setClassName(String JavaDoc className) {
44         this.className = className;
45     }
46
47     public String JavaDoc getPrincipalName() {
48         return principalName;
49     }
50
51     public void setPrincipalName(String JavaDoc principalName) {
52         this.principalName = principalName;
53     }
54
55     public boolean isDesignatedRunAs() {
56         return designatedRunAs;
57     }
58
59     public void setDesignatedRunAs(boolean designatedRunAs) {
60         this.designatedRunAs = designatedRunAs;
61     }
62
63     public static class PrincipalEditor extends TextPropertyEditorSupport {
64
65         public void setAsText(String JavaDoc text) {
66             if (text != null) {
67                 String JavaDoc[] parts = text.split("=");
68                 if (parts.length != 2) {
69                     throw new PropertyEditorException("Principal should have the form 'name=class'");
70                 }
71                 Principal principal = new Principal();
72                 principal.setPrincipalName(parts[0]);
73                 principal.setClassName(parts[1]);
74                 setValue(principal);
75             } else {
76                 setValue(null);
77             }
78         }
79
80         public String JavaDoc getAsText() {
81             Principal principal = (Principal) getValue();
82             if (principal == null) {
83                 return null;
84             }
85             return new StringBuffer JavaDoc(principal.getPrincipalName()).append("=").append(principal.getClassName()).toString();
86         }
87     }
88 }
89
Popular Tags