/** @Override */
 public function prepareToRead($encodedTokens)
 {
     $this->tokenList = array();
     $this->tokenListIndex = 0;
     $this->stringTable = null;
     $idx = 0;
     while (false !== ($nextIdx = mb_strpos($encodedTokens, self::RPC_SEPARATOR_CHAR, $idx))) {
         $current = mb_substr($encodedTokens, $idx, $nextIdx - $idx);
         $this->tokenList[] = $current;
         $idx = $nextIdx + 1;
     }
     if ($idx == 0) {
         // Didn't find any separator, assume an older version with different
         // separators and get the version as the sequence of digits at the
         // beginning of the encoded string.
         while ($idx < mb_strlen($encodedTokens) && Character::isDigit(mb_substr($encodedTokens, $idx, 1))) {
             ++$idx;
         }
         if ($idx == 0) {
             throw new IncompatibleRemoteException('Malformed or old RPC message received - expecting version between ' . self::SERIALIZATION_STREAM_MIN_VERSION . ' and ' . self::SERIALIZATION_STREAM_VERSION);
         } else {
             $version = Integer::valueOf(mb_substr($encodedTokens, 0, $idx));
             throw new IncompatibleRemoteServiceException('Expecting version between ' . self::SERIALIZATION_STREAM_MIN_VERSION . ' and ' . self::SERIALIZATION_STREAM_VERSION . " from client, got {$version}" . '.');
         }
     }
     parent::prepareToRead($encodedTokens);
     // Check the RPC version number sent by the client
     if ($this->getVersion() < self::SERIALIZATION_STREAM_MIN_VERSION || $this->getVersion() > self::SERIALIZATION_STREAM_VERSION) {
         throw new IncompatibleRemoteServiceException('Expecting version between ' . self::SERIALIZATION_STREAM_MIN_VERSION . ' and ' . self::SERIALIZATION_STREAM_VERSION . ' from client, got ' . $this->getVersion() . '.');
     }
     // Check the flags
     if (!$this->areFlagsValid()) {
         throw new IncompatibleRemoteServiceException('Got an unknown flag from ' . 'client: ' . $this->getFlags());
     }
     // Read the type name table
     $this->deserializeStringTable();
     // Write the serialization policy info
     $moduleBaseURL = $this->readString();
     $strongName = $this->readString();
     if (!is_null($this->serializationPolicyProvider)) {
         $this->serializationPolicy = $this->serializationPolicyProvider->getSerializationPolicy($moduleBaseURL, $strongName);
         if (is_null($this->serializationPolicy)) {
             throw new NullPointerException('serializationPolicyProvider.getSerializationPolicy()');
         }
     }
 }
