Author: vgritsenko Date: Fri Aug 10 19:38:13 2007 New Revision: 564822 URL: http://svn.apache.org/viewvc?view=rev&rev=564822 Log: cleanup exception handling around getSymbols(), and a bit more.
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java xml/xindice/trunk/java/src/org/apache/xindice/server/rpc/messages/GetResource.java Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?view=diff&rev=564822&r1=564821&r2=564822 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Fri Aug 10 19:38:13 2007 @@ -933,7 +933,7 @@ * * @return The Symbol Table */ - public final SymbolTable getSymbols() throws DBException { + public final SymbolTable getSymbols() { return symbols; } Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java?view=diff&rev=564822&r1=564821&r2=564822 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/DocumentCache.java Fri Aug 10 19:38:13 2007 @@ -81,16 +81,10 @@ } } else if (v.getValue() instanceof byte[]) { - try { - SymbolTable s = col.getSymbols(); - NodeSource ns = new NodeSource(col, key); - Document doc = new DocumentImpl((byte[]) v.getValue(), s, ns); - return new Entry(key, doc, v.getMeta()); - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("ignored exception", e); - } - } + SymbolTable s = col.getSymbols(); + NodeSource ns = new NodeSource(col, key); + Document doc = new DocumentImpl((byte[]) v.getValue(), s, ns); + return new Entry(key, doc, v.getMeta()); } return null; @@ -119,6 +113,7 @@ * @param col document collection * @param key document key * @param bytes compressed document + * @param meta document meta attributes map */ public void putDocument(Collection col, Key key, byte[] bytes, Map meta) { CacheKey ckey = new CacheKey(col, key); @@ -131,6 +126,7 @@ * @param col document collection * @param key document key * @param chars uncompressed document + * @param meta document meta attributes map */ public void putDocument(Collection col, Key key, String chars, Map meta) { CacheKey ckey = new CacheKey(col, key); Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java?view=diff&rev=564822&r1=564821&r2=564822 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java Fri Aug 10 19:38:13 2007 @@ -82,7 +82,7 @@ * @param collection Collection for this IndexManager * @throws DBException if can't get collection's symbols */ - public IndexManager(Collection collection, Timer timer) throws DBException { + public IndexManager(Collection collection, Timer timer) { this.collection = collection; this.symbols = collection.getSymbols(); this.timer = timer; Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java?view=diff&rev=564822&r1=564821&r2=564822 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java Fri Aug 10 19:38:13 2007 @@ -62,7 +62,15 @@ public NameIndexer() { - super(); + } + + public void setCollection(Collection collection) { + this.collection = collection; + this.symbols = collection.getSymbols(); + } + + private void setLocation(String location) { + setFile(new File(collection.getCollectionRoot(), location + ".idx")); } public void setConfig(Configuration config) { @@ -72,7 +80,7 @@ String pattern = config.getAttribute(PATTERN); wildcard = pattern.indexOf('*') != -1; - this.pattern = new IndexPattern(collection.getSymbols(), pattern, null); + this.pattern = new IndexPattern(symbols, pattern, null); setLocation(name); setupHandler(); @@ -107,21 +115,6 @@ return name; } - public void setLocation(String location) { - setFile(new File(collection.getCollectionRoot(), location + ".idx")); - } - - public void setCollection(Collection collection) { - try { - this.collection = collection; - symbols = collection.getSymbols(); - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("ignored exception", e); - } - } - } - public String getIndexStyle() { return STYLE_NODENAME; } @@ -131,34 +124,28 @@ } private Value getCombinedValue(Key key, short elemID, short attrID) { - Value result; - try { - int l = key.getLength(); - byte[] b = new byte[l + 5]; + int l = key.getLength(); + byte[] b = new byte[l + 5]; - // Write the key - key.copyTo(b, 0, l); - b[l] = 0; - - // Write the elemID - b[l + 1] = (byte) ((elemID >>> 8) & 0xFF); - b[l + 2] = (byte) ( elemID & 0xFF); - - // Write the attrID - b[l + 3] = (byte) ((attrID >>> 8) & 0xFF); - b[l + 4] = (byte) ( attrID & 0xFF); + // Write the key + key.copyTo(b, 0, l); + b[l] = 0; + + // Write the elemID + b[l + 1] = (byte) ((elemID >>> 8) & 0xFF); + b[l + 2] = (byte) ( elemID & 0xFF); + + // Write the attrID + b[l + 3] = (byte) ((attrID >>> 8) & 0xFF); + b[l + 4] = (byte) ( attrID & 0xFF); - result = new Value(b); - } catch (Exception e) { - result = null; // This will never happen - } - return result; + return new Value(b); } private IndexMatch getIndexMatch(Value v) { byte[] b = v.getData(); int l = b.length - 5; - Key key = new Key(b, 0, b.length - 5); + Key key = new Key(b, 0, l); short elemID = (short) ((b[l + 1] << 8) | b[l + 2]); short attrID = (short) ((b[l + 3] << 8) | b[l + 4]); Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java?view=diff&rev=564822&r1=564821&r2=564822 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java Fri Aug 10 19:38:13 2007 @@ -104,6 +104,15 @@ return header; } + public void setCollection(Collection collection) { + this.collection = collection; + symbols = collection.getSymbols(); + } + + private void setLocation(String location) { + setFile(new File(collection.getCollectionRoot(), location + ".idx")); + } + public void setConfig(Configuration config) { super.setConfig(config); try { @@ -142,7 +151,7 @@ } } - this.pattern = new IndexPattern(collection.getSymbols(), pattern, null); + this.pattern = new IndexPattern(symbols, pattern, null); typeSize = sizes[type]; setLocation(name); @@ -209,21 +218,6 @@ return name; } - public void setLocation(String location) { - setFile(new File(collection.getCollectionRoot(), location + ".idx")); - } - - public void setCollection(Collection collection) { - try { - this.collection = collection; - symbols = collection.getSymbols(); - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("ignored exception", e); - } - } - } - public String getIndexStyle() { return STYLE_NODEVALUE; } @@ -240,13 +234,12 @@ * index 0. Also, data arrays will behave as array of <b>unsigned</b> bytes with * values ranging from 0 to 255. * - * @param value + * @param value string value to convert * @return new Value object that represents specific value of this indexer type */ public Value getTypedValue(String value) { if (type != STRING && type != TRIMMED) { value = value.trim(); - if (value.length() == 0) { return EmptyValue; } @@ -356,46 +349,40 @@ } private Value getCombinedValue(Key key, int pos, int len, short elemID, short attrID) { - Value result; - try { - int l = key.getLength(); - byte[] b = new byte[l + 13]; + int l = key.getLength(); + byte[] b = new byte[l + 13]; - // Write the key - key.copyTo(b, 0, l); - b[l] = 0; - - // Write the pos - b[l + 1] = (byte) ((pos >>> 24) & 0xFF); - b[l + 2] = (byte) ((pos >>> 16) & 0xFF); - b[l + 3] = (byte) ((pos >>> 8) & 0xFF); - b[l + 4] = (byte) ( pos & 0xFF); - - // Write the len - b[l + 5] = (byte) ((len >>> 24) & 0xFF); - b[l + 6] = (byte) ((len >>> 16) & 0xFF); - b[l + 7] = (byte) ((len >>> 8) & 0xFF); - b[l + 8] = (byte) ( len & 0xFF); - - // Write the elemID - b[l + 9] = (byte) ((elemID >>> 8) & 0xFF); - b[l + 10] = (byte) ( elemID & 0xFF); - - // Write the attrID - b[l + 11] = (byte) ((attrID >>> 8) & 0xFF); - b[l + 12] = (byte) ( attrID & 0xFF); + // Write the key + key.copyTo(b, 0, l); + b[l] = 0; + + // Write the pos + b[l + 1] = (byte) ((pos >>> 24) & 0xFF); + b[l + 2] = (byte) ((pos >>> 16) & 0xFF); + b[l + 3] = (byte) ((pos >>> 8) & 0xFF); + b[l + 4] = (byte) ( pos & 0xFF); + + // Write the len + b[l + 5] = (byte) ((len >>> 24) & 0xFF); + b[l + 6] = (byte) ((len >>> 16) & 0xFF); + b[l + 7] = (byte) ((len >>> 8) & 0xFF); + b[l + 8] = (byte) ( len & 0xFF); + + // Write the elemID + b[l + 9] = (byte) ((elemID >>> 8) & 0xFF); + b[l + 10] = (byte) ( elemID & 0xFF); + + // Write the attrID + b[l + 11] = (byte) ((attrID >>> 8) & 0xFF); + b[l + 12] = (byte) ( attrID & 0xFF); - result = new Value(b); - } catch (Exception e) { - result = null; // This will never happen - } - return result; + return new Value(b); } private IndexMatch getIndexMatch(Value v) { byte[] b = v.getData(); int l = b.length - 13; - Key key = new Key(b, 0, b.length - 13); + Key key = new Key(b, 0, l); int pos = ((b[l + 1] << 24) | (b[l + 2] << 16) | (b[l + 3] << 8) | b[l + 4]); int len = ((b[l + 5] << 24) | (b[l + 6] << 16) | (b[l + 7] << 8) | b[l + 8]); Modified: xml/xindice/trunk/java/src/org/apache/xindice/server/rpc/messages/GetResource.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/server/rpc/messages/GetResource.java?view=diff&rev=564822&r1=564821&r2=564822 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/server/rpc/messages/GetResource.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/server/rpc/messages/GetResource.java Fri Aug 10 19:38:13 2007 @@ -56,19 +56,14 @@ Hashtable result = new Hashtable(); if (obj == null) { // Return empty result + } else if (obj.getEntryType() == Entry.BINARY) { // Binary resource result.put(RESULT, obj.getValue()); + } else if (message.containsKey(COMPRESSED)) { - SymbolSerializer symbolSerializer = null; - try { - symbolSerializer = new SymbolSerializer(col.getSymbols()); - } catch (Exception e) { - // It's ok (in theory) for a Collection to have no symbol table - if (log.isWarnEnabled()) { - log.warn("ignored exception", e); - } - } + // Compressed XML resource + SymbolSerializer symbolSerializer = new SymbolSerializer(col.getSymbols()); long timestamp = 1; /* TODO: Timestamp optimization. @@ -82,12 +77,14 @@ // Document might be compressed (with bytes) or not. In a latter case, convert to string. Document doc = (Document) obj.getValue(); - if (/*( timestamp != -1) &&*/ symbolSerializer != null && ((CompressedDocument) doc).getDataBytes() != null) { + if (/*( timestamp != -1) &&*/ ((CompressedDocument) doc).getDataBytes() != null) { result.put(RESULT, symbolSerializer.convertFromDocument(doc, timestamp)); } else { result.put(RESULT, TextWriter.toString(doc)); } + } else { + // XML resource Document doc = (Document) obj.getValue(); result.put(RESULT, TextWriter.toString(doc)); }