private static TemplateSerial createComposite(
            Object _value, bool _isKey, String _field, bool _isComparator)
        {
            if (_isComparator)
            {
                if (_value is IComparer)
                {
                    ComparatorSerial serializableFieldBis_ = new ComparatorSerial((IComparer)_value);
                    serializableFieldBis_.setKeyOfMap(_isKey);
                    serializableFieldBis_.setField(_field);
                    return(serializableFieldBis_);
                }
                return(null);
            }
            if (_value.GetType().IsArray)
            {
                ArraySerial serializableFieldTer_ = new ArraySerial((Array)_value);
                serializableFieldTer_.setKeyOfMap(_isKey);
                serializableFieldTer_.setField(_field);
                return(serializableFieldTer_);
            }
            ObjectSerial serializableField_ = new ObjectSerial(_value);

            serializableField_.setKeyOfMap(_isKey);
            serializableField_.setField(_field);
            return(serializableField_);
        }
Ejemplo n.º 2
0
        public static ArraySerial newListSerial(XmlNode _node)
        {
            if (!_node.Name.Equals(ARRAY))
            {
                //throw new ClassFoundException(_node.getNodeName(), ARRAY);
                throw new ClassFoundException();
            }
            XmlNamedNodeMap map_ = _node.Attributes;
            //		if (map_ == null) {
            //			throw new NoAttributeForSerializable(_node.getNodeName());
            //		}
            XmlNode className_ = map_.GetNamedItem(CLASS);
            XmlNode typeName_  = map_.GetNamedItem(ELEMENT_TYPE);

            if (typeName_ == null)
            {
                //throw new NoAttributeForSerializable(ELEMENT_TYPE, _node.getNodeName());
                throw new NoAttributeForSerializable();
            }
            ArraySerial listSerial_ = new ArraySerial();
            Type        class_;
            String      typeValue_ = typeName_.Value;

            try {
                class_ = Constants.classForName(typeValue_);
            } catch (Exception e_) {
                throw e_;
                //			if (typeValue_.equalsIgnoreCase(long.class.getName())) {
                //				class_ = long.class;
                //			} else if (typeValue_.equalsIgnoreCase(int.class.getName())) {
                //				class_ = int.class;
                //			} else if (typeValue_.equalsIgnoreCase(short.class.getName())) {
                //				class_ = short.class;
                //			} else if (typeValue_.equalsIgnoreCase(byte.class.getName())) {
                //				class_ = byte.class;
                //			} else if (typeValue_.equalsIgnoreCase(char.class.getName())) {
                //				class_ = char.class;
                //			} else if (typeValue_.equalsIgnoreCase(float.class.getName())) {
                //				class_ = float.class;
                //			} else if (typeValue_.equalsIgnoreCase(double.class.getName())) {
                //				class_ = double.class;
                //			} else if (typeValue_.equalsIgnoreCase(boolean.class.getName())) {
                //				class_ = boolean.class;
                //			} else {
                //				throw e_;
                //			}
            }
            listSerial_.array = Array.CreateInstance(class_, _node.ChildNodes.Count);
            XmlNode field_ = map_.GetNamedItem(FIELD);

            if (field_ != null)
            {
                listSerial_.setField(field_.Value);
            }
            XmlNode keyOfMap_ = map_.GetNamedItem(KEY);

            if (keyOfMap_ != null)
            {
                listSerial_.setKeyOfMap(true);
            }
            if (className_ != null)
            {
                listSerial_.setClassName(className_.Value);
            }
            return(listSerial_);
        }
