Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 1998-2015 Caucho Technology -- all rights reserved
*
* This file is part of Baratine(TM)
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* Baratine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Baratine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
* of NON-INFRINGEMENT. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with Baratine; if not, write to the
*
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330
* Boston, MA 02111-1307 USA
*
* @author Scott Ferguson
*/
package com.caucho.v5.kelp.query;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Objects;
import com.caucho.v5.h3.OutFactoryH3;
import com.caucho.v5.io.TempOutputStream;
import com.caucho.v5.kelp.RowCursor;
import com.caucho.v5.kelp.TableKelp;
/**
* Query program for hessian.
*/
public class EnvKelp implements PredicateKelp // , Hessian2Constants
{
//private static final PathMapNullHessian _nullPathMap = PathMapNullHessian.MAP;
private static final Double DOUBLE_ZERO = new Double(0);
private static final Double DOUBLE_ONE = new Double(1);
private TableKelp _table;
private final PathKelp []_paths;
private final ExprKelp _expr;
private final Object []_values;
private Object []_args;
private PathMapHessian _topPathMap;
private PathMapHessian _pathMap;
private ArrayList _classDefs = new ArrayList<>();
private HashMap _attributeMap = new HashMap<>();
private InputStream _is;
private int _peek;
private RowCursor _cursor;
EnvKelp(TableKelp table,
PathKelp []paths,
ExprKelp expr,
int valueLength)
{
Objects.requireNonNull(paths);
Objects.requireNonNull(expr);
_paths = paths;
_expr = expr;
_values = new Object[valueLength];
}
public EnvKelp(EnvKelp query, Object []args)
{
_paths = query._paths;
_expr = query._expr;
_values = new Object[query._values.length];
_args = args;
}
public EnvKelp(Object []args)
{
_paths = new PathKelp[0];
_expr = null;
_values = new Object[0];
_args = args;
}
public Object []getArgs()
{
return _args;
}
public Object []values()
{
return _values;
}
public RowCursor getCursor()
{
return _cursor;
}
public OutFactoryH3 serializationFactory()
{
return _table.serializer();
}
public Object getAttribute(String key)
{
return _attributeMap.get(key);
}
public void setAttribute(String key, Object value)
{
_attributeMap.put(key, value);
}
public void setCursor(RowCursor cursor)
{
_cursor = cursor;
}
@Override
public boolean test(RowCursor cursor)
{
Arrays.fill(_values, null);
_cursor = cursor;
for (PathKelp path : _paths) {
path.scan(this, _values, cursor);
}
return _expr.evalBoolean(this);
}
public boolean matchHessian(InputStream is)
throws IOException
{
Arrays.fill(_values, null);
for (PathKelp path : _paths) {
path.scan(this, _values, is);
}
return _expr.evalBoolean(this);
}
public boolean match(PathMapHessian pathMap, InputStream is)
{
System.out.println("MAT: " + is);
try {
_topPathMap = pathMap;
_is = is;
_peek = -1;
_classDefs.clear();
_pathMap = _topPathMap;
return matchImpl();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private boolean matchImpl()
throws IOException
{
//scanObject();
return _expr.evalBoolean(this);
}
public void scan(PathMapHessian pathMap, InputStream is)
{
_topPathMap = pathMap;
_is = is;
_peek = -1;
_classDefs.clear();
_pathMap = _topPathMap;
//scanObject();
}
/*
void scanObject()
throws IOException
{
int ch = read();
switch (ch) {
case 0x00: case 0x01: case 0x02: case 0x03:
case 0x04: case 0x05: case 0x06: case 0x07:
case 0x08: case 0x09: case 0x0a: case 0x0b:
case 0x0c: case 0x0d: case 0x0e: case 0x0f:
case 0x10: case 0x11: case 0x12: case 0x13:
case 0x14: case 0x15: case 0x16: case 0x17:
case 0x18: case 0x19: case 0x1a: case 0x1b:
case 0x1c: case 0x1d: case 0x1e: case 0x1f:
skip(ch - 0x00);
break;
case BC_MAP: {
String type = readType();
scanMap(type);
break;
}
case BC_MAP_UNTYPED: {
scanMap(null);
break;
}
case BC_OBJECT_DEF: {
scanObjectDef();
scanObject();
break;
}
case 0x60: case 0x61: case 0x62: case 0x63:
case 0x64: case 0x65: case 0x66: case 0x67:
case 0x68: case 0x69: case 0x6a: case 0x6b:
case 0x6c: case 0x6d: case 0x6e: case 0x6f:
{
int index = ch - 0x60;
String []fields = _classDefs.get(index);
String type = fields[fields.length - 1];
scanObjectInstance(type, fields, fields.length - 1);
break;
}
case BC_OBJECT:
{
int index = scanInt();
String []fields = _classDefs.get(index);
String type = fields[fields.length - 1];
scanObjectInstance(type, fields, fields.length - 1);
break;
}
default:
_peek = ch;
skipObject();
break;
}
}
*/
private void scanObjectDef()
throws IOException
{
StringBuilder sb = new StringBuilder();
readString(sb);
String type = sb.toString();
//String type = readType();
int len = scanInt();
String []fields = new String[len + 1];
fields[fields.length - 1] = type;
for (int i = 0; i < len; i++) {
fields[i] = scanString();
}
_classDefs.add(fields);
}
/**
* Reads the Hessian value as an object.
*/
Object readObject()
throws IOException
{
int ch = read();
switch (ch) {
case 0x00: case 0x01: case 0x02: case 0x03:
case 0x04: case 0x05: case 0x06: case 0x07:
case 0x08: case 0x09: case 0x0a: case 0x0b:
case 0x0c: case 0x0d: case 0x0e: case 0x0f:
case 0x10: case 0x11: case 0x12: case 0x13:
case 0x14: case 0x15: case 0x16: case 0x17:
case 0x18: case 0x19: case 0x1a: case 0x1b:
case 0x1c: case 0x1d: case 0x1e: case 0x1f:
return readString(ch - 0x00);
case 0x20: case 0x21: case 0x22: case 0x23:
case 0x24: case 0x25: case 0x26: case 0x27:
case 0x28: case 0x29: case 0x2a: case 0x2b:
case 0x2c: case 0x2d: case 0x2e: case 0x2f:
return readBinary(ch - 0x20);
case 0x30: case 0x31: case 0x32: case 0x33:
return readString(((ch - 0x30) << 8) + read());
case 0x34: case 0x35: case 0x36: case 0x37:
return readBinary(((ch - 0x34) << 8) + read());
// long three-byte
case 0x3c: case 0x3d: case 0x3e: case 0x3f:
return new Long(((ch - 0x3c) << 16) + (read() << 8) + read());
case 0x41:
_peek = ch;
return readBinary();
case 0x42: {
int len = readShort();
return readBinary(len);
}
// class def
case 0x43:
scanObjectDef();
return readObject();
case 0x44: { /* double */
long value = readLong();
return Double.longBitsToDouble(value);
}
case 'E':
throw new UnsupportedOperationException("Invalid Hessian 'E' error code.");
case 0x46:
return Boolean.FALSE;
case 0x47: {
int type = scanInt();
return readObject();
}
// untyped variable map
case 0x48: {
HashMap