Esempio n. 1
0
        public static InternalEventRouterDescForge GetValidatePreprocessing(
            EventType eventType,
            UpdateDesc desc,
            Attribute[] annotations)
        {
            if (!(eventType is EventTypeSPI)) {
                throw new ExprValidationException(
                    "Update statements require the event type to implement the " + typeof(EventTypeSPI) + " interface");
            }

            var eventTypeSPI = (EventTypeSPI) eventType;

            var size = desc.Assignments.Count;
            var wideners = new TypeWidenerSPI[size];
            var properties = new string[size];
            var expressions = new ExprNode[size];
            for (var i = 0; i < size; i++) {
                var onSet = desc.Assignments[i];
                var assignmentPair = ExprNodeUtilityValidate.CheckGetAssignmentToProp(onSet.Expression);
                if (assignmentPair == null) {
                    throw new ExprValidationException(
                        "Missing property assignment expression in assignment number " + i);
                }

                properties[i] = assignmentPair.First;
                expressions[i] = assignmentPair.Second;
                var writableProperty = eventTypeSPI.GetWritableProperty(assignmentPair.First);

                if (writableProperty == null) {
                    throw new ExprValidationException(
                        "Property '" + assignmentPair.First + "' is not available for write access");
                }

                try {
                    wideners[i] = TypeWidenerFactory.GetCheckPropertyAssignType(
                        ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(assignmentPair.Second),
                        assignmentPair.Second.Forge.EvaluationType,
                        writableProperty.PropertyType,
                        assignmentPair.First,
                        false,
                        null,
                        null);
                }
                catch (TypeWidenerException ex) {
                    throw new ExprValidationException(ex.Message, ex);
                }
            }

            // check copy-able
            var copyMethod = eventTypeSPI.GetCopyMethodForge(properties);
            if (copyMethod == null) {
                throw new ExprValidationException(
                    "The update-clause requires the underlying event representation to support copy (via Serializable by default)");
            }

            return new InternalEventRouterDescForge(
                copyMethod,
                wideners,
                eventType,
                annotations,
                desc.OptionalWhereClause,
                properties,
                expressions);
        }