Package org.apache.xindice.util

Source Code of org.apache.xindice.util.SymbolDeserializer

/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* CVS $Id: SymbolDeserializer.java,v 1.8 2004/02/08 02:59:39 vgritsenko Exp $
*/

package org.apache.xindice.util;

import org.apache.xindice.xml.SymbolTable;
import org.apache.xindice.xml.SymbolTableSymbols;
import org.apache.xindice.xml.dom.DocumentImpl;

import org.w3c.dom.Document;

import java.util.Hashtable;

/**
* SymbolDeserializer is a utility class for managing SymbolTables in
* the client context of Wire Compression.
*
* @version CVS $Revision: 1.8 $, $Date: 2004/02/08 02:59:39 $
*/
public final class SymbolDeserializer {
    private static final SymbolTableSymbols hcSyms = SymbolTableSymbols.getInstance();

    private SymbolTable syms = null; // The Collection's SymbolTable
    private long lastMod = 0;        // Last time we caught a SymbolTable modification

    /**
     * convertToDocument converts the compressed Hashtable to
     * a DOM Document.
     *
     * @param buffer The Hashtable
     * @return The Document
     */
    public Document convertToDocument(Hashtable buffer) {
        SymbolTable s = getSymbols(buffer);
        return new DocumentImpl((byte[]) buffer.get("document"), s, null);
    }

    /**
     * getSymbols returns the current SymbolTable image for the
     * server-side Collection that is being managed.  The Symbol
     * table is shipped as part of an Hashtable when the server
     * has determined that its image of the SymbolTable is out of
     * date.  This method either returns the current image or
     * extracts the new image from the Hashtable.
     *
     * @param buffer The Hashtable
     * @return The Symbol Table
     */
    public SymbolTable getSymbols(Hashtable buffer) {
        //if ( ((Long) buffer.get("timestamp")).longValue() != lastMod ) {
        // lastMod = ((Long) buffer.get("timestamp")).longValue();

        Document doc = new DocumentImpl((byte[]) buffer.get("symbols"), hcSyms, null);

        if (syms == null) {
            syms = new SymbolTable();
        }

        synchronized (syms) {
            syms.streamFromXML(doc.getDocumentElement());
        }
        // }
        return syms;
    }

    /**
     * getLastModified returns the last modified time stamp of the
     * client's image of the managed Symbol Table.
     *
     * @return The last modified stamp
     */
    public long getLastModified() {
        return lastMod;
    }
}
TOP

Related Classes of org.apache.xindice.util.SymbolDeserializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.