|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.common; |
|
27 |
|
28 public class LoginProperty<T> { |
|
29 // |
|
30 // Instance data |
|
31 // |
|
32 |
|
33 private String name; |
|
34 private T value; |
|
35 private boolean editable; |
|
36 private boolean editableOnError; |
|
37 private boolean errored; |
|
38 |
|
39 // |
|
40 // Constructors |
|
41 // |
|
42 |
|
43 public LoginProperty(String name, T value, boolean editable) { |
|
44 this.name = name; |
|
45 this.value = value; |
|
46 this.editable = editable; |
|
47 } |
|
48 |
|
49 public LoginProperty(T value, boolean editable) { |
|
50 this(null, value, editable); |
|
51 } |
|
52 |
|
53 public LoginProperty(T value) { |
|
54 this(null, value, true); |
|
55 } |
|
56 |
|
57 // |
|
58 // Object methods |
|
59 // |
|
60 |
|
61 @Override |
|
62 public String toString() { |
|
63 return String.format( |
|
64 "name=%s, value=%s, editable=%b, editableOnError=%b, errored=%b", |
|
65 name, value, editable, editableOnError, errored); |
|
66 } |
|
67 |
|
68 // |
|
69 // LoginProperty methods |
|
70 // |
|
71 |
|
72 /** |
|
73 * Gets the name of this {@code LoginProperty}. |
|
74 * |
|
75 * @return a {@code String}, or {@code null} if no name is appropriate |
|
76 * or necessary |
|
77 */ |
|
78 public String getName() { |
|
79 return name; |
|
80 } |
|
81 |
|
82 /** |
|
83 * Gets the value of this {@code LoginProperty} as a {@code T}. |
|
84 */ |
|
85 public T getValue() { |
|
86 return value; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Gets whether this {@code LoginProperty} is editable. |
|
91 */ |
|
92 public boolean isEditable() { |
|
93 return editable; |
|
94 } |
|
95 |
|
96 /** |
|
97 * Gets whether this {@code LoginProperty} is editable in an errored state. |
|
98 */ |
|
99 public boolean isEditableOnError() { |
|
100 return editableOnError; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Gets whether this {@code LoginProperty} is in an errored state. |
|
105 */ |
|
106 public boolean isErrored() { |
|
107 return errored; |
|
108 } |
|
109 |
|
110 /** |
|
111 * Sets whether this {@code LoginProperty} is editable. |
|
112 */ |
|
113 public void setEditable(boolean editable) { |
|
114 this.editable = editable; |
|
115 } |
|
116 |
|
117 /** |
|
118 * Sets whether this {@code LoginProperty} is editable in an errored state. |
|
119 */ |
|
120 public void setEditableOnError(boolean editableOnError) { |
|
121 this.editableOnError = editableOnError; |
|
122 } |
|
123 |
|
124 /** |
|
125 * Sets whether this {@code LoginProperty} is in an errored state. |
|
126 */ |
|
127 public void setErrored(boolean errored) { |
|
128 if (this.errored != errored) { |
|
129 this.errored = errored; |
|
130 if (errored && isEditableOnError()) { |
|
131 setEditable(true); |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 /** |
|
137 * Sets the value of this {@code LoginProperty}. |
|
138 * |
|
139 * @throws IllegalStateException |
|
140 * if this {@code LoginProperty} is not editable |
|
141 */ |
|
142 public void setValue(T value) { |
|
143 if (!editable) { |
|
144 throw new IllegalStateException(); |
|
145 } |
|
146 |
|
147 this.value = value; |
|
148 } |
|
149 |
|
150 /** |
|
151 * Validates the {@link #getValue set value} of this {@code LoginProperty}. |
|
152 * This default implementation does nothing. |
|
153 * |
|
154 * @param request |
|
155 * the request, if any, of which this {@code LoginProperty} is |
|
156 * part |
|
157 * |
|
158 * @param valid |
|
159 * optional set of valid values, if appropriate for this {@code |
|
160 * LoginProperty} |
|
161 * |
|
162 * @exception LoginPropertyException |
|
163 * if the set value is invalid |
|
164 */ |
|
165 public void validate(LoginRequest request, T... valid) |
|
166 throws LoginPropertyException { |
|
167 } |
|
168 } |