public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
 {
     var name = new QName(fieldDef.GetString("Name"), fieldDef.GetString("Ns"));
     bool optional = fieldDef.GetBool("Optional");
     GroupValue exponentDef = fieldDef.GetGroup("Exponent");
     GroupValue exponentOperatorDef = exponentDef.GetGroup("Operator").GetGroup(0);
     Operator exponentOperator = GetOperator(exponentOperatorDef.Group);
     ScalarValue exponentDefaultValue = ScalarValue.Undefined;
     if (exponentDef.IsDefined("InitialValue"))
         exponentDefaultValue = new IntegerValue(exponentDef.GetInt("InitialValue"));
     GroupValue mantissaDef = fieldDef.GetGroup("Mantissa");
     GroupValue mantissaOperatorDef = mantissaDef.GetGroup("Operator").GetGroup(0);
     Operator mantissaOperator = GetOperator(mantissaOperatorDef.Group);
     ScalarValue mantissaDefaultValue = ScalarValue.Undefined;
     if (mantissaDef.IsDefined("InitialValue"))
         mantissaDefaultValue = new LongValue(mantissaDef.GetInt("InitialValue"));
     ComposedScalar composedDecimal = Util.ComposedDecimal(name, exponentOperator, exponentDefaultValue,
                                                           mantissaOperator, mantissaDefaultValue, optional);
     IFieldValue retAuxId;
     if (fieldDef.TryGetValue("AuxId", out retAuxId) && retAuxId!=null)
     {
         composedDecimal.Id = retAuxId.ToString();
     }
     return composedDecimal;
 }
 public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
 {
     var scalar = (Scalar) base.Convert(fieldDef, templateRegistry, context);
     IFieldValue retLength;
     if (fieldDef.TryGetValue("Length", out retLength) && retLength != null)
         scalar.AddAttribute(FastConstants.LengthField, ((GroupValue) retLength).GetString("Name"));
     return scalar;
 }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            var name = new QName(fieldDef.GetString("Name"), fieldDef.GetString("Ns"));
            MessageTemplate template;
            if (templateRegistry.TryGetTemplate(name, out template))
                return new StaticTemplateReference(template);

            throw new ArgumentOutOfRangeException("fieldDef", name, "Referenced template name not defined.");
        }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var composedScalar = (ComposedScalar) field;
     var message = new Message(SessionControlProtocol11.CompDecimalInstr);
     SetNameAndId(field, message);
     message.SetInteger("Optional", field.IsOptional ? 1 : 0);
     GroupValue exponentDef = CreateComponent(composedScalar.Fields[0], "Exponent");
     GroupValue mantissaDef = CreateComponent(composedScalar.Fields[1], "Mantissa");
     message.SetFieldValue("Exponent", exponentDef);
     message.SetFieldValue("Mantissa", mantissaDef);
     return message;
 }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var scalar = (Scalar) field;
     GroupValue fieldDef = base.Convert(field, context);
     string value;
     if (scalar.TryGetAttribute(FastConstants.LengthField, out value))
     {
         var lengthDef = new GroupValue(fieldDef.Group.GetGroup("Length"));
         lengthDef.SetString("Name", value);
         fieldDef.SetFieldValue("Length", lengthDef);
     }
     return fieldDef;
 }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            string name = fieldDef.GetString("Name");
            string ns = fieldDef.GetString("Ns");
            var qname = new QName(name, ns);
            Field[] fields = GroupConverter.ParseFieldInstructions(fieldDef, templateRegistry, context);
            bool optional = fieldDef.GetBool("Optional");
            Scalar length = null;
            IFieldValue retLength;
            if (fieldDef.TryGetValue("Length", out retLength) && retLength!=null)
            {
                GroupValue lengthDef = (GroupValue)retLength;
                QName lengthName;
                string id = null;
                IFieldValue retName;
                if (lengthDef.TryGetValue("Name", out retName) && retName != null)
                {
                    GroupValue nameDef = (GroupValue)retName;
                    lengthName = new QName(nameDef.GetString("Name"), nameDef.GetString("Ns"));
                    IFieldValue retAuxId;
                    if (nameDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
                        id = retAuxId.ToString();
                }
                else
                    lengthName = Global.CreateImplicitName(qname);
                Operator op = Operator.None;
                IFieldValue retOperator;
                if (lengthDef.TryGetValue("Operator", out retOperator) && retOperator != null)
                    op = GetOperator(((GroupValue)retOperator).GetGroup(0).Group);
                ScalarValue initialValue = ScalarValue.Undefined;
                IFieldValue retInitialValue;
                if (lengthDef.TryGetValue("InitialValue", out retInitialValue) && retInitialValue != null)
                    initialValue = (ScalarValue) retInitialValue;
                length = new Scalar(lengthName, FastType.U32, op, initialValue, optional) {Id = id};
            }

            var sequence = new Sequence(qname, length, fields, optional);
            IFieldValue retTypeRef;
            if (fieldDef.TryGetValue("TypeRef", out retTypeRef) && retTypeRef != null)
            {
                GroupValue typeRef = (GroupValue)retTypeRef;
                string typeRefName = typeRef.GetString("Name");
                string typeRefNs = ""; // context.getNamespace();
                IFieldValue rettypeRefNs;
                if (typeRef.TryGetValue("Ns", out rettypeRefNs) && rettypeRefNs!=null)
                    typeRefNs = rettypeRefNs.ToString();
                sequence.TypeReference = new QName(typeRefName, typeRefNs);
            }
            return sequence;
        }
        public static Message Convert(Group group, Message groupMsg, ConversionContext context)
        {
            SetNameAndId(group, groupMsg);
            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group) SessionControlProtocol11
                                    .TypeRef
                                    .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            var instructions = new SequenceValue(
                SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions"));

            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11
                            .TypeRef
                            .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            Field[] fields = group.FieldDefinitions;
            for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++)
            {
                Field field = fields[i];

                IFieldInstructionConverter converter = context.GetConverter(field);
                if (converter == null)
                    throw new InvalidOperationException("No converter found for type " + field.GetType());

                IFieldValue v = converter.Convert(field, context);
                instructions.Add(new[] {v});
            }
            groupMsg.SetFieldValue("Instructions", instructions);
            return groupMsg;
        }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            FastType type = _templateTypeMap[fieldDef.Group];
            bool optional = fieldDef.GetBool("Optional");
            IFieldValue retInitialValue;
            ScalarValue initialValue = fieldDef.TryGetValue("InitialValue",out retInitialValue) && retInitialValue!=null
                                           ? (ScalarValue)retInitialValue
                                           : ScalarValue.Undefined;

            string name = fieldDef.GetString("Name");
            IFieldValue rettempNs;
            string tempNs = fieldDef.TryGetValue("Ns", out rettempNs) && rettempNs != null ? rettempNs.ToString() : "";
            var qname = new QName(name, tempNs);

            Scalar scalar;
            IFieldValue retOperator;
            if (fieldDef.TryGetValue("Operator", out retOperator) && retOperator!=null)
            {
                GroupValue operatorGroup = ((GroupValue)retOperator).GetGroup(0);
                Operator operatortemp = GetOperator(operatorGroup.Group);
                scalar = new Scalar(qname, type, operatortemp, initialValue, optional);
                IFieldValue retDictionary;
                if (operatorGroup.TryGetValue("Dictionary", out retDictionary) && retDictionary != null)
                    scalar.Dictionary = retDictionary.ToString();
                IFieldValue retKey;
                if (operatorGroup.TryGetValue("Key", out retKey) && retKey != null)
                {
                    GroupValue retOperatorGroup = (GroupValue) retKey;
                    string keyName = retOperatorGroup.GetString("Name");
                    string ns = retOperatorGroup.GetString("Ns");
                    scalar.Key = new QName(keyName, ns);
                }
            }
            else
            {
                scalar = new Scalar(qname, type, Operator.None, initialValue, optional);
            }
            IFieldValue retAuxId;
            if (fieldDef.TryGetValue("AuxId", out retAuxId) && retAuxId!=null)
            {
                scalar.Id = retAuxId.ToString();
            }
            return scalar;
        }