Ejemplo n.º 3
0
        public static Object fromXmlStringObject(String _xmlString)
        {
            XmlElement root_ = XmlParser.documentElement(XmlParser.parseSax(_xmlString));

            try {
                ElementsSerial elt_ = createPrimitive(root_);
                if (elt_ != null)
                {
                    return(elt_.getValue());
                }
            } catch (Exception) {
            }
            MyList <XmlNode> currentNodesToBeRead_ = new MyList <XmlNode>();

            currentNodesToBeRead_.Add(root_);
            MyList <TemplateSerial> currentSerializableElements_ = new MyList <TemplateSerial>();
            ObjectSerial            rootElement_;

            rootElement_ = ObjectSerial.newSerial(root_, false);
            currentSerializableElements_.Add(rootElement_);
            MyList <XmlNode>        newNodesToBeRead_        = new MyList <XmlNode>();
            MyList <TemplateSerial> newSerializableElements_ = new MyList <TemplateSerial>();
            MyList <ObjectSerial>   notEmptyMaps_            = new MyList <ObjectSerial>();
            bool modif_ = true;

            while (modif_)
            {
                modif_ = false;
                newSerializableElements_ = new MyList <TemplateSerial>();
                newNodesToBeRead_        = new MyList <XmlNode>();
                int len_;
                len_ = currentNodesToBeRead_.size();
                for (int i = List.FIRST_INDEX; i < len_; i++)
                {
                    XmlNode        currentNode_  = currentNodesToBeRead_.get(i);
                    TemplateSerial composite_    = currentSerializableElements_.get(i);
                    bool           isTreeMap_    = false;
                    bool           containsTree_ = false;
                    foreach (XmlNode nCh_ in XmlParser.childrenNodes(currentNode_))
                    {
                        if (!(nCh_ is XmlElement))
                        {
                            continue;
                        }
                        containsTree_ = nCh_.Attributes.GetNamedItem(TemplateSerial.COMPARATOR) != null;
                        if (containsTree_)
                        {
                            break;
                        }
                    }
                    if (containsTree_)
                    {
                        isTreeMap_ = true;
                    }
                    MyList <ElementsSerial> elt_ = new MyList <ElementsSerial>();
                    foreach (XmlNode n in XmlParser.childrenNodes(currentNode_))
                    {
                        if (!(n is XmlElement))
                        {
                            continue;
                        }
                        try
                        {
                            ArraySerial serialArray_ = ArraySerial.newListSerial(n);
                            elt_.Add(serialArray_);
                            newSerializableElements_.Add(serialArray_);
                            newNodesToBeRead_.Add(n);
                            continue;
                        }
                        catch (NoAttributeForSerializable e_)
                        {
                            throw e_;
                        }
                        catch (ClassFoundException)
                        {
                        }
                        try
                        {
                            ElementsSerial primitive_ = createPrimitive(n);
                            if (primitive_ == null)
                            {
                                throw new NullReferenceException();
                            }
                            elt_.Add(primitive_);
                            continue;
                        }
                        catch (NoAttributeForSerializable e_)
                        {
                            throw e_;
                        }
                        catch (InexistingValueForEnum e_)
                        {
                            throw e_;
                        }
                        catch (FormatException e_)
                        {
                            throw e_;
                        }

                        /*catch (InvocationTargetException e_)
                         * {
                         *  throw e_;
                         * }
                         * catch (InstantiationException e_)
                         * {
                         *  throw e_;
                         * }
                         * catch (SecurityException e_)
                         * {
                         *  throw e_;
                         * }
                         * catch (ClassNotFoundException e_)
                         * {
                         *  throw e_;
                         * }*/
                        catch (NullReferenceException)
                        {
                        }
                        ComparatorSerial cmp_ = getCmpSerial(n, isTreeMap_, composite_);
                        if (cmp_ != null)
                        {
                            elt_.Add(cmp_);
                            newSerializableElements_.Add(cmp_);
                            newNodesToBeRead_.Add(n);
                            continue;
                        }
                        ObjectSerial serial_ = ObjectSerial.newSerial(n, true);
                        elt_.Add(serial_);
                        newSerializableElements_.Add(serial_);
                        newNodesToBeRead_.Add(n);
                    }
                    composite_.appendElementSerialWithoutRef(elt_);
                    if (composite_ is ObjectSerial)
                    {
                        if (!((ObjectSerial)composite_).mapIsEmpty())
                        {
                            notEmptyMaps_.Add((ObjectSerial)composite_);
                        }
                    }
                }
                if (!newSerializableElements_.isEmpty())
                {
                    currentNodesToBeRead_        = new MyList <XmlNode>(newNodesToBeRead_);
                    currentSerializableElements_ = new MyList <TemplateSerial>(newSerializableElements_);
                    modif_ = true;
                }
            }
            List <ObjectSerial> filledMaps_   = new MyList <ObjectSerial>();
            List <ObjectSerial> fillableMaps_ = new MyList <ObjectSerial>();

            /*foreach (ObjectSerial m in notEmptyMaps_) {
             *      if (m.keysAllDifferent()) {
             *              fillableMaps_.Add(m);
             *      }
             * }
             * while (true) {
             *      for (MayBeMap m : fillableMaps_) {
             *              m.setComponents();
             *              filledMaps_.add(m);
             *      }
             *      fillableMaps_.clear();
             *      for (MayBeMap m : notEmptyMaps_) {
             *              if (!m.keysAllDifferent()) {
             *                      continue;
             *              }
             *              if (filledMaps_.containsObj(m)) {
             *                      continue;
             *              }
             *              fillableMaps_.add(m);
             *      }
             *      if (fillableMaps_.isEmpty()) {
             *              break;
             *      }
             * }
             * for (MayBeMap m : notEmptyMaps_) {
             *      if (!filledMaps_.containsObj(m)) {
             *              m.setComponents();
             *      }
             * }*/
            return(rootElement_.getValue());
        }