KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > config > ConfigParam


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000,2006 Oracle. All rights reserved.
5  *
6  * $Id: ConfigParam.java,v 1.26 2006/11/07 04:37:20 linda Exp $
7  */

8
9 package com.sleepycat.je.config;
10
11
12 /**
13  * A ConfigParam embodies the metatdata about a JE configuration parameter:
14  * the parameter name, default value, and a validation method.
15  *
16  * Validation can be done in the scope of this parameter, or as a function of
17  * other parameters.
18  */

19 public class ConfigParam {
20     // Delimiter used for string parameters that hold multiple values
21
public static final String JavaDoc CONFIG_DELIM = ";";
22
23     protected String JavaDoc name;
24     private String JavaDoc defaultValue;
25     private String JavaDoc description;
26     private boolean mutable;
27     private boolean forReplication;
28
29     /*
30      * Create a String parameter.
31      */

32     public ConfigParam(String JavaDoc configName,
33                        String JavaDoc configDefault,
34                        boolean mutable,
35                        boolean forReplication,
36                        String JavaDoc description)
37         throws IllegalArgumentException JavaDoc {
38         name = configName;
39         defaultValue = configDefault;
40         this.mutable = mutable;
41         this.description = description;
42         this.forReplication = forReplication;
43
44         /* Check that the name and default value are valid */
45         validateName(configName);
46         validateValue(configDefault);
47
48         /*
49          * Add it the list of supported environment parameters.
50          */

51         EnvironmentParams.addSupportedParam(this);
52     }
53
54     public String JavaDoc getName() {
55         return name;
56     }
57
58     public String JavaDoc getDescription() {
59         return description;
60     }
61
62     public String JavaDoc getExtraDescription() {
63         // None by default.
64
return null;
65     }
66
67     public String JavaDoc getDefault() {
68         return defaultValue;
69     }
70
71     public boolean isMutable() {
72         return mutable;
73     }
74
75     public boolean isForReplication() {
76         return forReplication;
77     }
78
79     public void setForReplication(boolean forReplication) {
80         this.forReplication = forReplication;
81     }
82     
83     /**
84      * Validate yourself.
85      */

86     public void validate()
87     throws IllegalArgumentException JavaDoc {
88
89         validateName(name);
90         validateValue(defaultValue);
91     }
92     
93     /*
94      * A param name can't be null or 0 length
95      */

96     private void validateName(String JavaDoc name)
97         throws IllegalArgumentException JavaDoc {
98
99         if ((name == null) || (name.length() < 1)) {
100             throw new IllegalArgumentException JavaDoc(" A configuration parameter" +
101                                                " name can't be null or 0" +
102                                                " length");
103         }
104     }
105
106     /*
107      * Validate your value. (No default validation for strings.
108      */

109     public void validateValue(String JavaDoc value)
110     throws IllegalArgumentException JavaDoc {
111     }
112
113     public String JavaDoc toString() {
114         return name;
115     }
116 }
117
Popular Tags