Example #9
0
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            string      name          = fieldDef.GetString("Name");
            string      namespacetemp = "";
            IFieldValue retns;

            if (fieldDef.TryGetValue("Ns", out retns) && retns != null)
            {
                namespacetemp = retns.ToString();
            }

            Field[] fields   = ParseFieldInstructions(fieldDef, templateRegistry, context);
            bool    optional = fieldDef.GetBool("Optional");
            var     group    = new Group(new QName(name, namespacetemp), fields, optional);

            IFieldValue retTypeRef;

            if (fieldDef.TryGetValue("TypeRef", out retTypeRef) && retTypeRef != null)
            {
                var         typeRef     = (GroupValue)retTypeRef;
                String      typeRefName = typeRef.GetString("Name");
                String      typeRefNs   = ""; // context.getNamespace();
                IFieldValue retNsTypeRef;
                if (typeRef.TryGetValue("Ns", out retNsTypeRef) && retNsTypeRef != null)
                {
                    typeRefNs = retNsTypeRef.ToString();
                }
                group.TypeReference = new QName(typeRefName, typeRefNs);
            }

            IFieldValue retAuxId;

            if (fieldDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
            {
                group.Id = retAuxId.ToString();
            }

            return(group);
        }
Example #10
0
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            FastType    type     = _templateTypeMap[fieldDef.Group];
            bool        optional = fieldDef.GetBool("Optional");
            IFieldValue retInitialValue;
            ScalarValue initialValue = fieldDef.TryGetValue("InitialValue", out retInitialValue) && retInitialValue != null
                                           ? (ScalarValue)retInitialValue
                                           : ScalarValue.Undefined;

            string      name = fieldDef.GetString("Name");
            IFieldValue rettempNs;
            string      tempNs = fieldDef.TryGetValue("Ns", out rettempNs) && rettempNs != null?rettempNs.ToString() : "";

            var qname = new QName(name, tempNs);

            Scalar      scalar;
            IFieldValue retOperator;

            if (fieldDef.TryGetValue("Operator", out retOperator) && retOperator != null)
            {
                GroupValue operatorGroup = ((GroupValue)retOperator).GetGroup(0);
                Operator   operatortemp  = GetOperator(operatorGroup.Group);
                scalar = new Scalar(qname, type, operatortemp, initialValue, optional);
                IFieldValue retDictionary;
                if (operatorGroup.TryGetValue("Dictionary", out retDictionary) && retDictionary != null)
                {
                    scalar.Dictionary = retDictionary.ToString();
                }
                IFieldValue retKey;
                if (operatorGroup.TryGetValue("Key", out retKey) && retKey != null)
                {
                    GroupValue retOperatorGroup = (GroupValue)retKey;
                    string     keyName          = retOperatorGroup.GetString("Name");
                    string     ns = retOperatorGroup.GetString("Ns");
                    scalar.Key = new QName(keyName, ns);
                }
            }
            else
            {
                scalar = new Scalar(qname, type, Operator.None, initialValue, optional);
            }
            IFieldValue retAuxId;

            if (fieldDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
            {
                scalar.Id = retAuxId.ToString();
            }
            return(scalar);
        }
 public abstract Field Convert(GroupValue param1, ITemplateRegistry param2,
                               ConversionContext param3);
 public abstract GroupValue Convert(Field param1, ConversionContext param2);
 public virtual GroupValue Convert(Field field, ConversionContext context)
 {
     return(SessionControlProtocol11.DynTempRefMessage);
 }
        public static Field[] ParseFieldInstructions(GroupValue groupDef, ITemplateRegistry registry,
                                                     ConversionContext context)
        {
            SequenceValue instructions = groupDef.GetSequence("Instructions");
            var fields = new Field[instructions.Length];
            for (int i = 0; i < fields.Length; i++)
            {
                GroupValue fieldDef = instructions[i].GetGroup(0);
                IFieldInstructionConverter converter = context.GetConverter(fieldDef.Group);
                if (converter == null)
                    throw new SystemException(
                        string.Format("Encountered unknown group {0} while processing field instructions {1}",
                                      fieldDef.Group, groupDef.Group));

                fields[i] = converter.Convert(fieldDef, registry, context);
            }
            return fields;
        }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            string name = fieldDef.GetString("Name");
            string namespacetemp = "";
            IFieldValue retns;

            if (fieldDef.TryGetValue("Ns", out retns) && retns != null)
                namespacetemp = retns.ToString();

            Field[] fields = ParseFieldInstructions(fieldDef, templateRegistry, context);
            bool optional = fieldDef.GetBool("Optional");
            var group = new Group(new QName(name, namespacetemp), fields, optional);

            IFieldValue retTypeRef;
            if (fieldDef.TryGetValue("TypeRef", out retTypeRef) && retTypeRef != null)
            {
                var typeRef = (GroupValue) retTypeRef;
                String typeRefName = typeRef.GetString("Name");
                String typeRefNs = ""; // context.getNamespace();
                IFieldValue retNsTypeRef;
                if (typeRef.TryGetValue("Ns", out retNsTypeRef) && retNsTypeRef != null)
                    typeRefNs = retNsTypeRef.ToString();
                group.TypeReference = new QName(typeRefName, typeRefNs);
            }

            IFieldValue retAuxId;
            if (fieldDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
                group.Id = retAuxId.ToString();

            return group;
        }
 public virtual Field Convert(GroupValue groupValue, ITemplateRegistry templateRegistry,
                              ConversionContext context)
 {
     return DynamicTemplateReference.Instance;
 }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var group = (Group) field;
     Message groupMsg = Convert(group, new Message(SessionControlProtocol11.GroupInstr), context);
     groupMsg.SetBool("Optional", field.IsOptional);
     return groupMsg;
 }
