/** * Enter description here... * * @param string $className * @return SimpleMappedClass */ public function getNative($className) { if (JavaSignatureUtil::isNative($className)) { $class = new SimpleMappedClass(); $class->setClassLoader($this->getClassLoader()); $class->setSignature($className); $class->setMappedName($className); $class->setCRC(JavaSignatureUtil::getSerializationSignatureForNative($className)); return $class; } else { return null; } }
/** * * @param SerializationStreamWriter $streamWriter * @param HashMap $instance * @param MappedClass $instanceClass * @throws SerializationException */ public static function serialize(SerializationStreamWriter $streamWriter, $instance, MappedClass $instanceClass) { ob_start(); print_r($instance); syslog(LOG_DEBUG, "instance = " . ob_get_contents()); ob_end_clean(); if ($instance instanceof HashMap) { $size = $instance->size(); $streamWriter->writeInt($size); foreach ($instance->getKeySet() as $key) { $streamWriter->writeObject($key); $streamWriter->writeObject($instance->get($key)); } } else { if (is_array($instance)) { // $instance is array //$size = $instance->size(); $size = count($instance); $streamWriter->writeInt($size); $typeParameters = $instanceClass->getTypeParameters(); //for (Object obj : instance) { if (defined('GWTPHP_FORCE_SHOEHORN') and !is_array($typeParameters)) { // Force casting to java.util.HashMap<java.lang.String,java.lang.String> require_once GWTPHP_DIR . '/lang/SimpleMappedClass.class.php'; $_class = new SimpleMappedClass(); $_class->setClassLoader(GWTPHPContext::getInstance()->getMappedClassLoader()->getClassLoader()); $_class->setMappedName("java.lang.String"); $_class->setSignature("java.lang.String"); $_class->setCRC("2004016611"); $typeParameters = array($_class, $_class); } else { if (!$instanceClass->isGeneric()) { class_exists('SerializationException') || (require_once GWTPHP_DIR . '/exceptions/SerializationException.class.php'); throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap must be mapped as generic type! add < > to signatures and CRC"); $typeParameters = $instanceClass->getTypeParameters(); } } if (!isset(HashMap_CustomFieldSerializer::$ACCEPTABLE_KEY_TYPES[$typeParameters[0]->getSignature()])) { class_exists('SerializationException') || (require_once GWTPHP_DIR . '/exceptions/SerializationException.class.php'); throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap_CustomFieldSerializer serialize only array() where " . "keys object are mapped by one of following types: " . "java.lang.String, java.lang.Byte, java.lang.Character, java.lang.Double, " . "java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short, but given: " . $typeParameters[0]->getSignature()); } foreach ($instance as $key => $obj) { $streamWriter->writeObject($key, $typeParameters[0]); $streamWriter->writeObject($obj, $typeParameters[1]); } } else { if (defined('GWTPHP_FORCE_SHOEHORN')) { // Compatibility hack. :( $streamWriter->writeInt(0); } else { throw new UnimplementedOperationException("HashMap_CustomFieldSerializer serialize type: " + gettype($instance) + " not implemented"); } } } }
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); } } } }
/** * Enter description here... * * @param string $className * @return SimpleMappedClass */ private function getNative($className) { if (JavaSignatureUtil::isNative($className)) { $class = new SimpleMappedClass(); $class->setClassLoader($this->getClassLoader()); $class->setSignature($className); return $class; } else { return null; } }