/** *Deserialize an object with the given type signature. * * @throws SerializationException * @param string $typeSignature the type signature to deserialize * @return Object the deserialized object */ protected function deserialize($typeSignature) { $this->logger->info("deserialize :" . $typeSignature); $serializedInstRef = SerializabilityUtil::decodeSerializedInstanceReference($typeSignature); $this->logger->info("serializedInstRef : " . $serializedInstRef->getName() . " " . $serializedInstRef->getSignature()); /*MappedClass*/ $instanceClass = $this->mappedClassLoader->loadMappedClass($serializedInstRef->getName()); $instanceClass->setCRC($serializedInstRef->getSignature()); $this->serializationPolicy->validateDeserialize($instanceClass); // {90%} $this->validateTypeVersions($instanceClass, $serializedInstRef); // {cut} // Class customSerializer = SerializabilityUtil.hasCustomFieldSerializer(instanceClass); // instance = instantiate(customSerializer, instanceClass); // rememberDecodedObject(instance); $customSerializer = SerializabilityUtil::hasCustomFieldSerializer($instanceClass); // {100%} $instance = $this->instantiate($customSerializer, $instanceClass); // {100%} $this->rememberDecodedObject(&$instance); $this->deserializeImpl($customSerializer, $instanceClass, &$instance); return $instance; //$instance = $customSerializer->instantiate($this); //$instance = $this->deserializeImpl($customSerializer, $serializedInstRef->getName()); //$instance = $this->deserializeImpl($customSerializer, $serializedInstRef->getName(), $instance); //return $instance; }
/** * Returns a string that encodes an exception. If method is not * <code>null</code>, it is an error if the exception is not in the * method's list of checked exceptions. * * <p> * If the serializationPolicy parameter is not <code>null</code>, it is * used to determine what types can be encoded as part of this response. If * this parameter is <code>null</code>, then only subtypes of * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or * types which have custom field serializers may be encoded. * </p> * * @param MappedMethod serviceMethod the method that threw the exception, may be * <code>null</code> * @param Exception cause the {@link Throwable} that was thrown * @param SerializationPolicy serializationPolicy determines the serialization policy to be used * @return a string that encodes the exception * * @throws NullPointerException if the the cause or the serializationPolicy * are <code>null</code> * @throws SerializationException if the result cannot be serialized * @throws UnexpectedException if the result was an unexpected exception (a * checked exception not declared in the serviceMethod's signature) */ public static function encodeResponseForFailure(MappedMethod $serviceMethod = null, Exception $cause, SerializationPolicy $serializationPolicy = null, MappedClassLoader $mappedClassLoader) { if ($cause === null) { throw new NullPointerException("cause cannot be null"); } if ($serializationPolicy === null) { $serializationPolicy = RPC::getDefaultSerializationPolicy(); //throw new NullPointerException("serializationPolicy"); } if ($serviceMethod != null && !RPC::isExpectedException($serviceMethod, $cause)) { class_exists('UnexpectedException') || (require GWTPHP_DIR . '/exceptions/UnexpectedException.class.php'); throw new UnexpectedException("Service method '" . RPC::getSourceRepresentation($serviceMethod) . "' threw an unexpected exception: " . $cause->__toString(), $cause); } //class_exists('UnimplementedOperationException') || require(GWTPHP_DIR.'/exceptions/UnimplementedOperationException.class.php'); //throw new UnimplementedOperationException("Exception serialization not implemented yet! " . print_r($cause,true)); //ArrayMappedClassLoader::loadMappedClass('pl.rmalinowski.gwtphp.client.dto.SimpleException'); $couseClass = $mappedClassLoader->findMappedClassByReflectionClass(new ReflectionObject($cause)); return RPC::encodeResponse($couseClass, $cause, true, $serializationPolicy); // return RPC::encodeResponse($cause.getClass(), $cause, true, $serializationPolicy); }
/** *Deserialize an object with the given type signature. * * @throws SerializationException * @param string $typeSignature the type signature to deserialize * @return Object the deserialized object */ protected function deserialize($typeSignature) { $this->logger->debug("deserialize :" . $typeSignature); $serializedInstRef = SerializabilityUtil::decodeSerializedInstanceReference($typeSignature); $this->logger->debug("serializedInstRef : " . $serializedInstRef->getName() . " " . $serializedInstRef->getSignature()); /*MappedClass*/ $instanceClass = $this->mappedClassLoader->loadMappedClass($serializedInstRef->getName()); $instanceClass->setCRC($serializedInstRef->getSignature()); assert($this->serializationPolicy !== null); $this->serializationPolicy->validateDeserialize($instanceClass); // {90%} $this->validateTypeVersions($instanceClass, $serializedInstRef); // {cut} // Class customSerializer = SerializabilityUtil.hasCustomFieldSerializer(instanceClass); // instance = instantiate(customSerializer, instanceClass); // rememberDecodedObject(instance); $customSerializer = SerializabilityUtil::hasCustomFieldSerializer($instanceClass); // {100%} $index = $this->reserveDecodedObjectIndex(); $instance = $this->instantiate($customSerializer, $instanceClass); // {100%} $this->rememberDecodedObject($index, $instance); $replacement = $this->deserializeImpl($customSerializer, $instanceClass, $instance); // It's possible that deserializing an object requires the original proxy // object to be replaced. if ($instance !== $replacement) { $this->rememberDecodedObject($index, $instance); $instance = $replacement; } return $instance; //$instance = $customSerializer->instantiate($this); //$instance = $this->deserializeImpl($customSerializer, $serializedInstRef->getName()); //$instance = $this->deserializeImpl($customSerializer, $serializedInstRef->getName(), $instance); //return $instance; }