/**
  * Enter description here...
  *
  * @param string $className
  * @return MappedClass
  */
 private function findMappedClass($className)
 {
     /*echo $className ."\n<br>";
     		try {
     			$this->getClassMapLoader()->loadClassMap($className);
     			echo "FOUND -- \n<br>";
     		} catch (ClassMapNotFoundException $ex) {
     			
     			echo $ex->getMessage()." NOT found -- \n<br>";
     		}*/
     foreach ($this->classMaps as $classMap) {
         if ($classMap['className'] == $className) {
             $_class = new SimpleMappedClass();
             $_class->setClassLoader($this->getClassLoader());
             $_class->setSignature($className);
             $_class->setMappedName($classMap['mappedBy']);
             //$_class->setPHPClass($this->classLoader->loadClass($classMap['mappedBy']));
             $_methods = array();
             if (isset($classMap['methods'])) {
                 foreach ($classMap['methods'] as $methodMap) {
                     $_method = new SimpleMappedMethod();
                     $_retClass = $this->loadMappedClass($methodMap['returnType']);
                     if (isset($methodMap['returnTypeCRC'])) {
                         $_retClass->setCRC($methodMap['returnTypeCRC'], true);
                     }
                     $_method->setReturnType($_retClass);
                     $_method->setMappedName($methodMap['mappedName']);
                     $_method->setName($methodMap['name']);
                     $_params = array();
                     foreach ($methodMap['params'] as $paramMap) {
                         $_params[] = $this->loadMappedClass($paramMap['type']);
                     }
                     $_method->setParameterTypes($_params);
                     $_method->setDeclaringMappedClass($_class);
                     $_exceptions = array();
                     if (isset($methodMap['throws'])) {
                         foreach ($methodMap['throws'] as $exceptionMap) {
                             $_exception = new SimpleMappedField();
                             $_exception = $this->loadMappedClass($exceptionMap['type']);
                             if (isset($exceptionMap['typeCRC'])) {
                                 $_exception->setCRC($exceptionMap['typeCRC'], true);
                             }
                             $_exceptions[] = $_exception;
                         }
                     }
                     $_method->setExceptionTypes($_exceptions);
                     $_methods[] = $_method;
                 }
             }
             $_class->setMappedMethods($_methods);
             $_fields = array();
             if (isset($classMap['fields'])) {
                 foreach ($classMap['fields'] as $fieldMap) {
                     $_field = new SimpleMappedField();
                     $_field->setName($fieldMap['name']);
                     $_fieldType = $this->loadMappedClass($fieldMap['type']);
                     if (isset($fieldMap['typeCRC'])) {
                         $_fieldType->setCRC($fieldMap['typeCRC'], true);
                     }
                     $_field->setType($_fieldType);
                     $_field->setDeclaringMappedClass($_class);
                     $_fields[] = $_field;
                 }
             }
             $_class->setMappedFields($_fields);
             if (isset($classMap['extends'])) {
                 $_class->setSuperclass($this->loadMappedClass($classMap['extends']));
             }
             if (isset($classMap['typeCRC'])) {
                 $_class->setCRC($classMap['typeCRC']);
             }
             return $_class;
         }
     }
 }
 /**
  * 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");
             }
         }
     }
 }