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_);
        }
Beispiel #2
0
        public static ObjectSerial newSerial(XmlNode _node, bool _requiredClass)
        {
            XmlNamedNodeMap map_    = _node.Attributes;
            ObjectSerial    serial_ = new ObjectSerial();

            if (_requiredClass)
            {
                XmlNode className_ = map_.GetNamedItem(CLASS);
                if (className_ != null)
                {
                    serial_.setClassName(className_.Value);
                }
            }
            XmlNode types_    = map_.GetNamedItem(TYPES);
            string  typesStr_ = "";

            if (types_ != null)
            {
                typesStr_ = types_.Value;
            }
            Type class_ = Constants.classForName(_node.Name, typesStr_);

            serial_.types = class_.GetGenericArguments();
            ConstructorInfo constr_ = class_.GetConstructor(new Type[] { });
            //		constr_.setAccessible(class_.getAnnotation(RwXml.class)!=null);
            //constr_.setAccessible(constr_.getAnnotation(RwXml.class)!=null);
            XmlNode field_ = map_.GetNamedItem(FIELD);

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

            if (keyOfMap_ != null)
            {
                serial_.setKeyOfMap(true);
            }
            try {
                serial_.value = constr_.Invoke(new object[] { });
                //} catch (IllegalArgumentException e) {
                //} catch (IllegalAccessException e) {
                //   e.printStackTrace();

                /*} catch (InstantiationException e) {
                 *      throw e;*/
            } catch (TargetInvocationException e) {
                throw e;
            }
            return(serial_);
        }
Beispiel #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());
        }
Beispiel #4
0
        public static XmlDocument getSource(Object _serialisable)
        {
            //XmlDocument document_ = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            XmlDocument document_ = new XmlDocument();

            try {
                ElementsSerial primitive_;
                primitive_ = CurrentSerializableElements.createPrimitive(_serialisable);
                if (primitive_ != null)
                {
                    XmlElement elt_ = primitive_.serializeWithoutRef(document_);
                    document_.AppendChild(elt_);
                    return(document_);
                }
            } catch (Exception) {
            }
            //XmlNode firstNode_ = document_.CreateElement(_serialisable.GetType().FullName);
            //XmlNode firstNode_ = document_.CreateElement(_serialisable.GetType().FullName.Split(new string[] { "`" }, StringSplitOptions.None)[0]);
            ObjectSerial base_ = new ObjectSerial(_serialisable);

            //XmlNode firstNode_ = document_.CreateElement(ElementsSerial.getTypeName(_serialisable));
            XmlNode firstNode_ = base_.serializeWithoutRef(document_);

            document_.AppendChild(firstNode_);
            MyList <XmlNode> currentNodesToBeCompleted_ = new MyList <XmlNode>();

            currentNodesToBeCompleted_.Add(firstNode_);

            CurrentSerializableElements currentThread_ = new CurrentSerializableElements(base_);

            currentThread_.initializeObjectsWithoutIdRef();
            MyList <TemplateSerial> currentSerializableElements_ = new MyList <TemplateSerial>();

            currentSerializableElements_.Add(base_);
            MyList <XmlNode>        newNodesToBeCompleted_   = new MyList <XmlNode>();
            MyList <TemplateSerial> newSerializableElements_ = new MyList <TemplateSerial>();
            bool modif_ = true;

            while (modif_)
            {
                modif_ = false;
                newSerializableElements_ = new MyList <TemplateSerial>();
                newNodesToBeCompleted_   = new MyList <XmlNode>();
                int len_;
                len_ = currentNodesToBeCompleted_.size();
                for (int i = List.FIRST_INDEX; i < len_; i++)
                {
                    XmlNode               currentNode_         = currentNodesToBeCompleted_.get(i);
                    TemplateSerial        currentSerializable_ = currentSerializableElements_.get(i);
                    List <ElementsSerial> elts_ = currentThread_.getComponentComposite(currentSerializable_);
                    foreach (ElementsSerial e in elts_)
                    {
                        XmlNode newNode_ = e.serializeWithoutRef(document_);
                        if (e is TemplateSerial && !(e is EnumSerial))
                        {
                            TemplateSerial t_ = (TemplateSerial)e;
                            if (t_.getRef() == null)
                            {
                                newNodesToBeCompleted_.Add(newNode_);
                                newSerializableElements_.Add(t_);
                            }
                        }
                        currentNode_.AppendChild(newNode_);
                    }
                }
                if (!newSerializableElements_.isEmpty())
                {
                    currentNodesToBeCompleted_   = new MyList <XmlNode>(newNodesToBeCompleted_);
                    currentSerializableElements_ = new MyList <TemplateSerial>(newSerializableElements_);
                    modif_ = true;
                }
            }
            return(document_);
        }
 public CurrentSerializableElements(ObjectSerial _base)
 {
     currents.Add(_base);
 }