/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: SymbolDeserializer.java 595817 2007-11-16 20:49:03Z vgritsenko $
*/
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;
import java.util.Map;
/**
* SymbolDeserializer is a utility class for managing SymbolTables in
* the client context of Wire Compression.
*
* @version $Revision: 595817 $, $Date: 2007-11-16 15:49:03 -0500 (Fri, 16 Nov 2007) $
*/
public final class SymbolDeserializer {
private static final SymbolTableSymbols hcSyms = SymbolTableSymbols.getInstance();
/**
* The collection's SymbolTable
*/
private SymbolTable syms;
/**
* Last time we caught a SymbolTable modification
*/
private long lastMod;
/**
* 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(Map 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;
}
}