Example #2
0
 /**
  * This test checks the Integer's valueOf() method.
  *
  * @return void
  */
 public function testValueOfWithNumberFormatException()
 {
     // set the expected exception
     $this->setExpectedException('\\AppserverIo\\Lang\\NumberFormatException');
     // initialize a new Integer instance
     $int = Integer::valueOf(new Strng('!17'));
 }
 private function decodeCommand()
 {
     $command = $this->next();
     if ($command == NL_CHAR) {
         $command = $this->next();
     }
     $token = $this->token();
     switch ($command) {
         case BOOLEAN_TYPE:
             $this->pushScalar(new BooleanValueCommand($token == '1'));
             break;
         case BYTE_TYPE:
             $this->pushScalar(new ByteValueCommand(Byte::valueOf($token)));
             break;
         case CHAR_TYPE:
             $this->pushScalar(new CharValueCommand(Character::chr(intval($token))));
             break;
         case DOUBLE_TYPE:
             $this->pushScalar(new DoubleValueCommand(Double::valueOf($token)));
             break;
         case FLOAT_TYPE:
             $this->pushScalar(new FloatValueCommand(Float::valueOf($token)));
             break;
         case INT_TYPE:
             $this->pushScalar(new IntValueCommand(Integer::valueOf($token)));
             break;
         case LONG_TYPE:
             $this->pushScalar(new LongValueCommand(Long::valueOf($token)));
             break;
         case VOID_TYPE:
             $this->pushScalar(NullValueCommand::INSTANCE());
             break;
         case SHORT_TYPE:
             $this->pushScalar(new ShortValueCommand(Short::valueOf($token)));
             break;
         case STRING_TYPE:
             // "4~abcd
             $length = Integer::valueOf($token);
             $value = $this->nextCount($length);
             if ($this->next() != RPC_SEPARATOR_CHAR) {
                 throw new RuntimeException('Overran string');
             }
             $this->pushString(new StringValueCommand($value));
             break;
         case ENUM_TYPE:
             // ETypeSeedName~IOrdinal~
             $ordinal = $this->readCommand('IntValueCommand')->getValue();
             $clazz = $this->findClass($token);
             $x = new EnumValueCommand($clazz);
             $this->pushIdentity($x);
             $x->setValue($ordinal);
             break;
         case ARRAY_TYPE:
             // Encoded as (leafType, dimensions, length, ...)
             $leaf = $this->findClass($token);
             $numDims = $this->readCommand('IntValueCommand')->getValue();
             $clazz = null;
             if ($numDims > 1) {
                 $clazz = ArrayType::clazz($leaf, $numDims);
             } else {
                 $clazz = $leaf;
             }
             $x = new ArrayValueCommand($clazz);
             $this->pushIdentity($x);
             $length = $this->readCommand('IntValueCommand')->getValue();
             for ($i = 0; $i < $length; $i++) {
                 $x->add($this->readCommand('ValueCommand'));
             }
             break;
         case OBJECT_TYPE:
             // LTypeSeedName~3... N-many setters ...
             $clazz = $this->findClass($token);
             $x = new InstantiateCommand($clazz);
             $this->pushIdentity($x);
             $this->readSetters($clazz, $x);
             break;
         case INVOKE_TYPE:
             // !TypeSeedName~Number of objects written by CFS~...CFS objects...~
             // Number of extra fields~...N-many setters...
             $clazz = $this->findClass($token);
             $serializerClass = null;
             $manualType = $clazz;
             while ($manualType != null) {
                 $serializerClass = SerializabilityUtil::hasCustomFieldSerializer($manualType);
                 if ($serializerClass != null) {
                     break;
                 }
                 $manualType = $manualType->getSuperClass();
             }
             if ($serializerClass == null) {
                 throw new IncompatibleRemoteServiceException('Class [' . $clazz->getName() . '] has no custom serializer on server');
             }
             $x = new InvokeCustomFieldSerializerCommand($clazz, $serializerClass, $manualType);
             $this->pushIdentity($x);
             $this->readFields($x);
             $this->readSetters($clazz, $x);
             break;
         case RETURN_TYPE:
             // R4~...values...
             $this->toReturn = new ReturnCommand();
             $toRead = Integer::valueOf($token);
             for ($i = 0; $i < $toRead; $i++) {
                 $this->toReturn->addValue($this->readCommand('ValueCommand'));
             }
             break;
         case THROW_TYPE:
             // T...value...
             $this->toThrow = $this->readCommand('ValueCommand');
             break;
         case BACKREF_TYPE:
             // @backrefNumber~
             $x = $this->backRefs[Integer::valueOf($token)];
             assert($x != null);
             array_push($this->commands, $x);
             break;
         case RPC_SEPARATOR_CHAR:
             throw new RuntimeException('Segmentation overrun at ' + $this->idx);
         default:
             throw new RuntimeException('Unknown Command ' + $command);
     }
 }
Example #4
0
 /**
  * Returns a new <code>Integer</code> initialized to the value
  * represented by the specified <code>Strng</code>, as performed
  * by the <code>valueOf</code> method of class <code>Integer</code>.
  *
  * @param Strng $string The string to be parsed.
  *
  * @return \AppserverIo\Lang\Integer The <code>Integer</code> value represented by the string argument.
  * @exception \AppserverIo\Lang\NumberFormatException If the string does not contain a parsable <code>Integer</code>.
  * @see \AppserverIo\Lang\Integer::valueOf($string)
  */
 public static function parseInteger(Strng $string)
 {
     return Integer::valueOf($string)->intValue();
 }