예제 #1
0
 /**
  * Create the service wrapper for a SCA Component. In the event that the mapping
  * of the SCA Component methods the base_class and xmldas types are set to
  * null.
  *
  * @param string $class_name
  * @param string $wsdl_filename
  */
 public function __construct($instance, $class_name, $wsdl_filename)
 {
     SCA::$logger->log("Entering");
     $this->class_name = $class_name;
     $this->instance_of_the_base_class = $instance;
     SCA::fillInReferences($this->instance_of_the_base_class);
     // create a JSON DAS and populate it with the valid types
     // that this service can create. Not strinctly required
     // for json encoding but the JSON Server uses this
     // DAS for decoding
     $xsds = SCA_Helper::getAllXsds($class_name);
     $this->json_das = new SDO_DAS_Json();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $this->json_das->addTypesXsdFile($xsd);
         }
     }
 }
예제 #2
0
파일: Wrapper.php 프로젝트: psagi/sdo
 /**
  * Create the service wrapper for a SCA Component.
  *
  * @param object $instance      Instance
  * @param string $class_name    Class
  * @param string $wsdl_filename WSDL
  */
 public function __construct($instance, $class_name, $wsdl_filename)
 {
     SCA::$logger->log("Wrapper {$class_name}");
     $this->class_name = $class_name;
     $this->instance_of_the_base_class = $instance;
     SCA::fillInReferences($this->instance_of_the_base_class);
     $this->annotations = new SCA_AnnotationReader($this->instance_of_the_base_class);
     // create an XML-RPC DAS and populate it with the valid types
     // that this service can create.
     $xsds = SCA_Helper::getAllXsds($class_name);
     $this->xmlrpc_das = new SCA_Bindings_Xmlrpc_DAS();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $this->xmlrpc_das->addTypesXsdFile($xsd);
         }
     }
     $this->xmlrpc_server = xmlrpc_server_create();
     $service_description = $this->annotations->reflectService();
     $serviceDescGen = new SCA_Bindings_Xmlrpc_ServiceDescriptionGenerator();
     $serviceDescGen->addIntrospectionData($this->xmlrpc_server, $service_description, $this->method_aliases, $this->xmlrpc_das);
 }
예제 #3
0
    /**
     * Generate method and type information to add introspection data.
     * The information required is generated from annotations.
     * All methods are registered with the server, and introspection data
     * is added to the server.
     *
     * @param resource $xmlrpc_server       XML RPC server
     * @param array    $service_description Description
     * @param array    &$method_aliases     Aliases
     * @param object   $xmlrpc_das          Unknown
     *
     * @return string  Method description
     */
    public function addIntrospectionData($xmlrpc_server, $service_description, &$method_aliases, $xmlrpc_das = null)
    {
        if ($xmlrpc_das == null) {
            $xsds = SCA_Helper::getAllXsds($service_description->class_name);
            $xmlrpc_das = new SCA_Bindings_Xmlrpc_DAS();
            foreach ($xsds as $index => $xsds) {
                list($namespace, $xsdfile) = $xsds;
                if (SCA_Helper::isARelativePath($xsdfile)) {
                    $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $service_description->class_name);
                    $xmlrpc_das->addTypesXsdFile($xsd);
                }
            }
        }
        $type_list = array();
        $methodDesc = <<<END
<?xml version='1.0'?>

<introspection version='1.0'>