Example #18
0
 public abstract Field Convert(GroupValue param1, ITemplateRegistry param2,
                               ConversionContext param3);
Example #19
0
 public abstract GroupValue Convert(Field param1, ConversionContext param2);
        public override GroupValue Convert(Field field, ConversionContext context)
        {
            var scalar = (Scalar) field;
            var scalarTemplate = (MessageTemplate) _typeTemplateMap[scalar.FastType];
            var scalarMsg = new Message(scalarTemplate);
            SetNameAndId(scalar, scalarMsg);
            scalarMsg.SetInteger("Optional", scalar.IsOptional ? 1 : 0);

            if (!scalar.Operator.Equals(Operator.None))
                scalarMsg.SetFieldValue(
                    "Operator",
                    new GroupValue(scalarTemplate.GetGroup("Operator"), new IFieldValue[] {CreateOperator(scalar)}));

            if (!scalar.DefaultValue.IsUndefined)
                scalarMsg.SetFieldValue("InitialValue", scalar.DefaultValue);

            return scalarMsg;
        }
 public override GroupValue Convert(Field field, ConversionContext context)
 {
     var strDef = new Message(SessionControlProtocol11.StatTempRefInstr);
     SetNameAndId(field, strDef);
     return strDef;
 }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            var             name = new QName(fieldDef.GetString("Name"), fieldDef.GetString("Ns"));
            MessageTemplate template;

            if (templateRegistry.TryGetTemplate(name, out template))
            {
                return(new StaticTemplateReference(template));
            }

            throw new ArgumentOutOfRangeException("fieldDef", name, "Referenced template name not defined.");
        }
 public static ConversionContext CreateInitialContext()
 {
     var context = new ConversionContext();
     context.AddFieldInstructionConverter(new ScalarConverter());
     context.AddFieldInstructionConverter(new SequenceConverter());
     context.AddFieldInstructionConverter(new GroupConverter());
     context.AddFieldInstructionConverter(new DynamicTemplateReferenceConverter());
     context.AddFieldInstructionConverter(new StaticTemplateReferenceConverter());
     context.AddFieldInstructionConverter(new ComposedDecimalConverter());
     context.AddFieldInstructionConverter(new VariableLengthInstructionConverter());
     return context;
 }
        public override GroupValue Convert(Field field, ConversionContext context)
        {
            var sequence = (Sequence) field;
            Message seqDef = GroupConverter.Convert(
                sequence.Group,
                new Message(SessionControlProtocol11.SequenceInstr),
                context);

            seqDef.SetBool("Optional", sequence.IsOptional);
            if (!sequence.ImplicitLength)
            {
                Group lengthGroup = SessionControlProtocol11.SequenceInstr.GetGroup("Length");
                var lengthDef = new GroupValue(lengthGroup);
                Scalar length = sequence.Length;
                var nameDef = new GroupValue(lengthGroup.GetGroup("Name"));
                SetNameAndId(length, nameDef);
                lengthDef.SetFieldValue("Name", nameDef);
                seqDef.SetFieldValue("Length", lengthDef);

                if (!length.Operator.Equals(Operator.None))
                {
                    var operatorDef = new GroupValue(lengthGroup.GetGroup("Operator"));
                    operatorDef.SetFieldValue(0, CreateOperator(length));
                    lengthDef.SetFieldValue("Operator", operatorDef);
                }

                if (!length.DefaultValue.IsUndefined)
                {
                    lengthDef.SetFieldValue("InitialValue", length.DefaultValue);
                }
            }

            if (sequence.TypeReference != null && !FastConstants.AnyType.Equals(sequence.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11.TypeRef.GetField(new QName("TypeRef",
                                                                              SessionControlProtocol11.Namespace)));
                SetName(typeRef, sequence.TypeReference);
                seqDef.SetFieldValue("TypeRef", typeRef);
            }

            return seqDef;
        }
 public virtual Field Convert(GroupValue groupValue, ITemplateRegistry templateRegistry,
                              ConversionContext context)
 {
     return(DynamicTemplateReference.Instance);
 }
 public virtual GroupValue Convert(Field field, ConversionContext context)
 {
     return SessionControlProtocol11.DynTempRefMessage;
 }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            var         scalar = (Scalar)base.Convert(fieldDef, templateRegistry, context);
            IFieldValue retLength;

            if (fieldDef.TryGetValue("Length", out retLength) && retLength != null)
            {
                scalar.AddAttribute(FastConstants.LengthField, ((GroupValue)retLength).GetString("Name"));
            }
            return(scalar);
        }
