private boolean canSetPropertyForType(int requiredType, Value value, String[] constraints)
   {

      if (requiredType == value.getType())
      {
         return checkValueConstraints(requiredType, constraints, value);
      }
      else if (requiredType == PropertyType.BINARY
               && (value.getType() == PropertyType.STRING || value.getType() == PropertyType.DATE
                        || value.getType() == PropertyType.LONG || value.getType() == PropertyType.DOUBLE
                        || value.getType() == PropertyType.NAME || value.getType() == PropertyType.PATH || value
                        .getType() == PropertyType.BOOLEAN))
      {
         return checkValueConstraints(requiredType, constraints, value);
      }
      else if (requiredType == PropertyType.BOOLEAN)
      {
         if (value.getType() == PropertyType.STRING)
         {
            return checkValueConstraints(requiredType, constraints, value);
         }
         else if (value.getType() == PropertyType.BINARY)
         {
            try
            {
               return isCharsetString(value.getString(), Constants.DEFAULT_ENCODING)
                  && checkValueConstraints(requiredType, constraints, value);
            }
            catch (Exception e)
            {
               // Hm, this is not string and not UTF-8 too
               return false;
            }
         }
         else
         {
            return false;
         }
      }
      else if (requiredType == PropertyType.DATE)
      {
         String likeDataString = null;
         try
         {
            if (value.getType() == PropertyType.STRING)
            {
               likeDataString = value.getString();
            }
            else if (value.getType() == PropertyType.BINARY)
            {
               likeDataString = getCharsetString(value.getString(), Constants.DEFAULT_ENCODING);
            }
            else if (value.getType() == PropertyType.DOUBLE || value.getType() == PropertyType.LONG)
            {
               return checkValueConstraints(requiredType, constraints, value);
            }
            else
            {
               return false;
            }
            // try parse...
            JCRDateFormat.parse(likeDataString);
            // validate
            return checkValueConstraints(requiredType, constraints, value);
         }
         catch (Exception e)
         {
            // Hm, this is not date format string
            return false;
         }
      }
      else if (requiredType == PropertyType.DOUBLE)
      {
         String likeDoubleString = null;
         try
         {
            if (value.getType() == PropertyType.STRING)
            {
               likeDoubleString = value.getString();
            }
            else if (value.getType() == PropertyType.BINARY)
            {
               likeDoubleString = getCharsetString(value.getString(), Constants.DEFAULT_ENCODING);
            }
            else if (value.getType() == PropertyType.DATE)
            {
               return true;
            }
            else if (value.getType() == PropertyType.LONG)
            {
               return checkValueConstraints(requiredType, constraints, value);
            }
            else
            {
               return false;
            }
            Double doubleValue = new Double(likeDoubleString);
            return doubleValue != null && checkValueConstraints(requiredType, constraints, value);
         }
         catch (Exception e)
         {
            // Hm, this is not double formated string
            return false;
         }
      }
      else if (requiredType == PropertyType.LONG)
      {
         String likeLongString = null;
         try
         {
            if (value.getType() == PropertyType.STRING)
            {
               likeLongString = value.getString();
            }
            else if (value.getType() == PropertyType.BINARY)
            {
               likeLongString = getCharsetString(value.getString(), Constants.DEFAULT_ENCODING);
            }
            else if (value.getType() == PropertyType.DATE)
            {
               return true;
            }
            else if (value.getType() == PropertyType.DOUBLE)
            {
               return true;
            }
            else
            {
               return false;
            }
            Long longValue = new Long(likeLongString);
            return longValue != null && checkValueConstraints(requiredType, constraints, value);
         }
         catch (Exception e)
         {
            // Hm, this is not long formated string
            return false;
         }
      }
      else if (requiredType == PropertyType.NAME)
      {
         String likeNameString = null;
         try
         {
            if (value.getType() == PropertyType.STRING)
            {
               likeNameString = value.getString();
            }
            else if (value.getType() == PropertyType.BINARY)
            {
               likeNameString = getCharsetString(value.getString(), Constants.DEFAULT_ENCODING);
            }
            else if (value.getType() == PropertyType.PATH)
            {
               String pathString = value.getString();
               String[] pathParts = pathString.split("\\/");
               if (pathString.startsWith("/") && (pathParts.length > 1 || pathString.indexOf("[") > 0))
               {
                  // Path is not relative - absolute
                  // FALSE if it is more than one element long
                  // or has an index
                  return false;
               }
               else if (!pathString.equals("/") && pathParts.length == 1 && pathString.indexOf("[") < 0)
               {
                  // Path is relative
                  // TRUE if it is one element long
                  // and has no index
                  return checkValueConstraints(requiredType, constraints, value);
               }
               else if (pathString.startsWith("/") && pathString.lastIndexOf("/") < 1 && pathString.indexOf("[") < 0)
               {
                  return checkValueConstraints(requiredType, constraints, value);
               }
               else
               {
                  return false;
               }
            }
            else
            {
               return false;
            }
            try
            {
               Value nameValue = valueFactory.createValue(likeNameString, requiredType);
               return nameValue != null && checkValueConstraints(requiredType, constraints, value);
            }
            catch (Exception e)
            {
               return false;
            }
         }
         catch (Exception e)
         {
            return false;
         }
      }
      else if (requiredType == PropertyType.PATH)
      {
         String likeNameString = null;
         try
         {
            if (value.getType() == PropertyType.STRING)
            {
               likeNameString = value.getString();
            }
            else if (value.getType() == PropertyType.BINARY)
            {
               likeNameString = getCharsetString(value.getString(), Constants.DEFAULT_ENCODING);
            }
            else if (value.getType() == PropertyType.NAME)
            {
               return checkValueConstraints(requiredType, constraints, value);
            }
            else
            {
               return false;
            }
            try
            {
               Value nameValue = valueFactory.createValue(likeNameString, requiredType);
               return nameValue != null && checkValueConstraints(requiredType, constraints, value);
            }
            catch (Exception e)
            {
               return false;
            }
         }
         catch (Exception e)
         {
            return false;
         }
      }
      else if (requiredType == PropertyType.STRING)
      {
         String likeStringString = null;
         try
         {
            if (value.getType() == PropertyType.BINARY)
            {
               likeStringString = getCharsetString(value.getString(), Constants.DEFAULT_ENCODING);
            }
            else if (value.getType() == PropertyType.DATE || value.getType() == PropertyType.LONG
               || value.getType() == PropertyType.BOOLEAN || value.getType() == PropertyType.NAME
               || value.getType() == PropertyType.PATH || value.getType() == PropertyType.DOUBLE)
            {
               likeStringString = value.getString();
            }
            else
            {
               return false;
            }
            return likeStringString != null && checkValueConstraints(requiredType, constraints, value);
         }
         catch (Exception e)
         {
            return false;
         }
      }
      else if (requiredType == PropertyType.UNDEFINED)
      {
         return checkValueConstraints(requiredType, constraints, value);
      }
      else
      {
         return false;
      }
   }