<methodList>
END;
        foreach ($service_description->operations as $methodName => $methodInfo) {
            $methodParams = "";
            $methodReturn = "";
            if (array_key_exists("name", $methodInfo) && array_key_exists("name", $methodInfo["name"]) && $methodInfo["name"]["name"] != null && strlen($methodInfo["name"]["name"]) > 0) {
                $xmlrpcMethodName = $methodInfo["name"]["name"];
                $method_aliases[$xmlrpcMethodName] = $methodName;
            } else {
                $xmlrpcMethodName = $methodName;
            }
            xmlrpc_server_register_method($xmlrpc_server, $xmlrpcMethodName, $methodName);
            if (array_key_exists("parameters", $methodInfo) && $methodInfo["parameters"] != null) {
                foreach ($methodInfo["parameters"] as $param) {
                    $paramName = $param["name"];
                    if (array_key_exists('objectType', $param)) {
                        $paramType = $param["objectType"];
                        $this->generateType($param["namespace"], $param["objectType"], $type_list, $xmlrpc_das);
                    } else {
                        $paramType = $this->sdoTypeToXmlRpcType($param["type"]);
                    }
                    $methodParams = $methodParams . <<<END

                        <value type='{$paramType}' desc='{$paramName}'>
                        </value>
END;
                }
            }
            if (array_key_exists("return", $methodInfo) && $methodInfo["return"] != null) {
                foreach ($methodInfo["return"] as $ret) {
                    if (array_key_exists('objectType', $ret)) {
                        $retType = $ret["objectType"];
                        $this->generateType($ret["namespace"], $ret["objectType"], $type_list, $xmlrpc_das);
                    } else {
                        $retType = $this->sdoTypeToXmlRpcType($ret["type"]);
                    }
                    $methodReturn = $methodReturn . <<<END

                        <value type='{$retType}' desc='return'>
                        </value>
END;
                }
            }
            $methodDesc = $methodDesc . <<<END

<methodDescription name='{$xmlrpcMethodName}'>
    <author></author>
    <purpose></purpose>
    <version></version>
    <signatures>
        <signature>
            <params>
                {$methodParams}
            </params>
            <returns>
                {$methodReturn}
            </returns>
        </signature>
    </signatures>

</methodDescription>

END;
        }
        $methodDesc = $methodDesc . "</methodList>\n";
        if (count($type_list) > 0) {
            $methodDesc = $methodDesc . "<typeList>\n";
            foreach ($type_list as $type) {
                $methodDesc = $methodDesc . <<<END

<typeDescription name='{$type->name}' basetype='struct' desc='{$type->name}'>
END;
                foreach ($type->typedef->properties as $prop) {
                    $methodDesc = $methodDesc . <<<END

    <value type='{$prop->type}' name='{$prop->name}'></value>

END;
                }
                $methodDesc = $methodDesc . <<<END

</typeDescription>
END;
            }
            $methodDesc = $methodDesc . "</typeList>\n";
        }
        $methodDesc = $methodDesc . "</introspection>\n";
        $descArray = xmlrpc_parse_method_descriptions($methodDesc);
        xmlrpc_server_add_introspection_data($xmlrpc_server, $descArray);
    }
예제 #4
0
파일: SCA_Helper.php 프로젝트: psagi/sdo
 /**
  * Am repeating this code here (it's in the previous method also)
  * as we are seeing a number of different combinitations of
  * creating and XMLDAS based on the \@type annotations in the
  * \@Service comment or in the \@Reference comment
  *
  * TODO - create a more complete model of the service in memory
  *        so that we can pick bits from it rather than having to
  *        rescan the class and regen it every time we need a bit
  *
  * @param string $class_name Class name
  * @param mixed  $xsds       XSDs
  *
  * @return SDO_DAS_XML
  */
 public static function getXmldasFormXsdArray($class_name, $xsds)
 {
     $xmldas = SDO_DAS_XML::create();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $xmldas->addTypes($xsd);
         }
     }
     return $xmldas;
 }