Example #28
0
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            string name  = fieldDef.GetString("Name");
            string ns    = fieldDef.GetString("Ns");
            var    qname = new QName(name, ns);

            Field[]     fields   = GroupConverter.ParseFieldInstructions(fieldDef, templateRegistry, context);
            bool        optional = fieldDef.GetBool("Optional");
            Scalar      length   = null;
            IFieldValue retLength;

            if (fieldDef.TryGetValue("Length", out retLength) && retLength != null)
            {
                GroupValue  lengthDef = (GroupValue)retLength;
                QName       lengthName;
                string      id = null;
                IFieldValue retName;
                if (lengthDef.TryGetValue("Name", out retName) && retName != null)
                {
                    GroupValue nameDef = (GroupValue)retName;
                    lengthName = new QName(nameDef.GetString("Name"), nameDef.GetString("Ns"));
                    IFieldValue retAuxId;
                    if (nameDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
                    {
                        id = retAuxId.ToString();
                    }
                }
                else
                {
                    lengthName = Global.CreateImplicitName(qname);
                }
                Operator    op = Operator.None;
                IFieldValue retOperator;
                if (lengthDef.TryGetValue("Operator", out retOperator) && retOperator != null)
                {
                    op = GetOperator(((GroupValue)retOperator).GetGroup(0).Group);
                }
                ScalarValue initialValue = ScalarValue.Undefined;
                IFieldValue retInitialValue;
                if (lengthDef.TryGetValue("InitialValue", out retInitialValue) && retInitialValue != null)
                {
                    initialValue = (ScalarValue)retInitialValue;
                }
                length = new Scalar(lengthName, FastType.U32, op, initialValue, optional)
                {
                    Id = id
                };
            }

            var         sequence = new Sequence(qname, length, fields, optional);
            IFieldValue retTypeRef;

            if (fieldDef.TryGetValue("TypeRef", out retTypeRef) && retTypeRef != null)
            {
                GroupValue  typeRef     = (GroupValue)retTypeRef;
                string      typeRefName = typeRef.GetString("Name");
                string      typeRefNs   = ""; // context.getNamespace();
                IFieldValue rettypeRefNs;
                if (typeRef.TryGetValue("Ns", out rettypeRefNs) && rettypeRefNs != null)
                {
                    typeRefNs = rettypeRefNs.ToString();
                }
                sequence.TypeReference = new QName(typeRefName, typeRefNs);
            }
            return(sequence);
        }
