geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject [43/51] [partial] incubator-geode git commit: SGA #2
Date Fri, 03 Jul 2015 19:21:44 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/CQResult.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/CQResult.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/CQResult.java
new file mode 100644
index 0000000..aa5053a
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/CQResult.java
@@ -0,0 +1,235 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2011, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.gemstone.gemfire.cache.query.CqEvent;
+import com.gemstone.gemfire.cache.query.CqListener;
+import com.gemstone.gemfire.cache.query.Struct;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionRepository;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryUtil;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ResultSet;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event.ErrorEvent;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event.ICQEvent;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event.RowAdded;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event.RowDeleted;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event.RowUpdated;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.internal.PdxHelper;
+
+public final class CQResult implements ResultSet, CqListener {
+  private List<CQEventListener>            listeners;
+  private List<TypeListener>               type_listeners;
+  private Map<Object, IntrospectionResult> types;
+  private Map<Object, EventDataImpl>       key_to_value_map;
+
+  public CQResult() {
+    this.types = Collections
+        .synchronizedMap(new HashMap<Object, IntrospectionResult>());
+    this.key_to_value_map = Collections
+        .synchronizedMap(new HashMap<Object, EventDataImpl>());
+
+    this.listeners = Collections
+        .synchronizedList(new ArrayList<CQEventListener>());
+    this.type_listeners = Collections
+        .synchronizedList(new ArrayList<TypeListener>());
+  }
+
+  public void close() {
+    Collection<CQEventListener> _listeners = getCQEventListeners();
+    for (CQEventListener listener : _listeners) {
+      listener.close();
+    }
+  }
+
+  public Object getColumnValue(Object tuple, int index)
+      throws ColumnNotFoundException, ColumnValueNotAvailableException {
+    Object type = (tuple instanceof Struct) ? ((Struct) tuple).getStructType()
+        : tuple.getClass();
+
+    if (this.types.containsKey(type)) {
+      IntrospectionResult metaInfo = this.types.get(type);
+      return metaInfo.getColumnValue(tuple, index);
+    }
+
+    throw new ColumnNotFoundException("Could not identify type :" + type);
+  }
+
+  public IntrospectionResult[] getIntrospectionResult() {
+    return this.types.values().toArray(new IntrospectionResult[0]);
+  }
+
+  public Collection<?> getQueryResult() {
+    throw new UnsupportedOperationException();
+  }
+
+  public Collection<?> getQueryResult(IntrospectionResult metaInfo) {
+    throw new UnsupportedOperationException();
+  }
+
+  public boolean isEmpty() {
+    return this.key_to_value_map.isEmpty();
+  }
+
+  public void addCQEventListener(CQEventListener listener) {
+    this.listeners.add(listener);
+  }
+
+  public void removeCQEventListener(CQEventListener listener) {
+    this.listeners.remove(listener);
+  }
+
+  public void addTypeListener(TypeListener listener) {
+    this.type_listeners.add(listener);
+  }
+
+  public void removeTypeListener(TypeListener listener) {
+    this.type_listeners.remove(listener);
+  }
+
+  public void onEvent(CqEvent cqEvent) {
+    Object key = cqEvent.getKey();
+
+    // Here the entry is destroyed from the result set.
+    if (cqEvent.getQueryOperation().isDestroy()) {
+      // Clear the key_to_value map.
+      EventData data = this.key_to_value_map.remove(key);
+      if (data != null) {
+        RowDeleted delEvent = new RowDeleted(data);
+        invokeListeners(delEvent);
+      }
+    } else {
+      // Add/Update the entry operation.
+      Object value = cqEvent.getNewValue();
+      // The new entry value should be not-null for this.
+      if (value != null) {
+        try {
+          // Get the type of the object and invoke listeners if the new type is
+          // detected.
+          IntrospectionResult metaInfo = getObjectType(value);
+
+          EventDataImpl oldEvent = this.key_to_value_map.get(key);
+          // Old entry is available for this key.
+          if (oldEvent != null) {
+            IntrospectionResult oldMetaInfo = oldEvent.getIntrospectionResult();
+            // Types are same. Hence just update the record.
+            if (metaInfo.equals(oldMetaInfo)) {
+              oldEvent.setValue(metaInfo, value);
+              invokeListeners(new RowUpdated(oldEvent));
+
+            } else {
+              // Types are different. Delete the old record and add the new one.
+              EventDataImpl temp = (EventDataImpl) oldEvent.clone();
+              invokeListeners(new RowDeleted(temp));
+
+              oldEvent.setValue(metaInfo, value);
+              invokeListeners(new RowAdded(oldEvent));
+            }
+
+          } else {
+            // There is no old entry for this key. Add it as a new one.
+            EventDataImpl newValue = new EventDataImpl(key, value, metaInfo);
+            this.key_to_value_map.put(key, newValue);
+            invokeListeners(new RowAdded(newValue));
+          }
+        } catch (Exception e) {
+          ErrorEvent errorEvent = new ErrorEvent(e);
+          invokeListeners(errorEvent);
+        }
+      }
+    }
+  }
+
+  public void onError(CqEvent cqEvent) {
+    // Propagate the exception.
+    invokeListeners(new ErrorEvent(cqEvent.getThrowable()));
+  }
+
+  public EventData getValueForKey(Object key) {
+    return this.key_to_value_map.get(key);
+  }
+
+  public Set<Object> getKeys() {
+    Set<Object> keys = new HashSet<Object>();
+    synchronized (this.key_to_value_map) {
+      keys.addAll(this.key_to_value_map.keySet());
+    }
+
+    return keys;
+  }
+
+  private void invokeListeners(ICQEvent event) {
+    Collection<CQEventListener> _listeners = getCQEventListeners();
+
+    for (CQEventListener listener : _listeners) {
+      listener.onEvent(event);
+    }
+  }
+
+  private IntrospectionResult getObjectType(Object value)
+      throws IntrospectionException {
+    Object type = value.getClass();
+    if (QueryUtil.isPdxInstance(value)) {
+      //PdxInfoType is used for PdxInstance
+      type = PdxHelper.getInstance().getPdxInfoType(value);
+    }
+    IntrospectionResult metaInfo = this.types.get(type);
+    if (metaInfo == null) {
+      metaInfo = IntrospectionRepository.singleton().introspectTypeByObject(value);
+      this.types.put(type, metaInfo);
+
+      notifyTypeListeners(metaInfo);
+    }
+
+    return metaInfo;
+  }
+
+  /**
+   * Notifies the available TypeListeners about newly added IntrospectionResult
+   * 
+   * @param metaInfo
+   *          newly added IntrospectionResult
+   */
+  private void notifyTypeListeners(IntrospectionResult metaInfo) {
+    Collection<TypeListener> typeListeners = getTypeListeners();
+
+    for (TypeListener listener : typeListeners) {
+      listener.onNewTypeAdded(metaInfo);
+    }
+  }
+
+  private Collection<CQEventListener> getCQEventListeners() {
+    List<CQEventListener> result = new ArrayList<CQEventListener>();
+
+    synchronized (this.listeners) {
+      result.addAll(this.listeners);
+    }
+
+    return result;
+  }
+
+  private Collection<TypeListener> getTypeListeners() {
+    List<TypeListener> result = new ArrayList<TypeListener>();
+
+    synchronized (this.listeners) {
+      result.addAll(this.type_listeners);
+    }
+
+    return result;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventData.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventData.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventData.java
new file mode 100644
index 0000000..de044f0
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventData.java
@@ -0,0 +1,22 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+
+public interface EventData extends Comparable<EventData> {
+  
+  public long getId();
+  
+  public Object getKey();
+  
+  public Object getValue();
+  
+  public IntrospectionResult getIntrospectionResult();
+  
+  public void setValue(IntrospectionResult metaInfo, Object value);  
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventDataImpl.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventDataImpl.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventDataImpl.java
new file mode 100644
index 0000000..f9c978b
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/EventDataImpl.java
@@ -0,0 +1,84 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+
+public final class EventDataImpl implements EventData, Cloneable {
+  private static volatile AtomicLong _id = new AtomicLong(0);
+
+  private Object               key;
+  private Object               value;
+  private IntrospectionResult  metaInfo;
+  // This is used for ordering the events.
+  private long                 id;
+
+  public EventDataImpl(Object k, Object v, IntrospectionResult mInf) {
+    this.key = k;
+    this.value = v;
+    this.metaInfo = mInf;
+    id = _id.getAndIncrement();
+  }
+
+  @Override
+  protected Object clone() throws CloneNotSupportedException {
+    EventDataImpl obj;
+    obj = (EventDataImpl) super.clone();
+
+    obj.key = key;
+    obj.value = value;
+    obj.metaInfo = metaInfo;
+    obj.id = id;
+    return obj;
+  }
+
+  public Object getKey() {
+    return key;
+  }
+
+  public synchronized Object getValue() {
+    return value;
+  }
+
+  public synchronized long getId() {
+    return id;
+  }
+
+  public synchronized void setValue(IntrospectionResult mInf, Object val) {
+    this.metaInfo = mInf;
+    this.value = val;
+    id = _id.getAndIncrement();
+  }
+
+  public synchronized IntrospectionResult getIntrospectionResult() {
+    return metaInfo;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj instanceof EventData) {
+      EventData data = (EventData) obj;
+
+      return this.key.equals(data.getKey());
+    }
+
+    return super.equals(obj);
+  }
+
+  @Override
+  public int hashCode() {
+    return this.key.hashCode();
+  }
+
+  public int compareTo(EventData o) {
+    if (this.equals(o))
+      return 0;
+
+    return (this.getId() < o.getId()) ? -1 : +1;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/TypeListener.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/TypeListener.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/TypeListener.java
new file mode 100644
index 0000000..4017a01
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/TypeListener.java
@@ -0,0 +1,20 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+
+public interface TypeListener {
+  
+  /**
+   * This method is invoked when a new type is introduced as part of 
+   * the execution of the CQ. This method is primarily useful for the 
+   * user-interface components, preparing them to lay out data of this
+   * type.
+   */
+  public void onNewTypeAdded(IntrospectionResult result);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ErrorEvent.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ErrorEvent.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ErrorEvent.java
new file mode 100644
index 0000000..74dc0c0
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ErrorEvent.java
@@ -0,0 +1,20 @@
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.EventData;
+
+public class ErrorEvent implements ICQEvent {
+
+  private Throwable cause;
+  
+  public ErrorEvent(Throwable thrw) {
+   this.cause = thrw; 
+  }
+  
+  public EventData getEventData() {    
+    return null;
+  }
+
+  public Throwable getThrowable() {
+    return cause;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ICQEvent.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ICQEvent.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ICQEvent.java
new file mode 100644
index 0000000..17e0e9a
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/ICQEvent.java
@@ -0,0 +1,17 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.EventData;
+
+
+public interface ICQEvent {
+  
+  public EventData getEventData(); 
+  
+  public Throwable getThrowable();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowAdded.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowAdded.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowAdded.java
new file mode 100644
index 0000000..801b71a
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowAdded.java
@@ -0,0 +1,22 @@
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.EventData;
+
+public class RowAdded implements ICQEvent {
+  
+  private EventData data;
+
+  public RowAdded(EventData evtData) {
+    super();
+    data = evtData;
+  }
+
+  public EventData getEventData() {
+    return data;
+  }
+
+  public Throwable getThrowable() {
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowDeleted.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowDeleted.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowDeleted.java
new file mode 100644
index 0000000..d675ff2
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowDeleted.java
@@ -0,0 +1,21 @@
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.EventData;
+
+public class RowDeleted implements ICQEvent {
+  private EventData data;
+
+  public RowDeleted(EventData evtData) {
+    super();
+    data = evtData;
+  }
+
+  public EventData getEventData() {
+    return data;
+  }
+
+  public Throwable getThrowable() {
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowUpdated.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowUpdated.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowUpdated.java
new file mode 100644
index 0000000..f4d34b1
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/cq/event/RowUpdated.java
@@ -0,0 +1,21 @@
+package com.gemstone.gemfire.mgmt.DataBrowser.query.cq.event;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.cq.EventData;
+
+public class RowUpdated implements ICQEvent {
+  private EventData data;
+
+  public RowUpdated(EventData evtData) {
+    super();
+    data = evtData;
+  }
+
+  public EventData getEventData() {
+    return data;
+  }
+
+  public Throwable getThrowable() {
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryDataExportHandler.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryDataExportHandler.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryDataExportHandler.java
new file mode 100644
index 0000000..2432a5f
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryDataExportHandler.java
@@ -0,0 +1,66 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2011, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+
+/**
+ * This class provides an interface for defining application specific 
+ * call-back handler during export of the query result.
+ * 
+ * @author Hrishi
+ **/
+public interface QueryDataExportHandler {
+  public final String COLLECTION_NAME = "Collection";
+  public final String COLLECTION_TYPE_NAME = "CollectionType";
+  public final String COLLECTION_ELEMENT_NAME = "element";  
+  public final String STRUCT_TYPE_NAME = "StructType";
+  public final String STRUCT_ELEMENT_NAME = "Struct";
+  public final String QUERY_RESULT_NAME = "QueryResult";
+    
+  public void handleStartDocument();
+  
+  public void handleEndDocument();
+  
+  public void handleStartCollectionElement(String name, IntrospectionResult metaInfo, Object element);
+  
+  public void handleEndCollectionElement(String name);
+  
+  public void handlePrimitiveType(String name, Class type, Object value);
+  
+  public void handleStartCompositeType(String name, IntrospectionResult metaInfo,
+      Object value) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException;
+  
+  public void handleEndCompositeType(String name, IntrospectionResult metaInfo,
+      Object value) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException;
+  
+  public void handleStartCollectionType(String name, String typeName, Object value) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException;
+
+  public void handleEndCollectionType(String name, String typeName, Object value) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException;
+  
+  public void handleStartStructType(String name, IntrospectionResult metaInfo,
+      Object val) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException;  
+  
+  public void handleEndStructType(String name, IntrospectionResult metaInfo,
+      Object val) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException;
+  
+  public void handleStartPdxType(String name, IntrospectionResult metaInfo,
+      Object value);
+
+  public void handleEndPdxType(String name, IntrospectionResult metaInfo,
+      Object value);
+  
+  public Object getResultDocument();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryResultExporter.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryResultExporter.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryResultExporter.java
new file mode 100644
index 0000000..61f76c0
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QueryResultExporter.java
@@ -0,0 +1,528 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2011, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionRepository;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryUtil;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ResultSet;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.internal.CollectionTypeResultImpl;
+import com.gemstone.gemfire.mgmt.DataBrowser.utils.LogUtil;
+
+/**
+ * This class is responsible to navigate through the object graph of the Query
+ * result and help to prepare an application specific model representation of
+ * the graph. This is achieved by making call-backs to the application specific
+ * handlers.
+ * 
+ * @author Hrishi
+ **/
+public class QueryResultExporter {
+
+  private QueryDataExportHandler dataHandler;
+  private int                    depthRequired;
+  private int                    depth;
+
+  public QueryResultExporter(QueryDataExportHandler dataHndlr, int depthReq) {
+    dataHandler = dataHndlr;
+    depthRequired = depthReq;
+    depth = -1;
+  }
+
+  public int getDepthRequired() {
+    return depthRequired;
+  }
+
+  public void resetDepth() {
+    this.depth = 0;
+  }
+
+  public void exportData(QueryResult result) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException {
+
+    if (this.dataHandler == null) {
+      throw new IllegalStateException(
+          "dataHandler is required to export data. Please provide valid dataHandler");
+    }
+
+    this.dataHandler.handleStartDocument();
+
+    this.depth = -2;
+
+    // Dummy type created so as to use handleCollectionType API for main
+    // resultset as well.
+    IntrospectionResult type = new CollectionTypeResultImpl(result
+        .getQueryResult().getClass());
+    IntrospectionRepository.singleton().addIntrospectionResult(
+        result.getQueryResult().getClass(), type);
+
+    Class<?> typeClass = type.getJavaType();
+    handleCollectionType("QueryResult", typeClass, result);
+    this.dataHandler.handleEndDocument();
+  }
+
+  public void exportObject(String name, IntrospectionResult metaInfo, Object obj)
+      throws ColumnNotFoundException, ColumnValueNotAvailableException {
+
+    // Increment the depth by 1 and check against the required depth.
+    boolean shallow = isRequiredDepthReached(true);
+
+    int resultType = metaInfo.getResultType();
+
+    // If shallow = true and colClass is not primitive, then we will treat this
+    // as a primitive type.
+    // This will stop the subsequent navigation of the object tree.
+    if ((shallow) || (resultType == IntrospectionResult.PRIMITIVE_TYPE_RESULT)) {
+      Class<?> type = metaInfo.getColumnClass(0);
+      Object value = obj;
+      dataHandler.handlePrimitiveType(name, type, value);
+
+    } else if (resultType == IntrospectionResult.COMPOSITE_TYPE_RESULT) {
+
+      handleCompositeType(name, metaInfo, obj);
+
+    } else if (resultType == IntrospectionResult.COLLECTION_TYPE_RESULT) {
+      ResultSet temp = (ResultSet) metaInfo.getColumnValue(obj, 0);
+      Class<?> type = metaInfo.getJavaType();
+      handleCollectionType(name, type, temp);
+      temp.close();
+
+    } else if (resultType == IntrospectionResult.STRUCT_TYPE_RESULT) {
+      handleStructType(name, metaInfo, obj);
+
+    } else if (resultType == IntrospectionResult.MAP_TYPE_RESULT) {
+      ResultSet temp = (ResultSet) metaInfo.getColumnValue(obj, 0);
+      Class<?> type = metaInfo.getJavaType();
+      handleCollectionType(name, type, temp);
+      temp.close();
+    } else if (resultType == IntrospectionResult.PDX_TYPE_RESULT) {
+      handlePdxType(name, metaInfo, obj);
+    }
+
+    // Since we are complete, decrement the depth by one.
+    decrDepth();
+  }
+
+  private void handleCompositeType(String nm, IntrospectionResult metaInfo,
+      Object value) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException {
+
+    // Increment the depth by 1 and check against the required depth.
+    boolean shallow = isRequiredDepthReached(true);
+    String name = (null != nm) ? nm : metaInfo.getJavaType().getSimpleName();
+
+    // Start of the Composite object.
+    this.dataHandler.handleStartCompositeType(name, metaInfo, value);
+
+    // This object is not null. For a null object, there is no special
+    // processing.
+    if (value != null) {
+
+      for (int k = 0; k < metaInfo.getColumnCount(); k++) {
+        int      columnType = metaInfo.getColumnType(value, k);
+        String   colName    = metaInfo.getColumnName(k);
+        Object   colValue   = metaInfo.getColumnValue(value, k);
+        Class<?> colClass   = metaInfo.getColumnClass(value, k);
+
+        // If shallow = true and colClass is not primitive, then we will treat
+        // this as a primitive type.
+        // This will stop the subsequent navigation of the object tree.
+        if ((shallow)
+            || (columnType == IntrospectionResult.PRIMITIVE_TYPE_COLUMN)) {
+          this.dataHandler.handlePrimitiveType(colName, colClass, colValue);
+
+        } else if (columnType == IntrospectionResult.COMPOSITE_TYPE_COLUMN) {
+          IntrospectionResult meta = IntrospectionRepository.singleton()
+              .getIntrospectionResult(colClass);
+          handleCompositeType(colName, meta, colValue);
+
+        } else if (columnType == IntrospectionResult.COLLECTION_TYPE_COLUMN) {
+          ResultSet temp = (ResultSet) colValue;
+          handleCollectionType(colName, colClass, temp);
+          temp.close();
+
+        } else if (columnType == IntrospectionResult.MAP_TYPE_COLUMN) {
+          ResultSet temp = (ResultSet) colValue;
+          handleCollectionType(colName, colClass, temp);
+          temp.close();
+        } else if (columnType == IntrospectionResult.PDX_TYPE_COLUMN || 
+            columnType == IntrospectionResult.PDX_OBJECT_TYPE_COLUMN) {//eventually goes to introspectAndHandleElement if it's not a PdxInstance
+          IntrospectionResult colMetaInfo = null;
+          try {
+            colMetaInfo = IntrospectionRepository.singleton().introspectTypeByObject(colValue);
+            handlePdxType(name, colMetaInfo, colValue);
+          } catch (IntrospectionException e) {
+            colMetaInfo = null;
+            LogUtil.warning("Could not introspect: "+colValue+", skipping it..", e);
+          }
+        }
+      }
+    }
+
+    this.dataHandler.handleEndCompositeType(name, metaInfo, value);
+
+    // Since we are complete, decrement the depth by one.
+    decrDepth();
+  }
+
+  // TODO MGH - added check to avoid a NPE later in the code.
+  private void handleCollectionType(String name, Class<?> type, Object value)
+      throws ColumnNotFoundException, ColumnValueNotAvailableException,
+      NullPointerException {
+    if (null == type) {
+      throw new NullPointerException(
+        "'type' argument for the collection to introspect is null, can't introspect.");
+    }
+
+    // For a null object, there is no special processing. Hence return
+    // immediately.
+    final String typeName = type.getCanonicalName();
+    if (value == null) {
+      this.dataHandler.handleStartCollectionType(name, typeName, value);
+      this.dataHandler.handleEndCollectionType(name, typeName, value);
+      return;
+    }
+
+    // Increment the depth by 1 and check against the required depth.
+    boolean shallow = isRequiredDepthReached(true);
+
+    if (!shallow) {
+      boolean isArray = type.isArray();
+      ResultSet result = (ResultSet) value;
+      this.dataHandler.handleStartCollectionType(name, typeName, value);
+
+      IntrospectionResult[] types = result.getIntrospectionResult();
+
+      for (int i = 0; i < types.length; i++) {
+        String elemName = QueryDataExportHandler.COLLECTION_ELEMENT_NAME;
+
+        Collection<?> data = null;
+
+        // In case of Arrays of primitive types, the collection can not have
+        // elements of
+        // multiple types. Here we get the complete results so as to accommodate
+        // for the
+        // Java auto-boxing feature. (We need to specify the correct element
+        // type).
+        if (isArray && types[i].getJavaType().isPrimitive()) {
+          data = result.getQueryResult();
+
+        } else {
+          data = result.getQueryResult(types[i]);
+        }
+
+        Iterator<?> iter = data.iterator();
+        while (iter.hasNext()) {
+          Object val = iter.next();
+          this.dataHandler
+              .handleStartCollectionElement(elemName, types[i], val);
+          exportObject(QueryDataExportHandler.COLLECTION_ELEMENT_NAME,
+              types[i], val);
+          this.dataHandler.handleEndCollectionElement(elemName);
+        }
+      }
+
+      this.dataHandler.handleEndCollectionType(name, typeName, value);
+
+    } else {
+      this.dataHandler.handlePrimitiveType(name, type, value);
+    }
+
+    // Since we are complete, decrement the depth by one.
+    decrDepth();
+  }
+
+  private void handleStructType(String nm, IntrospectionResult metaInfo,
+      Object val) throws ColumnNotFoundException,
+      ColumnValueNotAvailableException {
+
+    // Increment the depth by 1 and check against the required depth.
+    boolean shallow = isRequiredDepthReached(true);
+
+    String name = (null != nm) ? nm
+        : QueryDataExportHandler.STRUCT_ELEMENT_NAME;
+
+    this.dataHandler.handleStartStructType(name, metaInfo, val);
+
+    for (int k = 0; k < metaInfo.getColumnCount(); k++) {
+      Object   colValue   = metaInfo.getColumnValue(val, k);
+      int      columnType = metaInfo.getColumnType(val, k);
+      String   colName    = metaInfo.getColumnName(k);
+      Class<?> colClass   = metaInfo.getColumnClass(val, k);
+
+      // If shallow = true and colClass is not primitive, then we will treat
+      // this as a primitive type.
+      // This will stop the subsequent navigation of the object tree.
+      if ((shallow)
+          || (columnType == IntrospectionResult.PRIMITIVE_TYPE_COLUMN)) {
+        this.dataHandler.handlePrimitiveType(colName, colClass, colValue);
+
+      } else if (columnType == IntrospectionResult.COMPOSITE_TYPE_COLUMN) {
+        IntrospectionResult meta = IntrospectionRepository.singleton()
+            .getIntrospectionResult(colClass);
+        handleCompositeType(colName, meta, colValue);
+
+      } // This will take care for objects of type (Collection, Map and Array).
+      else if (columnType == IntrospectionResult.COLLECTION_TYPE_COLUMN) {
+        ResultSet temp = (ResultSet) colValue;
+        handleCollectionType(colName, colClass, temp);
+        temp.close();
+
+      } else if (columnType == IntrospectionResult.UNKNOWN_TYPE_COLUMN) {
+
+        this.dataHandler.handlePrimitiveType(colName, colClass, colValue);
+      } else if (columnType == IntrospectionResult.PDX_TYPE_COLUMN) {
+        IntrospectionResult colMetaInfo = null;
+        try {
+          colMetaInfo = IntrospectionRepository.singleton().introspectTypeByObject(colValue);
+          handlePdxType(colName, colMetaInfo, colValue);
+        } catch (IntrospectionException e) {
+          colMetaInfo = null;
+          LogUtil.warning("Could not introspect: "+colValue+", skipping it..", e);
+        }
+      }
+    }
+
+    this.dataHandler.handleEndStructType(name, metaInfo, val);
+
+    // Since we are complete, decrement the depth by one.
+    decrDepth();
+  }
+
+  /**
+   * Handles exporting for objects of GemFire type PdxInstanceImpl in the tree 
+   * model.
+   * 
+   * @param name
+   *          name to be used for start node for the given pdxInstanceObj
+   * @param metaInfo
+   *          IntrospectionResult for the given pdxInstanceObj
+   * @param pdxInstanceObj
+   *          PdxInstanceImpl object to be introspected
+   * @throws ColumnNotFoundException
+   *           if column/field at given index is not found
+   * @throws ColumnValueNotAvailableException
+   *           if value for column/field at given index is not found
+   */
+  /* PdxInstance could also be part of a Collection/Map, Struct, Composite. This
+   * method (handlePdxType) is called from handleXXX methods for Struct &
+   * Composite. The handleXXX method for Collection calls exportObject() for
+   * individual elements and exportObject() calls handlePdxType if an element 
+   * is a PdxInstance */
+  private void handlePdxType(String name, IntrospectionResult metaInfo, Object pdxInstanceObj) 
+    throws ColumnNotFoundException, ColumnValueNotAvailableException {
+    // Increment the depth by 1 and check against the required depth.
+    boolean shallow = isRequiredDepthReached(true);
+    String nameOpt = (null != name) ? name : metaInfo.getJavaTypeName();
+
+    // Start of the Composite object.
+    this.dataHandler.handleStartPdxType(nameOpt, metaInfo, pdxInstanceObj);
+    
+    // This object is not null. For a null object, there is no special
+    // processing.
+    if (pdxInstanceObj != null) {
+
+      for (int k = 0; k < metaInfo.getColumnCount(); k++) {
+        int      columnType = metaInfo.getColumnType(pdxInstanceObj, k);
+        String   colName    = metaInfo.getColumnName(k);
+        Object   colValue   = metaInfo.getColumnValue(pdxInstanceObj, k);
+        Class<?> colClass   = metaInfo.getColumnClass(pdxInstanceObj, k);
+        
+        // If shallow = true and colClass is not primitive, then we will treat
+        // this as a primitive type.
+        // This will stop the subsequent navigation of the object tree.
+        if ((shallow) || 
+            (columnType == IntrospectionResult.PRIMITIVE_TYPE_COLUMN)) {
+          this.dataHandler.handlePrimitiveType(colName, colClass, colValue);
+//          System.out.println("QueryResultExporter.handlePdxType()");
+        } else if (columnType == IntrospectionResult.COLLECTION_TYPE_COLUMN) {
+//          System.out.println("QueryResultExporter.handlePdxType() : isCollectionType1");
+          handleSimpleCollectionType(colName, colClass, colValue);
+        } else if (columnType == IntrospectionResult.PDX_OBJECT_TYPE_COLUMN) {
+//          LogUtil.info("QueryResultExporter.handlePdxType() : value :: "+value);
+          //for a PDX_OBJECT_TYPE_COLUMN ignore colClass & use colValue.getClass()
+          Class<?> colValueClass = Object.class;
+          if (colValue != null) {
+            colValueClass = colValue.getClass();//TODO: Just to avoid NPE???? Make it better
+          }
+          if (QueryUtil.isPdxInstanceType(colValueClass)) {
+            IntrospectionResult nestedObjMetaInfo;
+            try {
+              nestedObjMetaInfo = IntrospectionRepository.singleton().introspectTypeByObject(colValue);
+              handlePdxType(colName, nestedObjMetaInfo, colValue);
+            } catch (IntrospectionException e) {
+              LogUtil.warning("Could not introspect: "+colValue+", skipping it..", e);
+            }
+          } else if (QueryUtil.isCollectionType(colValueClass)) {
+            //it was probably a collection/array serialized as Object using writeObject()
+            handleSimpleCollectionType(colName, colValueClass, colValue);
+          } else if (QueryUtil.isMapType(colValueClass)) {
+            //it was probably a map serialized as Object using writeObject()
+            Map<?,?> valuesMap = (Map<?,?>) colValue;
+            Set<?>   entrySet  = valuesMap.entrySet();
+            handleSimpleCollectionType(colName, entrySet.getClass(), entrySet);
+          } else {
+            introspectAndHandleElement(colName, colValue);
+          }
+        }
+      }
+    }
+    this.dataHandler.handleEndPdxType(name, metaInfo, pdxInstanceObj);
+
+    // Since we are complete, decrement the depth by one.
+    decrDepth();
+  }
+
+  /**
+   * Handles exporting for the given collection/array/map and objects in it the
+   * tree model. handleCollectionType works on ResultSet but this method uses
+   * the actual collection/array/map.
+   * 
+   * @param name
+   *          name to be used for start node for the given collectionObj
+   * @param type
+   *          type (java.lang.Class) of the given collection
+   * @param collectionObj
+   *          instance of one of collection/array/map
+   * @throws ColumnNotFoundException
+   *           if column/field at given index is not found
+   * @throws ColumnValueNotAvailableException
+   *           if value for column/field at given index is not found
+   */
+  private void handleSimpleCollectionType(String name, Class<?> type, Object collectionObj) 
+      throws ColumnNotFoundException, ColumnValueNotAvailableException {
+    if (null == type) {
+      throw new NullPointerException(
+        "'type' for the collection to introspect is null, can't introspect.");
+    }
+
+    // For a null object, there is no special processing. Hence return
+    // immediately.
+    final String typeName = type.getCanonicalName();
+    if (collectionObj == null) {
+      this.dataHandler.handleStartCollectionType(name, typeName, collectionObj);
+      this.dataHandler.handleEndCollectionType(name, typeName, collectionObj);
+      return;
+    }
+
+    // Increment the depth by 1 and check against the required depth.
+    boolean shallow = isRequiredDepthReached(true);
+    
+    if (!shallow) {
+      boolean isArray = type.isArray();
+      this.dataHandler.handleStartCollectionType(name, typeName, collectionObj);
+
+      if (isArray) {
+        Class<?> componentType = type.getComponentType();
+        int length = Array.getLength(collectionObj);
+        if (componentType.isPrimitive()) {
+          //Not using exportObject() to handle here, as it's simple for primitive types
+          if (boolean.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getBoolean(collectionObj, i));
+            }
+          } else if (byte.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getByte(collectionObj, i));
+            }
+          } else if (char.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getChar(collectionObj, i));
+            }
+          } else if (short.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getShort(collectionObj, i));
+            }
+          } else if (int.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getInt(collectionObj, i));
+            }
+          } else if (long.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getLong(collectionObj, i));
+            }
+          } else if (float.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getFloat(collectionObj, i));
+            }
+          } else if (double.class == componentType) {
+            for (int i = 0; i < length; i++) {
+              this.dataHandler.handlePrimitiveType(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, componentType, Array.getDouble(collectionObj, i));
+            }
+          }
+        } else {
+          Object[] arr = (Object[]) collectionObj;
+          for (int i = 0; i < length; i++) {
+            introspectAndHandleElement(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, arr[i]);
+          }
+        }
+      } else if (QueryUtil.isCollectionType(type)) {//double check for collection type?
+        Collection<?> valuesCollection = (Collection<?>) collectionObj;
+        for (Iterator<?> it = valuesCollection.iterator(); it.hasNext();) {
+          introspectAndHandleElement(QueryDataExportHandler.COLLECTION_ELEMENT_NAME, it.next());
+        }
+      }
+      this.dataHandler.handleEndCollectionType(name, typeName, collectionObj);
+    } else {
+      this.dataHandler.handlePrimitiveType(name, type, collectionObj);
+    }
+    
+  }
+
+  /**
+   * Introspects and handles exporting for the given data object in it the tree
+   * model.
+   * 
+   * @param data
+   *          object to be introspected
+   * @throws ColumnNotFoundException
+   *           if column/field at given index is not found
+   * @throws ColumnValueNotAvailableException
+   *           if value for column/field at given index is not found
+   */
+  private void introspectAndHandleElement(String treeNodeName, Object data) 
+      throws ColumnNotFoundException, ColumnValueNotAvailableException {
+    IntrospectionRepository singleton = IntrospectionRepository.singleton();
+    IntrospectionResult dataElementMetaInfo = null;
+    Object dataElement = data != null ? data : new Object();
+    try {
+      dataElementMetaInfo = singleton.introspectTypeByObject(dataElement);
+      exportObject(treeNodeName, dataElementMetaInfo, dataElement);
+    } catch (IntrospectionException e) {
+      LogUtil.warning("Could not introspect: "+data+", skipping it..", e);
+      //return after logging exception
+    }
+  }
+
+  private boolean isRequiredDepthReached(boolean incrDepth) {
+    if (incrDepth) {
+      depth = depth + 1;
+    }
+
+    if (depthRequired == -1) {
+      return false;
+    }
+
+    return (depth < depthRequired) ? false : true;
+  }
+
+  private void decrDepth() {
+    if (depth > 0) {
+      depth = depth - 1;
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExportHandler.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExportHandler.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExportHandler.java
new file mode 100644
index 0000000..4ed61ab
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExportHandler.java
@@ -0,0 +1,40 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+
+/**
+ * This class defines an interface for defining application specific call-back
+ * handler for preparing a model for query schema.
+ * 
+ * @author Hrishi
+ **/
+public interface QuerySchemaExportHandler {
+  
+  public String getSchema();
+  
+  public void handleStartSchema();
+  
+  public void handleEndSchema();
+
+  public void handlePrimitiveType(IntrospectionResult metaInfo)
+      throws ColumnNotFoundException;
+
+  public void handleCompositeType(IntrospectionResult metaInfo)
+      throws ColumnNotFoundException;
+
+  public void handleCollectionType(IntrospectionResult metaInfo)
+      throws ColumnNotFoundException;
+
+  public void handleMapType(IntrospectionResult metaInfo)
+      throws ColumnNotFoundException;
+
+  public void handleStructType(IntrospectionResult metaInfo)
+      throws ColumnNotFoundException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExporter.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExporter.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExporter.java
new file mode 100644
index 0000000..e7e9a95
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/QuerySchemaExporter.java
@@ -0,0 +1,66 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionRepository;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryResult;
+
+/**
+ * This class is responsible to iterate through the introspection results of the query result
+ * and help to prepare an application specific model representation of the same. This
+ * is achieved by making call-backs to the application specific handlers.
+ * 
+ * @author Hrishi
+ **/
+public class QuerySchemaExporter {
+  
+  public static void exportSchema(QuerySchemaExportHandler schemaHandler, QueryResult result) throws ColumnNotFoundException {
+    if(schemaHandler == null) {
+      throw new IllegalStateException("schemaHandler is required to export schema. Please provide valid schemaHandler");
+    }
+    
+    schemaHandler.handleStartSchema();
+    
+    IntrospectionResult[] info = result.getIntrospectionResult();
+    for(int i = 0; i < info.length ; i++) {
+     if(info[i].getResultType() == IntrospectionResult.STRUCT_TYPE_RESULT) {
+       schemaHandler.handleStructType(info[i]);
+       break;    
+     }
+    }
+  
+    info = IntrospectionRepository.singleton().getIntrospectionResultInfo();
+    
+    for(int i = 0 ; i < info.length ; i++) {
+      IntrospectionResult metaInfo = info[i];
+      int resultType = metaInfo.getResultType();
+      
+      switch (resultType) {
+        case IntrospectionResult.COMPOSITE_TYPE_RESULT: {
+          schemaHandler.handleCompositeType(metaInfo);
+          break;
+        }
+
+        case IntrospectionResult.COLLECTION_TYPE_RESULT: {
+          schemaHandler.handleCollectionType(metaInfo);
+          break;
+        }
+        
+        case IntrospectionResult.MAP_TYPE_RESULT: {
+          schemaHandler.handleMapType(metaInfo);
+          break;
+        }
+        
+        default: //Not implemented.
+          break;
+      }  
+    }
+    
+    schemaHandler.handleEndSchema();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/TypeConversion.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/TypeConversion.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/TypeConversion.java
new file mode 100644
index 0000000..0984f6f
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/TypeConversion.java
@@ -0,0 +1,48 @@
+/*=========================================================================
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export.xml;
+
+
+public class TypeConversion {
+
+  public static String getXmlType(Class type) {
+    if(java.lang.Number.class.isAssignableFrom(type) ||
+       type.equals(short.class) ||
+       type.equals(int.class) ||
+       type.equals(long.class) ||
+       type.equals(float.class) ||
+       type.equals(double.class)) {
+         return "xsd:decimal";
+    }
+
+    if(java.lang.CharSequence.class.isAssignableFrom(type)) {
+      return "xsd:string";
+    }
+
+    if(java.lang.Byte.class.isAssignableFrom(type) ||
+       type.equals(byte.class)
+    ) {
+      return "xsd:byte";
+    }
+
+    if(java.lang.Boolean.class.isAssignableFrom(type)
+       || type.equals(boolean.class)) {
+      return "xsd:boolean";
+    }
+
+//    if(java.util.Date.class.isAssignableFrom(type)) {
+//      return "xsd:date";
+//    }
+
+    //If the type is not known, just print the string representation.
+    return "xsd:string";
+  }
+
+  public static boolean isOptional(Class type) {
+    return !type.isPrimitive();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLDocExportHandler.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLDocExportHandler.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLDocExportHandler.java
new file mode 100644
index 0000000..2df1cb0
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLDocExportHandler.java
@@ -0,0 +1,120 @@
+/*=========================================================================
+ * (c)Copyright 2002-2011, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export.xml;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.export.QueryDataExportHandler;
+
+public class XMLDocExportHandler implements QueryDataExportHandler {
+
+  private FileWriter file_buffer = null;
+  private PrintWriter writer = null;
+
+  public XMLDocExportHandler(File docFile) throws IOException {
+   this.file_buffer = new FileWriter(docFile);
+   this.writer = new PrintWriter(file_buffer);
+  }
+
+  public void handleEndDocument() {
+    writer.println("</QueryResult>");
+  }
+
+  public void handleStartDocument() {
+    writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+    writer.println();
+    writer.println("<QueryResult xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
+    writer.println("             xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
+  }
+
+  public void handleStartCollectionElement(String name, IntrospectionResult metaInfo, Object element) {
+   //Do nothing.
+  }
+
+
+  public void handleEndCollectionElement(String name) {
+   // Do nothing.
+  }
+
+  public void handleEndCompositeType(String name, IntrospectionResult metaInfo, Object value) {
+    writer.println("</" + name + ">");
+  }
+
+  public void handleStartCompositeType(String name, IntrospectionResult metaInfo, Object value) {
+    String xmlType = metaInfo.getJavaType().getSimpleName();
+    String nm = ( null != name ) ? name : xmlType;
+
+    writer.print("<" + nm);
+    writer.print(" xsi:type=\""+xmlType+"\"");
+    writer.println(">");
+  }
+
+  public void handleStartStructType(String name, IntrospectionResult metaInfo, Object val) {
+    writer.print("<" + name);
+    writer.print(" xsi:type=\""+STRUCT_TYPE_NAME+"\"");
+    writer.println(">");
+  }
+
+  public void handleEndStructType(String name, IntrospectionResult metaInfo, Object val) {
+    writer.println("</" + name + ">");
+  }
+
+  public Object getResultDocument() {
+    return this.file_buffer;
+  }
+
+  public void close() throws IOException {
+    this.file_buffer.flush();
+    this.file_buffer.close();
+  }
+
+  public void handlePrimitiveType(String name, Class type, Object value) {
+    if(value == null) {
+     return;
+    }
+
+    String xmlType = TypeConversion.getXmlType(type);
+
+    writer.print("<"+name);
+    if(type != null)
+     writer.print(" xsi:type=\""+xmlType+"\"");
+     writer.print(">");
+     writer.print(String.valueOf(value));
+     writer.print("</"+name+">");
+     writer.println();
+  }
+
+  public void handleEndCollectionType(String name, String typeName, Object value) {
+    if(!QUERY_RESULT_NAME.equals(name)) {
+      writer.println("</" + name + ">");
+    }
+  }
+
+  public void handleStartCollectionType(String name, String typeName, Object value)  {
+    if(!QUERY_RESULT_NAME.equals(name)) {
+      writer.println("<" + name + " xsi:type=\""+COLLECTION_TYPE_NAME+"\">");
+    }
+  }
+
+  public void handleEndPdxType(String name, IntrospectionResult metaInfo,
+      Object value) {
+    writer.println("</" + name + ">");
+  }
+
+  public void handleStartPdxType(String name, IntrospectionResult metaInfo,
+      Object value) {
+    String xmlType = metaInfo.getJavaTypeName();
+    String nm = ( null != name ) ? name : xmlType;
+
+    writer.print("<" + nm);
+    writer.print(" xsi:type=\""+xmlType+"\"");
+    writer.println(">");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLSchemaExportHandler.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLSchemaExportHandler.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLSchemaExportHandler.java
new file mode 100644
index 0000000..ff643d5
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/export/xml/XMLSchemaExportHandler.java
@@ -0,0 +1,183 @@
+/*=========================================================================
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.export.xml;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryUtil;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.export.QuerySchemaExportHandler;
+
+
+public class XMLSchemaExportHandler implements QuerySchemaExportHandler {
+
+  private static final String STRUCT_TYPE_SCHEMA_NAME = "StructType";
+  private static final String COLLECTION_TYPE_SCHEMA_NAME = "CollectionType";
+
+  private StringWriter schema_buffer;
+  private PrintWriter schema_writer;
+  private boolean isCollectionTypeDefined;
+
+  public XMLSchemaExportHandler() {
+    this.schema_buffer = new StringWriter();
+    this.schema_writer = new PrintWriter(this.schema_buffer);
+    this.isCollectionTypeDefined = false;
+  }
+
+  public String getSchema() {
+    return this.schema_buffer.toString();
+  }
+
+  public void handleEndSchema() {
+    schema_writer.println();
+    schema_writer.println("</xsd:schema>");
+    schema_writer.println();
+  }
+
+  public void handleStartSchema() {
+    schema_writer.println("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
+    schema_writer.println();
+
+    schema_writer.println("<xsd:element name=\"QueryResult\" type=\"CollectionType\"/>");
+    schema_writer.println();
+  }
+
+  public void handleCollectionType(IntrospectionResult metaInfo) {
+    if(!this.isCollectionTypeDefined) {
+      schema_writer.println("<xsd:complexType name=\""+COLLECTION_TYPE_SCHEMA_NAME+"\" >");
+      schema_writer.println("<xsd:sequence>");
+      schema_writer.println("<xsd:element name=\"element\"   type=\"xsd:anyType\"  minOccurs=\"0\" maxOccurs=\"unbounded\" />");
+      schema_writer.println("</xsd:sequence>");
+      schema_writer.println("</xsd:complexType>");
+      schema_writer.println();
+
+      this.isCollectionTypeDefined = true;
+    }
+  }
+
+  public void handleCompositeType(IntrospectionResult metaInfo) throws ColumnNotFoundException {
+    schema_writer.print("<xsd:complexType name=\"");
+    schema_writer.print(metaInfo.getJavaType().getSimpleName());
+    schema_writer.println("\">");
+
+    schema_writer.println("<xsd:complexContent>");
+
+    //In case of Composite type, check if the type has a custom super type (which should not be
+    //equal to java.lang.Object.class). In this case we prepare the schema definition using the
+    //extension mechanism. Else, we use XML schema restriction mechanism.
+    boolean extenstion = false;
+    Class superClass = metaInfo.getJavaType().getSuperclass();
+    if(superClass != null && !java.lang.Object.class.equals(superClass)) {
+      extenstion = true;
+      String superType = superClass.getSimpleName();
+      schema_writer.println("<xsd:extension base=\""+superType+"\">");
+
+    } else {
+      extenstion = false;
+      schema_writer.println("<xsd:restriction base=\"xsd:anyType\">");
+    }
+
+    schema_writer.println("<xsd:sequence>");
+
+    for(int k = 0 ; k < metaInfo.getColumnCount() ; k++) {
+      int columnType = metaInfo.getColumnType(k);
+      String colName = metaInfo.getColumnName(k);
+      String xmlType = null;
+      boolean isOptional = TypeConversion.isOptional(metaInfo.getColumnClass(k));
+      int minOccur = (isOptional) ? 0 : -1;
+
+      //If this column is not declared in this type, then do not redefine the same,
+      //since it will always be present in the super-type declaration.
+      if(!QueryUtil.isColumnDeclaredInType(metaInfo, k)) {
+       continue;
+      }
+
+      if(columnType == IntrospectionResult.PRIMITIVE_TYPE_COLUMN) {
+        xmlType = TypeConversion.getXmlType(metaInfo.getColumnClass(k));
+      } else if (columnType == IntrospectionResult.COMPOSITE_TYPE_COLUMN) {
+        xmlType = metaInfo.getColumnClass(k).getSimpleName();
+     }  else if(columnType == IntrospectionResult.COLLECTION_TYPE_COLUMN) {
+        xmlType = "CollectionType";
+     }  else {
+        xmlType = metaInfo.getColumnClass(k).getSimpleName();
+     }
+
+      handleSchemaElement(colName, xmlType, minOccur, false, -1);
+    }
+
+    schema_writer.println("</xsd:sequence>");
+
+    if(extenstion) {
+      schema_writer.println("</xsd:extension>");
+    } else {
+      schema_writer.println("</xsd:restriction>");
+    }
+
+    schema_writer.println("</xsd:complexContent>");
+    schema_writer.println("</xsd:complexType>");
+    schema_writer.println();
+  }
+
+  public void handleMapType(IntrospectionResult metaInfo) {
+    //Do nothing.
+  }
+
+  public void handlePrimitiveType(IntrospectionResult metaInfo) throws ColumnNotFoundException {
+    String javaType = metaInfo.getColumnClass(0).getSimpleName();
+    String colName = metaInfo.getColumnName(0);
+    String elementName = javaType+colName;
+    String xmlType = TypeConversion.getXmlType(metaInfo.getColumnClass(0));
+    boolean isOptional = TypeConversion.isOptional(metaInfo.getColumnClass(0));
+    int minOccur = (isOptional) ? 0 : -1;
+
+    handleSchemaElement(elementName, xmlType, minOccur, true, -1);
+  }
+
+  public void handleStructType(IntrospectionResult metaInfo) throws ColumnNotFoundException {
+    schema_writer.print("<xsd:complexType name=\"");
+    schema_writer.print(STRUCT_TYPE_SCHEMA_NAME);
+    schema_writer.println("\">");
+
+    schema_writer.println("<xsd:sequence>");
+
+    for(int k = 0 ; k < metaInfo.getColumnCount() ; k++) {
+      String colName = metaInfo.getColumnName(k);
+      handleSchemaElement(colName, "xsd:anyType", 0, false, -1);
+    }
+
+    schema_writer.println("</xsd:sequence>");
+    schema_writer.println("</xsd:complexType>");
+    schema_writer.println();
+  }
+
+  private void handleSchemaElement(String name, String type, int minOccur, boolean includeMaxOccur, int maxOccur) {
+    schema_writer.print("<xsd:element name=\"");
+    schema_writer.print(name);
+    schema_writer.print("\"   type=\"");
+    schema_writer.print(type);
+    schema_writer.print("\" ");
+    if(minOccur >= 0) {
+      schema_writer.print(" minOccurs=\""+minOccur+"\" ");
+    }
+    if(includeMaxOccur){
+      if(maxOccur == -1) {
+        schema_writer.print(" maxOccurs=\"unbounded\"");
+      } else {
+        schema_writer.print(" maxOccurs=\""+maxOccur+"\" ");
+      }
+    }
+
+    schema_writer.println(" />");
+  }
+
+  @Override
+  public String toString() {
+    return this.schema_buffer.toString();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/CollectionTypeResultImpl.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/CollectionTypeResultImpl.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/CollectionTypeResultImpl.java
new file mode 100644
index 0000000..440300f
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/CollectionTypeResultImpl.java
@@ -0,0 +1,104 @@
+/*=========================================================================
+ * (c)Copyright 2002-2011, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.internal;
+
+import java.util.Collection;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryExecutionException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryUtil;
+
+public final class CollectionTypeResultImpl implements IntrospectionResult {
+  private static final int CONST_COLUMN_COUNT = 1;
+  public static final String CONST_COLUMN_NAME = "Result";
+  private Class<?> type;
+  
+  public CollectionTypeResultImpl(Class<?> ty) {
+   this.type = ty; 
+  }
+  
+
+  public int getResultType() {
+    return COLLECTION_TYPE_RESULT;
+  }
+  
+  
+  public Class<?> getJavaType() {
+    return this.type;
+  }  
+
+  public Class getColumnClass(int index) {
+    return this.type;
+  }
+  
+  public Class getColumnClass(Object tuple, int index)
+      throws ColumnNotFoundException {
+    return getColumnClass(index);
+  }
+
+  public int getColumnCount() {
+    return CONST_COLUMN_COUNT;
+  }
+
+  public String getColumnName(int index) {
+    return CONST_COLUMN_NAME;
+  }
+  
+  public int getColumnIndex(String name) throws ColumnNotFoundException {
+    if(CONST_COLUMN_NAME.equals(name))
+     return 0;
+    
+    throw new ColumnNotFoundException("Column not available for name :" + name);
+  }
+
+  public Object getColumnValue(Object tuple, int index) throws ColumnValueNotAvailableException {
+    if(this.type.isArray()) {
+      try {
+       return QueryUtil.introspectArrayType(this.type, tuple);
+      
+      }catch (IntrospectionException e) {
+        throw new ColumnValueNotAvailableException(e);
+      }      
+    }else if(tuple instanceof Collection) {
+      Collection temp = (Collection)tuple;
+      
+      try {
+        return QueryUtil.introspectCollectionObject(temp);
+      
+      }catch (QueryExecutionException e) {
+        throw new ColumnValueNotAvailableException(e);
+      }     
+    }    
+    throw new ColumnValueNotAvailableException(" Invalid object type. It should be java.util.Collection : "+tuple);    
+  }
+
+  public int getColumnType(int index) throws ColumnNotFoundException {
+    if(index < CONST_COLUMN_COUNT)
+      return COLLECTION_TYPE_COLUMN;
+    
+    throw new ColumnNotFoundException("Column not available for index :" + index);
+  }
+  
+  public int getColumnType(Object tuple, int index)
+      throws ColumnNotFoundException {
+    return getColumnType(index);
+  }
+
+  public String getJavaTypeName() {
+    Class<?> javaType = getJavaType();
+    
+    return javaType != null ? javaType.getName() : null;
+  }
+
+  public boolean isCompatible(Object data) {
+    //checks for equality by reference not assignable. Using == assuming single 
+    //instance of a class
+    return data != null && getJavaType() == data.getClass();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/FieldTypeAccessor.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/FieldTypeAccessor.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/FieldTypeAccessor.java
new file mode 100644
index 0000000..b62c07e
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/FieldTypeAccessor.java
@@ -0,0 +1,158 @@
+/*
+ * =========================================================================
+ * Copyright (c) 2002-2012 VMware, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. VMware products are covered by
+ * more patents listed at http://www.vmware.com/go/patents.
+ * All Rights Reserved.
+ * ========================================================================
+ */
+package com.gemstone.gemfire.mgmt.DataBrowser.query.internal;
+
+import java.lang.reflect.Field;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.utils.LogUtil;
+
+/**
+ * FieldType enum is made 1 public class since GemFire 6.6.2. 
+ * In 6.6 it is:   com.gemstone.gemfire.pdx.internal.FieldType
+ * In 6.6.2 it is: com.gemstone.gemfire.pdx.FieldType
+ * 
+ * This class is used to access the enums defined by FieldType using reflection. 
+ * 
+ * @author abhishek
+ *
+ */
+public class FieldTypeAccessor {
+  
+  private Class<?> fieldTypeClass;
+
+  FieldTypeAccessor(Class<?> fieldTypeClass) {
+    this.fieldTypeClass = fieldTypeClass;
+  }
+  
+  public Object getField(String name) {
+    Object value = null;
+    try {
+      Field declaredField = fieldTypeClass.getDeclaredField(name);
+      //No null check as it'll throw NoSuchFieldException if Field is not found
+      value = declaredField.get(fieldTypeClass);
+    } catch (SecurityException e) {
+      LogUtil.info("Could not access "+name+" in "+fieldTypeClass, e);
+      value = null;
+    } catch (NoSuchFieldException e) {
+      LogUtil.info("Could not find "+name+" in "+fieldTypeClass, e);
+      value = null;
+    } catch (IllegalArgumentException e) {
+      LogUtil.info("Could not find "+name+" in "+fieldTypeClass, e);
+      value = null;
+    } catch (IllegalAccessException e) {
+      LogUtil.info("Could not access "+name+" in "+fieldTypeClass, e);
+      value = null;
+    }
+    
+    return value;
+  }
+  
+  public Object getBoolean() {
+    return getField("BOOLEAN");
+  }
+  
+  public Object getByte() {
+    return getField("BYTE");
+  }
+  
+  public Object getChar() {
+    return getField("CHAR");
+  }
+  
+  public Object getShort() {
+    return getField("SHORT");
+  }
+  
+  public Object getInt() {
+    return getField("INT");
+  }
+  
+  public Object getLong() {
+    return getField("LONG");
+  }
+  
+  public Object getFloat() {
+    return getField("FLOAT");
+  }
+  
+  public Object getDouble() {
+    return getField("DOUBLE");
+  }
+  
+  public Object getDate() {
+    return getField("DATE");
+  }
+  
+  public Object getString() {
+    return getField("STRING");
+  }
+  
+  public Object getObject() {
+    return getField("OBJECT");
+  }
+  
+  public Object getBooleanArray() {
+    return getField("BOOLEAN_ARRAY");
+  }
+  
+  public Object getByteArray() {
+    return getField("BYTE_ARRAY");
+  }
+  
+  public Object getCharArray() {
+    return getField("CHAR_ARRAY");
+  }
+  
+  public Object getShortArray() {
+    return getField("SHORT_ARRAY");
+  }
+  
+  public Object getIntArray() {
+    return getField("INT_ARRAY");
+  }
+  
+  public Object getLongArray() {
+    return getField("LONG_ARRAY");
+  }
+  
+  public Object getFloatArray() {
+    return getField("FLOAT_ARRAY");
+  }
+  
+  public Object getDoubleArray() {
+    return getField("DOUBLE_ARRAY");
+  }
+  
+  public Object getStringArray() {
+    return getField("STRING_ARRAY");
+  }
+  
+  public Object getObjectArray() {
+    return getField("OBJECT_ARRAY");
+  }
+  
+  public Object getArrayOfByteArrays() {
+    return getField("ARRAY_OF_BYTE_ARRAYS");
+  }
+  
+//  public static void main(String[] args) throws ClassNotFoundException {
+////    FieldTypeProxy proxy = new FieldTypeProxy(Class.forName("com.gemstone.gemfire.pdx.internal.FieldType"));
+//    FieldTypeProxy proxy = new FieldTypeProxy(Class.forName("com.gemstone.gemfire.pdx.FieldType"));
+//    
+//    System.out.println(proxy.getBoolean());
+//    System.out.println(proxy.getByte());
+//  }
+  
+  @Override
+  public String toString() {
+    return FieldTypeAccessor.class.getSimpleName()+"["+fieldTypeClass+"]";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/MapTypeResultImpl.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/MapTypeResultImpl.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/MapTypeResultImpl.java
new file mode 100644
index 0000000..0e4bc03
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/MapTypeResultImpl.java
@@ -0,0 +1,97 @@
+/*=========================================================================
+ * (c)Copyright 2002-2011, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.internal;
+
+import java.util.Collection;
+import java.util.Map;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnNotFoundException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.IntrospectionResult;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryExecutionException;
+import com.gemstone.gemfire.mgmt.DataBrowser.query.QueryUtil;
+
+public class MapTypeResultImpl implements IntrospectionResult {
+  private static final int CONST_COLUMN_COUNT = 1;
+  public static final String CONST_COLUMN_NAME = "Result";
+  private Class<?> type;
+  
+  public MapTypeResultImpl(Class<?> ty) {
+   this.type = ty; 
+  }
+  
+  
+  public int getResultType() {
+    return MAP_TYPE_RESULT;
+  }
+  
+  public Class<?> getJavaType() {
+    return this.type;
+  }  
+
+  public Class getColumnClass(int index) {
+    return this.type;
+  }
+  
+  public Class getColumnClass(Object tuple, int index)
+      throws ColumnNotFoundException {
+    return getColumnClass(index);
+  }
+
+  public int getColumnCount() {
+    return CONST_COLUMN_COUNT;
+  }
+
+  public String getColumnName(int index) {
+    return CONST_COLUMN_NAME;
+  }
+  
+  public int getColumnIndex(String name) throws ColumnNotFoundException {
+    if(CONST_COLUMN_NAME.equals(name))
+     return 0;
+    
+    throw new ColumnNotFoundException("Column not available for name :" + name);
+  }
+
+  public Object getColumnValue(Object tuple, int index) throws ColumnValueNotAvailableException {
+    if(tuple instanceof Map) {
+      Collection temp = null;
+      temp = ((Map)tuple).entrySet();   
+      
+      try {
+        return QueryUtil.introspectCollectionObject(temp);
+      }
+      catch (QueryExecutionException e) {
+        throw new ColumnValueNotAvailableException(e);
+      }
+    }    
+    throw new ColumnValueNotAvailableException(" Invalid object type. It should be java.util.Map : "+tuple);    
+  }
+
+  public int getColumnType(int index) throws ColumnNotFoundException {
+    if(index < CONST_COLUMN_COUNT)
+      return MAP_TYPE_COLUMN;
+    
+    throw new ColumnNotFoundException("Column not available for index :" + index);
+  }
+  
+  public int getColumnType(Object tuple, int index)
+      throws ColumnNotFoundException {
+    return getColumnType(index);
+  }
+  
+  public String getJavaTypeName() {
+    Class<?> javaType = getJavaType();
+    
+    return javaType != null ? javaType.getName() : null;
+  }
+
+  public boolean isCompatible(Object data) {
+    //checks for equality by reference not assignable. Using == assuming single 
+    //instance of a class
+    return data != null && getJavaType() == data.getClass();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectColumn.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectColumn.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectColumn.java
new file mode 100644
index 0000000..2f4a088
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectColumn.java
@@ -0,0 +1,30 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.internal;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+
+/**
+ * This interface represents a Column for a given Java type, which can either be
+ * a field or a Java Beans TM property of that type.
+ * 
+ * @author Hrishi
+ **/
+public interface ObjectColumn {
+
+  public Class getFieldType();
+
+  public String getFieldName();
+
+  public boolean isReadOnly();
+  
+  public boolean isFinal();
+  
+  public Class getDeclaringClass();
+  
+  public Object getValue(Object object)throws ColumnValueNotAvailableException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1709e627/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectFieldImpl.java
----------------------------------------------------------------------
diff --git a/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectFieldImpl.java b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectFieldImpl.java
new file mode 100644
index 0000000..4a42a06
--- /dev/null
+++ b/databrowser/src/com/gemstone/gemfire/mgmt/DataBrowser/query/internal/ObjectFieldImpl.java
@@ -0,0 +1,76 @@
+/*========================================================================= 
+ * (c)Copyright 2002-2009, GemStone Systems, Inc. All Rights Reserved.
+ * 1260 NW Waterhouse Ave., Suite 200, Beaverton, OR 97006 
+ * All Rights Reserved.
+ * =======================================================================*/
+package com.gemstone.gemfire.mgmt.DataBrowser.query.internal;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import com.gemstone.gemfire.mgmt.DataBrowser.query.ColumnValueNotAvailableException;
+
+public class ObjectFieldImpl implements ObjectColumn {
+  private Field field;
+  private boolean readOnly;
+  private boolean Final;
+    
+  public ObjectFieldImpl(Field fld, boolean ro) {
+    super();
+    this.field = fld;
+    this.readOnly = ro;
+    int modifier = this.field.getModifiers();
+    this.Final = (this.field.getType().isPrimitive() || Modifier.isFinal(modifier));
+  }
+
+  public Class<?> getFieldType() {
+    return field.getType();
+  }
+
+  public String getFieldName() {
+    return field.getName();
+  }
+
+  public boolean isReadOnly() {
+    return this.readOnly;
+  }
+  
+  public boolean isFinal() {
+    return this.Final;
+  }
+  
+  public Class getDeclaringClass() {
+    return this.field.getDeclaringClass();
+  }
+    
+  public Object getValue(Object object) throws ColumnValueNotAvailableException {
+    try {
+      return field.get(object);
+    }
+    catch (Exception e) {
+      throw new ColumnValueNotAvailableException(e);
+    }   
+  }
+  
+  @Override
+  public int hashCode() {
+    return this.field.getName().hashCode();
+  }
+  
+  @Override
+  public String toString() {
+    StringBuffer buffer = new StringBuffer();
+    buffer.append("ObjectFieldImpl [ declaringClass :"+this.getDeclaringClass()+" name :"+this.getFieldName()+" ]");
+    return buffer.toString();
+  }
+    
+  
+  @Override
+  public boolean equals(Object obj) {
+    if(obj instanceof ObjectColumn) {
+      ObjectColumn other = (ObjectColumn)obj;  
+      return (this.getFieldName().equals(other.getFieldName()));
+    }
+    return false;
+  }
+}


Mime
View raw message