public static function serialize(SerializationStreamWriter $streamWriter, $instance, MappedClass $instanceClass)
 {
     $itemCount = count($instance);
     $streamWriter->writeInt($itemCount);
     for ($itemIndex = 0; $itemIndex < $itemCount; ++$itemIndex) {
         $streamWriter->writeObject($instance[$itemIndex], $instanceClass->getComponentType());
     }
 }
Example #2
0
 /**
  * Straight copy from
  * {@link com.google.gwt.dev.util.TypeInfo#getSourceRepresentation(Class)} to
  * avoid runtime dependency on gwt-dev.
  */
 private static function printTypeName(MappedClass $type)
 {
     // Primitives
     //
     if ($type->isPrimitive()) {
         switch ($type) {
             case TypeSignatures::$BOOLEAN:
                 return 'boolean';
             case TypeSignatures::$BYTE:
                 return 'byte';
             case TypeSignatures::$CHAR:
                 return 'char';
             case TypeSignatures::$DOUBLE:
                 return 'double';
             case TypeSignatures::$FLOAT:
                 return 'float';
             case TypeSignatures::$INT:
                 return 'int';
             case TypeSignatures::$LONG:
                 return 'long';
             case TypeSignatures::$SHORT:
                 return 'short';
             default:
                 'unknown';
         }
     }
     // Arrays
     //
     if ($type->isArray()) {
         $componentType = $type->getComponentType();
         return RPC::printTypeName($componentType) + '[]';
     }
     // Everything else
     //
     return $type->getName();
     //.replace('$', '.');
 }
 /**
  * Enter description here...
  *
  * @param MappedClass $mappedClass
  * @return ReflectionClass
  */
 public static function computeHasCustomFieldSerializer(MappedClass $instanceType)
 {
     assert($instanceType != null);
     $qualifiedTypeName = null;
     if ($instanceType->isArray()) {
         /*MappedClass*/
         $componentType = $instanceType->getComponentType();
         if ($componentType->isPrimitive()) {
             $qualifiedTypeName = 'java.lang.' . $componentType->getName();
         } else {
             $qualifiedTypeName = 'java.lang.Object';
         }
         $qualifiedTypeName .= '_Array';
     } else {
         $qualifiedTypeName = $instanceType->getName();
     }
     $classLoader = GWTPHPContext::getInstance()->getClassLoader();
     $simpleSerializerName = $qualifiedTypeName . "_CustomFieldSerializer";
     $customSerializer = SerializabilityUtil::getCustomFieldSerializer($classLoader, $simpleSerializerName);
     if ($customSerializer != null) {
         return $customSerializer;
     }
     // Try with the regular name
     /*ReflectionClass*/
     $customSerializerClass = SerializabilityUtil::getCustomFieldSerializer($classLoader, SerializabilityUtil::$JRE_SERIALIZER_PACKAGE . '.' . $simpleSerializerName);
     if ($customSerializerClass != null) {
         return $customSerializerClass;
     }
     return null;
 }
 private function deserializeWithCustomFieldDeserializer(ReflectionClass $customSerializer, MappedClass $instanceClass, $instance)
 {
     //	return $customSerializer->deserialize()
     //	throw new Exception('Unsuporter operation exception');
     if ($instanceClass->isArray()) {
         /*MappedClass*/
         $componentType = $instanceClass->getComponentType();
         if (!$componentType->isPrimitive()) {
             $instanceClass = array();
             //Class.forName("[Ljava.lang.Object;");
         }
     }
     /*MappedMethod*/
     $deserialize = $customSerializer->getMethod("deserialize");
     //SerializationStreamReader.class, instanceClass);
     $deserialize->invoke(null, $this, &$instance);
 }
 /**
  * Instantiable types are primitives, {@line IsSerializable}, types with
  * custom serializers, and any arrays of those types. Merely
  * {@link Serializable} types cannot be instantiated or serialized directly
  * (only as super types of legacy serializable types).
  * @param MappedClass $mappedClass 
  * @return boolean
  */
 private function isInstantiable(MappedClass $mappedClass)
 {
     if ($mappedClass->isPrimitive()) {
         return true;
     }
     if ($mappedClass->isArray()) {
         return $this->isInstantiable($mappedClass->getComponentType());
     }
     if ($mappedClass->getReflectionClass() != null && $mappedClass->getReflectionClass()->isSubclassOf(SerializationPolicy::$IS_SERIALIZABLE_INTERFACE_CLASS_NAME)) {
         return true;
     }
     //if (IsSerializable.class.isAssignableFrom(clazz)) {
     //  return true;
     //}
     return SerializabilityUtil::hasCustomFieldSerializer($mappedClass) != null;
 }
 private function deserializeWithCustomFieldDeserializer(ReflectionClass $customSerializer, MappedClass $instanceClass, &$instance)
 {
     // TODO: gwt 1-5 tutaj nigdy array nie trafai assert not array,
     //	return $customSerializer->deserialize()
     //	throw new Exception('Unsuporter operation exception');
     if ($instanceClass->isArray()) {
         /*MappedClass*/
         $componentType = $instanceClass->getComponentType();
         if (!$componentType->isPrimitive()) {
             $instanceClass = array();
             //Class.forName("[Ljava.lang.Object;");
         }
     }
     /*MappedMethod*/
     $deserialize = $customSerializer->getMethod("deserialize");
     //SerializationStreamReader.class, instanceClass);
     /* this wont works, must send $instance as reference in array like in next line
     		   $deserialize->invoke(null, $this, &$instance);
     		*/
     $deserialize->invokeArgs(null, array($this, &$instance));
 }
 public function write(ServerSerializationStreamWriter $stream, $instance, MappedClass $instanceClass = null)
 {
     $stream->writeInt(count($instance));
     for ($i = 0, $n = count($instance); $i < $n; ++$i) {
         $stream->writeObject($instance[$i], $instanceClass->getComponentType());
     }
 }