Exemple #1
0
        public override IValue interpret(Context context)
        {
            List <object> toDelete = null;

            if (deletables != null)
            {
                toDelete = new List <object>();
                deletables.ForEach((exp) => CollectDeletables(context, exp, toDelete));
            }
            List <IStorable> toStore = null;

            if (storables != null)
            {
                toStore = new List <IStorable>();
                storables.ForEach((exp) => CollectStorables(context, exp, toStore));
            }
            if (deletables != null || storables != null)
            {
                IAuditMetadata withMeta = null;
                if (metadata != null)
                {
                    IValue value = metadata.interpret(context);
                    if (value is DocumentValue)
                    {
                        DocumentValue doc = (DocumentValue)value;
                        withMeta = DataStore.Instance.NewAuditMetadata();
                        foreach (String name in doc.GetMemberNames())
                        {
                            value          = doc.GetMemberValue(context, name, false);
                            withMeta[name] = value.GetStorableData();
                        }
                    }
                }
                DataStore.Instance.DeleteAndStore(toDelete, toStore, withMeta);
            }
            if (andThen != null)
            {
                andThen.interpret(context);
            }
            return(null);
        }
Exemple #2
0
        public override IValue interpret(Context context)
        {
            CategoryDeclaration cd = context.getRegisteredDeclaration <CategoryDeclaration>(this.type.GetTypeName());

            if (cd == null)
            {
                throw new SyntaxError("Unknown category " + this.type.GetTypeName());
            }
            checkFirstHomonym(context, cd);
            IInstance instance = type.newInstance(context);

            instance.setMutable(true);
            try
            {
                if (copyFrom != null)
                {
                    Object copyObj = copyFrom.interpret(context);
                    if (copyObj is IInstance)
                    {
                        IInstance copyInstance = (IInstance)copyObj;
                        foreach (String name in copyInstance.GetMemberNames())
                        {
                            if (name == "dbId")
                            {
                                continue;
                            }
                            else if (cd.hasAttribute(context, name))
                            {
                                IValue value = copyInstance.GetMemberValue(context, name, false);
                                if (value != null && value.IsMutable() && !this.type.Mutable)
                                {
                                    throw new NotMutableError();
                                }
                                instance.SetMemberValue(context, name, value);
                            }
                        }
                    }
                    else if (copyObj is DocumentValue)
                    {
                        DocumentValue copyDoc = (DocumentValue)copyObj;
                        foreach (String name in copyDoc.GetMemberNames())
                        {
                            if (name == "dbId")
                            {
                                continue;
                            }
                            else if (cd.hasAttribute(context, name))
                            {
                                IValue value = copyDoc.GetMemberValue(context, name, false);
                                if (value != null && value.IsMutable() && !this.type.Mutable)
                                {
                                    throw new NotMutableError();
                                }
                                // TODO convert to attribute type, see Java version
                                instance.SetMemberValue(context, name, value);
                            }
                        }
                    }
                }
                if (arguments != null)
                {
                    foreach (Argument argument in arguments)
                    {
                        IValue value = argument.getExpression().interpret(context);
                        if (value != null && value.IsMutable() && !this.type.Mutable)
                        {
                            throw new NotMutableError();
                        }
                        instance.SetMemberValue(context, argument.GetName(), value);
                    }
                }
            }
            finally
            {
                instance.setMutable(this.type.Mutable);
            }
            return(instance);
        }
Exemple #3
0
 protected override IValue readValue(String name, Func <IValue> supplier)
 {
     return(document.GetMemberValue(calling, name, false));
 }