public void Prototype_Pattern_Test()
        {
            var factoryOne = new PrototypeFactory(new Ype(), new Rose(), new Apple());
            var factoryTwo = new PrototypeFactory(new Pine(), new Lothus(), new Papaya());

            var ype   = factoryOne.MakeTree();
            var rose  = factoryOne.MakeFlower();
            var apple = factoryOne.MakeFruit();

            var pine   = factoryTwo.MakeTree();
            var lothus = factoryTwo.MakeFlower();
            var papaya = factoryTwo.MakeFruit();

            Assert.AreEqual(ype.Warning, "Eu sou um ypê-roxo!");
            Assert.IsInstanceOfType(ype, typeof(Ype));

            Assert.AreEqual(rose.Warning, "Eu sou uma Rosa");
            Assert.IsInstanceOfType(rose, typeof(Rose));

            Assert.AreEqual(apple.Warning, "Eu sou uma Maçã!");
            Assert.IsInstanceOfType(apple, typeof(Apple));

            Assert.AreEqual(pine.Warning, "Eu sou um pinheiro!");
            Assert.IsInstanceOfType(pine, typeof(Pine));

            Assert.AreEqual(lothus.Warning, "Eu sou uma flor de lótus!");
            Assert.IsInstanceOfType(lothus, typeof(Lothus));

            Assert.AreEqual(papaya.Warning, "Eu sou um mamão!");
            Assert.IsInstanceOfType(papaya, typeof(Papaya));
        }
Exemplo n.º 2
0
		/* === (DE)SERIALIZATION === */
		
		/// <summary> Read the object from stream.</summary>
		//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
		public virtual void  readExternal(System.IO.BinaryReader dis, PrototypeFactory pf)
		{
			fallbackDefaultLocale = ExtUtil.readBool(dis);
			fallbackDefaultForm = ExtUtil.readBool(dis);
			
			localeResources =(OrderedMap < String, List< LocaleDataSource >>) ExtUtil.read(dis, new ExtWrapMap(String.
		}
Exemplo n.º 3
0
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     len = (int)ExtUtil.readNumeric(in_);
     for (int i = 0; i < len; i++)
     {
         gp[i] = ExtUtil.readDecimal(in_);
     }
 }
Exemplo n.º 4
0
 public void readExternal(BinaryReader in_renamed, PrototypeFactory pf)
 {
     isLocalizable_ = ExtUtil.readBool(in_renamed);
     setLabelInnerText(ExtUtil.nullIfEmpty(ExtUtil.readString(in_renamed)));
     TextID = ExtUtil.nullIfEmpty(ExtUtil.readString(in_renamed));
     value  = ExtUtil.nullIfEmpty(ExtUtil.readString(in_renamed));
     //index will be set by questiondef
 }
Exemplo n.º 5
0
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     ref_         = (IDataReference)ExtUtil.read(in_, new ExtWrapTagged(typeof(IDataReference)));
     method       = ExtUtil.readString(in_);
     action       = ExtUtil.readString(in_);
     mediaType    = ExtUtil.nullIfEmpty(ExtUtil.readString(in_));
     attributeMap = (Dictionary <String, String>)ExtUtil.read(in_, new ExtWrapMap(typeof(String), typeof(String)));
 }
Exemplo n.º 6
0
		//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
		public virtual void  readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf)
		{
			ref_Renamed = (IDataReference) ExtUtil.read(in_Renamed, new ExtWrapTagged(typeof(IDataReference)));
			method = ExtUtil.readString(in_Renamed);
			action = ExtUtil.nullIfEmpty(ExtUtil.readString(in_Renamed));
			mediaType = ExtUtil.nullIfEmpty(ExtUtil.readString(in_Renamed));
			
			attributeMap =(HashMap < String, String >) ExtUtil.read(in, new ExtWrapMap(String.
		}
Exemplo n.º 7
0
        public void readExternal(BinaryReader in_, PrototypeFactory pf)
        {
            int length = in_.ReadInt32();

            data = new IDataPointer[length];
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = (IDataPointer)ExtUtil.read(in_, new ExtWrapTagged());
            }
        }
Exemplo n.º 8
0
        /* (non-Javadoc)
         * @see org.javarosa.core.services.storage.utilities.Externalizable#readExternal(java.io.DataInputStream)
         */
        public void readExternal(BinaryReader in_, PrototypeFactory pf)
        {
            ID            = ((String)ExtUtil.read(in_, new ExtWrapNullable(typeof(String)), pf));
            DataType      = (ExtUtil.readInt(in_));
            Preload       = ((String)ExtUtil.read(in_, new ExtWrapNullable(typeof(String)), pf));
            PreloadParams = ((String)ExtUtil.read(in_, new ExtWrapNullable(typeof(String)), pf));
            ref_          = (IDataReference)ExtUtil.read(in_, new ExtWrapTagged());

            //don't bother reading relevancy/required/readonly/constraint/calculate right now; they're only used during parse anyway
        }
Exemplo n.º 9
0
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     if (in_.ReadByte() == (byte)0x00)
     {
         d = ExtUtil.readNumeric(in_);
     }
     else
     {
         d = ExtUtil.readDecimal(in_);
     }
 }
