/// <exception cref="Org.Apache.Hadoop.Hdfs.Util.XMLUtils.InvalidXmlException"/>
        public static CachePoolInfo ReadCachePoolInfo(XMLUtils.Stanza st)
        {
            string        poolName = st.GetValue("POOLNAME");
            CachePoolInfo info     = new CachePoolInfo(poolName);

            if (st.HasChildren("OWNERNAME"))
            {
                info.SetOwnerName(st.GetValue("OWNERNAME"));
            }
            if (st.HasChildren("GROUPNAME"))
            {
                info.SetGroupName(st.GetValue("GROUPNAME"));
            }
            if (st.HasChildren("MODE"))
            {
                info.SetMode(FSEditLogOp.FsPermissionFromXml(st));
            }
            if (st.HasChildren("LIMIT"))
            {
                info.SetLimit(long.Parse(st.GetValue("LIMIT")));
            }
            if (st.HasChildren("MAXRELATIVEEXPIRY"))
            {
                info.SetMaxRelativeExpiryMs(long.Parse(st.GetValue("MAXRELATIVEEXPIRY")));
            }
            return(info);
        }
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Util.XMLUtils.InvalidXmlException"/>
        public static CacheDirectiveInfo ReadCacheDirectiveInfo(XMLUtils.Stanza st)
        {
            CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder();
            builder.SetId(long.Parse(st.GetValue("ID")));
            string path = st.GetValueOrNull("PATH");

            if (path != null)
            {
                builder.SetPath(new Path(path));
            }
            string replicationString = st.GetValueOrNull("REPLICATION");

            if (replicationString != null)
            {
                builder.SetReplication(short.ParseShort(replicationString));
            }
            string pool = st.GetValueOrNull("POOL");

            if (pool != null)
            {
                builder.SetPool(pool);
            }
            string expiryTime = st.GetValueOrNull("EXPIRATION");

            if (expiryTime != null)
            {
                builder.SetExpiration(CacheDirectiveInfo.Expiration.NewAbsolute(long.Parse(expiryTime
                                                                                           )));
            }
            return(builder.Build());
        }
 public override void StartDocument()
 {
     state       = OfflineEditsXmlLoader.ParseState.ExpectEditsTag;
     stanza      = null;
     stanzaStack = new Stack <XMLUtils.Stanza>();
     opCode      = null;
     cbuf        = new StringBuilder();
     nextTxId    = -1;
 }
        public override void EndElement(string uri, string name, string qName)
        {
            string str = XMLUtils.UnmangleXmlString(cbuf.ToString(), false).Trim();

            cbuf = new StringBuilder();
            switch (state)
            {
            case OfflineEditsXmlLoader.ParseState.ExpectEditsTag:
            {
                throw new XMLUtils.InvalidXmlException("expected <EDITS/>");
            }

            case OfflineEditsXmlLoader.ParseState.ExpectVersion:
            {
                if (!name.Equals("EDITS_VERSION"))
                {
                    throw new XMLUtils.InvalidXmlException("expected </EDITS_VERSION>");
                }
                try
                {
                    int version = System.Convert.ToInt32(str);
                    visitor.Start(version);
                }
                catch (IOException e)
                {
                    // Can't throw IOException from a SAX method, sigh.
                    throw new RuntimeException(e);
                }
                state = OfflineEditsXmlLoader.ParseState.ExpectRecord;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectRecord:
            {
                if (name.Equals("EDITS"))
                {
                    state = OfflineEditsXmlLoader.ParseState.ExpectEnd;
                }
                else
                {
                    if (!name.Equals("RECORD"))
                    {
                        throw new XMLUtils.InvalidXmlException("expected </EDITS> or </RECORD>");
                    }
                }
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectOpcode:
            {
                if (!name.Equals("OPCODE"))
                {
                    throw new XMLUtils.InvalidXmlException("expected </OPCODE>");
                }
                opCode = FSEditLogOpCodes.ValueOf(str);
                state  = OfflineEditsXmlLoader.ParseState.ExpectData;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectData:
            {
                throw new XMLUtils.InvalidXmlException("expected <DATA/>");
            }

            case OfflineEditsXmlLoader.ParseState.HandleData:
            {
                stanza.SetValue(str);
                if (stanzaStack.Empty())
                {
                    if (!name.Equals("DATA"))
                    {
                        throw new XMLUtils.InvalidXmlException("expected </DATA>");
                    }
                    state = OfflineEditsXmlLoader.ParseState.ExpectRecord;
                    FSEditLogOp op = opCache.Get(opCode);
                    opCode = null;
                    try
                    {
                        op.DecodeXml(stanza);
                        stanza = null;
                    }
                    finally
                    {
                        if (stanza != null)
                        {
                            System.Console.Error.WriteLine("fromXml error decoding opcode " + opCode + "\n" +
                                                           stanza.ToString());
                            stanza = null;
                        }
                    }
                    if (fixTxIds)
                    {
                        if (nextTxId <= 0)
                        {
                            nextTxId = op.GetTransactionId();
                            if (nextTxId <= 0)
                            {
                                nextTxId = 1;
                            }
                        }
                        op.SetTransactionId(nextTxId);
                        nextTxId++;
                    }
                    try
                    {
                        visitor.VisitOp(op);
                    }
                    catch (IOException e)
                    {
                        // Can't throw IOException from a SAX method, sigh.
                        throw new RuntimeException(e);
                    }
                    state = OfflineEditsXmlLoader.ParseState.ExpectRecord;
                }
                else
                {
                    stanza = stanzaStack.Pop();
                }
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectEnd:
            {
                throw new XMLUtils.InvalidXmlException("not expecting anything after </EDITS>");
            }
            }
        }
        public override void StartElement(string uri, string name, string qName, Attributes
                                          atts)
        {
            switch (state)
            {
            case OfflineEditsXmlLoader.ParseState.ExpectEditsTag:
            {
                if (!name.Equals("EDITS"))
                {
                    throw new XMLUtils.InvalidXmlException("you must put " + "<EDITS> at the top of the XML file! "
                                                           + "Got tag " + name + " instead");
                }
                state = OfflineEditsXmlLoader.ParseState.ExpectVersion;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectVersion:
            {
                if (!name.Equals("EDITS_VERSION"))
                {
                    throw new XMLUtils.InvalidXmlException("you must put " + "<EDITS_VERSION> at the top of the XML file! "
                                                           + "Got tag " + name + " instead");
                }
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectRecord:
            {
                if (!name.Equals("RECORD"))
                {
                    throw new XMLUtils.InvalidXmlException("expected a <RECORD> tag");
                }
                state = OfflineEditsXmlLoader.ParseState.ExpectOpcode;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectOpcode:
            {
                if (!name.Equals("OPCODE"))
                {
                    throw new XMLUtils.InvalidXmlException("expected an <OPCODE> tag");
                }
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectData:
            {
                if (!name.Equals("DATA"))
                {
                    throw new XMLUtils.InvalidXmlException("expected a <DATA> tag");
                }
                stanza = new XMLUtils.Stanza();
                state  = OfflineEditsXmlLoader.ParseState.HandleData;
                break;
            }

            case OfflineEditsXmlLoader.ParseState.HandleData:
            {
                XMLUtils.Stanza parent = stanza;
                XMLUtils.Stanza child  = new XMLUtils.Stanza();
                stanzaStack.Push(parent);
                stanza = child;
                parent.AddChild(name, child);
                break;
            }

            case OfflineEditsXmlLoader.ParseState.ExpectEnd:
            {
                throw new XMLUtils.InvalidXmlException("not expecting anything after </EDITS>");
            }
            }
        }