01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.security.deploy;
17:
18: import java.beans.PropertyEditorManager;
19: import java.io.Serializable;
20:
21: import org.apache.geronimo.common.propertyeditor.PropertyEditorException;
22: import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport;
23:
24: /**
25: * @version $Rev: 545781 $ $Date: 2007-06-09 10:44:02 -0700 (Sat, 09 Jun 2007) $
26: */
27: public class PrincipalInfo implements Serializable {
28:
29: static {
30: PropertyEditorManager.registerEditor(PrincipalInfo.class,
31: PrincipalEditor.class);
32: }
33:
34: private final String className;
35: private final String principalName;
36:
37: public PrincipalInfo(String className, String principalName) {
38: this .className = className;
39: this .principalName = principalName;
40: }
41:
42: public String getClassName() {
43: return className;
44: }
45:
46: public String getPrincipalName() {
47: return principalName;
48: }
49:
50: public static class PrincipalEditor extends
51: TextPropertyEditorSupport {
52:
53: public void setAsText(String text) {
54: if (text != null) {
55: String[] parts = text.split(",");
56: if (parts.length != 2) {
57: throw new PropertyEditorException(
58: "Principal should have the form 'name,class'");
59: }
60: PrincipalInfo principalInfo = new PrincipalInfo(
61: parts[0], parts[1]);
62: setValue(principalInfo);
63: } else {
64: setValue(null);
65: }
66: }
67:
68: public String getAsText() {
69: PrincipalInfo principalInfo = (PrincipalInfo) getValue();
70: if (principalInfo == null) {
71: return null;
72: }
73: return principalInfo.getPrincipalName() + ","
74: + principalInfo.getClassName();
75: }
76: }
77: }
|