Exemplo n.º 10
0
        public void readExternal(BinaryReader in_renamed, PrototypeFactory pf)
        {
            id = (XPathQName)ExtUtil.read(in_renamed, typeof(XPathQName));
            ArrayList v = (ArrayList)ExtUtil.read(in_renamed, new ExtWrapListPoly(), pf);

            args = new XPathExpression[v.Count];
            for (int i = 0; i < args.Length; i++)
            {
                args[i] = (XPathExpression)v[i];
            }
        }
Exemplo n.º 11
0
        /*
         * (non-Javadoc)
         *
         * @see
         * org.javarosa.core.services.storage.utilities.Externalizable#readExternal
         * (java.io.DataInputStream)
         */
        public void readExternal(BinaryReader in_, PrototypeFactory pf)
        {
            id        = ExtUtil.readInt(in_);
            formId    = ExtUtil.readInt(in_);
            name      = (String)ExtUtil.read(in_, new ExtWrapNullable(typeof(String)), pf);
            schema    = (String)ExtUtil.read(in_, new ExtWrapNullable(typeof(String)), pf);
            dateSaved = (DateTime)ExtUtil.read(in_, new ExtWrapNullable(typeof(DateTime)), pf);

            namespaces = (Hashtable)ExtUtil.read(in_, new ExtWrapMap(typeof(String), typeof(String)));
            setRoot((TreeElement)ExtUtil.read(in_, typeof(TreeElement), pf));
        }
Exemplo n.º 12
0
        /* (non-Javadoc)
         * @see org.javarosa.core.util.externalizable.Externalizable#readExternal(java.io.DataInputStream, org.javarosa.core.util.externalizable.PrototypeFactory)
         */
        //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
        public virtual void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf)
        {
            int length = in_Renamed.ReadInt32();

            if (length > 0)
            {
                this.payload = new byte[length];
                in_Renamed.Read(this.payload, 0, this.payload.Length);
            }
            id = ExtUtil.nullIfEmpty(ExtUtil.readString(in_Renamed));
        }
Exemplo n.º 13
0
        public void readExternal(BinaryReader in_, PrototypeFactory pf)
        {
            x = (XPathExpression)ExtUtil.read(in_, new ExtWrapTagged(), pf);
            ArrayList v = (ArrayList)ExtUtil.read(in_, new ExtWrapListPoly(), pf);

            predicates = new XPathExpression[v.Count];
            for (int i = 0; i < predicates.Length; i++)
            {
                predicates[i] = (XPathExpression)v[i];
            }
        }
Exemplo n.º 14
0
 public void readExternal(BinaryReader in_renamed, PrototypeFactory pf)
 {
     nodesetRef   = (TreeReference)ExtUtil.read(in_renamed, typeof(TreeReference), pf);
     nodesetExpr  = (IConditionExpr)ExtUtil.read(in_renamed, new ExtWrapTagged(), pf);
     contextRef   = (TreeReference)ExtUtil.read(in_renamed, typeof(TreeReference), pf);
     labelRef     = (TreeReference)ExtUtil.read(in_renamed, typeof(TreeReference), pf);
     labelExpr    = (IConditionExpr)ExtUtil.read(in_renamed, new ExtWrapTagged(), pf);
     valueRef     = (TreeReference)ExtUtil.read(in_renamed, new ExtWrapNullable(typeof(TreeReference)), pf);
     valueExpr    = (IConditionExpr)ExtUtil.read(in_renamed, new ExtWrapNullable(new ExtWrapTagged()), pf);
     copyRef      = (TreeReference)ExtUtil.read(in_renamed, new ExtWrapNullable(typeof(TreeReference)), pf);
     labelIsItext = ExtUtil.readBool(in_renamed);
     copyMode     = ExtUtil.readBool(in_renamed);
 }
