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_);
        }
예제 #2
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());
        }
예제 #3
0
        public override void appendElementSerialWithoutRef(MyList <ElementsSerial> _elt)
        {
            keys   = new MyList <object>();
            values = new MyList <object>();
            MethodInfo ADD_METHOD = value.GetType().GetMethod("Add", types);

            foreach (ElementsSerial e in _elt)
            {
                if (e is ComparatorSerial)
                {
                    continue;
                }
                Type   t_        = typeof(IEnumerable);
                string fullType_ = Constants.getTypeFullString(t_);
                if (fullType_.ToLower().Equals(e.getClassName().ToLower()))
                {
                    object obj_ = e.getValue();

                    /*if (obj_ != null)
                     * {
                     *  if (obj_.GetType().IsPrimitive)
                     *  {
                     *      if (types.ElementAt(0).IsEnum)
                     *      {
                     *          throw new ArgumentException();
                     *          //Console.WriteLine("%%%"+ obj_);
                     *      }
                     *  }
                     *  if (types.ElementAt(0).IsPrimitive)
                     *  {
                     *      if (obj_.GetType().IsEnum)
                     *      {
                     *          throw new ArgumentException();
                     *          //Console.WriteLine("%%%"+ obj_);
                     *      }
                     *  }
                     * }*/
                    ADD_METHOD.Invoke(value, new object[] { obj_ });
                    continue;
                }

                /*if (typeof(IEnumerable).FullName.ToLower().Equals(e.getClassName().ToLower()))
                 * {
                 *                  ADD_METHOD.Invoke(value, new object[] { e.getValue() });
                 *                  continue;
                 *          }*/
            }
            foreach (ElementsSerial e in _elt)
            {
                if (e is ComparatorSerial)
                {
                    cmpSerial = (ComparatorSerial)e;
                    continue;
                }
                Type   t_        = typeof(ListableKey);
                string fullType_ = Constants.getTypeFullString(t_);
                if (!fullType_.ToLower().Equals(e.getClassName().ToLower()))
                {
                    continue;
                }
                object obj_ = e.getValue();

                /*if (!typeof(ListableKey).FullName.ToLower().Equals(e.getClassName().ToLower()))
                 * {
                 *  continue;
                 * }*/
                /*if (!e.getClassName().equalsIgnoreCase(Map.class.getName())) {
                 *              continue;
                 *          }*/
                if (!e.isKeyOfMap())
                {
                    /*if (obj_ != null)
                     * {
                     *  if (obj_.GetType().IsPrimitive)
                     *  {
                     *      if (types.ElementAt(1).IsEnum)
                     *      {
                     *          throw new ArgumentException();
                     *          //Console.WriteLine("%%%"+ obj_);
                     *      }
                     *  }
                     *  if (types.ElementAt(1).IsPrimitive)
                     *  {
                     *      if (obj_.GetType().IsEnum)
                     *      {
                     *          throw new ArgumentException();
                     *          //Console.WriteLine("%%%"+ obj_);
                     *      }
                     *  }
                     * }*/
                    values.Add(e.getValue());
                }
                else
                {
                    /*if (obj_ != null)
                     * {
                     *  if (obj_.GetType().IsPrimitive)
                     *  {
                     *      if (types.ElementAt(0).IsEnum)
                     *      {
                     *          throw new ArgumentException();
                     *          //Console.WriteLine("%%%"+ obj_);
                     *      }
                     *  }
                     *  if (types.ElementAt(0).IsPrimitive)
                     *  {
                     *      if (obj_.GetType().IsEnum)
                     *      {
                     *          throw new ArgumentException();
                     *          //Console.WriteLine("%%%"+ obj_);
                     *      }
                     *  }
                     * }*/
                    keys.Add(e.getValue());
                }
            }
            foreach (ElementsSerial e in _elt)
            {
                if (e is ComparatorSerial)
                {
                    continue;
                }
                Type   t_        = typeof(IEnumerable);
                string fullType_ = Constants.getTypeFullString(t_);
                //Console.WriteLine(e.getClassName() + "%%" + fullType_);

                /*Type t2_ = typeof(IEnumerable);
                 * string str2_ = ElementsSerial.getType(t_);
                 * string assName2_ = t_.Assembly.GetName().Name;
                 * string fullType2_ = assName_ + ".." + str_;*/
                if (fullType_.ToLower().Equals(e.getClassName().ToLower()))
                {
                    continue;
                }
                t_        = typeof(ListableKey);
                fullType_ = Constants.getTypeFullString(t_);
                if (fullType_.ToLower().Equals(e.getClassName().ToLower()))
                {
                    continue;
                }

                /*if (typeof(IEnumerable).FullName.ToLower().Equals(e.getClassName().ToLower()))
                 * {
                 *  continue;
                 * }
                 * if (typeof(ListableKey).FullName.ToLower().Equals(e.getClassName().ToLower()))
                 * {
                 *  continue;
                 * }*/
                /*if (e.getClassName().equalsIgnoreCase(List.class.getName())) {
                 *                  continue;
                 *          }
                 *          if (e.getClassName().equalsIgnoreCase(Map.class.getName())) {
                 *                  continue;
                 *          }*/
                //Type class_ = Constants.classForName(e.getClassName());
                string str_ = e.getClassName();
                Type   class_;
                if (str_.Contains(SPECIAL_SEP))
                {
                    string types_ = str_.Substring(str_.IndexOf(SPECIAL_SEP));
                    class_ = Constants.classForName(str_, types_);
                }
                else
                {
                    class_ = Constants.classForName(str_);
                }
                if (!class_.IsInstanceOfType(value))
                {
                    continue;
                }

                /*FieldInfo field_ = class_.GetField(e.getField(), BindingFlags.NonPublic |
                 * BindingFlags.Instance);*/
                FieldInfo field_ = SerializeXmlObject.getField(class_, e.getField());
                object    obj_   = e.getValue();

                /*if (obj_ != null)
                 * {
                 *  if (obj_.GetType().IsPrimitive)
                 *  {
                 *      if (field_.FieldType.IsEnum)
                 *      {
                 *          throw new ArgumentException();
                 *          //Console.WriteLine("%%%"+ obj_);
                 *      }
                 *  }
                 *  if (obj_.GetType().IsEnum)
                 *  {
                 *      if (field_.FieldType.IsPrimitive)
                 *      {
                 *          throw new ArgumentException();
                 *          //Console.WriteLine("%%%"+ obj_);
                 *      }
                 *  }
                 * }*/
                /*if (!SerializeXmlObject.isUpdateFinalFields()) {
                 *                  if (Modifier.isFinal(field_.getModifiers())) {
                 *                          continue;
                 *                  }
                 *          }
                 *          if (Modifier.isStatic(field_.getModifiers())) {
                 *                  continue;
                 *          }*/
                //field_.setAccessible(class_.getAnnotation(RwXml.class)!=null);

                field_.SetValue(value, e.getValue());
            }
            if (value is ListableKey && !(value is IComparableKeys))
            {
                FieldInfo LIST_FIELD = value.GetType().GetField("list", BindingFlags.NonPublic |
                                                                BindingFlags.Instance);
                Object list_ = LIST_FIELD.GetValue(value);
                ADD_METHOD = list_.GetType().GetMethod("Add");
                Type treeMapTypeGene_ = typeof(Map <,>);
                //string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + ".." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name;
                string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + "." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name;
                treeMapType_ = treeMapType_.Substring(0, treeMapType_.IndexOf(ElementsSerial.SPECIAL_SEP) + 1);
                Type curType_ = value.GetType();
                while (true)
                {
                    if (curType_ == null)
                    {
                        break;
                    }
                    if (Constants.getTypeFullString(curType_).StartsWith(treeMapType_))
                    {
                        break;
                    }
                    curType_ = curType_.BaseType;
                }
                Type[]          args_        = curType_.GetGenericArguments();
                Type            genericType_ = typeof(Entry <,>).MakeGenericType(args_);
                ConstructorInfo ctor_        = genericType_.GetConstructor(args_);
                int             len_         = keys.size();
                for (int i = 0; i < len_; i++)
                {
                    //PUT_METHOD.invoke(value, keys.get(i),values.get(i));
                    object e_ = ctor_.Invoke(new object[] { keys.get(i), values.get(i) });
                    ADD_METHOD.Invoke(list_, new object[] { e_ });
                }
                keys.Clear();
                values.Clear();
            }
            if (value is IComparableKeys)
            {
                Type treeMapTypeGene_ = typeof(TreeMap <,>);
                //string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + ".." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name;
                string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + "." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name;
                treeMapType_ = treeMapType_.Substring(0, treeMapType_.IndexOf(ElementsSerial.SPECIAL_SEP) + 1);
                Type curType_ = value.GetType();
                while (true)
                {
                    if (curType_ == null)
                    {
                        break;
                    }
                    if (Constants.getTypeFullString(curType_).StartsWith(treeMapType_))
                    {
                        break;
                    }
                    curType_ = curType_.BaseType;
                }
                Type[] args_ = curType_.GetGenericArguments();
                if (cmpSerial != null)
                {
                    Type dicoMapType_;    // = typeof(SortedDictionary<,>);
                    Type speTreeMapType_; // = dicoMapType_.MakeGenericType(args_);

                    /*foreach (PropertyInfo p in SerializeXmlObject.getProperties(speTreeMapType_))
                     * {
                     *  Console.WriteLine(p.Name);
                     * }*/
                    //PropertyInfo p_ = SerializeXmlObject.getProperty(speTreeMapType_, COMPARATOR);
                    //f_.setAccessible(true);
                    //Console.WriteLine(cmpSerial.getValue().GetType());
                    //Console.WriteLine(p_.PropertyType);
                    //p_.GetSetMethod(true)
                    //p_.GetSetMethod(true).Invoke(value, new object[] { cmpSerial.getValue() });
                    //p_.SetValue(value, cmpSerial.getValue());
                    dicoMapType_    = typeof(TreeMap <,>);
                    speTreeMapType_ = dicoMapType_.MakeGenericType(args_);
                    FieldInfo f_ = SerializeXmlObject.getField(speTreeMapType_, "comparator");
                    //f_.setAccessible(true);
                    f_.SetValue(value, cmpSerial.getValue());
                }
                MethodInfo m_   = curType_.GetMethod("put", args_);
                int        len_ = keys.size();
                for (int i = 0; i < len_; i++)
                {
                    m_.Invoke(value, new object[] { keys.get(i), values.get(i) });
                }
                keys.Clear();
                values.Clear();
            }

            /*if (PairUtil.isMap(value)) {
             *
             * }*/
        }
