diff options
author | John Ross | 2013-09-11 10:36:18 +0000 |
---|---|---|
committer | John Ross | 2013-09-16 17:37:00 +0000 |
commit | 5f41f307cf746e0e3469855f20f798962e051221 (patch) | |
tree | 844fa695d00f2f4c1eaa5f14eb387b57910db7c1 | |
parent | ede377dd311210ae0fe7f72985635507bcd6a211 (diff) | |
download | rt.equinox.bundles-5f41f307cf746e0e3469855f20f798962e051221.tar.gz rt.equinox.bundles-5f41f307cf746e0e3469855f20f798962e051221.tar.xz rt.equinox.bundles-5f41f307cf746e0e3469855f20f798962e051221.zip |
Bug 416640 - [metatype] Consider providing API access to min/max values from metadata XML.
Add new methods to the EquinoxAttributeDefinition interface allowing access to the min and max values. The return type is
String which matches the type defined by the metatype XML schema.
Update implementation to accept min/max values that are not integers for type String. If min and max are integers, a string
length comparison takes place. If either min or max is not an integer, then String.compareTo is called.
Increment bundle minor version.
Update equinox metatype api version to 1.3.
7 files changed, 58 insertions, 13 deletions
diff --git a/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF index dbf4a941f..5a4391d63 100644 --- a/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Bundle-ManifestVersion: 2 Bundle-Name: %bundleName -Bundle-Version: 1.3.100.qualifier +Bundle-Version: 1.4.0.qualifier Bundle-SymbolicName: org.eclipse.equinox.metatype Bundle-Activator: org.eclipse.equinox.metatype.impl.Activator Import-Package: javax.xml.parsers, @@ -14,7 +14,7 @@ Import-Package: javax.xml.parsers, org.xml.sax, org.xml.sax.helpers Export-Package: org.eclipse.equinox.metatype;version="1.2.0", - org.eclipse.equinox.metatype.impl;version="1.2.0";x-friends:=org.eclipse.equinox.compendium.tests + org.eclipse.equinox.metatype.impl;version="1.3.0";x-friends:=org.eclipse.equinox.compendium.tests Bundle-Vendor: %bundleVendor Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/bundles/org.eclipse.equinox.metatype/pom.xml b/bundles/org.eclipse.equinox.metatype/pom.xml index 9e08dc287..f499cab2d 100644 --- a/bundles/org.eclipse.equinox.metatype/pom.xml +++ b/bundles/org.eclipse.equinox.metatype/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.metatype</artifactId> - <version>1.3.100-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <build> <plugins> diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/EquinoxAttributeDefinition.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/EquinoxAttributeDefinition.java index 99070ffd2..dcf73d71a 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/EquinoxAttributeDefinition.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/EquinoxAttributeDefinition.java @@ -23,5 +23,21 @@ import org.osgi.service.metatype.AttributeDefinition; * */ public interface EquinoxAttributeDefinition extends AttributeDefinition, Extendable { - // Empty interface to support extendable attribute definitions. + /** + * Get the maximum value this attribute may hold as specified by the + * optional "max" XML attribute of the <AD> element. + * + * @return The maximum value this attribute may hold, or <code>null</code> + * if unspecified. + */ + public String getMax(); + + /** + * Get the minimum value this attribute may hold as specified by the + * optional "min" XML attribute of the <AD> element. + * + * @return The minimum value this attribute may hold, or <code>null</code> + * if unspecified. + */ + public String getMin(); } diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/AttributeDefinitionImpl.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/AttributeDefinitionImpl.java index a0c2d9cb8..2e671d6c4 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/AttributeDefinitionImpl.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/AttributeDefinitionImpl.java @@ -313,4 +313,12 @@ public class AttributeDefinitionImpl extends LocalizationElement implements Equi public Set<String> getExtensionUris() { return helper.getExtensionUris(); } + + public String getMax() { + return _maxValue == null ? null : String.valueOf(_maxValue); + } + + public String getMin() { + return _minValue == null ? null : String.valueOf(_minValue); + } } diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java index 850b78f75..176e23691 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java @@ -123,8 +123,7 @@ public class DataParser { // PASSWORD should be treated like STRING. case AttributeDefinition.PASSWORD : case AttributeDefinition.STRING : - // Both the min and max of STRING are Integers. - return new Integer(value); + return value; case AttributeDefinition.LONG : return new Long(value); case AttributeDefinition.INTEGER : diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java index 5433cebcf..5e4c87524 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java @@ -10,11 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.metatype.impl; -import org.eclipse.equinox.metatype.*; - import java.io.IOException; import java.io.InputStream; import java.util.*; +import org.eclipse.equinox.metatype.*; import org.eclipse.osgi.util.NLS; import org.osgi.framework.*; import org.osgi.service.cm.ManagedService; @@ -273,6 +272,14 @@ public class MetaTypeProviderTracker implements EquinoxMetaTypeInformation { public Set<String> getExtensionUris() { return Collections.EMPTY_SET; } + + public String getMax() { + return null; + } + + public String getMin() { + return null; + } }); } return result.toArray(new EquinoxAttributeDefinition[result.size()]); diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java index 9e2897863..d9160551d 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java @@ -142,6 +142,25 @@ public class ValueTokenizer { return buffer.toString(); } + private boolean validateString(AttributeDefinitionImpl ad, String value) { + // Try validating the string length. + try { + // All or nothing. If either min or max is not null and cannot be + // parsed as an integer, do the string comparison instead. + Integer min = ad._minValue == null ? null : Integer.valueOf((String) ad._minValue); + Integer max = ad._maxValue == null ? null : Integer.valueOf((String) ad._maxValue); + if (min != null && value.length() < min) + return true; + if (max != null && value.length() > max) + return true; + } catch (NumberFormatException e) { + // Either min or max was not an integer. Do a string comparison. + if ((ad._minValue != null && value.compareTo((String) ad._minValue) < 0) || (ad._maxValue != null && value.compareTo((String) ad._maxValue) > 0)) + return true; + } + return false; + } + public String validate(AttributeDefinitionImpl ad) { // An empty list means the original value was null. Null is never valid. if (values.isEmpty()) { @@ -173,11 +192,7 @@ public class ValueTokenizer { switch (ad._dataType) { case AttributeDefinition.PASSWORD : case AttributeDefinition.STRING : - if (ad._minValue != null && s.length() < (Integer) ad._minValue) { - rangeError = true; - } else if (ad._maxValue != null && s.length() > (Integer) ad._maxValue) { - rangeError = true; - } + rangeError = validateString(ad, s); break; case AttributeDefinition.INTEGER : Integer intVal = new Integer(s); |