Exemplo n.º 15
0
        //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
        public virtual void  readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf)
        {
            refLevel     = ExtUtil.readInt(in_Renamed);
            instanceName = ((System.String)ExtUtil.read(in_Renamed, new ExtWrapNullable(typeof(System.String)), pf));
            contextType  = ExtUtil.readInt(in_Renamed);
            int size = ExtUtil.readInt(in_Renamed);

            for (int i = 0; i < size; ++i)
            {
                TreeReferenceLevel level = (TreeReferenceLevel)ExtUtil.read(in_Renamed, typeof(TreeReferenceLevel));
                this.add(level.intern());
            }
        }
Exemplo n.º 16
0
        /**
         * deserialize a compact instance. note the retrieval of the template data instance
         */
        public void readExternal(BinaryReader in_renamed, PrototypeFactory pf)
        {
            int formID = ExtUtil.readInt(in_renamed);

            instance = getTemplateInstance(formID).clone();

            instance.ID = (ExtUtil.readInt(in_renamed));
            instance.setDateSaved((DateTime)ExtUtil.read(in_renamed, new ExtWrapNullable(typeof(DateTime))));
            //formID, name, schema, versions, and namespaces are all invariants of the template instance

            TreeElement root = instance.getRoot();

            readTreeElement(root, in_renamed, pf);
        }
Exemplo n.º 17
0
        /* === (DE)SERIALIZATION === */

        /**
         * Read the object from stream.
         */
        public void readExternal(System.IO.BinaryReader dis, PrototypeFactory pf)
        {
            fallbackDefaultLocale = ExtUtil.readBool(dis);
            fallbackDefaultForm   = ExtUtil.readBool(dis);
            localeResources       = (OrderedHashtable)ExtUtil.read(dis, new ExtWrapMap(typeof(String), new ExtWrapListPoly(), 1), pf);;
            locales = (ArrayList)ExtUtil.read(dis, new ExtWrapList(typeof(String)));
            setDefaultLocale((String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf));
            String currentLocale = (String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf);

            if (currentLocale != null)
            {
                Locale = currentLocale;
            }
        }
Exemplo n.º 18
0
        public void readExternal(BinaryReader in_, PrototypeFactory pf)
        {
            init_context = ExtUtil.readInt(in_);
            if (init_context == INIT_CONTEXT_EXPR)
            {
                filtExpr = (XPathFilterExpr)ExtUtil.read(in_, typeof(XPathFilterExpr), pf);
            }

            ArrayList v = (ArrayList)ExtUtil.read(in_, new ExtWrapList(typeof(XPathStep)), pf);

            steps = new XPathStep[v.Count];
            for (int i = 0; i < steps.Length; i++)
            {
                steps[i] = (XPathStep)v[i];
            }
        }
