|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SymbolDeserializer.java | 50% | 84.6% | 75% | 73.9% |
|
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | * | |
17 | * $Id: SymbolDeserializer.java 712565 2008-11-09 21:52:26Z vgritsenko $ | |
18 | */ | |
19 | ||
20 | package org.apache.xindice.util; | |
21 | ||
22 | import org.apache.commons.logging.Log; | |
23 | import org.apache.commons.logging.LogFactory; | |
24 | import org.apache.xindice.xml.SymbolTable; | |
25 | import org.apache.xindice.xml.SymbolTableSymbols; | |
26 | import org.apache.xindice.xml.dom.DocumentImpl; | |
27 | ||
28 | import org.w3c.dom.Document; | |
29 | ||
30 | import java.util.Map; | |
31 | ||
32 | /** | |
33 | * SymbolDeserializer is a utility class for managing SymbolTables in | |
34 | * the client context of Wire Compression. | |
35 | * | |
36 | * @version $Revision: 712565 $, $Date: 2008-11-09 21:52:26 +0000 (Sun, 09 Nov 2008) $ | |
37 | */ | |
38 | public final class SymbolDeserializer { | |
39 | ||
40 | private static final Log log = LogFactory.getLog(SymbolSerializer.class); | |
41 | ||
42 | /** | |
43 | * The collection's SymbolTable | |
44 | */ | |
45 | private final SymbolTable syms; | |
46 | ||
47 | /** | |
48 | * Last time we caught a SymbolTable modification | |
49 | */ | |
50 | private long lastMod; | |
51 | ||
52 | ||
53 | 1138 | public SymbolDeserializer() { |
54 | 1138 | this.syms = new SymbolTable(); |
55 | } | |
56 | ||
57 | /** | |
58 | * getSymbols returns the Symbol Table being managed by this | |
59 | * deserializer. | |
60 | * | |
61 | * @return The Symbol Table | |
62 | */ | |
63 | 0 | public SymbolTable getSymbols() { |
64 | 0 | return syms; |
65 | } | |
66 | ||
67 | /** | |
68 | * getLastModified returns the last modified time stamp of the | |
69 | * client's image of the managed symbol table. | |
70 | * | |
71 | * @return The last modified stamp | |
72 | */ | |
73 | 176 | public long getLastModified() { |
74 | 176 | return lastMod; |
75 | } | |
76 | ||
77 | /** | |
78 | * getSymbols returns the current SymbolTable image for the | |
79 | * server-side Collection that is being managed. The Symbol | |
80 | * table is shipped as part of an Map when the server | |
81 | * has determined that its image of the SymbolTable is out of | |
82 | * date. This method either returns the current image or | |
83 | * extracts the new image from the Map. | |
84 | * | |
85 | * @param buffer The Map | |
86 | * @return The Symbol Table | |
87 | */ | |
88 | 169 | public SymbolTable getSymbols(Map buffer) { |
89 | 169 | byte[] symBytes = (byte[]) buffer.get("symbols"); |
90 | 169 | if (symBytes != null) { |
91 | 169 | String ts = (String) buffer.get("timestamp"); |
92 | 169 | if (log.isDebugEnabled()) { |
93 | 0 | log.info("Receiving symbols. Client ts=" + lastMod + ", Server ts=" + ts); |
94 | } | |
95 | ||
96 | 169 | Document doc = new DocumentImpl(symBytes, SymbolTableSymbols.getInstance(), null); |
97 | 169 | synchronized (syms) { |
98 | 169 | syms.streamFromXML(doc.getDocumentElement()); |
99 | // Server v1.1 won't be sending timestamp. Will use 0. | |
100 | 169 | lastMod = ts == null ? 0 : Long.parseLong(ts); |
101 | } | |
102 | } | |
103 | ||
104 | 169 | return syms; |
105 | } | |
106 | } |
|