[jboss-cvs] JBossAS SVN: r81573 - in projects/jboss-man/trunk: managed/src/main/java/org/jboss/managed/api/annotation and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 25 16:05:19 EST 2008
Author: scott.stark at jboss.org
Date: 2008-11-25 16:05:19 -0500 (Tue, 25 Nov 2008)
New Revision: 81573
Added:
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java
projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/ConstrainedBean.java
projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyConstraintsUnitTestCase.java
Removed:
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java
Modified:
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java
projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java
Log:
JBMAN-46, use MetaValue in comparables and extend the constraints populator interface
svn merge -c81525,-c81526 https://svn.jboss.org/repos/jbossas/projects/jboss-man/branches/Branch_2_0
Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -152,14 +152,14 @@
/**
* Get the minimum value
*
- * @return the minimum value
+ * @return the minimum value, a MetaValue implementing Comparable
*/
Comparable<? extends MetaValue> getMinimumValue();
/**
- * Get the miximum value
+ * Get the maximum value
*
- * @return the maximum value
+ * @return the maximum value, a MetaValue implementing Comparable
*/
Comparable<? extends MetaValue> getMaximumValue();
Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -43,4 +43,12 @@
{
/** The constraints, allowed values populator factory */
Class<? extends ManagedPropertyConstraintsPopulatorFactory> value();
+ /** Optional string representation of min value */
+ String min() default "";
+ /** Optional string representation of max value */
+ String max() default "";
+ /** Optional string representation of legal values */
+ String[] legalValues() default {};
+ /** Optional arguments to pass to the factory */
+ String[] args() default {};
}
Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -325,7 +325,7 @@
setField(Fields.LEGAL_VALUES, (Serializable)values);
}
- public Comparable<? extends MetaValue> getMinimumValue()
+ public Comparable<MetaValue> getMinimumValue()
{
return getField(Fields.MINIMUM_VALUE, Comparable.class);
}
@@ -335,14 +335,14 @@
*
* @param value the value
*/
- public void setMinimumValue(Comparable<? extends MetaValue> value)
+ public void setMinimumValue(Comparable<MetaValue> value)
{
setField(Fields.MINIMUM_VALUE, (Serializable)value);
}
- public Comparable<? extends MetaValue> getMaximumValue()
+ public Comparable<MetaValue> getMaximumValue()
{
- Comparable<? extends MetaValue> field = getField(Fields.MAXIMUM_VALUE, Comparable.class);
+ Comparable<MetaValue> field = getField(Fields.MAXIMUM_VALUE, Comparable.class);
return field;
}
@@ -351,14 +351,31 @@
*
* @param value the value
*/
- public void setMaximumValue(Comparable<? extends MetaValue> value)
+ public void setMaximumValue(Comparable<MetaValue> value)
{
setField(Fields.MAXIMUM_VALUE, (Serializable)value);
}
public String checkValidValue(MetaValue value)
{
- // TODO check min/max/etc.
+ Comparable<MetaValue> min = getMinimumValue();
+ if(min != null)
+ {
+ if(min.compareTo(value) > 0)
+ return "min("+min+") > "+value;
+ }
+ Comparable<MetaValue> max = getMaximumValue();
+ if(max != null)
+ {
+ if(max.compareTo(value) < 0)
+ return "max("+max+") < "+value;
+ }
+ Set<MetaValue> legalValues = getLegalValues();
+ if(legalValues != null && legalValues.size() > 0)
+ {
+ if(legalValues.contains(value) == false)
+ return legalValues+" does not contain: "+value;
+ }
return null;
}
Copied: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints)
Deleted: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java 2008-11-25 07:09:24 UTC (rev 81525)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.constraints;
-
-import java.lang.reflect.Method;
-
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-
-/**
- * A ManagedPropertyConstraintsPopulator for Number min/max values
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class NumberConstraintsPopulator
- implements ManagedPropertyConstraintsPopulator
-{
- Number min;
- Number max;
-
- private static boolean isFloat(String str)
- {
- boolean isFloat = false;
- if(str != null)
- isFloat = str.indexOf('.') >= 0;
- return isFloat;
- }
-
- public NumberConstraintsPopulator(String min, String max, String numberClassName)
- throws Exception
- {
- Class<?> numberClass;
-
- if(numberClassName != null)
- {
- numberClass = Class.forName(numberClassName);
- }
- else if(isFloat(min) || isFloat(max))
- {
- numberClass = Double.class;
- }
- else
- {
- numberClass = Long.class;
- }
-
- Class<?>[] sig = {String.class};
- Method parse = numberClass.getDeclaredMethod("valueOf", sig);
- if(min != null)
- {
- Object[] args = {min};
- Number n = (Number) parse.invoke(null, args);
- setMin(n);
- }
- if(max != null)
- {
- Object[] args = {max};
- Number n = (Number) parse.invoke(null, args);
- setMax(n);
- }
- }
-
- public Number getMin()
- {
- return min;
- }
- public void setMin(Number min)
- {
- this.min = min;
- }
-
- public Number getMax()
- {
- return max;
- }
- public void setMax(Number max)
- {
- this.max = max;
- }
-
- public void populateManagedProperty(Class attachmentClass,
- PropertyInfo info, Fields fields)
- {
- if(min != null)
- {
- MetaValue minMV = SimpleValueSupport.wrap(min);
- fields.setField(Fields.MINIMUM_VALUE, minMV);
- }
- if(max != null)
- {
- MetaValue maxMV = SimpleValueSupport.wrap(max);
- fields.setField(Fields.MAXIMUM_VALUE, maxMV);
- }
- }
-
-}
Copied: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java)
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulator.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.constraints;
+
+import java.lang.reflect.Method;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+
+/**
+ * A ManagedPropertyConstraintsPopulator for Number min/max values
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class NumberConstraintsPopulator
+ implements ManagedPropertyConstraintsPopulator
+{
+ Number min;
+ Number max;
+
+ private static boolean isFloat(String str)
+ {
+ boolean isFloat = false;
+ if(str != null)
+ isFloat = str.indexOf('.') >= 0;
+ return isFloat;
+ }
+
+ public NumberConstraintsPopulator(String min, String max, String numberClassName)
+ throws Exception
+ {
+ Class<?> numberClass;
+
+ if(numberClassName != null)
+ {
+ numberClass = Class.forName(numberClassName);
+ }
+ else if(isFloat(min) || isFloat(max))
+ {
+ numberClass = Double.class;
+ }
+ else
+ {
+ numberClass = Long.class;
+ }
+
+ Class<?>[] sig = {String.class};
+ Method parse = numberClass.getDeclaredMethod("valueOf", sig);
+ if(min != null)
+ {
+ Object[] args = {min};
+ Number n = (Number) parse.invoke(null, args);
+ setMin(n);
+ }
+ if(max != null)
+ {
+ Object[] args = {max};
+ Number n = (Number) parse.invoke(null, args);
+ setMax(n);
+ }
+ }
+
+ public Number getMin()
+ {
+ return min;
+ }
+ public void setMin(Number min)
+ {
+ this.min = min;
+ }
+
+ public Number getMax()
+ {
+ return max;
+ }
+ public void setMax(Number max)
+ {
+ this.max = max;
+ }
+
+ public void populateManagedProperty(Class attachmentClass,
+ PropertyInfo info, Fields fields)
+ {
+ if(min != null)
+ {
+ MetaValue minMV = SimpleValueSupport.wrap(min);
+ fields.setField(Fields.MINIMUM_VALUE, minMV);
+ }
+ if(max != null)
+ {
+ MetaValue maxMV = SimpleValueSupport.wrap(max);
+ fields.setField(Fields.MAXIMUM_VALUE, maxMV);
+ }
+ }
+
+}
Deleted: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java 2008-11-25 07:09:24 UTC (rev 81525)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -1,59 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.constraints;
-
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
-
-/**
- * ManagedPropertyConstraintsPopulatorFactory for Number constraints
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class NumberConstraintsPopulatorFactory
- implements ManagedPropertyConstraintsPopulatorFactory
-{
-
- public ManagedPropertyConstraintsPopulator newInstance(String min,
- String max, String[] legalValues, String... args)
- {
- String numberClass = null;
- if(args != null && args.length == 1)
- numberClass = args[0];
- try
- {
- return new NumberConstraintsPopulator(min, max, numberClass);
- }
- catch(Exception e)
- {
- throw new IllegalArgumentException(e);
- }
- }
-
- public ManagedPropertyConstraintsPopulator newInstance(String min,
- String max, String[] legalValues)
- {
- String[] args = null;
- return newInstance(min, max, legalValues, args);
- }
-
-}
Copied: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java)
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/NumberConstraintsPopulatorFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.constraints;
+
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+
+/**
+ * ManagedPropertyConstraintsPopulatorFactory for Number constraints
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class NumberConstraintsPopulatorFactory
+ implements ManagedPropertyConstraintsPopulatorFactory
+{
+
+ public ManagedPropertyConstraintsPopulator newInstance(String min,
+ String max, String[] legalValues, String... args)
+ {
+ String numberClass = null;
+ if(args != null && args.length == 1)
+ numberClass = args[0];
+ try
+ {
+ return new NumberConstraintsPopulator(min, max, numberClass);
+ }
+ catch(Exception e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public ManagedPropertyConstraintsPopulator newInstance(String min,
+ String max, String[] legalValues)
+ {
+ String[] args = null;
+ return newInstance(min, max, legalValues, args);
+ }
+
+}
Deleted: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java 2008-11-25 07:09:24 UTC (rev 81525)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.constraints;
-
-import java.util.HashSet;
-
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-
-/**
- * A populator for a set of string values
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class StringLegalValuesPopulator implements
- ManagedPropertyConstraintsPopulator
-{
- private String[] legalValues;
-
- public StringLegalValuesPopulator(String[] legalValues)
- {
- this.legalValues = legalValues;
- }
-
- public void populateManagedProperty(Class attachmentClass,
- PropertyInfo info, Fields fields)
- {
- HashSet<MetaValue> values = new HashSet<MetaValue>();
- for(String s : legalValues)
- {
- SimpleValue svalue = SimpleValueSupport.wrap(s);
- values.add(svalue);
- }
- fields.setField(Fields.LEGAL_VALUES, values);
- }
-
-}
Copied: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java)
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulator.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.constraints;
+
+import java.util.HashSet;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+
+/**
+ * A populator for a set of string values
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class StringLegalValuesPopulator implements
+ ManagedPropertyConstraintsPopulator
+{
+ private String[] legalValues;
+
+ public StringLegalValuesPopulator(String[] legalValues)
+ {
+ this.legalValues = legalValues;
+ }
+
+ public void populateManagedProperty(Class attachmentClass,
+ PropertyInfo info, Fields fields)
+ {
+ HashSet<MetaValue> values = new HashSet<MetaValue>();
+ for(String s : legalValues)
+ {
+ SimpleValue svalue = SimpleValueSupport.wrap(s);
+ values.add(svalue);
+ }
+ fields.setField(Fields.LEGAL_VALUES, values);
+ }
+
+}
Deleted: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java 2008-11-25 07:09:24 UTC (rev 81525)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.constraints;
-
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
-
-/**
- * A factory for string legal values populator
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class StringLegalValuesPopulatorFactory
- implements ManagedPropertyConstraintsPopulatorFactory
-{
- public ManagedPropertyConstraintsPopulator newInstance(String min,
- String max, String[] legalValues, String... strings)
- {
- return new StringLegalValuesPopulator(legalValues);
- }
-
- public ManagedPropertyConstraintsPopulator newInstance(String min,
- String max, String[] legalValues)
- {
- String[] args = null;
- return newInstance(min, max, legalValues, args);
- }
-}
Copied: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java)
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/constraints/StringLegalValuesPopulatorFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.constraints;
+
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+
+/**
+ * A factory for string legal values populator
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class StringLegalValuesPopulatorFactory
+ implements ManagedPropertyConstraintsPopulatorFactory
+{
+ public ManagedPropertyConstraintsPopulator newInstance(String min,
+ String max, String[] legalValues, String... strings)
+ {
+ return new StringLegalValuesPopulator(legalValues);
+ }
+
+ public ManagedPropertyConstraintsPopulator newInstance(String min,
+ String max, String[] legalValues)
+ {
+ String[] args = null;
+ return newInstance(min, max, legalValues, args);
+ }
+}
Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -454,6 +454,7 @@
String nameType = null;
String attachmentName = classInfo.getName();
Class<? extends Fields> moFieldsFactory = null;
+ ConstraintsPopulatorFactory moCPF = null;
Class<? extends ManagedPropertyConstraintsPopulatorFactory> moConstraintsFactory = null;
Class<? extends ManagedProperty> moPropertyFactory = null;
if (managementObject != null)
@@ -480,9 +481,9 @@
FieldsFactory ff = getAnnotation(FieldsFactory.class, classInfo, metaData);
if(ff != null)
moFieldsFactory = ff.value();
- ConstraintsPopulatorFactory cpf = getAnnotation(ConstraintsPopulatorFactory.class, classInfo, metaData);
- if(cpf != null)
- moConstraintsFactory = cpf.value();
+ moCPF = getAnnotation(ConstraintsPopulatorFactory.class, classInfo, metaData);
+ if(moCPF != null)
+ moConstraintsFactory = moCPF.value();
ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, classInfo, metaData);
if(mpf != null)
moPropertyFactory = mpf.value();
@@ -701,10 +702,12 @@
ConstraintsPopulatorFactory cpf = getAnnotation(ConstraintsPopulatorFactory.class, propertyInfo, metaData);
if(cpf != null)
factoryClass = cpf.value();
+ else
+ cpf = moCPF;
if(factoryClass != null)
{
ManagedPropertyConstraintsPopulatorFactory mpcpf = factoryClass.newInstance();
- ManagedPropertyConstraintsPopulator populator = mpcpf.newInstance();
+ ManagedPropertyConstraintsPopulator populator = mpcpf.newInstance(cpf.min(), cpf.max(), cpf.legalValues(), cpf.args());
if (populator != null)
populator.populateManagedProperty(clazz, propertyInfo, fields);
}
Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -269,11 +269,11 @@
try
{
ConstraintsPopulatorFactory cpf = propertyInfo.getUnderlyingAnnotation(ConstraintsPopulatorFactory.class);
- if(factory != null)
+ if(cpf != null)
{
Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = cpf.value();
ManagedPropertyConstraintsPopulatorFactory pfactory = factoryClass.newInstance();
- ManagedPropertyConstraintsPopulator populator = pfactory.newInstance();
+ ManagedPropertyConstraintsPopulator populator = pfactory.newInstance(cpf.min(), cpf.max(), cpf.legalValues(), cpf.args());
if (populator != null)
{
Class<?> clazz = propertyInfo.getBeanInfo().getClassInfo().getType();
Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -29,5 +29,23 @@
*/
public interface ManagedPropertyConstraintsPopulatorFactory
{
- ManagedPropertyConstraintsPopulator newInstance();
+ /**
+ *
+ * @param min
+ * @param max
+ * @param legalValues
+ * @return
+ */
+ ManagedPropertyConstraintsPopulator newInstance(String min, String max, String[] legalValues);
+
+ /**
+ *
+ * @param min
+ * @param max
+ * @param legalValues
+ * @param strings
+ * @return
+ */
+ ManagedPropertyConstraintsPopulator newInstance(String min, String max,
+ String[] legalValues, String...strings);
}
Copied: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/ConstrainedBean.java (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/ConstrainedBean.java)
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/ConstrainedBean.java (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/ConstrainedBean.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support;
+
+import org.jboss.managed.api.annotation.ConstraintsPopulatorFactory;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.plugins.constraints.NumberConstraintsPopulatorFactory;
+import org.jboss.managed.plugins.constraints.StringLegalValuesPopulatorFactory;
+
+/**
+ * Test bean for validating ConstraintsPopulatorFactory on managed properties
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject
+public class ConstrainedBean
+{
+ private float temperature;
+ private Float pi;
+ private Short dayOfYear;
+ private int day;
+ private String month;
+
+ @ManagementProperty()
+ @ConstraintsPopulatorFactory(value=NumberConstraintsPopulatorFactory.class,
+ min="0",max="100")
+ public float getTemperature()
+ {
+ return temperature;
+ }
+ public void setTemperature(float temperature)
+ {
+ this.temperature = temperature;
+ }
+ @ManagementProperty()
+ @ConstraintsPopulatorFactory(value=NumberConstraintsPopulatorFactory.class,
+ min="3",max="3.14159")
+ public Float getPi()
+ {
+ return pi;
+ }
+ public void setPi(Float pi)
+ {
+ this.pi = pi;
+ }
+ @ManagementProperty()
+ @ConstraintsPopulatorFactory(value=NumberConstraintsPopulatorFactory.class,
+ min="1",max="365")
+ public Short getDayOfYear()
+ {
+ return dayOfYear;
+ }
+ public void setDayOfYear(Short dayOfYear)
+ {
+ this.dayOfYear = dayOfYear;
+ }
+ @ManagementProperty()
+ @ConstraintsPopulatorFactory(value=StringLegalValuesPopulatorFactory.class,
+ legalValues={"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"})
+ public String getMonth()
+ {
+ return month;
+ }
+ public void setMonth(String month)
+ {
+ this.month = month;
+ }
+ @ManagementProperty()
+ @ConstraintsPopulatorFactory(value=NumberConstraintsPopulatorFactory.class,
+ min="1",max="31")
+ public int getDay()
+ {
+ return day;
+ }
+ public void setDay(int day)
+ {
+ this.day = day;
+ }
+}
Copied: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyConstraintsUnitTestCase.java (from rev 81525, projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyConstraintsUnitTestCase.java)
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyConstraintsUnitTestCase.java (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyConstraintsUnitTestCase.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.PropertiesMetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ConstrainedBean;
+import org.jboss.test.managed.factory.support.ObjectNameBean;
+
+/**
+ * Tests of specifying constraints on managed properties
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertyConstraintsUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+
+ public PropertyConstraintsUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testTemperature()
+ throws Exception
+ {
+ ConstrainedBean bean = new ConstrainedBean();
+ ManagedObject managedObject = super.initManagedObject(bean);
+
+ // Test the temperature constraints
+ ManagedProperty temperature = managedObject.getProperty("temperature");
+ SimpleValue minValue = (SimpleValue) temperature.getMinimumValue();
+ assertNotNull(minValue);
+ getLog().debug("min: "+minValue);
+ int compare = minValue.compareTo(SimpleValueSupport.wrap(0f));
+ assertTrue("temperature >= 0; "+compare, compare == 0);
+ compare = minValue.compareTo(SimpleValueSupport.wrap(0.1f));
+ assertTrue("temperature 0.1 > min; "+compare, compare < 0);
+ compare = minValue.compareTo(SimpleValueSupport.wrap(-0.1f));
+ assertTrue("temperature -0.1 < min; "+compare, compare > 0);
+ compare = minValue.compareTo(SimpleValueSupport.wrap(50f));
+ assertTrue("temperature 50 > min; "+compare, compare < 0);
+ compare = minValue.compareTo(SimpleValueSupport.wrap(-50f));
+ assertTrue("temperature -50 < min; "+compare, compare > 0);
+ SimpleValue maxValue = (SimpleValue) temperature.getMaximumValue();
+ assertNotNull(maxValue);
+ getLog().debug("max: "+maxValue);
+ compare = maxValue.compareTo(SimpleValueSupport.wrap(100f));
+ assertTrue("temperature <= 100; "+compare, compare == 0);
+ compare = maxValue.compareTo(SimpleValueSupport.wrap(50f));
+ assertTrue("temperature 50 < max; "+compare, compare > 0);
+ compare = maxValue.compareTo(SimpleValueSupport.wrap(150f));
+ assertTrue("temperature 150 > max; "+compare, compare < 0);
+
+ String check = temperature.checkValidValue(SimpleValueSupport.wrap(100f));
+ assertNull(check, check);
+ check = temperature.checkValidValue(SimpleValueSupport.wrap(1f));
+ assertNull(check, check);
+ check = temperature.checkValidValue(SimpleValueSupport.wrap(-1f));
+ assertNotNull(check, check);
+
+ }
+
+ public void testMonth()
+ {
+ ConstrainedBean bean = new ConstrainedBean();
+ ManagedObject managedObject = super.initManagedObject(bean);
+
+ // Test the month constraints
+ ManagedProperty month = managedObject.getProperty("month");
+ Set<MetaValue> legalValues = month.getLegalValues();
+ assertEquals("There are 12 legal values", 12, legalValues.size());
+ MetaValue JUN = SimpleValueSupport.wrap("JUN");
+ assertTrue("JUN", legalValues.contains(JUN));
+
+ String check = month.checkValidValue(JUN);
+ assertNull(check, check);
+ check = month.checkValidValue(SimpleValueSupport.wrap("XYZ"));
+ assertNotNull("XYZ", check);
+ }
+
+}
Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java 2008-11-25 21:00:56 UTC (rev 81572)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java 2008-11-25 21:05:19 UTC (rev 81573)
@@ -221,6 +221,42 @@
{
compare = 0;
}
+ else if(value instanceof Number && sv.getValue() instanceof Number)
+ {
+ // Compare two Numbers using the most precise type
+ Number n0 = (Number) value;
+ Number n1 = (Number) sv.getValue();
+ if(n0 instanceof BigDecimal)
+ {
+ BigDecimal db0 = (BigDecimal) n0;
+ BigDecimal db1 = new BigDecimal(n1.doubleValue());
+ compare = db0.compareTo(db1);
+ }
+ else if(n1 instanceof BigDecimal)
+ {
+ BigDecimal db1 = (BigDecimal) n1;
+ BigDecimal db0 = new BigDecimal(n0.doubleValue());
+ compare = db0.compareTo(db1);
+ }
+ else if(n0 instanceof Float || n0 instanceof Double
+ || n1 instanceof Float || n1 instanceof Double)
+ {
+ double d0 = n0.doubleValue();
+ double d1 = n1.doubleValue();
+ compare = Double.compare(d0, d1);
+ }
+ else
+ {
+ long l0 = n0.longValue();
+ long l1 = n1.longValue();
+ if(l0 < l1)
+ compare = -1;
+ else if(l0 > l1)
+ compare = 1;
+ else
+ compare = 0;
+ }
+ }
return compare;
}
More information about the jboss-cvs-commits
mailing list