Exemplo n.º 19
0
            public override void readExternal(BinaryReader in_Renamed, PrototypeFactory pf)
            {
                byte flag = in_Renamed.ReadByte();

                if (flag == 0x00)
                {
                    val = null;
                }
                else
                {
                    Type answerType = classForDataType(dataType);

                    if (answerType == null)
                    {
                        //custom data types
                        val = ExtUtil.read(in_Renamed, new ExtWrapTagged(), pf);
                    }
                    else if (answerType == typeof(SelectOneData))
                    {
                        val = instance.getSelectOne(ExtUtil.read(in_Renamed, org.javarosa.core.model.instance.utils.CompactInstanceWrapper.CHOICE_MODE == org.javarosa.core.model.instance.utils.CompactInstanceWrapper.CHOICE_VALUE ? typeof(System.String) : typeof(System.Int32)));
                    }
                    else if (answerType == typeof(SelectMultiData))
                    {
                        val = instance.getSelectMulti((System.Collections.ArrayList)ExtUtil.read(in_Renamed, new ExtWrapList(org.javarosa.core.model.instance.utils.CompactInstanceWrapper.CHOICE_MODE == org.javarosa.core.model.instance.utils.CompactInstanceWrapper.CHOICE_VALUE ? typeof(System.String) : typeof(System.Int32))));
                    }
                    else
                    {
                        switch (flag)
                        {
                        case 0x40: answerType = typeof(StringData); break;

                        case 0x41: answerType = typeof(IntegerData); break;

                        case 0x42: answerType = typeof(DecimalData); break;

                        case 0x43: answerType = typeof(DateData); break;

                        case 0x44: answerType = typeof(BooleanData); break;
                        }

                        val = (IAnswerData)ExtUtil.read(in_Renamed, answerType);
                    }
                }
            }
        /// <summary>
        /// This example uses the Prototype creational pattern to help build a hypothetical Dining Room Designer.
        /// Users of the application can copy icons representing furniture to compose collections of objects at runtime.
        /// This Console Application is a mock example of some steps that might be part of client-side code for
        /// generating these shapes by deep-copying them from a prototype as a means of construction.
        /// It might also be the case that our client application does not have anything to work with except
        /// the roomDesigner instance - we might not be have the ability to __construct__ any of the objects, including the
        /// IChairIcon, ITableIcon, or PrototypeFactory instances.  In such cases, the ability for the PrototypeFactory
        /// to expose a public API for creating complex underlying objects is crucial to our being able to use these objects
        /// in our client-side code.
        /// </summary>
        /// <returns></returns>
        private static void Main()
        {
            var logger = new ConsoleLogger();

            logger.LogInfo("📝  Welcome Dining Room Designer!");

            // Construct prototype instances of furniture icons and a PrototypeFactory.
            var chairPrototype = new OakChairIcon();
            var tablePrototype = new OakTableIcon();
            var roomDesigner   = new PrototypeFactory(tablePrototype, chairPrototype, logger);

            // Use the RoomDesigner to create instances of furniture icons.
            var chair1 = roomDesigner.CloneChair();
            var chair2 = roomDesigner.CloneChair();
            var chair3 = roomDesigner.CloneChair();
            var chair4 = roomDesigner.CloneChair();
            var table1 = roomDesigner.CloneTable();

            var chairs = new List <IChairIcon> {
                chair1, chair2, chair3, chair4
            };

            var numberOfSeatCushionsToOrder = chairs.Count(chair => chair.HasSeatCushions);
            var numberOfTableLegs           = table1.GetTableNumberOfLegs();
            var tableShape = table1.GetTableTopShape();

            logger.LogInfo($"Current room design state includes a {tableShape}-shaped " +
                           $"table with {numberOfTableLegs} legs.");

            if (numberOfSeatCushionsToOrder == 0)
            {
                logger.LogInfo("No chairs in the design take seat cushions.");
            }

            logger.LogInfo("Chair Prototype Object HashCode:");
            logger.LogInfo(chairPrototype.GetHashCode().ToString(), ConsoleColor.Yellow);

            logger.LogInfo("Chair Object HashCodes:");
            logger.LogInfo(chair1.GetHashCode().ToString(), ConsoleColor.Yellow);
            logger.LogInfo(chair2.GetHashCode().ToString(), ConsoleColor.Yellow);
            logger.LogInfo(chair3.GetHashCode().ToString(), ConsoleColor.Yellow);
            logger.LogInfo(chair4.GetHashCode().ToString(), ConsoleColor.Yellow);
        }
