Ejemplo n.º 1
0
 /**
  * Merge two null check expression trees by removing duplicate nodes.
  *
  * @param AbstractExpression $nullCheckExpTree1 First expression.
  * @param AbstractExpression $nullCheckExpTree2 Second expression.
  * 
  * @return UnaryExpression or LogicalExpression
  */
 private function _mergeNullableExpressionTrees($nullCheckExpTree1, $nullCheckExpTree2)
 {
     $this->_mapTable = array();
     $this->_map($nullCheckExpTree1);
     $this->_map($nullCheckExpTree2);
     $expression = null;
     $isNullFunctionDescription = null;
     foreach ($this->_mapTable as $node) {
         if ($expression == null) {
             $expression = new UnaryExpression(new FunctionCallExpression(FunctionDescription::isNullCheckFunction($node->getType()), array($node)), ExpressionType::NOT_LOGICAL, new Boolean());
         } else {
             $expression = new LogicalExpression($expression, new UnaryExpression(new FunctionCallExpression(FunctionDescription::isNullCheckFunction($node->getType()), array($node)), ExpressionType::NOT_LOGICAL, new Boolean()), ExpressionType::AND_LOGICAL);
         }
     }
     return $expression;
 }
 /**
  * Function to create a nullable expression subtree for checking the
  * nullablilty of parent (and current poperty optionally) properties
  * 
  * @param boolean $includeMe Boolean flag indicating whether to include null
  *                           check for this property along with parents
  * 
  * @return AbstractExpression Instance of UnaryExpression, LogicalExpression
  *                            or Null
  * 
  */
 public function createNullableExpressionTree($includeMe)
 {
     $basePropertyExpression = $this;
     while ($basePropertyExpression != null && $basePropertyExpression->parent != null) {
         $basePropertyExpression = $basePropertyExpression->parent;
     }
     //This property is direct child of ResourceSet, no need to check
     //nullability for direct ResourceSet properties
     // ($c->CustomerID, $c->Order, $c->Address) unless $includeMe is true
     if ($basePropertyExpression == $this) {
         if ($includeMe) {
             return new UnaryExpression(new FunctionCallExpression(FunctionDescription::isNullCheckFunction($basePropertyExpression->getType()), array($basePropertyExpression)), ExpressionType::NOT_LOGICAL, new Boolean());
         }
         return null;
     }
     //This property is a property of a complex type or resource reference
     //$c->Order->OrderID, $c->Address->LineNumber,
     // $c->complex1->complex2->primitveVar
     //($c->Order != null),($c->Address != null),
     // (($c->complex1 != null) && ($c->complex1->complex2 != null))
     $expression = new UnaryExpression(new FunctionCallExpression(FunctionDescription::isNullCheckFunction($basePropertyExpression->getType()), array($basePropertyExpression)), ExpressionType::NOT_LOGICAL, new Boolean());
     while ($basePropertyExpression->getChild() != null && $basePropertyExpression->getChild()->getChild() != null) {
         $basePropertyExpression = $basePropertyExpression->getChild();
         $expression2 = new UnaryExpression(new FunctionCallExpression(FunctionDescription::isNullCheckFunction($basePropertyExpression->getType()), array($basePropertyExpression)), ExpressionType::NOT_LOGICAL, new Boolean());
         $expression = new LogicalExpression($expression, $expression2, ExpressionType::AND_LOGICAL);
     }
     if ($includeMe) {
         $basePropertyExpression = $basePropertyExpression->getChild();
         $expression2 = new UnaryExpression(new FunctionCallExpression(FunctionDescription::isNullCheckFunction($basePropertyExpression->getType()), array($basePropertyExpression)), ExpressionType::NOT_LOGICAL, new Boolean());
         $expression = new LogicalExpression($expression, $expression2, ExpressionType::AND_LOGICAL);
     }
     return $expression;
 }