Exemplo n.º 1
0
        /// <summary>
        /// build a XPT Node out of a selection condition
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public bool BuildXPTNode(SelectConditionContext ctx)
        {
            string entryName;

            //|   RPAREN selectConditions [$ClassName, $keypos] LPAREN
            if (ctx.selectConditions() != null)
            {
                if (ctx.NOT() == null)
                {
                    ctx.XPTreeNode = ctx.selectConditions().XPTreeNode;
                }
                else
                {
                    ctx.XPTreeNode = LogicalExpression.NOT((IExpression)ctx.selectConditions().XPTreeNode);
                }
                // set the max priority for disabling reshuffle
                ((OperationExpression)ctx.XPTreeNode).Priority = uint.MaxValue;
                return(true);
            }
            else
            {
                // determine the key name with the key is not provided by the key position
                //
                if (ctx.dataObjectEntry == null)
                {
                    string aClassName = GetDefaultClassName(ctx);
                    if (this.Engine.Repository.HasDataObjectDefinition(aClassName))
                    {
                        iObjectDefinition aObjectDefinition = this.Engine.GetDataObjectDefinition(aClassName);
                        if (ctx.keypos <= aObjectDefinition.Keys.Count())
                        {
                            entryName = aClassName + "." + aObjectDefinition.Keys[ctx.keypos - 1];
                        }
                        else
                        {
                            this.NotifyErrorListeners(String.Format(Messages.RCM_8, aClassName, aObjectDefinition.Keys.Count(), ctx.keypos));
                            return(false);
                        }
                    }
                    else
                    {
                        this.NotifyErrorListeners(String.Format(Messages.RCM_9, aClassName));
                        return(false);
                    }
                }
                else
                {
                    entryName = ctx.dataObjectEntry.entryname;
                }

                // get the symbol
                DataObjectEntrySymbol aSymbol = new DataObjectEntrySymbol(entryName, engine: this.Engine);

                // Operator
                Operator anOperator;
                // default operator is the EQ operator
                if (ctx.Operator == null)
                {
                    anOperator = Engine.GetOperator(new Token(Token.EQ));
                }
                else
                {
                    anOperator = ctx.Operator.Operator;
                }

                // build the comparer expression
                CompareExpression aCompare = null;
                if (aSymbol != null && ctx.select.XPTreeNode != null)
                {
                    aCompare = new CompareExpression(anOperator, aSymbol, (IExpression)ctx.select.XPTreeNode);
                }
                else
                {
                    return(false);
                }
                // set it
                ctx.XPTreeNode = aCompare;
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// build a XPT Node out of a selection condition
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public bool BuildXPTNode(SelectConditionContext ctx)
        {
            string entryName;
             //|   RPAREN selectConditions [$ClassName, $keypos] LPAREN
             if (ctx.selectConditions() != null)
             {
                 if (ctx.NOT()==null) ctx.XPTreeNode = ctx.selectConditions().XPTreeNode;
                 else ctx.XPTreeNode = LogicalExpression.NOT((IExpression)ctx.selectConditions().XPTreeNode);
                 // set the max priority for disabling reshuffle
                 ((OperationExpression)ctx.XPTreeNode).Priority = uint.MaxValue;
                 return true;
             }
             else
             {
                 // determine the key name with the key is not provided by the key position
                 //
                 if (ctx.dataObjectEntry == null)
                 {
                     string aClassName = GetDefaultClassName(ctx);
                     if (this.Engine.Repository.HasDataObjectDefinition(aClassName))
                     {
                         iObjectDefinition aObjectDefinition = this.Engine.GetDataObjectDefinition(aClassName);
                         if (ctx.keypos <= aObjectDefinition.Keys.Count())
                             entryName = aClassName + "." + aObjectDefinition.Keys[ctx.keypos - 1];
                         else
                         {
                             this.NotifyErrorListeners(String.Format(Messages.RCM_8, aClassName, aObjectDefinition.Keys.Count(), ctx.keypos));
                             return false;
                         }
                     }else
                     {
                         this.NotifyErrorListeners(String.Format(Messages.RCM_9, aClassName));
                         return false;
                     }

                 }
                 else entryName = ctx.dataObjectEntry.entryname;

                 // get the symbol
                 DataObjectEntrySymbol aSymbol = new DataObjectEntrySymbol(entryName, engine: this.Engine);

                 // Operator
                 Operator anOperator;
                 // default operator is the EQ operator
                 if (ctx.Operator == null) anOperator = Engine.GetOperator(new Token(Token.EQ));
                 else anOperator = ctx.Operator.Operator;

                 // build the comparer expression
                 CompareExpression aCompare = null;
                 if (aSymbol != null && ctx.select.XPTreeNode != null) aCompare = new CompareExpression(anOperator, aSymbol, (IExpression)ctx.select.XPTreeNode);
                 else return false;
                 // set it
                 ctx.XPTreeNode = aCompare;
                 return true;
             }
             return false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// returns true if this a Data Object class
        /// </summary>
        /// <returns></returns>
        bool IsDataObjectEntry(string name, RuleContext context)
        {
            // check the name might be a full name
            CanonicalName aName       = new CanonicalName(name);
            string        aClassname  = aName.IsCanonical() ? aName.ClassName() : String.Empty;
            string        anEntryName = aName.EntryName();

            // if we are in the right context
            if (context is DataObjectEntryNameContext)
            {
                DataObjectEntryNameContext ctx = (DataObjectEntryNameContext)context;
                if (string.IsNullOrEmpty(ctx.ClassName))
                {
                    aClassname = GetDefaultClassName(context);
                }
                else if (!String.IsNullOrWhiteSpace(ctx.ClassName))
                {
                    // if classname differs than it is not allowed
                    if (string.Compare(ctx.ClassName, aClassname, true) != 00)
                    {
                        this.NotifyErrorListeners(String.Format(Messages.RCM_12, ctx.ClassName));
                    }
                    else
                    {
                        aClassname = ctx.ClassName;
                    }
                }
            }
            else if (context is SelectExpressionContext)
            {
                SelectExpressionContext ctx = (SelectExpressionContext)context;
                string aDefaultname         = GetDefaultClassName(ctx);
                if (!(String.IsNullOrEmpty(aDefaultname)))
                {
                    aClassname = aDefaultname;
                }
            }
            else if (context is SelectConditionContext)
            {
                SelectConditionContext ctx = (SelectConditionContext)context;
                string aDefaultname        = GetDefaultClassName(ctx);
                if (!(String.IsNullOrEmpty(aDefaultname)))
                {
                    aClassname = aDefaultname;
                }
            }
            else if (context is ResultSelectionContext)
            {
                ResultSelectionContext ctx = (ResultSelectionContext)context;
                string aDefaultname        = GetDefaultClassName(ctx);
                if (string.IsNullOrEmpty(ctx.ClassName))
                {
                    aClassname = GetDefaultClassName(context);
                }
                else if (!String.IsNullOrWhiteSpace(ctx.ClassName))
                {
                    aClassname = ctx.ClassName;
                }
            }

            // check if DataObjectEntry is there
            if (!string.IsNullOrWhiteSpace(aClassname) && Engine.Repository.HasDataObjectDefinition(aClassname))
            {
                return(Engine.Repository.GetDataObjectDefinition(aClassname).HasEntry(anEntryName));
            }
            // no way to get classname and entryname
            return(false);
        }