001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: /*
037: * ConfigProperty.java
038: */
039: package com.sun.jbi.jsf.bean;
040:
041: import java.util.List;
042:
043: /**
044: * Defines when and how a configuration property is to be
045: * initialized, displayed, edited, and validated based on
046: * the option Open ESB configuration extension elements (e.g.
047: * <code><config:Property ...></code> in a JBI
048: * component's jbi.xml descriptor.
049: *
050: * @author Sun Microsystems Inc.
051: */
052: public class ConfigProperty {
053: // === static utility methods ===
054:
055: /**
056: * Determines if the specified property is to be displayed during
057: * component installation configuration
058: *
059: * @param aConfigProperty a property to be checked
060: * @return true for installation configuration display
061: * (i.e. showDisplay of <code>all</code> or
062: * <code>install</code>)
063: */
064: public static boolean isInstallTime(ConfigProperty aConfigProperty) {
065: boolean result = false;
066: String showDisplay = aConfigProperty.getShowDisplay();
067: if ((SHOW_DISPLAY_TYPE_ALL.equals(showDisplay))
068: || (SHOW_DISPLAY_TYPE_INSTALL.equals(showDisplay))) {
069: result = true;
070: }
071: return result;
072: }
073:
074: /**
075: * Determines if the specified property is to be displayed during
076: * component runtime configuration
077: *
078: * @param aConfigProperty a property to be checked
079: * @return true for runtime configuration display
080: * (i.e. showDisplay of <code>all</code> or
081: * <code>runtime</code>)
082: */
083: public static boolean isRuntime(ConfigProperty aConfigProperty) {
084: boolean result = false;
085: String showDisplay = aConfigProperty.getShowDisplay();
086: if ((SHOW_DISPLAY_TYPE_ALL.equals(showDisplay))
087: || (SHOW_DISPLAY_TYPE_RUNTIME.equals(showDisplay))) {
088: result = true;
089: }
090: return result;
091: }
092:
093: // === constructor(s) ===
094:
095: /**
096: * Empty Constructor (use setters after instantiation)
097: */
098: public ConfigProperty() {
099: }
100:
101: // === getters ===
102:
103: /**
104: * Gets the Display Name
105: *
106: * @return The name to be displayed in user interface
107: */
108: public String getDisplayName() {
109: return mDisplayName;
110: }
111:
112: /**
113: * Gets the Default Numeric Value attribute, if any
114: *
115: * @return The DefaultNumericValue value or null if none
116: */
117: public int getDefaultNumericValue() {
118: return mDefaultNumericValue;
119: }
120:
121: /**
122: * Gets the Default String Value attribute, if any
123: *
124: * @return The DefaultStringValue value or null if none
125: */
126: public String getDefaultStringValue() {
127: return mDefaultStringValue;
128: }
129:
130: /**
131: * Gets the Display Description
132: *
133: * @return The DisplayDescription I18n value to be used for
134: * field help or tool tips
135: */
136: public String getDisplayDescription() {
137: return mDisplayDescription;
138: }
139:
140: /**
141: * Gets the Constraint Enumeration if any
142: *
143: * @return A List of allowable values for a selection widget
144: * or null if the field is to be manually entered
145: */
146: public List<String> getConstraintEnumeration() {
147: return mConstraintEnumeration;
148: }
149:
150: /**
151: * Gets the Constraint Max Inclusive attribute if applicable
152: *
153: * @return The max allowed value for a numeric field
154: */
155: public int getConstraintMaxInclusive() {
156: return mConstraintMaxInclusive;
157: }
158:
159: /**
160: * Gets the Constraint Min Inclusive attribute if applicable
161: *
162: * @return The ConstraintMinInclusive value
163: */
164: public int getConstraintMinInclusive() {
165: return mConstraintMinInclusive;
166: }
167:
168: /**
169: * Gets the Application Restart Required attribute
170: *
171: * @return true if changing this property requires the display
172: * of an application-restart-is-required message
173: */
174: public boolean getIsAppRestartRequired() {
175: return mIsAppRestartRequired;
176: }
177:
178: /**
179: * Gets the Component Restart Required attribute
180: *
181: * @return true if changing this property requires the display
182: * of a component-restart-is-required message
183: */
184: public boolean getIsCompRestartRequired() {
185: return mIsCompRestartRequired;
186: }
187:
188: /**
189: * Gets the Is Encrypted attribute
190: *
191: * @return true if this property is to be hidden when viewing or editing
192: */
193: public boolean getIsEncrypted() {
194: return mIsEncrypted;
195: }
196:
197: /**
198: * Gets the Is Required attribute
199: *
200: * @return true if a value is required for this property
201: */
202: public boolean getIsRequired() {
203: return mIsRequired;
204: }
205:
206: /**
207: * Gets the Is Server Restart Required attribute
208: *
209: * @return true if changing this property requires the display
210: * of a server-restart-is-required message
211: */
212: public boolean getIsServerRestartRequired() {
213: return mIsServerRestartRequired;
214: }
215:
216: /**
217: * Gets the Name attribute
218: *
219: * @return The non-I18n Name of this property
220: */
221: public String getName() {
222: return mName;
223: }
224:
225: /**
226: * Gets the On Change Message attribute, if any
227: *
228: * @return an I18n message to be displayed if this value is changed
229: * or null if there is no on-change-message for this property
230: */
231: public String getOnChangeMessage() {
232: return mOnChangeMessage;
233: }
234:
235: /**
236: * Gets the Show Display attribute
237: *
238: * @return one of: <code>all</code>, <code>install</code>, or
239: * <code>runtime</code>
240: */
241: public String getShowDisplay() {
242: return mShowDisplay;
243: }
244:
245: /**
246: * Gets the Type attribute
247: *
248: * @return The XSD type of value for this property (which determines
249: * whether it is boolean, numeric, or string). one of:
250: * <code>xsd:boolean</code>, <code>xsd:int</code>, or
251: * <code>xsd:string</code>.
252: */
253: public String getXSDType() {
254: return mXSDType;
255: }
256:
257: /**
258: * Gets the Value attribute
259: *
260: * @return The current value of the property, if any
261: */
262: public Object getValue() {
263: return mValue;
264: }
265:
266: // === setters ===
267:
268: /**
269: * Sets the Constraint Enumeration values
270: *
271: * @param aConstraintEnumeration A list of display strings to be used
272: * in a selection widget (or null if
273: * this is a manually entered value)
274: */
275: public void setConstraintEnumeration(
276: List<String> aConstraintEnumeration) {
277: mConstraintEnumeration = aConstraintEnumeration;
278: }
279:
280: /**
281: * Sets the Constraint Max Inclusive attribute
282: *
283: * @param aConstraintMaxInclusive The maximum allowed numeric value
284: */
285: public void setConstraintMaxInclusive(int aConstraintMaxInclusive) {
286: mConstraintMaxInclusive = aConstraintMaxInclusive;
287: }
288:
289: /**
290: * Sets the Constraint Min Inclusive attribute
291: *
292: * @param aConstraintMinInclusive The minimum allowed numeric value
293: */
294: public void setConstraintMinInclusive(int aConstraintMinInclusive) {
295: mConstraintMinInclusive = aConstraintMinInclusive;
296: }
297:
298: /**
299: * Sets the Display Name attribute
300: *
301: * @param aDisplayName The I18n String to be displayed in the
302: * user interface
303: */
304: public void setDisplayName(String aDisplayName) {
305: mDisplayName = aDisplayName;
306: }
307:
308: /**
309: * Sets the Default Numeric Value attribute
310: *
311: * @param aDefaultNumericValue The default value to display, if numeric
312: * or null if non-numeric
313: */
314: public void setDefaultNumericValue(int aDefaultNumericValue) {
315: mDefaultNumericValue = aDefaultNumericValue;
316: }
317:
318: /**
319: * Sets the Default String Value attribute
320: *
321: * @param aDefaultStringValue The new DefaultStringValue value
322: */
323: public void setDefaultStringValue(String aDefaultStringValue) {
324: mDefaultStringValue = aDefaultStringValue;
325: }
326:
327: /**
328: * Sets the Display Description attribute
329: *
330: * @param aDisplayDescription an I18n String to describe this property
331: * e.g. for inline help or tooltip
332: */
333: public void setDisplayDescription(String aDisplayDescription) {
334: mDisplayDescription = aDisplayDescription;
335: }
336:
337: /**
338: * Sets the Is Application Restart Required attribute
339: *
340: * @param isAppRestartRequired true if changing this property
341: * should result in an
342: * application-restart-required message
343: */
344: public void setIsAppRestartRequired(boolean isAppRestartRequired) {
345: mIsAppRestartRequired = isAppRestartRequired;
346: }
347:
348: /**
349: * Sets the IsCompRestartRequired attribute of the ConfigProperty object
350: *
351: * @param isCompRestartRequired true if changing this property
352: * should result in an
353: * component-restart-required message
354: */
355: public void setIsCompRestartRequired(boolean isCompRestartRequired) {
356: mIsCompRestartRequired = isCompRestartRequired;
357: }
358:
359: /**
360: * Sets the Is Encrypted attribute
361: *
362: * @param isEncrypted true if this property's value is to be hidden
363: * when viewed or prompted-for (e.g. password field)
364: * (also hidden during logging)
365: */
366: public void setIsEncrypted(boolean isEncrypted) {
367: mIsEncrypted = isEncrypted;
368: }
369:
370: /**
371: * Sets the IsServerRestartRequired attribute of the ConfigProperty object
372: *
373: * @param isServerRestartRequired true if changing this property
374: * should result in an
375: * component-restart-required message
376: */
377: public void setIsServerRestartRequired(
378: boolean isServerRestartRequired) {
379: mIsServerRestartRequired = isServerRestartRequired;
380: }
381:
382: /**
383: * Sets the Is Required attribute
384: *
385: * @param isRequired true if a value is required for this property
386: */
387: public void setIsRequired(boolean isRequired) {
388: mIsRequired = isRequired;
389: }
390:
391: /**
392: * Sets the Name attribute
393: *
394: * @param aName a non-I18n String to name this property
395: */
396: public void setName(String aName) {
397: mName = aName;
398: }
399:
400: /**
401: * Sets the On Change Message attribute
402: *
403: * @param anOnChangeMessage an I18n String with a message to be
404: * displayed if this property's value is changed
405: * (or null if there is no such message)
406: */
407: public void setOnChangeMessage(String anOnChangeMessage) {
408: mOnChangeMessage = anOnChangeMessage;
409: }
410:
411: /**
412: * Sets the Show Display attribute
413: *
414: * @param aShowDisplay an I18n String to display in the user-interface
415: */
416: public void setShowDisplay(String aShowDisplay) {
417: mShowDisplay = aShowDisplay;
418: }
419:
420: /**
421: * Sets the Type attribute to specify if this is a boolean, numeric, or
422: * string property
423: *
424: * @param anXSDType one of: <code>xsd:boolean</code>, <code>xsd:int</code>,
425: * or <code>xsd:string</code>
426: */
427: public void setXSDType(String anXSDType) {
428: mXSDType = anXSDType;
429: }
430:
431: /**
432: * Sets the Value attribute
433: *
434: * @param aValue The value of this property to be viewed, edited,
435: * and passed to the component's installation
436: * configuration and/or runtime configuration MBean.
437: */
438: public void setValue(Object aValue) {
439: mValue = aValue;
440: }
441:
442: /**
443: * Converts to a String representation of the object.
444: *
445: * @return A non-I18n String for logging the state of this object
446: * (for an "encrypted" property,
447: * the value is <code>*hidden*</code>)
448: */
449: public String toString() {
450: StringBuffer result = new StringBuffer(CN);
451: result.append(", mConstraintEnumeration=[");
452: if (null != mConstraintEnumeration) {
453: boolean first = true;
454: for (int i = 0; i < mConstraintEnumeration.size(); ++i) {
455: if (!first) {
456: result.append(", ");
457: } else {
458: first = false;
459: }
460: result.append(mConstraintEnumeration.get(i));
461: }
462: }
463: result.append("], mConstraintMaxInclusive=");
464: result.append(mConstraintMaxInclusive);
465: result.append(", mConstraintMinInclusive=");
466: result.append(mConstraintMinInclusive);
467: result.append(", mDefaultNumericValue=");
468: result.append(mDefaultNumericValue);
469: result.append(", mDefaultStringValue=");
470: result.append(mDefaultStringValue);
471: result.append(", mDisplayDescription=");
472: result.append(mDisplayDescription);
473: result.append(", mDisplayName=");
474: result.append(mDisplayName);
475: result.append(", mIsAppRestartRequired=");
476: result.append(mIsAppRestartRequired);
477: result.append(", mIsAppRestartRequired=");
478: result.append(mIsCompRestartRequired);
479: result.append(", mIsCompRestartRequired=");
480: result.append(mIsEncrypted);
481: result.append(", mIsRequired=");
482: result.append(mIsRequired);
483: result.append(", mIsServerRestartRequired=");
484: result.append(mIsServerRestartRequired);
485: result.append(", mName=");
486: result.append(mName);
487: result.append(", mOnChangeMessage=");
488: result.append(mOnChangeMessage);
489:
490: result.append(", mValue=");
491: if (mIsEncrypted) {
492: result.append("*hidden*");
493: } else {
494: result.append(mValue);
495: }
496: result.append(", mShowDisplay=");
497: result.append(mShowDisplay);
498: result.append(", mXSDType=");
499: result.append(mXSDType);
500:
501: return result.toString();
502: }
503:
504: // === static fields ===
505:
506: private static final String CN = ConfigProperty.class.getName();
507:
508: private static final String SHOW_DISPLAY_TYPE_ALL = "all";
509: private static final String SHOW_DISPLAY_TYPE_INSTALL = "install";
510: private static final String SHOW_DISPLAY_TYPE_RUNTIME = "runtime";
511:
512: // === member variables ===
513:
514: private int mDefaultNumericValue;
515: private String mDefaultStringValue;
516: private String mDisplayDescription;
517: private String mDisplayName;
518: private List<String> mConstraintEnumeration = null;
519: private int mConstraintMaxInclusive;
520: private int mConstraintMinInclusive;
521: private boolean mIsAppRestartRequired;
522: private boolean mIsCompRestartRequired;
523: private boolean mIsEncrypted;
524: private boolean mIsRequired;
525: private boolean mIsServerRestartRequired;
526: private String mName;
527: private String mOnChangeMessage;
528: private String mShowDisplay;
529: private Object mValue;
530: private String mXSDType;
531: }
|