Exemple #1
0
 protected function init()
 {
     if ($this->initialized) {
         return;
     }
     \Logger::configure($this->pixie->config->get('logger'));
     \GWTPHPContext::getInstance()->setServicesRootDir(realpath(dirname(__FILE__) . '/../../gwtphp-maps'));
     \GWTPHPContext::getInstance()->setGWTPHPRootDir(GWTPHP_DIR);
     $this->initialized = true;
 }
 function resolveRPCTarget(MappedClass $interface)
 {
     $target = \GWTPHPContext::getInstance()->getClassLoader()->loadClass($interface->getMappedName() . 'Impl');
     $instance = $target->newInstance();
     $interfaces = class_implements($instance);
     if (in_array('App\\IPixifiable', $interfaces)) {
         $instance->setPixie($this->pixie);
     }
     if (in_array('GWTModule\\IGWTService', $interfaces)) {
         /** @var IGWTService $instance */
         $instance->setServlet($this->pixie->gwt->getServlet());
         $instance->setRequest($this->request);
     }
     return $instance;
 }
 /**
  * 
  *
  * @param string $className
  * @return array
  */
 public function getFullClassMapPaths($className)
 {
     $classMapPaths = array();
     if (($pos = strpos($className, INNER_JAVA_CLASS_SEPARATOR)) !== false) {
         // since 1.4 - depracted (od tej chwili kazda inner classa to plik postaci ParentClass___InnerClass.class.php
         if (GWTPHPContext::getInstance()->getGwtCompatibilityVersion() < GWTPHPContext::GWT_VERSION_1_5_0) {
             $className = substr($className, 0, $pos);
         } else {
             // since 1.5
             $className = str_replace(INNER_JAVA_CLASS_SEPARATOR, INNER_PHP_CLASS_SEPARATOR, $className);
         }
     }
     $classNameToPath = str_replace('.', DIRECTORY_SEPARATOR, $className) . parent::getFilePostfix();
     //echo '<br><br>Looking for ' . $className;
     foreach (parent::getClassMapPaths() as $classMapPath) {
         $classMapPaths[] = $classMapPath . DIRECTORY_SEPARATOR . $classNameToPath;
     }
     return $classMapPaths;
 }
 public function getFullClassPaths($className)
 {
     $classPaths = array();
     if (($pos = strpos($className, INNER_PHP_CLASS_SEPARATOR)) !== false) {
         if (GWTPHPContext::getInstance()->getGwtCompatibilityVersion() < GWTPHPContext::GWT_VERSION_1_5_0) {
             $className = substr($className, 0, $pos);
         } else {
             // since 1.5
             $className = JavaSignatureUtil::innecJavaClassNameToPHPClassName($className);
         }
     }
     $classNameToPath = str_replace('.', DIRECTORY_SEPARATOR, $className) . parent::getFilePostfix();
     foreach (parent::getClassPaths() as $rootPath) {
         $classPaths[] = $rootPath . DIRECTORY_SEPARATOR . $classNameToPath;
     }
     //		$r = parent::getRootPath().'/';
     //		$d = str_replace('.', DIRECTORY_SEPARATOR ,$className);
     //		$p = parent::getFilePostfix();
     //		$cmd = $r.$d.$p;
     return $classPaths;
     //return $this->rootPath.str_replace('.', DIRECTORY_SEPARATOR ,$className).parent::getFilePostfix();
 }
 /**
  *
  * @return MappedClassLoader
  */
 public function getMappedClassLoader()
 {
     return null === $this->mappedClassLoader ? $this->mappedClassLoader = GWTPHPContext::getInstance()->getMappedClassLoader() : $this->mappedClassLoader;
 }
Exemple #6
0
//
// Authors:
// 	Jeff Buchbinder <*****@*****.**>
//
// FreeMED Electronic Medical Record and Practice Management System
// Copyright (C) 1999-2012 FreeMED Software Foundation
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// Handle public methods for initialization
include_once dirname(__FILE__) . "/lib/freemed.php";
define('LOG4PHP_CONFIGURATION', dirname(__FILE__) . "/data/config/log4php.xml");
define('GWTPHP_FORCE_SHOEHORN', true);
define('FORCE_CAST_TO_PHP_PRIMITIVE_TYPES', true);
include_once LOG4PHP_DIR . '/LoggerManager.php';
include_once GWTPHP_DIR . '/RemoteServiceServlet.class.php';
GWTPHPContext::getInstance()->setServicesRootDir(dirname(__FILE__) . '/lib/');
GWTPHPContext::getInstance()->setGWTPHPRootDir(dirname(__FILE__) . "/lib/gwtphp/");
$servlet = CreateObject('org.freemedsoftware.core.AuthenticatedRemoteServiceServlet');
$servlet->start();
 /**
  * returns default class loader (used by getClassMapLoader if class loader is null)
  * @return ClassMapLoader
  */
 public function getDefaultClassMapLoader()
 {
     return GWTPHPContext::getInstance()->getClassMapLoader();
     //new SimpleClassLoader();
 }
 /**
  * 
  *
  * @return GWTPHPContext
  */
 public static function getInstance()
 {
     return null === self::$instance ? self::$instance = new GWTPHPContext() : self::$instance;
 }
 /**
  * Enter description here...
  *
  * @param MappedClass $mappedClass
  * @return ReflectionClass
  */
 public static function computeHasCustomFieldSerializer(MappedClass $instanceType)
 {
     assert($instanceType != null);
     $qualifiedTypeName = null;
     if ($instanceType->isArray()) {
         /*MappedClass*/
         $componentType = $instanceType->getComponentType();
         if ($componentType->isPrimitive()) {
             $qualifiedTypeName = 'java.lang.' . $componentType->getName();
         } else {
             $qualifiedTypeName = 'java.lang.Object';
         }
         $qualifiedTypeName .= '_Array';
     } else {
         $qualifiedTypeName = $instanceType->getName();
     }
     $classLoader = GWTPHPContext::getInstance()->getClassLoader();
     $simpleSerializerName = $qualifiedTypeName . "_CustomFieldSerializer";
     $customSerializer = SerializabilityUtil::getCustomFieldSerializer($classLoader, $simpleSerializerName);
     if ($customSerializer != null) {
         return $customSerializer;
     }
     // Try with the regular name
     /*ReflectionClass*/
     $customSerializerClass = SerializabilityUtil::getCustomFieldSerializer($classLoader, SerializabilityUtil::$JRE_SERIALIZER_PACKAGE . '.' . $simpleSerializerName);
     if ($customSerializerClass != null) {
         return $customSerializerClass;
     }
     return null;
 }
 public function rectifyType($instance, $type)
 {
     if ($type === null || $type->isInterface() || $type->isAbstract() || gettype($instance) === "object" && $type->getSimpleMappedName() != get_class($instance)) {
         $_type = GWTPHPContext::getInstance()->getMappedClassLoader()->findMappedClassByObject($instance);
         if ($type != NULL && $type->getMappedName() != "java.lang.Object") {
             //ensure class compatibility, all objects are assumed to extend "java.lang.Object"
             $compatible = false;
             $class = $_type;
             $super = $type->getMappedName();
             while (($class = $class->getSuperclass()) != NULL) {
                 if ($class->getMappedName() === $super) {
                     $compatible = true;
                     break;
                 }
             }
             unset($class);
             unset($super);
             if (!$compatible) {
                 require_once GWTPHP_DIR . '/maps/com/google/gwt/user/client/rpc/SerializableException.class.php';
                 throw new SerializableException("Cannot serialize type: " . $_type->getMappedName());
             }
         }
         //if ($type->isInterface()) {
         //				if (!$_type->getReflectionClass()->implementsInterface($type->getSimpleMappedName())) {
         //					throw new Exception("Expected that".$_type->getName()." implements ".$type->getName()." (generic return type?) ");
         //				}
         //}
         $type = $_type;
         unset($_type);
     } else {
         $loader = GWTPHPContext::getInstance()->getMappedClassLoader();
         switch (gettype($instance)) {
             case "string":
                 return $loader->getNative("java.lang.String");
             case "boolean":
                 return $loader->getNative("java.lang.Boolean");
             case "double":
                 return $loader->getNative("java.lang.Double");
             case "integer":
                 if ($type->getSignature() === "java.lang.Long") {
                     return $loader->getNative("java.lang.Long");
                 } else {
                     return $loader->getNative("java.lang.Integer");
                 }
             default:
                 return $type;
         }
     }
     return $type;
 }
Exemple #11
0
<?php

require_once dirname(__FILE__) . "/../vendor/autoload.php";
Logger::configure(array('rootLogger' => array('appenders' => array('default')), 'appenders' => array('default' => array('class' => 'LoggerAppenderNull'))));
GWTPHPContext::getInstance()->setServicesRootDir(dirname(__FILE__) . '/gwtphp-maps');
GWTPHPContext::getInstance()->setGWTPHPRootDir(GWTPHP_DIR);
function processRequest($input)
{
    $servlet = new RemoteServiceServlet();
    $mappedClassLoader = new FolderMappedClassLoader();
    $servlet->setMappedClassLoader($mappedClassLoader);
    $ret = $servlet->start($input);
    return $ret;
}
 /**
  *
  * @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");
             }
         }
     }
 }
 /**
  * 
  * @param Object $instance
  * @throws SerializationException
  */
 public function writeObject($instance, MappedClass $type = null)
 {
     if ($instance === null) {
         // write a null string
         $this->writeString(null);
         return;
     }
     /*int*/
     $objIndex = $this->getIndexForObject($instance);
     if ($objIndex >= 0) {
         // We've already encoded this object, make a backref
         // Transform 0-based to negative 1-based
         $this->writeInt(-($objIndex + 1));
         return;
     }
     $this->saveIndexForObject($instance);
     // Serialize the type signature
     /*String*/
     // $typeSignature = $this->getObjectTypeSignature($instance);
     // TODO: implement calculation of signature
     if ($type === null) {
         $type = GWTPHPContext::getMappedClassLoader()->findMappedClassByObject($instance);
     }
     $typeSignature = $type->getSignature() . '/' . $type->getCRC();
     //$typeSignature = 'java.lang.Integer/3438268394';//$type->getCRC();
     $this->writeString($typeSignature);
     // Now serialize the rest of the object
     $this->serialize($instance, $typeSignature, $type);
 }
 function resolveRPCTarget(MappedClass $interface)
 {
     $target = GWTPHPContext::getInstance()->getClassLoader()->loadClass($interface->getMappedName() . 'Impl');
     return $target->newInstance();
 }
 /**
  * @param Object $value
  * @param MappedClass $type
  * @throws SerializationException
  */
 public function serializeValue($value, MappedClass $type = null)
 {
     if ($type === null) {
         $type = GWTPHPContext::getMappedClassLoader()->findMappedClassByObject($value);
     }
     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);
     }
 }
Exemple #16
0
 /**
  * 
  *
  * @return GWTPHPContext
  */
 public static function getInstance()
 {
     return null === GWTPHPContext::$instance ? GWTPHPContext::$instance = new GWTPHPContext() : GWTPHPContext::$instance;
 }