private function forSignature($signature) { if (JavaSignatureUtil::isVoid($signature)) { $_class = new SimpleMappedClass(); $_class->setPrimitive(false); $_class->setSignature($signature); return $_class; } else { if (JavaSignatureUtil::isPrimitive($signature)) { $_class = new SimpleMappedClass(); $_class->setPrimitive(true); $_class->setSignature($signature); return $_class; } else { if (JavaSignatureUtil::isArray($signature)) { $_class = new SimpleMappedClass(); $_class->setPrimitive(true); $_class->setSignature($signature); $_class->setArray(true); $_class->setComponentType($this->loadMappedClass(JavaSignatureUtil::getSignatureForComponentTypeOfArray($signature))); return $_class; } else { require_once GWTPHP_DIR . '/maps/java/lang/SignatureParseException.class.php'; throw new SignatureParseException("Signature for not primitive or array type: " . $signature); } } } }
/** * Returns a string that encodes the object. It is an error to try to encode * an object that is not assignable to the service method's return type. * * <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 ReflectionMethod $serviceMethod the method whose result we are encoding * @param Object $object the instance that we wish to encode * @param SerializationPolicy $serializationPolicy determines the serialization policy to be used * @return String a string that encodes the object, if the object is compatible with * the service method's declared return type * * @throws IllegalArgumentException if the result is not assignable to the * service method's return type * @throws NullPointerException if the serviceMethod or the * serializationPolicy are <code>null</code> * @throws SerializationException if the result cannot be serialized */ public static function encodeResponseForSuccess(MappedMethod $serviceMethod, $object, SerializationPolicy $serializationPolicy, MappedClassLoader $mappedClassLoader) { if ($serviceMethod === null) { throw new NullPointerException("serviceMethod cannot be null"); } if ($serializationPolicy === null) { throw new NullPointerException("serializationPolicy"); } /*MappedClass*/ $methodReturnType = $serviceMethod->getReturnType(); if ($methodReturnType != '' && $object !== null) { $actualReturnType; if ($methodReturnType->isPrimitive()) { //$actualReturnType = RPC::getPrimitiveClassFromWrapper(object.getClass()); } else { //actualReturnType = object.getClass(); } // if (actualReturnType == null // || !methodReturnType.isAssignableFrom(actualReturnType)) { // throw new IllegalArgumentException("Type '" // + printTypeName(object.getClass()) // + "' does not match the return type in the method's signature: '" // + getSourceRepresentation(serviceMethod) + "'"); // } } // TODO: fix this mess if ($methodReturnType !== null && ($methodReturnType->isPrimitive() || $methodReturnType->isArray() || JavaSignatureUtil::isVoid($methodReturnType->getSignature()))) { } else { if (is_object($object)) { //echo "<br>\n : ".print_r($object,true); //echo "<br>\n : ".print_r($methodReturnType,true); //echo "<br>\n <hr>"; $_methodReturnType = $mappedClassLoader->findMappedClassByObject($object); if ($_methodReturnType != null) { $methodReturnType = $_methodReturnType; } } } return RPC::encodeResponse($methodReturnType, $object, false, $serializationPolicy); }