Example #29
0
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            var         name                 = new QName(fieldDef.GetString("Name"), fieldDef.GetString("Ns"));
            bool        optional             = fieldDef.GetBool("Optional");
            GroupValue  exponentDef          = fieldDef.GetGroup("Exponent");
            GroupValue  exponentOperatorDef  = exponentDef.GetGroup("Operator").GetGroup(0);
            Operator    exponentOperator     = GetOperator(exponentOperatorDef.Group);
            ScalarValue exponentDefaultValue = ScalarValue.Undefined;

            if (exponentDef.IsDefined("InitialValue"))
            {
                exponentDefaultValue = new IntegerValue(exponentDef.GetInt("InitialValue"));
            }
            GroupValue  mantissaDef          = fieldDef.GetGroup("Mantissa");
            GroupValue  mantissaOperatorDef  = mantissaDef.GetGroup("Operator").GetGroup(0);
            Operator    mantissaOperator     = GetOperator(mantissaOperatorDef.Group);
            ScalarValue mantissaDefaultValue = ScalarValue.Undefined;

            if (mantissaDef.IsDefined("InitialValue"))
            {
                mantissaDefaultValue = new LongValue(mantissaDef.GetInt("InitialValue"));
            }
            ComposedScalar composedDecimal = Util.ComposedDecimal(name, exponentOperator, exponentDefaultValue,
                                                                  mantissaOperator, mantissaDefaultValue, optional);
            IFieldValue retAuxId;

            if (fieldDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
            {
                composedDecimal.Id = retAuxId.ToString();
            }
            return(composedDecimal);
        }