Class PropertyRestrictor


  • public class PropertyRestrictor
    extends Object

    Property restrictor which consists of collections of classes, fields, default values which should be considered in property verification process

    General Constraint Convention: Normally you will need NullConstraint, DefaultInitializedConstraint and EmptyContainerConstraint. If default constructor is used those will be initialized at generalConstraints indices Integer.MIN_VALUE, Integer.MIN_VALUE + 1 and Integer.MIN_VALUE + 2.

    You can use the PropertyRestrictor in a spring configuration file like:

            <bean name="restrictor" class="science.aist.gtf.verification.syntactic.PropertyRestrictor">
             <!-- ignored classes -->
             <property name="ignoredClasses">
                 <list>
                     <value>java.lang.String</value>
                     <value>java.lang.Integer</value>
                     <value>science.aist.gtf.core.FieldTuple</value>
                 </list>
             </property>
    
             <!-- ignored fields of class -->
             <property name="ignoredFieldsInClass">
                 <list value-type="science.aist.gtf.core.FieldTuple">
                     <bean class="science.aist.gtf.core.FieldTuple">
                         <constructor-arg name="first" value="java.lang.Integer"/>
                         <constructor-arg name="second" value="SIZE"/>
                     </bean>
                     <bean class="science.aist.gtf.core.FieldTuple">
                         <constructor-arg name="first" value="java.lang.Integer"/>
                         <constructor-arg name="second" value="BYTES"/>
                     </bean>
                     <bean class="science.aist.gtf.core.FieldTuple">
                         <constructor-arg name="first" value="science.aist.gtf.core.FieldTuple"/>
                         <constructor-arg name="second" value="first"/>
                     </bean>
                     <bean class="science.aist.gtf.core.FieldTuple">
                         <constructor-arg name="first" value="science.aist.gtf.core.FieldTuple"/>
                         <constructor-arg name="second" value="second"/>
                     </bean>
                 </list>
             </property>
    
             <!-- general constraints -->
    
             <property name="generalConstraints">
                 <map>
                     <entry key="#{ T(java.lang.Integer).MIN_VALUE }">
                         <bean class="science.aist.gtf.verification.syntactic.constraint.impl.NullConstraint"/>
                     </entry>
                     <entry key="#{ T(java.lang.Integer).MIN_VALUE + 1 }">
                         <bean class="science.aist.gtf.verification.syntactic.constraint.impl.DefaultInitializedConstraint">
                             <property name="userdefinedDefaultValues">
                                 <map>
                                     <entry key="science.aist.gtf.core.Tuple">
                                         <map>
                                             <entry key="first" value="10"/>
                                             <entry key="second" value="5"/>
                                         </map>
                                     </entry>
                                     <entry key="java.lang.Integer">
                                         <map>
                                             <entry key="SIZE" value-type="java.lang.Integer" value="10"/>
                                         </map>
                                     </entry>
                                 </map>
                             </property>
                         </bean>
                     </entry>
                     <entry key="#{ T(java.lang.Integer).MIN_VALUE + 2 }">
                         <bean class="science.aist.gtf.verification.syntactic.constraint.impl.EmptyContainerConstraint"/>
                     </entry>
                 </map>
             </property>
    
             <!-- class constraints -->
             <property name="classConstraints">
                 <map>
                     <entry key="java.lang.Integer">
                         <map>
                             <entry key="0">
                                 <bean class="science.aist.gtf.verification.syntactic.constraint.impl.IntegerRangeConstraint">
                                     <property name="lowerBound" value="0"/>
                                     <property name="upperBound" value="5"/>
                                 </bean>
                             </entry>
                         </map>
                     </entry>
                 </map>
             </property>
    
             <!-- fields per class constraints -->
    
             <property name="fieldConstraints">
                 <map>
                     <entry>
                         <key>
                             <bean name="keyBean1" class="science.aist.gtf.core.FieldTuple">
                                 <constructor-arg name="first" value="test.something.SomeClass"/>
                                 <constructor-arg name="second" value="someBooleanField"/>
                             </bean>
                         </key>
                         <map>
                             <entry key="0">
                                 <bean class="science.aist.gtf.verification.syntactic.constraint.impl.BooleanConstraint">
                                     <property name="expectedValue" value="true"/>
                                 </bean>
                             </entry>
                         </map>
                     </entry>
                 </map>
             </property>
         </bean>
     
    Since:
    1.0
    Author:
    Christoph Praschl
    • Method Detail

      • getIgnoredClasses

        public Collection<Class<?>> getIgnoredClasses()
        Returns:
        Collection with classes which should be ignored
      • getIgnoredFieldsInClass

        public Collection<Field> getIgnoredFieldsInClass()
        Returns:
        Collection with Tuples for a field in a given class which should be ignored
      • setIgnoredFieldsInClass

        public void setIgnoredFieldsInClass​(Iterable<science.aist.jack.data.Pair<Class<?>,​String>> ignoredFieldsInClass)
        Parameters:
        ignoredFieldsInClass - sets the collection of ignoredFieldsInClass
      • addIgnoredClassField

        public void addIgnoredClassField​(Field field)
        Method to ignore a field in a class (helpful for fields which are not touched by transformation for some reason)
        Parameters:
        field - Field which should be ignored
      • addIgnoredClassField

        public void addIgnoredClassField​(Class<?> clazz,
                                         String fieldName)
        Method to ignore a field in a class (helpful for fields which are not touched by transformation for some reason)
        Parameters:
        clazz - Class which contains the field
        fieldName - Name of the Field which should be ignored
      • addIgnoredClass

        public void addIgnoredClass​(Class<?> clazz)
        Method to add a class to be ignored (helpful for e.q. boolean which has often the default value `false` and is so often misinterpreted as IsDefaultInitialized)
        Parameters:
        clazz - clazz which should be ignored
      • setFieldConstraints

        public void setFieldConstraints​(Map<science.aist.jack.data.Pair<Class<?>,​String>,​Map<Integer,​Constraint<?>>> fieldConstraints)
        Parameters:
        fieldConstraints - Constraints for a specific field
      • addGeneralConstraint

        public void addGeneralConstraint​(Integer priority,
                                         Constraint<?> c)
        Adds a general constraint checked for every field if suitable
        Parameters:
        priority - priority of the constraint
        c - constraint
      • addFieldConstraint

        public void addFieldConstraint​(Field f,
                                       Constraint<?> c)
        Add a constraint for a given field (takes the next possible priority)
        Parameters:
        f - field for which the constraint should be defined
        c - constraint which should be added
      • addFieldConstraint

        public void addFieldConstraint​(Class<?> clazz,
                                       String fieldName,
                                       Constraint<?> c)
        Add a constraint for a given field (takes the next possible priority)
        Parameters:
        clazz - Class which contains the field
        fieldName - Name of the Field for which constraint is added
        c - constraint which should be added
      • addFieldConstraint

        public void addFieldConstraint​(Field f,
                                       Constraint<?> c,
                                       Integer priority)
        Add a constraint for a given field with a given priority Attention: Only one constraint per priority! Calling multiple times with same priority will always replace the constraint.
        Parameters:
        f - field for which the constraint should be defined
        c - constraint which should be added
        priority - the priority of the constraint
      • addClassConstraint

        public <T> void addClassConstraint​(Class<T> clazz,
                                           Constraint<T> c)
        Add a constraint for a given class (takes the next possible priority)
        Type Parameters:
        T - type parameter of class
        Parameters:
        clazz - class for which the constraint should be defined
        c - constraint which should be added
      • addClassConstraint

        public <T> void addClassConstraint​(Class<T> clazz,
                                           Constraint<T> c,
                                           Integer priority)
        Add a constraint for a given class with a given priority Attention: Only one constraint per priority! Calling multiple times with same priority will always replace the constraint.
        Type Parameters:
        T - type parameter of class
        Parameters:
        clazz - class for which the constraint should be defined
        c - constraint which should be added
        priority - the priority of the constraint