|
From: <jg...@us...> - 2006-08-08 08:34:35
|
Revision: 43 Author: jgongo Date: 2006-08-08 01:34:17 -0700 (Tue, 08 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=43&view=rev Log Message: ----------- Initial set of value domain classes Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java Added Paths: ----------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/LogicalValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/StringValueDomain.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-07 12:59:49 UTC (rev 42) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-08 08:34:17 UTC (rev 43) @@ -27,6 +27,8 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import org.hibernate.annotations.GenericGenerator; @@ -35,6 +37,7 @@ * @author jsegura */ @Entity +@Inheritance(strategy = InheritanceType.JOINED) public abstract class ValueDomain implements Serializable, Cloneable { private static final long serialVersionUID = -83487445078388347L; Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java 2006-08-08 08:34:17 UTC (rev 43) @@ -0,0 +1,96 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.core.metadata.domain; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.ManyToOne; + +import org.surveyforge.classification.Level; +import org.surveyforge.core.metadata.ValueDomain; + +/** + * @author jgonzalez + */ +@Entity +public class ClassificationValueDomain extends ValueDomain + { + private static final long serialVersionUID = 2295375925240989153L; + + @ManyToOne + private Level level; + private boolean sublevelsAllowed = true; + + public ClassificationValueDomain( Level level ) + { + this( level, true ); + } + + public ClassificationValueDomain( Level level, boolean sublevelsAllowed ) + { + this.setLevel( level ); + this.setSublevelsAllowed( sublevelsAllowed ); + } + + public Level getLevel( ) + { + return this.level; + } + + public void setLevel( Level level ) + { + if( level != null ) + this.level = level; + else + throw new NullPointerException( ); + } + + public boolean isSublevelsAllowed( ) + { + return this.sublevelsAllowed; + } + + public void setSublevelsAllowed( boolean sublevelsAllowed ) + { + this.sublevelsAllowed = sublevelsAllowed; + } + + @Override + public boolean isValid( Serializable object ) + { + if( object instanceof String ) + { + String code = (String) object; + return this.getLevel( ).isIncludedInLevel( code, this.isSublevelsAllowed( ) ); + } + else + return false; + } + + @Override + public ClassificationValueDomain clone( ) + { + ClassificationValueDomain copy = (ClassificationValueDomain) super.clone( ); + return copy; + } + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Copied: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/LogicalValueDomain.java (from rev 38, trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java) =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/LogicalValueDomain.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/LogicalValueDomain.java 2006-08-08 08:34:17 UTC (rev 43) @@ -0,0 +1,48 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.core.metadata.domain; + +import java.io.Serializable; + +import javax.persistence.Entity; + +import org.surveyforge.core.metadata.ValueDomain; + +/** + * @author jsegura + */ +@Entity +public class LogicalValueDomain extends ValueDomain + { + private static final long serialVersionUID = 2066579378848047283L; + + public boolean isValid( Serializable object ) + { + return (Boolean.class.isInstance( object )); + } + + @Override + public LogicalValueDomain clone( ) + { + return (LogicalValueDomain) super.clone( ); + } + } Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java 2006-08-08 08:34:17 UTC (rev 43) @@ -0,0 +1,150 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.core.metadata.domain; + +import java.io.Serializable; +import java.math.BigDecimal; + +import javax.persistence.Entity; + +import org.surveyforge.core.metadata.ValueDomain; + +/** + * @author jgonzalez + */ +@Entity +public class QuantityValueDomain extends ValueDomain + { + private static final long serialVersionUID = 475119088217988415L; + + private int precision = 1; + private int scale; + + private BigDecimal minimum = BigDecimal.valueOf( Integer.MIN_VALUE ); + private BigDecimal maximum = BigDecimal.valueOf( Integer.MAX_VALUE ); ; + + /** + * + */ + public QuantityValueDomain( int precision, int scale ) + { + this.setPrecision( precision ); + this.setScale( scale ); + } + + /** + * @return Returns the precision. + */ + public int getPrecision( ) + { + return precision; + } + + /** + * @param precision The precision to set. + */ + public void setPrecision( int precision ) + { + if( precision > 0 && precision >= this.getScale( ) ) + this.precision = precision; + else + throw new IllegalArgumentException( ); + } + + /** + * @return Returns the scale. + */ + public int getScale( ) + { + return scale; + } + + /** + * @param scale The scale to set. + */ + public void setScale( int scale ) + { + if( scale >= 0 && scale <= this.getPrecision( ) ) + this.scale = scale; + else + throw new IllegalArgumentException( ); + } + + /** + * @return Returns the minimum. + */ + public BigDecimal getMinimum( ) + { + return this.minimum; + } + + /** + * @param minimum The minimum to set. + */ + public void setMinimum( BigDecimal minimum ) + { + if( minimum.compareTo( this.getMaximum( ) ) < 0 ) + this.minimum = minimum; + else + throw new IllegalArgumentException( ); + } + + /** + * @return Returns the maximum. + */ + public BigDecimal getMaximum( ) + { + return this.maximum; + } + + /** + * @param maximum The maximum to set. + */ + public void setMaximum( BigDecimal maximum ) + { + if( this.getMinimum( ).compareTo( maximum ) < 0 ) + this.maximum = maximum; + else + throw new IllegalArgumentException( ); + } + + @Override + public boolean isValid( Serializable object ) + { + if( object instanceof BigDecimal ) + { + BigDecimal quantity = (BigDecimal) object; + return quantity.scale( ) <= this.getScale( ) + && (quantity.precision( ) - quantity.scale( )) <= (this.getPrecision( ) - this.getScale( )) + && this.getMinimum( ).compareTo( quantity ) <= 0 && quantity.compareTo( this.getMaximum( ) ) <= 0; + } + else + return false; + } + + @Override + public QuantityValueDomain clone( ) + { + QuantityValueDomain copy = (QuantityValueDomain) super.clone( ); + return copy; + } + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/StringValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/StringValueDomain.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/StringValueDomain.java 2006-08-08 08:34:17 UTC (rev 43) @@ -0,0 +1,91 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.core.metadata.domain; + +import java.io.Serializable; + +import javax.persistence.Entity; + +import org.surveyforge.core.metadata.ValueDomain; + +/** + * @author jgonzalez + */ +@Entity +public class StringValueDomain extends ValueDomain + { + private static final long serialVersionUID = -5056062679246063821L; + + private int minLength = 0; + private int maxLength = Integer.MAX_VALUE; + + public StringValueDomain( int minLength, int maxLength ) + { + this.setMinLength( minLength ); + this.setMaxLength( maxLength ); + } + + public int getMinLength( ) + { + return this.minLength; + } + + public void setMinLength( int minLength ) + { + if( minLength >= 0 && minLength <= this.getMaxLength( ) ) + this.minLength = minLength; + else + throw new IllegalArgumentException( ); + } + + public int getMaxLength( ) + { + return this.maxLength; + } + + public void setMaxLength( int maxLength ) + { + if( maxLength > 0 && maxLength >= this.getMinLength( ) ) + this.maxLength = maxLength; + else + throw new IllegalArgumentException( ); + } + + @Override + public boolean isValid( Serializable object ) + { + if( object instanceof String ) + { + String string = (String) object; + return this.getMinLength( ) <= string.length( ) && string.length( ) <= this.getMaxLength( ); + } + else + return false; + } + + @Override + public StringValueDomain clone( ) + { + StringValueDomain copy = (StringValueDomain) super.clone( ); + return copy; + } + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/StringValueDomain.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |