Example #1
0
 public function testWsdlXsdRead()
 {
     $xmldas = SDO_DAS_XML::create();
     $xmldas->addTypes(dirname(__FILE__) . "/../../../../SCA/Bindings/soap/soap/2003-02-11.xsd");
     $doc = $xmldas->createDocument();
     $definitions = $doc->getRootDataObject();
     $reflection = new SDO_Model_ReflectionDataObject($definitions);
     $sdo_type = $reflection->getType();
     $type_name = $sdo_type->getName();
     $this->assertEquals($type_name, 'tDefinitions', 'SCA/Bindings/soap/soap/2003-02-11.xsd not read correctly');
     //$this->printSdoType($definitions);
 }
Example #2
0
 public static function ToSDO($p_resultSet, $p_rootDO, $p_elementTypeName, $p_mapping)
 {
     Debug::Singleton()->log('Util::ToSDO(): $p_rootDO = ' . SDO_Model_ReflectionDataObject::export(new SDO_Model_ReflectionDataObject($p_rootDO), true));
     foreach ($p_resultSet as $v_record) {
         $v_result_DO = is_null($p_elementTypeName) ? $p_rootDO : $p_rootDO->createDataObject($p_elementTypeName);
         foreach ($p_mapping as $v_dBField => $v_sDOField) {
             $v_result_DO[$v_sDOField] = $v_record[$v_dBField];
             Debug::Singleton()->log("Util::ToSDO(): mapped: " . "\$v_record['{$v_dBField}'] = {$v_record[$v_dBField]} => " . "\$v_result_DO['{$v_sDOField}'] = " . "{$v_result_DO[$v_sDOField]}");
         }
         if (is_null($p_elementTypeName)) {
             break;
         }
     }
     //echo('CloudBankServer::ToSDO(): $p_rootDO = '); var_dump($p_rootDO);
     return count($p_resultSet) ? $p_rootDO : (is_null($p_elementTypeName) ? NULL : $p_rootDO);
 }
Example #3
0
 public function testDerivedType()
 {
     $this->dmsDf->addType(COMPANY_NS, 'DerivedStringType', array('basetype' => array(SDO_TYPE_NAMESPACE_URI, 'String')));
     $this->dmsDf->addType(COMPANY_NS, 'BaseObjectType', array('abstract' => true));
     $this->dmsDf->addType(COMPANY_NS, 'DerivedObjectType', array('basetype' => array(COMPANY_NS, 'BaseObjectType')));
     $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'derivedString', COMPANY_NS, 'DerivedStringType');
     $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'derivedObject', COMPANY_NS, 'DerivedObjectType');
     $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'abstractObject', COMPANY_NS, 'BaseObjectType');
     $company = $this->dmsDf->create(COMPANY_NS, COMPANY_TYPE);
     $company->name = "ACME Corp";
     $company->derivedString = 'Special string';
     $do = $this->dmsDf->create(COMPANY_NS, 'DerivedObjectType');
     try {
         $this->dmsDf->create(COMPANY_NS, 'BaseObjectType');
         $this->assertTrue(false, 'Succeeded in instantiating an abstract type.');
     } catch (SDO_UnsupportedOperationException $e) {
     } catch (SDO_Exception $e) {
         $this->assertTrue(false, 'Incorrect exception thrown from creating an object of an abstract type:' . $e->getMessage());
     }
     /* It's OK to assign an object of a derived type to a property of an abstract type */
     $company->abstractObject = $do;
     $rcompany = new SDO_Model_ReflectionDataObject($company);
     $special_type = $rcompany->getType()->getProperty('derivedString')->getType();
     $base_type = $special_type->getBaseType();
     $this->assertEquals(SDO_TYPE_NAMESPACE_URI, $base_type->getNamespaceURI(), 'incorrect namespaceURI for base type');
     $this->assertEquals('String', $base_type->getName(), 'incorrect name for base type');
     $this->assertTrue($base_type->isDataType(), 'incorrect data type for base type');
     $rdo = new SDO_Model_ReflectionDataObject($do);
     $derived_type = $rdo->getType();
     $this->assertFalse($derived_type->isAbstractType(), 'non-abstract type passes isAbstractType()');
     $this->assertTrue($derived_type->isInstance($do), 'object of derived type fails DerivedType::isInstance()');
     $base_type = $derived_type->getBaseType();
     $this->assertEquals(COMPANY_NS, $base_type->getNamespaceURI(), 'incorrect namespaceURI for base type');
     $this->assertEquals('BaseObjectType', $base_type->getName(), 'incorrect name for base type');
     $this->assertFalse($base_type->isDataType(), 'incorrect data type for base type');
     $this->assertTrue($base_type->isAbstractType(), 'abstract type fails isAbstractType()');
     $this->assertTrue($base_type->isInstance($do), 'object of derived type fails BaseType::isInstance()');
 }
Example #4
0
 /**
  * Here we contruct an extension to the SMD where types are
  * described using a simple hierarchy. Dojo ignores this at
  * present but we can take account of it in SCA
  */
 public static function generateSmdType($smd, $type_name, $namespace, &$type_array)
 {
     // ensure that there is a types array. We only generate
     // a types array at this late stage so that we only generate
     // one if there are types to add to it
     if (isset($smd->types) == false) {
         $smd->types = array();
     }
     $composite_type_name = $namespace . ":" . $type_name;
     // ensure that types are only written out once
     if (!array_key_exists($composite_type_name, $type_array)) {
         $type = new stdClass();
         $smd->types[] = $type;
         $type_array[$composite_type_name] = $type;
         $type->name = $type_name;
         $type->typedef = new stdClass();
         $type->typedef->properties = array();
         // create a data object of the required type
         // TODO - we shouldn't have to do this but I can't work out
         //        how to get the named type from the data factory
         $do = self::$xmldas->createDataObject($namespace, $type_name);
         // get the type information for the data object
         $reflection = new SDO_Model_ReflectionDataObject($do);
         $do_type = $reflection->getType();
         // test to make sure this is not a primitive type
         if ($do_type->isDataType()) {
             // shouldn't get here I don't think
             // what to do - raise an error?
         }
         // iterate over the properties of this type
         foreach ($do_type->getProperties() as $property) {
             $property_name = $property->getName();
             $property_type = $property->getType();
             $property_type_name = $property_type->getName();
             $property_type_namespace = $property_type->getNamespaceURI();
             // create the entry for the type
             $property_object = new stdClass();
             $property_object->name = $property_name;
             // convert from SDO property type names to JSON property type names
             $property_object->type = self::sdoTypeToSmdType($property_type_name);
             // work out if this is an array or not
             if ($property->isMany()) {
                 $property_object->type .= " []";
             }
             // store away the property in the typedef
             $type->typedef->properties[] = $property_object;
             // If this type is a complex type then recurse.
             if (!$property_type->isDataType()) {
                 self::generateSmdType($smd, $property_type_name, $property_type_namespace, $type_array);
             }
         }
         // TODO - what to do about non-containment references
     }
 }
Example #5
0
 public function testCreateDocumentThreeArgs()
 {
     try {
         $xmldas = SDO_DAS_XML::create(dirname(__FILE__) . "/company.xsd");
         $root_do = $xmldas->createDataObject('companyNS', 'CompanyType');
         $xdoc = $xmldas->createDocument('newNS', 'newElement', $root_do);
         $rdo = new SDO_Model_ReflectionDataObject($root_do);
         $type = $rdo->getType();
         $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name);
         $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI);
         $this->assertTrue($xdoc->getRootElementURI() == 'newNS', 'namespace for the document should be newNS but was ' . $xdoc->getRootElementURI());
         $this->assertTrue($xdoc->getRootElementName() == 'newElement', 'root element name should be newElement but was ' . $xdoc->getRootElementName());
     } catch (SDO_Exception $e) {
         $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught: " . $e->getMessage() . ' ' . $e->getCause());
     }
 }
Example #6
0
File: Proxy.php Project: psagi/sdo
 private function _copyPositionalArgumentsIntoSdoProperties($operation_sdo, $arguments)
 {
     $reflection = new SDO_Model_ReflectionDataObject($operation_sdo);
     $type = $reflection->getType();
     $i = 0;
     foreach ($type->getProperties() as $property) {
         $arg = $arguments[$i];
         $operation_sdo[$property->getName()] = is_object($arg) ? clone $arg : $arg;
         $i++;
     }
     return $operation_sdo;
 }
Example #7
0
File: Json.php Project: psagi/sdo
 private function _encodeObjectFromSDO($sdo, &$json_string)
 {
     $json_string .= "{";
     $reflection = new SDO_Model_ReflectionDataObject($sdo);
     $sdo_type = $reflection->getType();
     $sdo_size = $this->_count($sdo);
     $i = 0;
     foreach ($sdo as $property_name => $property_value) {
         $json_string .= "\"" . $property_name . "\":";
         $sdo_property = null;
         $sdo_property_type = null;
         $sdo_property_type_name = null;
         $is_array = false;
         $is_object = false;
         // get the property entry from the type so that we can.
         // find out if we are dealing with a many valued property.
         // Need to take account of any open types where the named property
         // won't exist in the model
         try {
             $sdo_property = $sdo_type->getProperty($property_name);
             $sdo_property_type = $sdo_property->getType();
             $sdo_property_type_name = $sdo_property_type->getName();
             $is_array = $sdo_property->isMany();
             $is_object = !$sdo_property_type->isDataType();
         } catch (SDO_PropertyNotFoundException $ex) {
             if ($sdo_type->isOpenType() == true) {
                 // We can validly have properties that
                 // don't appear in the model. For now we
                 // assume that these are single valued
                 // so $is_array is left as false.
                 //
                 // We have to go a little further to get the
                 // property type as we can't pluck it directly from
                 // the model (the model doesn't have the type in
                 // it as the model is open).
                 // First take a look at the php type as we can't reflect
                 // on the data unless it is an SDO object (as opposed to
                 // a primitive type)
                 $php_type = gettype($property_value);
                 if ($php_type == "object") {
                     $is_object = true;
                     $reflection = new SDO_Model_ReflectionDataObject($property_value);
                     $sdo_property_type = $reflection->getType();
                     $sdo_property_type_name = $sdo_property_type->getName();
                 } else {
                     $is_object = false;
                     $sdo_property_type_name = $php_type;
                 }
             } else {
                 // there is a real problem so throw
                 // the exception on
                 throw $ex;
             }
         }
         if ($is_array) {
             // it's an array
             $this->_encodeArrayFromSDO($property_value, $json_string, $sdo_property_type);
         } else {
             if ($is_object) {
                 // it's an object
                 $this->_encodeObjectFromSDO($property_value, $json_string);
             } else {
                 // it's a primitive type
                 $this->_encodePrimitiveFromSDO($property_value, $json_string, $sdo_property_type_name);
             }
         }
         $i++;
         if ($i < $sdo_size) {
             $json_string .= ",";
         }
     }
     $json_string .= "}";
 }
 /**
  * Generate type information to add introspection data.
  *
  * @param string $namespace  Namespace
  * @param string $type_name  Type name
  * @param array  &$type_list (Reference parameter containing type list)
  * @param object $xmlrpc_das XMLRPC DAS
  *
  * @return null
  */
 protected function generateType($namespace, $type_name, &$type_list, $xmlrpc_das)
 {
     if ($type_name == null || strlen($type_name) == 0) {
         return;
     }
     $composite_type_name = $namespace . ":" . $type_name;
     // ensure that types are only written out once
     if (!array_key_exists($composite_type_name, $type_list)) {
         $type = new stdClass();
         $type_list[$composite_type_name] = $type;
         $type->name = $type_name;
         $type->typedef = new stdClass();
         $type->typedef->properties = array();
         // create a data object of the required type
         $do = $xmlrpc_das->getXmlDas()->createDataObject($namespace, $type_name);
         // get the type information for the data object
         $reflection = new SDO_Model_ReflectionDataObject($do);
         $do_type = $reflection->getType();
         // test to make sure this is not a primitive type
         if ($do_type->isDataType()) {
             return;
         }
         // iterate over the properties of this type
         foreach ($do_type->getProperties() as $property) {
             $property_name = $property->getName();
             $property_type = $property->getType();
             $property_type_name = $property_type->getName();
             $property_type_namespace = $property_type->getNamespaceURI();
             // create the entry for the type
             $property_object = new stdClass();
             $property_object->name = $property_name;
             // convert from SDO property type names to XmlRpc property type names
             $property_object->type = $this->sdoTypeToXmlRpcType($property_type_name);
             // work out if this is an array or not
             if ($property->isMany()) {
                 $property_object->type .= " []";
             }
             // store away the property in the typedef
             $type->typedef->properties[] = $property_object;
             // If this type is a complex type then recurse.
             if (!$property_type->isDataType()) {
                 $this->generateType($property_type_namespace, $property_type_name, $type_list, $xmlrpc_das);
             }
         }
         // TODO - what to do about non-containment references
     }
 }
Example #9
0
*/
session_start();
require './contacts_config.inc.php';
$handle = $_POST['sdo-root'];
$root = $_SESSION[$handle];
unset($_SESSION[$handle]);
$contact = $root->contact[0];
if (!$contact) {
    header('Location: http://' . APP_ROOT . '/welcome.php');
    return;
}
if (isset($_POST['fullname']) && $contact['fullname'] != $_POST['fullname']) {
    $contact->fullname = $_POST['fullname'];
}
$address = $contact->address[0];
$reflection = new SDO_Model_ReflectionDataObject($address);
$properties = $reflection->getType()->getProperties();
foreach ($properties as $property) {
    $name = $property->getName();
    if (isset($_POST[$name]) && $address[$name] != $_POST[$name]) {
        $address[$name] = $_POST[$name];
    }
}
require './contacts_data.inc.php';
?>
<html>
 
<head>
    <title>MyContacts</title>
</head>
<body BGCOLOR="#EFEFEF">
Example #10
0
 public static function getApplicationType($data_object)
 {
     $model_reflection_object = new SDO_Model_ReflectionDataObject($data_object);
     $type = $model_reflection_object->getType();
     return $type->name;
 }
Example #11
0
 private static function isRoot($do)
 {
     $rdo = new SDO_Model_ReflectionDataObject($do);
     $type = $rdo->getType();
     return $type->namespaceURI == SDO_DAS_Relational::DAS_NAMESPACE && $type->name == SDO_DAS_Relational::DAS_ROOT_TYPE;
 }