Exemplo n.º 21
0
        /*
         * (non-Javadoc)
         * @see org.javarosa.core.util.Externalizable#readExternal(java.io.DataInputStream)
         */
        public void readExternal(BinaryReader dis, PrototypeFactory pf)
        {
            ID             = ExtUtil.readInt(dis);
            binding        = (IDataReference)ExtUtil.read(dis, new ExtWrapNullable(new ExtWrapTagged()), pf);
            AppearanceAttr = ((System.String)ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf));
            TextID         = ((System.String)ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf));
            LabelInnerText = ((System.String)ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf));
            HelpText       = ((System.String)ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf));
            HelpTextID     = ((System.String)ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf));
            HelpInnerText  = ((System.String)ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf));

            ControlType = ExtUtil.readInt(dis);

            choices = ExtUtil.nullIfEmpty((List <SelectChoice>)ExtUtil.read(dis, new ExtWrapList(typeof(SelectChoice)), pf));
            for (int i = 0; i < NumChoices; i++)
            {
                ((SelectChoice)choices[i]).Index = i;
            }
            DynamicChoices = (ItemsetBinding)ExtUtil.read(dis, new ExtWrapNullable(typeof(ItemsetBinding)));
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            //We create the initial price list
            //This has the products with the list price
            PriceListImpl standarPriceList = new PriceListImpl("Standar Price List");

            for (int c = 1; c <= 5; c++)
            {
                ProductItem item = new ProductItem("Product " + c, c * 2);
                standarPriceList.addProductItem(item);
            }
            PrototypeFactory.AddPrototype(standarPriceList.getListName(), standarPriceList);

            //Second list for wholesale customers from the list
            //standard with a 10% discount on the standard price list.
            PriceListImpl wholesalePriceList = (PriceListImpl)PrototypeFactory.GetPrototype("Standar Price List");

            wholesalePriceList.setListName("Wholesale Price List");
            foreach (ProductItem item in wholesalePriceList.getProducts())
            {
                item.Price = item.Price * 0.90;
            }
            PrototypeFactory.AddPrototype(wholesalePriceList.getListName(), wholesalePriceList);

            //Third price list for VIP customers from the list
            //wholesale with 10% on the wholesale price list.
            PriceListImpl vipPriceList = (PriceListImpl)PrototypeFactory.GetPrototype("Wholesale Price List");

            vipPriceList.setListName("VIP Price List");
            foreach (ProductItem item in vipPriceList.getProducts())
            {
                item.Price = item.Price * 0.90;
            }

            //Imprimimos las listas de precio.
            Console.WriteLine(standarPriceList);
            Console.WriteLine(wholesalePriceList);
            Console.WriteLine(vipPriceList);
        }
Exemplo n.º 23
0
        public void readExternal(BinaryReader in_, PrototypeFactory pf)
        {
            axis = ExtUtil.readInt(in_);
            test = ExtUtil.readInt(in_);

            switch (test)
            {
            case TEST_NAME: name = (XPathQName)ExtUtil.read(in_, typeof(XPathQName)); break;

            case TEST_NAMESPACE_WILDCARD: namespace_ = ExtUtil.readString(in_); break;

            case TEST_TYPE_PROCESSING_INSTRUCTION: literal = (String)ExtUtil.read(in_, new ExtWrapNullable(typeof(String))); break;
            }

            ArrayList v = (ArrayList)ExtUtil.read(in_, new ExtWrapListPoly(), pf);

            predicates = new XPathExpression[v.Count];
            for (int i = 0; i < predicates.Length; i++)
            {
                predicates[i] = (XPathExpression)v[i];
            }
        }
Exemplo n.º 24
0
        /** Reads a group definition object from the supplied stream. */
        public void readExternal(BinaryReader dis, PrototypeFactory pf)
        {
            ID = ExtUtil.readInt(dis);
            setAppearanceAttr((String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf));
            Bind           = (IDataReference)ExtUtil.read(dis, new ExtWrapTagged(), pf);
            TextID         = (String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf);
            LabelInnerText = ((String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf));
            Repeat         = (ExtUtil.readBool(dis));
            Children       = (List <IFormElement>)ExtUtil.read(dis, new ExtWrapListPoly(), pf);

            noAddRemove = ExtUtil.readBool(dis);
            count       = (IDataReference)ExtUtil.read(dis, new ExtWrapNullable(new ExtWrapTagged()), pf);

            chooseCaption    = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            addCaption       = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            delCaption       = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            doneCaption      = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            addEmptyCaption  = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            doneEmptyCaption = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            entryHeader      = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            delHeader        = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
            mainHeader       = ExtUtil.nullIfEmpty(ExtUtil.readString(dis));
        }
Exemplo n.º 25
0
    public void TestGenericInstanceCreation() {
      ConcretePrototype template = new ConcretePrototype(42);

      IAbstractFactory<IProduct> factory = new PrototypeFactory<
        IProduct, ConcretePrototype
      >(template);

      IProduct factoryCreatedProduct = factory.CreateInstance();

      Assert.AreEqual(template.Value, factoryCreatedProduct.Value);
    }