private boolean canSetPropertyForType ( int requiredType , Value value , String [ ] constraints ) { if ( requiredType == value . getType ( ) ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else if ( requiredType == PropertyType . BINARY && ( value . getType ( ) == PropertyType . STRING || value . getType ( ) == PropertyType . DATE || value . getType ( ) == PropertyType . LONG || value . getType ( ) == PropertyType . DOUBLE || value . getType ( ) == PropertyType . NAME || value . getType ( ) == PropertyType . PATH || value . getType ( ) == PropertyType . BOOLEAN ) ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else if ( requiredType == PropertyType . BOOLEAN ) { if ( value . getType ( ) == PropertyType . STRING ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else if ( value . getType ( ) == PropertyType . BINARY ) { try { return isCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) && checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } else { return false ; } } else if ( requiredType == PropertyType . DATE ) { String likeDataString = null ; try { if ( value . getType ( ) == PropertyType . STRING ) { likeDataString = value . getString ( ) ; } else if ( value . getType ( ) == PropertyType . BINARY ) { likeDataString = getCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) ; } else if ( value . getType ( ) == PropertyType . DOUBLE || value . getType ( ) == PropertyType . LONG ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else { return false ; } JCRDateFormat . parse ( likeDataString ) ; return checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } else if ( requiredType == PropertyType . DOUBLE ) { String likeDoubleString = null ; try { if ( value . getType ( ) == PropertyType . STRING ) { likeDoubleString = value . getString ( ) ; } else if ( value . getType ( ) == PropertyType . BINARY ) { likeDoubleString = getCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) ; } else if ( value . getType ( ) == PropertyType . DATE ) { return true ; } else if ( value . getType ( ) == PropertyType . LONG ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else { return false ; } Double doubleValue = new Double ( likeDoubleString ) ; return doubleValue != null && checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } else if ( requiredType == PropertyType . LONG ) { String likeLongString = null ; try { if ( value . getType ( ) == PropertyType . STRING ) { likeLongString = value . getString ( ) ; } else if ( value . getType ( ) == PropertyType . BINARY ) { likeLongString = getCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) ; } else if ( value . getType ( ) == PropertyType . DATE ) { return true ; } else if ( value . getType ( ) == PropertyType . DOUBLE ) { return true ; } else { return false ; } Long longValue = new Long ( likeLongString ) ; return longValue != null && checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } else if ( requiredType == PropertyType . NAME ) { String likeNameString = null ; try { if ( value . getType ( ) == PropertyType . STRING ) { likeNameString = value . getString ( ) ; } else if ( value . getType ( ) == PropertyType . BINARY ) { likeNameString = getCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) ; } else if ( value . getType ( ) == PropertyType . PATH ) { String pathString = value . getString ( ) ; String [ ] pathParts = pathString . split ( "\\/" ) ; if ( pathString . startsWith ( "/" ) && ( pathParts . length > 1 || pathString . indexOf ( "[" ) > 0 ) ) { return false ; } else if ( ! pathString . equals ( "/" ) && pathParts . length == 1 && pathString . indexOf ( "[" ) < 0 ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else if ( pathString . startsWith ( "/" ) && pathString . lastIndexOf ( "/" ) < 1 && pathString . indexOf ( "[" ) < 0 ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else { return false ; } } else { return false ; } try { Value nameValue = valueFactory . createValue ( likeNameString , requiredType ) ; return nameValue != null && checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } catch ( Exception e ) { return false ; } } else if ( requiredType == PropertyType . PATH ) { String likeNameString = null ; try { if ( value . getType ( ) == PropertyType . STRING ) { likeNameString = value . getString ( ) ; } else if ( value . getType ( ) == PropertyType . BINARY ) { likeNameString = getCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) ; } else if ( value . getType ( ) == PropertyType . NAME ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else { return false ; } try { Value nameValue = valueFactory . createValue ( likeNameString , requiredType ) ; return nameValue != null && checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } catch ( Exception e ) { return false ; } } else if ( requiredType == PropertyType . STRING ) { String likeStringString = null ; try { if ( value . getType ( ) == PropertyType . BINARY ) { likeStringString = getCharsetString ( value . getString ( ) , Constants . DEFAULT_ENCODING ) ; } else if ( value . getType ( ) == PropertyType . DATE || value . getType ( ) == PropertyType . LONG || value . getType ( ) == PropertyType . BOOLEAN || value . getType ( ) == PropertyType . NAME || value . getType ( ) == PropertyType . PATH || value . getType ( ) == PropertyType . DOUBLE ) { likeStringString = value . getString ( ) ; } else { return false ; } return likeStringString != null && checkValueConstraints ( requiredType , constraints , value ) ; } catch ( Exception e ) { return false ; } } else if ( requiredType == PropertyType . UNDEFINED ) { return checkValueConstraints ( requiredType , constraints , value ) ; } else { return false ; } }
Returns true if satisfy type and constrains. Otherwise returns false.

@param requiredType - type.
@param value - value.
@param constraints - constraints.
@return a boolean.