/**
  * 
  * @see RPCTargetResolverStrategy::resolveRPCTarget()
  */
 function resolveRPCTarget(MappedClass $interface)
 {
     if ($interface->getReflectionClass()->isInterface()) {
         require_once GWTPHP_DIR . '/maps/com/google/gwt/user/client/rpc/IncompatibleRemoteServiceException.class.php';
         throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '" . $interface->getName() . "' where class expected; this is either misconfiguration or a hack attempt");
     }
     return null;
 }
 /**
  * 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 deserializeWithDefaultFieldDeserializer(MappedClass $instanceClass, $instance)
 {
     /*MappedField[]*/
     $declFields = $instanceClass->getDeclaredFields();
     /*MappedField[]*/
     $serializableFields = SerializabilityUtil::applyFieldSerializationPolicy($declFields);
     foreach ($serializableFields as $declField) {
         $value = $this->deserializeValue($declField->getType());
         $propName = $declField->getName();
         $rClass = $instanceClass->getReflectionClass();
         if ($rClass == null) {
             throw new ClassNotFoundException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains ReflectionClass infomration');
         }
         if (!$rClass->hasProperty($propName)) {
             throw new SerializationException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains property: ' . $propName . ' Did you mapped all properties?');
         }
         $rProperty = $rClass->getProperty($propName);
         if ($rProperty->isPublic()) {
             $rProperty->setValue($instance, $value);
         } else {
             // not public access to property, we try invoke setter method
             $propNameSetter = 'set' . strtoupper($propName[0]) . substr($propName, 1, strlen($propName));
             if (!$rClass->hasMethod($propNameSetter)) {
                 throw new SerializationException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains setter method for private property: ' . $propName . '. Mapped object should be in pojo style?');
             }
             $rMethod = $rClass->getMethod($propNameSetter);
             if ($rMethod->isPublic()) {
                 $rMethod->invoke($instance, $value);
             } else {
                 throw new SerializationException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains public setter method for private property: ' . $propName . '. Mapped object should be in pojo style?');
             }
         }
         /*
         	Object value = deserializeValue(declField.getType());
         
         	boolean isAccessible = declField.isAccessible();
         	boolean needsAccessOverride = !isAccessible
         	  && !Modifier.isPublic(declField.getModifiers());
         	if (needsAccessOverride) {
         	// Override access restrictions
         	declField.setAccessible(true);
         	}
         	
         	declField.set(instance, value);
         	
         	if (needsAccessOverride) {
         	// Restore access restrictions
         	declField.setAccessible(isAccessible);
         	}
         */
     }
     $superClass = $instanceClass->getSuperclass();
     if ($superClass != null && $this->getSerializationPolicy()->shouldDeserializeFields($superClass)) {
         $this->deserializeImpl(SerializabilityUtil::hasCustomFieldSerializer($superClass), $superClass, $instance);
     }
     /*
     Class<?> superClass = instanceClass.getSuperclass();
     	    if (serializationPolicy.shouldDeserializeFields(superClass)) {
     	      deserializeImpl(SerializabilityUtil.hasCustomFieldSerializer(superClass),
     	          superClass, instance);
     	    }
     */
 }
 /**
  *
  *
  * @param Object $instance
  * @param MappedClass $instanceClass
  * @ throws SerializationException
  */
 private function serializeClass($instance, MappedClass $instanceClass)
 {
     assert($instance != null);
     /*MappedField[]*/
     $declFields = $instanceClass->getDeclaredFields();
     /*MappedField[]*/
     $serializableFields = SerializabilityUtil::applyFieldSerializationPolicy($declFields);
     foreach ($serializableFields as $declField) {
         assert($declField != null);
         $value = null;
         $propName = $declField->getName();
         $rClass = $instanceClass->getReflectionClass();
         //$rClass = new ReflectionObject($instance);
         if ($rClass == null) {
             throw new ClassNotFoundException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains ReflectionClass infomration');
         }
         if (!$rClass->hasProperty($propName)) {
             throw new SerializationException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains property: ' . $propName . ' Did you mapped all properties?');
         }
         $rProperty = $rClass->getProperty($propName);
         if ($rProperty->isPublic()) {
             $value = $rProperty->getValue($instance);
         } else {
             // not public access to property, we try invoke getter method
             $propNameSetter = 'get' . strtoupper($propName[0]) . substr($propName, 1, strlen($propName));
             if (!$rClass->hasMethod($propNameSetter)) {
                 throw new SerializationException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains getter method for private property: ' . $propName . '. Mapped object should be in pojo style?');
             }
             $rMethod = $rClass->getMethod($propNameSetter);
             if ($rMethod->isPublic()) {
                 $value = $rMethod->invoke($instance);
             } else {
                 throw new SerializationException('MappedClass: ' . $instanceClass->getSignature() . ' do not contains public getter method for private property: ' . $propName . '. Mapped object should be in pojo style?');
             }
         }
         $this->serializeValue($value, $declField->getType());
     }
     /* assert (instance != null);
     
     		Field[] declFields = instanceClass.getDeclaredFields();
     		Field[] serializableFields = SerializabilityUtil.applyFieldSerializationPolicy(declFields);
     		for (Field declField : serializableFields) {
     		assert (declField != null);
     
     		boolean isAccessible = declField.isAccessible();
     		boolean needsAccessOverride = !isAccessible
     		&& !Modifier.isPublic(declField.getModifiers());
     		if (needsAccessOverride) {
     		// Override the access restrictions
     		declField.setAccessible(true);
     		}
     
     		Object value;
     		try {
     		value = declField.get(instance);
     		serializeValue(value, declField.getType());
     
     		} catch (IllegalArgumentException e) {
     		throw new SerializationException(e);
     
     		} catch (IllegalAccessException e) {
     		throw new SerializationException(e);
     		}
     
     		if (needsAccessOverride) {
     		// Restore the access restrictions
     		declField.setAccessible(isAccessible);
     		}
     		}
     
     		Class<?> superClass = instanceClass.getSuperclass();
     		if (serializationPolicy.shouldSerializeFields(superClass)) {
     		serializeImpl(instance, superClass);
     		}*/
     $superClass = $instanceClass->getSuperclass();
     if ($superClass != null && $this->serializationPolicy->shouldDeserializeFields($superClass)) {
         $this->serializeImpl($instance, $superClass);
     }
 }