From a0005e703a1c267b53f089c0709e32c8a898c646 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 11 Jun 2007 14:49:23 +0000
Subject: [PATCH] Add support for specifying a "usage" string for string based property definitions which define a pattern constraint. The usage string is used when the syntax of a property needs to be displayed, for example in a CLI help screen or in server-side log messages when a bad property value is encountered. For example, a property whose values must be a valid UNIX mode could have the following string syntax definition:
---
opends/src/admin/defn/org/opends/server/admin/std/FileBasedAccessLogPublisherConfiguration.xml | 1
opends/src/admin/defn/org/opends/server/admin/std/FileBasedDebugLogPublisherConfiguration.xml | 1
opends/src/admin/defn/org/opends/server/admin/std/DebugTargetConfiguration.xml | 1
opends/src/admin/defn/org/opends/server/admin/std/MultimasterDomainConfiguration.xml | 1
opends/resource/admin/admin.xsd | 10 +++
opends/src/admin/defn/org/opends/server/admin/std/JEBackendConfiguration.xml | 1
opends/resource/admin/property-types/string.xsl | 3
opends/tests/unit-tests-testng/src/server/org/opends/server/admin/StringPropertyDefinitionTest.java | 2
opends/src/server/org/opends/server/admin/StringPropertyDefinition.java | 147 +++++++++++++++++++++++++++++--------------------
opends/src/admin/defn/org/opends/server/admin/std/FileBasedErrorLogPublisherConfiguration.xml | 1
opends/src/admin/defn/org/opends/server/admin/std/FixedTimeLogRotationPolicyConfiguration.xml | 1
opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml | 1
12 files changed, 108 insertions(+), 62 deletions(-)
diff --git a/opends/resource/admin/admin.xsd b/opends/resource/admin/admin.xsd
index c011f3b..81124e7 100644
--- a/opends/resource/admin/admin.xsd
+++ b/opends/resource/admin/admin.xsd
@@ -1275,6 +1275,16 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
+ <xsd:element name="usage" type="xsd:string">
+ <xsd:annotation>
+ <xsd:documentation>
+ The usage string which should be displayed in
+ help relating to this string based property. For
+ example, a pattern which is used to match a
+ host/port string could have the usage HOST:PORT.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
<xsd:element name="synopsis"
type="tns:rich-description-type">
<xsd:annotation>
diff --git a/opends/resource/admin/property-types/string.xsl b/opends/resource/admin/property-types/string.xsl
index 13f32c9..a689829 100644
--- a/opends/resource/admin/property-types/string.xsl
+++ b/opends/resource/admin/property-types/string.xsl
@@ -44,7 +44,8 @@
<xsl:if test="adm:pattern/adm:regex">
<xsl:value-of
select="concat(' builder.setPattern("',
- normalize-space(adm:pattern/adm:regex), '");
')" />
+ normalize-space(adm:pattern/adm:regex), '", "',
+ normalize-space(adm:pattern/adm:usage), '");
')" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/DebugTargetConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/DebugTargetConfiguration.xml
index c7a473a..b331d57 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/DebugTargetConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/DebugTargetConfiguration.xml
@@ -28,6 +28,7 @@
<adm:regex>
^([A-Za-z][A-Za-z0-9_]*\\.)*[A-Za-z][A-Za-z0-9_]*(#[A-Za-z][A-Za-z0-9_]*)?$
</adm:regex>
+ <adm:usage>JAVA_NAME</adm:usage>
<adm:synopsis>
A fully-qualified OpenDS Java package, class, or method name.
</adm:synopsis>
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/FileBasedAccessLogPublisherConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/FileBasedAccessLogPublisherConfiguration.xml
index 6382aa7..f3c8b69 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/FileBasedAccessLogPublisherConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/FileBasedAccessLogPublisherConfiguration.xml
@@ -89,6 +89,7 @@
<adm:regex>
^([0-7][0-7][0-7])$
</adm:regex>
+ <adm:usage>MODE</adm:usage>
<adm:synopsis>
An valid UNIX mode string. The mode string must contain three
digits between zero and seven.
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/FileBasedDebugLogPublisherConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/FileBasedDebugLogPublisherConfiguration.xml
index ec54cbf..6241e86 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/FileBasedDebugLogPublisherConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/FileBasedDebugLogPublisherConfiguration.xml
@@ -89,6 +89,7 @@
<adm:regex>
^([0-7][0-7][0-7])$
</adm:regex>
+ <adm:usage>MODE</adm:usage>
<adm:synopsis>
An valid UNIX mode string. The mode string must contain three
digits between zero and seven.
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/FileBasedErrorLogPublisherConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/FileBasedErrorLogPublisherConfiguration.xml
index b4f720d..c0aed67 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/FileBasedErrorLogPublisherConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/FileBasedErrorLogPublisherConfiguration.xml
@@ -89,6 +89,7 @@
<adm:regex>
^([0-7][0-7][0-7])$
</adm:regex>
+ <adm:usage>MODE</adm:usage>
<adm:synopsis>
An valid UNIX mode string. The mode string must contain three
digits between zero and seven.
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/FixedTimeLogRotationPolicyConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/FixedTimeLogRotationPolicyConfiguration.xml
index 99d34f5..c18ffc3 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/FixedTimeLogRotationPolicyConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/FixedTimeLogRotationPolicyConfiguration.xml
@@ -35,6 +35,7 @@
<adm:regex>
^(([0-1][0-9])|([2][0-3]))([0-5][0-9])$
</adm:regex>
+ <adm:usage>HHmm</adm:usage>
<adm:synopsis>
24 hour time of day in HHmm format.
</adm:synopsis>
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/JEBackendConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/JEBackendConfiguration.xml
index 6693b40..f045999 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/JEBackendConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/JEBackendConfiguration.xml
@@ -389,6 +389,7 @@
<adm:string>
<adm:pattern>
<adm:regex>7[0-7][0-7]</adm:regex>
+ <adm:usage>MODE</adm:usage>
<adm:synopsis>
Any octal value between 700 and 777 (the owner must always have
read, write, and execute permissions on the directory).
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/MultimasterDomainConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/MultimasterDomainConfiguration.xml
index e19ac3f..820d1fc 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/MultimasterDomainConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/MultimasterDomainConfiguration.xml
@@ -61,6 +61,7 @@
<adm:string>
<adm:pattern>
<adm:regex>.+:[0-9]+</adm:regex>
+ <adm:usage>HOST:PORT</adm:usage>
<adm:synopsis>
A hostname, followed by a ":" followed by a port number.
</adm:synopsis>
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
index 0d12170..5a8ac94 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
@@ -65,6 +65,7 @@
<adm:string>
<adm:pattern>
<adm:regex>.+:[0-9]+</adm:regex>
+ <adm:usage>HOST:PORT</adm:usage>
<adm:synopsis>
A hostname, followed by a ":" followed by a port number.
</adm:synopsis>
diff --git a/opends/src/server/org/opends/server/admin/StringPropertyDefinition.java b/opends/src/server/org/opends/server/admin/StringPropertyDefinition.java
index 1025d14..c1ebeb7 100644
--- a/opends/src/server/org/opends/server/admin/StringPropertyDefinition.java
+++ b/opends/src/server/org/opends/server/admin/StringPropertyDefinition.java
@@ -45,15 +45,6 @@
*/
public final class StringPropertyDefinition extends PropertyDefinition<String> {
- // Flag indicating whether values of this property are
- // case-insensitive.
- private final boolean isCaseInsensitive;
-
- // Optional pattern which values of this property must match.
- private final Pattern pattern;
-
-
-
/**
* An interface for incrementally constructing string property
* definitions.
@@ -68,6 +59,10 @@
// Optional pattern which values of this property must match.
private Pattern pattern = null;
+ // Pattern usage which provides a user-friendly summary of the
+ // pattern if present.
+ private String patternUsage = null;
+
// Private constructor
@@ -99,16 +94,23 @@
* @param pattern
* The regular expression pattern string, or
* <code>null</code> if there is no pattern.
+ * @param patternUsage
+ * A user-friendly usage string representing the pattern
+ * which can be used in error messages and help (e.g. for
+ * patterns which match a host/port combination, the
+ * usage string "HOST:PORT" would be appropriate).
* @throws PatternSyntaxException
* If the provided regular expression pattern has an
* invalid syntax.
*/
- public final void setPattern(String pattern)
+ public final void setPattern(String pattern, String patternUsage)
throws PatternSyntaxException {
if (pattern == null) {
this.pattern = null;
+ this.patternUsage = null;
} else {
this.pattern = Pattern.compile(pattern);
+ this.patternUsage = patternUsage;
}
}
@@ -123,7 +125,7 @@
EnumSet<PropertyOption> options,
DefaultBehaviorProvider<String> defaultBehavior) {
return new StringPropertyDefinition(d, propertyName, options,
- defaultBehavior, isCaseInsensitive, pattern);
+ defaultBehavior, isCaseInsensitive, pattern, patternUsage);
}
}
@@ -140,22 +142,72 @@
* The property name.
* @return Returns the new string property definition builder.
*/
- public static Builder createBuilder(
- AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
+ public static Builder createBuilder(AbstractManagedObjectDefinition<?, ?> d,
+ String propertyName) {
return new Builder(d, propertyName);
}
+ // Flag indicating whether values of this property are
+ // case-insensitive.
+ private final boolean isCaseInsensitive;
+
+ // Optional pattern which values of this property must match.
+ private final Pattern pattern;
+
+ // Pattern usage which provides a user-friendly summary of the
+ // pattern if present.
+ private final String patternUsage;
+
// Private constructor.
- private StringPropertyDefinition(
- AbstractManagedObjectDefinition<?, ?> d, String propertyName,
- EnumSet<PropertyOption> options,
+ private StringPropertyDefinition(AbstractManagedObjectDefinition<?, ?> d,
+ String propertyName, EnumSet<PropertyOption> options,
DefaultBehaviorProvider<String> defaultBehavior,
- boolean isCaseInsensitive, Pattern pattern) {
+ boolean isCaseInsensitive, Pattern pattern, String patternUsage) {
super(d, String.class, propertyName, options, defaultBehavior);
this.isCaseInsensitive = isCaseInsensitive;
this.pattern = pattern;
+ this.patternUsage = patternUsage;
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
+ return v.visitString(this, p);
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <R, P> R accept(PropertyValueVisitor<R, P> v, String value, P p) {
+ return v.visitString(this, value, p);
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String decodeValue(String value)
+ throws IllegalPropertyValueStringException {
+ ensureNotNull(value);
+
+ try {
+ validateValue(value);
+ } catch (IllegalPropertyValueException e) {
+ throw new IllegalPropertyValueStringException(this, value);
+ }
+
+ return value;
}
@@ -208,8 +260,8 @@
String property = "property." + getName()
+ ".syntax.string.pattern.synopsis";
try {
- return resource.getMessage(getManagedObjectDefinition(),
- property, locale);
+ return resource
+ .getMessage(getManagedObjectDefinition(), property, locale);
} catch (MissingResourceException e) {
return null;
}
@@ -218,6 +270,21 @@
/**
+ * Gets a user-friendly usage string representing the pattern which
+ * can be used in error messages and help (e.g. for patterns which
+ * match a host/port combination, the usage string "HOST:PORT" would
+ * be appropriate).
+ *
+ * @return Returns the user-friendly pattern usage string, or
+ * <code>null</code> if there is no pattern.
+ */
+ public String getPatternUsage() {
+ return patternUsage;
+ }
+
+
+
+ /**
* Query whether values of this property are case-insensitive.
*
* @return Returns <code>true</code> if values are
@@ -250,8 +317,7 @@
* {@inheritDoc}
*/
@Override
- public void validateValue(String value)
- throws IllegalPropertyValueException {
+ public void validateValue(String value) throws IllegalPropertyValueException {
ensureNotNull(value);
if (pattern != null) {
@@ -261,43 +327,4 @@
}
}
}
-
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String decodeValue(String value)
- throws IllegalPropertyValueStringException {
- ensureNotNull(value);
-
- try {
- validateValue(value);
- } catch (IllegalPropertyValueException e) {
- throw new IllegalPropertyValueStringException(this, value);
- }
-
- return value;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) {
- return v.visitString(this, p);
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <R, P> R accept(PropertyValueVisitor<R, P> v, String value, P p) {
- return v.visitString(this, value, p);
- }
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/StringPropertyDefinitionTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/StringPropertyDefinitionTest.java
index 4b74482..b8e04c6 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/StringPropertyDefinitionTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/StringPropertyDefinitionTest.java
@@ -102,7 +102,7 @@
StringPropertyDefinition.Builder builder = StringPropertyDefinition
.createBuilder(RootCfgDefn.getInstance(), "test-property");
builder.setCaseInsensitive(isCaseInsensitive);
- builder.setPattern(pattern);
+ builder.setPattern(pattern, "STRING");
return builder.getInstance();
}
}
--
Gitblit v1.10.0