Location: PHPKode > projects > SimpleSPML > SimpleSPML/lib/msg/suspend/ResumeRequest.php
<?php
require_once "lib/msg/core/Request.php";
require_once "lib/msg/core/PSOIdentifier.php";

/*
<complexType name = "ResumeRequestType">
     <complexContent>
        <extension base = "spml:RequestType">
        <sequence>
            <element name = "psoID" type = "spml:PSOIdentifierType" />
        </sequence>
        <attribute name = "effectiveDate" type = "dateTime" use = "optional"/>
        </extension>
    </complexContent>
</complexType>
*/

/**
 * ResumeRequest
 * 
 * A requestor must send a <resumeRequest> to a provider
 * in order to (ask the provider to) re-enable an existing
 * object
 * 
 * @package SimpleSPML
 * @author Alessandra Bozzo <hide@address.com>
 */
class ResumeRequest extends Request
{
    /**
	 * Date from which an existing object is re-enabled
	 * 
	 * @access protected
	 * @var XsdDateTime
	 */
    protected $effectiveDate = null;
    
    /**
	 * Object identifier
	 * 
	 * @access protected
	 * @var Core::PSOIdentifier
	 */
    protected $psoID = null;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->setBaseAttributes("effectiveDate");

        $this->setBaseElements("psoID");
        
        parent::__construct();
    }

    /**
     * Return effectiveDate value
     * @access public
     * @return XsdDateTime
     */
    public function __getEffectiveDate()
    {
        return $this->effectiveDate;
    }
    
    /**
     * Return psoID value
     * @access public
     * @return Core::PSOIdentifier
     */
    public function __getPsoID()
    {
        return $this->psoID;
    }

    /**
     * Sets the value of effectiveDate
     * @access public
     * @param string $effectiveDate 
     */
    public function __setEffectiveDate($effectiveDate)
    {
        if($effectiveDate)
        {
            try
            {
                $this->effectiveDate = new XsdDateTime($effectiveDate);
            }
            
            catch(Exception $e)
            {
                throw new WrongTypeException(get_class($this) . "::effectiveDate");
            }
        }
    }
    
    /**
     * Sets the value of psoID
     * @access public
     * @param Core::PSOIdentifier $psoID 
     */
    public function __setPsoID($psoID)
    {
        if(!$psoID)
            throw new MissingParameterException(get_class($this) . "::psoID");
        
        if(!($psoID instanceof PSOIdentifier))
            throw new WrongTypeException(get_class($this) . "::psoID");
            
        $this->psoID = $psoID;
    }
    
    /**
     * Return an array of string attributes
     * @access protected
     * @return array(string)
     */
    protected function attributesToString()
    {
        $attributes = array();
        
        if($this->effectiveDate)
            $attributes["effectiveDate"] = $this->effectiveDate->toString();
        
        return array_merge(parent::attributesToString(), $attributes);
    }
    
    /**
     * Read the SPML message
     * @access public
     * @param SimpleXMLIterator $obj
     */
    public function readMessage($obj)
    {
        $this->checkNamespace($obj, "urn:oasis:names:tc:SPML:2:0");
        
        // Load attributes
        $this->readAttribute($obj, "effectiveDate");
                        
        // Load elements
        $children = $obj->children();
        
        // psoID
        if(!$children->psoID)
        	throw new MalformedMessageException(get_class($this) . "::psoID");
        
        $psoID = new PSOIdentifier();
        $psoID->readMessage($children->psoID);
        $this->setElement("psoID", $psoID);
        unset($children->psoID);
        
        parent::readMessage($obj);
        
        if(!$this->isValid())
            throw new InvalidMessageException(get_class($this));
    }
    
    /**
     * Write the SPML message
     * @access public
     * @param int $level
     * @return string
     */
    public function writeMessage($level = 0)
    {
        if(!$this->isValid())
            throw new InvalidObjectException(get_class($this));
        
        $ind = $this->indentation($level);
        
        $spmlstr = $ind . '<resumeRequest xmlns="urn:oasis:names:tc:SPML:2:0"';
        
        // write resumeRequest attributes
        $spmlstr .= $this->writeAttributes();
                
        // write parent elements
        $spmlmidstr = parent::writeMessage($level + 1);
        
        // write resumeRequest elements
        $spmlmidstr .= $this->psoID->writeElement("psoID", $level + 1);
        
        return $this->tagCloser("resumeRequest", $spmlstr, $spmlmidstr, $ind);
    }
    
    /**
     * Check if the object is valid
     * @access public
     * @return boolean
     */
    public function isValid()
    {
        return(($this->psoID != null) && parent::isValid());
    }
}
?>
Return current item: SimpleSPML