/**
  * 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;
 }
예제 #2
0
파일: RPC.class.php 프로젝트: rrsc/freemed
 /**
  * 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('$', '.');
 }
 /**
  * @param Object $value
  * @param MappedClass $type
  * @throws SerializationException
  */
 public function serializeValue($value, MappedClass $type = null)
 {
     $logger = Logger::getLogger('gwtphp.rpc.RPC');
     if (!$type->isPrimitive()) {
         $type = $this->rectifyType($value, $type);
     }
     if (gettype($value) === "object") {
         $logger->debug("ImplSerialize object: " . get_class($value));
     } else {
         $logger->debug("ImplSerialize " . gettype($value) . ", " . $type->getSignature());
     }
     switch ($type->getSignature()) {
         case TypeSignatures::$BOOLEAN:
             $this->writeBoolean((bool) $value);
             break;
         case TypeSignatures::$BYTE:
             $this->writeByte($value);
             break;
         case TypeSignatures::$CHAR:
             $this->writeChar($value);
             break;
         case TypeSignatures::$DOUBLE:
             $this->writeDouble($value);
             break;
         case TypeSignatures::$FLOAT:
             $this->writeFloat($value);
             break;
         case TypeSignatures::$INT:
             $this->writeInt($value);
             break;
         case TypeSignatures::$LONG:
             $this->writeLong($value);
             break;
         case TypeSignatures::$SHORT:
             $this->writeShort($value);
             break;
         case "java.lang.String":
             $this->writeString($value);
             break;
         default:
             $this->writeObject($value, $type);
     }
 }