예제 #4
0
        public override void appendElementSerial(MyList <ElementsSerial> _elt)
        {
            indexesRef = new Map <int?, long?>();
            int i_ = 0;

            keys           = new MyList <object>();
            keysIndexesRef = new Map <int?, long?>();
            int iKey_ = 0;

            values           = new MyList <object>();
            valuesIndexesRef = new Map <int?, long?>();
            int        iValue_    = 0;
            MethodInfo ADD_METHOD = value.GetType().GetMethod("Add");

            foreach (ElementsSerial e in _elt)
            {
                if (e is ComparatorSerial)
                {
                    continue;
                }
                if (typeof(IEnumerable).FullName.ToLower().Equals(e.getClassName().ToLower()))
                {
                    if (e is TemplateSerial)
                    {
                        if (((TemplateSerial)e).getRef() != null)
                        {
                            indexesRef.put(i_, ((TemplateSerial)e).getRef());
                        }
                    }
                    ADD_METHOD.Invoke(value, new object[] { e.getValue() });
                    i_++;
                    continue;
                }
            }
            foreach (ElementsSerial e in _elt)
            {
                if (e is ComparatorSerial)
                {
                    cmpSerial = (ComparatorSerial)e;
                    continue;
                }
                //ListableKey
                //
                if (!typeof(ListableKey).FullName.ToLower().Equals(e.getClassName().ToLower()))
                {
                    continue;
                }

                /*if (!e.getClassName().equalsIgnoreCase(Map.class.getName())) {
                 *                  continue;
                 *          }*/
                if (!e.isKeyOfMap())
                {
                    if (e is TemplateSerial)
                    {
                        if (((TemplateSerial)e).getRef() != null)
                        {
                            valuesIndexesRef.put(iValue_, ((TemplateSerial)e).getRef());
                        }
                    }
                    values.Add(e.getValue());
                    iValue_++;
                }
                else
                {
                    if (e is TemplateSerial)
                    {
                        if (((TemplateSerial)e).getRef() != null)
                        {
                            keysIndexesRef.put(iKey_, ((TemplateSerial)e).getRef());
                        }
                    }
                    keys.Add(e.getValue());
                    iKey_++;
                }
            }
            foreach (ElementsSerial e in _elt)
            {
                if (e is ComparatorSerial)
                {
                    continue;
                }
                Type   t_        = typeof(IEnumerable);
                string fullType_ = Constants.getTypeFullString(t_);
                if (fullType_.ToLower().Equals(e.getClassName().ToLower()))
                {
                    continue;
                }
                t_        = typeof(ListableKey);
                fullType_ = Constants.getTypeFullString(t_);
                if (fullType_.ToLower().Equals(e.getClassName().ToLower()))
                {
                    continue;
                }

                /*if (e.getClassName().equalsIgnoreCase(List.class.getName())) {
                 *                  continue;
                 *          }
                 *          if (e.getClassName().equalsIgnoreCase(Map.class.getName())) {
                 *                  continue;
                 *          }*/
                string str_ = e.getClassName();
                Type   class_;
                if (str_.Contains(SPECIAL_SEP))
                {
                    string types_ = str_.Substring(str_.IndexOf(SPECIAL_SEP));
                    class_ = Constants.classForName(str_, types_);
                }
                else
                {
                    class_ = Constants.classForName(str_);
                }
                if (!class_.IsInstanceOfType(value))
                {
                    continue;
                }
                //FieldInfo field_ = class_.GetField(e.getField(), BindingFlags.NonPublic |
                //         BindingFlags.Instance);
                FieldInfo field_ = SerializeXmlObject.getField(class_, e.getField());

                /*if (!SerializeXmlObject.isUpdateFinalFields()) {
                 *                  if (Modifier.isFinal(field_.getModifiers())) {
                 *                          continue;
                 *                  }
                 *          }*/
                /*if (Modifier.isStatic(field_.getModifiers())) {
                 *                  continue;
                 *          }*/
                //field_.setAccessible(class_.getAnnotation(RwXml.class)!=null);
                field_.SetValue(value, e.getValue());
            }
        }