예제 #5
0
파일: SCA.php 프로젝트: psagi/sdo
 /**
  * THE OLD VERSION OF createInstanceAndFillInReferences(). INCLUDES
  * FUNCTIONALITY REQUIRED WHEN SCA IS RUNNING EMBEDDED IN TUSCANY SCA C++
  *
  * Instantiate the component, examine the annotations, find the dependencies,
  * call getService to create a proxy for each one, and assign to the
  * instance variables. The call(s) to getService may recurse back through here
  * if those dependencies also have dependencies
  *
  * @param string $class_name name of the class
  *
  * @return class instance
  */
 public static function createInstanceAndFillInReferences($class_name)
 {
     self::$logger->log("Entering");
     self::$logger->log("Class name of component to instantiate is {$class_name}");
     $instance = new $class_name();
     $reader = new SCA_AnnotationReader($instance);
     $references = $reader->reflectReferencesFull($instance);
     self::$logger->log("There are " . count($references) . " references to be filled in");
     $reflection = new ReflectionObject($instance);
     foreach ($references as $ref_name => $ref_type) {
         $ref_value = $ref_type->getBinding();
         self::$logger->log("Reference name = {$ref_name}, binding = {$ref_value}");
         $reference_proxy = null;
         if (self::$is_embedded) {
             $reference_proxy = new SCA_TuscanyProxy($ref_value);
         } else {
             if (SCA_Helper::isARelativePath($ref_value)) {
                 $ref_value = SCA_Helper::constructAbsolutePath($ref_value, $class_name);
             }
             $reference_proxy = SCA::getService($ref_value);
         }
         $prop = $reflection->getProperty($ref_name);
         // add the reference information to the proxy
         // this is added just in case there are any
         // extra types specified in the doc comment
         // for this reference
         $ref_type->addClassName($class_name);
         $reference_proxy->addReferenceType($ref_type);
         $prop->setValue($instance, $reference_proxy);
         // NB recursion here
     }
     self::$logger->log("Exiting");
     return $instance;
 }
예제 #6
0
 public function getJsonDas($xsds, $class_name)
 {
     $json_das = new SDO_DAS_Json();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $json_das->addTypesXsdFile($xsd);
         }
     }
     return $json_das;
 }
예제 #7
0
 /**
  * Get XML DAS for Atom
  *
  * @param string $class_name    Class name
  * @param string $namespace_uri Namespace
  *
  * @todo refactor this back into getXmldas - should just be able to load the atom schema if the namespace and type are http://www.w3.org/2005/Atom and entryType. This needs some thought though as the namespace could change, and someone else might use the type name entryType in a non-atom schema
  *
  * @return XML_DAS
  */
 public static function getXmldasForAtom($class_name, $namespace_uri)
 {
     SCA::$logger->log("Entering");
     $xmldas = SDO_DAS_XML::create(dirname(__FILE__) . '/Atom1.0.xsd');
     // expect to find xsds along with the SCA code - automatically loads xhtml1.xsd and xml.xsd as part of this.
     // TODO examine this code again
     // one might imagine that what is wanted is a map:
     // array(namespace => Set Of xsd)
     // but this is not what we have
     // Code Analyser correctly picks up a number
     // of strangenesses
     $xsds = SCA_Helper::getAllXsds($class_name);
     //$atomhelperlog->log("SCA_ServiceWrapperAtom::getXmldasForAtom() Just tried to find xsds in the component: ". print_r($xsds, true) ." \n");
     //$xmldas = SDO_DAS_XML::create();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $class_name);
             $xmldas->addTypes($xsd);
         }
     }
     // $atomhelperlog->log("SCA_ServiceWrapperAtom::getXmldasForAtom() xmldas after adding other types from the class:: $xmldas \n");
     SCA::$logger->log("Exiting");
     return $xmldas;
 }
예제 #8
0
파일: Proxy.php 프로젝트: psagi/sdo
 /**
  * Create XMLRPCDAS
  *
  * @param SCA_ReferenceType $reference_type Reference type
  *
  * @return object
  */
 protected function createXmlRpcDas($reference_type)
 {
     $xsds = $reference_type->getTypes();
     $xmlrpc_das = new SCA_Bindings_Xmlrpc_DAS();
     foreach ($xsds as $index => $xsds) {
         list($namespace, $xsdfile) = $xsds;
         if (SCA_Helper::isARelativePath($xsdfile)) {
             $xsd = SCA_Helper::constructAbsolutePath($xsdfile, $reference_type->getClassName());
             $xmlrpc_das->addTypesXsdFile($xsd);
         }
     }
     return $xmlrpc_das;
 }