Exemplo n.º 26
0
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     s = ExtUtil.readString(in_);
 }
Exemplo n.º 27
0
 /* (non-Javadoc)
  * @see org.javarosa.core.services.storage.utilities.Externalizable#readExternal(java.io.DataInputStream)
  */
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     d = ExtUtil.readDecimal(in_);
 }
Exemplo n.º 28
0
    public void TestPrototypeDisposal() {
      ConcretePrototype template = new ConcretePrototype(42);

      PrototypeFactory<IProduct, ConcretePrototype> factory = new PrototypeFactory<
        IProduct, ConcretePrototype
      >(template);

      Assert.IsFalse(template.IsDisposed);
      factory.Dispose();
      Assert.IsTrue(template.IsDisposed);
    }
Exemplo n.º 29
0
 public override void metaReadExternal(BinaryReader in_, PrototypeFactory pf)
 {
     throw new SystemException("not supported");
 }
Exemplo n.º 30
0
        /**
         * recursively read in a node of the instance, by filling out the template instance
         * @param e
         * @param ref
         * @param in
         * @param pf
         * @throws IOException
         * @throws DeserializationException
         */
        private void readTreeElement(TreeElement e, BinaryReader in_, PrototypeFactory pf)
        {
            TreeElement templ   = instance.getTemplatePath(e.getRef());
            Boolean     isGroup = !templ.isLeaf();

            if (isGroup)
            {
                ArrayList childTypes = new ArrayList();
                for (int i = 0; i < templ.getNumChildren(); i++)
                {
                    String childName = templ.getChildAt(i).getName();
                    if (!childTypes.Contains(childName))
                    {
                        childTypes.Add(childName);
                    }
                }

                for (int i = 0; i < childTypes.Count; i++)
                {
                    String childName = (String)childTypes[i];

                    TreeReference childTemplRef = e.getRef().extendRef(childName, 0);
                    TreeElement   childTempl    = instance.getTemplatePath(childTemplRef);

                    Boolean repeatable = childTempl.repeatable;
                    int     n          = ExtUtil.readInt(in_);

                    Boolean relevant = (n > 0);
                    if (!repeatable && n > 1)
                    {
                        throw new DeserializationException("Detected repeated instances of a non-repeatable node");
                    }

                    if (repeatable)
                    {
                        int mult = e.getChildMultiplicity(childName);
                        for (int j = mult - 1; j >= 0; j--)
                        {
                            e.removeChild(childName, j);
                        }

                        for (int j = 0; j < n; j++)
                        {
                            TreeReference dstRef = e.getRef().extendRef(childName, j);
                            try
                            {
                                instance.copyNode(childTempl, dstRef);
                            }
                            catch (InvalidReferenceException ire)
                            {
                                //If there is an invalid reference, this is a malformed instance,
                                //so we'll throw a Deserialization exception.
                                TreeReference r = ire.InvalidReference;
                                if (r == null)
                                {
                                    throw new DeserializationException("Null Reference while attempting to deserialize! " + ire.Message);
                                }
                                else
                                {
                                    throw new DeserializationException("Invalid Reference while attemtping to deserialize! Reference: " + r.toString(true) + " | " + ire.Message);
                                }
                            }

                            TreeElement child = e.getChild(childName, j);
                            child.setRelevant(true);
                            readTreeElement(child, in_, pf);
                        }
                    }
                    else
                    {
                        TreeElement child = e.getChild(childName, 0);
                        child.setRelevant(relevant);
                        if (relevant)
                        {
                            readTreeElement(child, in_, pf);
                        }
                    }
                }
            }
            else
            {
                e.setValue((IAnswerData)ExtUtil.read(in_, new ExtWrapAnswerData(e.dataType)));
            }
        }
Exemplo n.º 31
0
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     constraint    = (IConditionExpr)ExtUtil.read(in_, new ExtWrapTagged(), pf);
     constraintMsg = ExtUtil.nullIfEmpty(ExtUtil.readString(in_));
     attemptConstraintCompile();
 }
Exemplo n.º 32
0
 public void readExternal(BinaryReader in_, PrototypeFactory pf)
 {
     base.readExternal(in_, pf);
 }