All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.internal.admin.remote.EntryValueNodeImpl Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */

package com.gemstone.gemfire.internal.admin.remote;

import com.gemstone.gemfire.*;
import com.gemstone.gemfire.internal.admin.*;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;

import java.lang.reflect.*;
import java.io.*;
import java.util.*;

/**
 * This class holds the metadata for a single object field in a value
 * stored in the cache.  They are built during construction of {@link
 * ObjectDetailsResponse} instances and returned to the console. This
 * class does not implement {@link
 * com.gemstone.gemfire.DataSerializable} since that
 * mechanism gets confused by the often cyclical refrences between
 * instances of this class.
 */
public class EntryValueNodeImpl implements EntryValueNode, Externalizable/*, DataSerializable */ {

  private Object primitiveVal;
  private String type;
  private String name;
  private boolean primitive;
  private EntryValueNodeImpl[] fields;
  private static ThreadLocal recursionSet = new ThreadLocal();

  public static EntryValueNodeImpl createFromValueRoot(Object value,
                                                       boolean logicalInspection) {
    recursionSet.set(new IdentityHashMap());
    EntryValueNodeImpl retVal = null;
    if (value != null) {
      retVal = createFromObject(constructKeyDisplay(value), value, logicalInspection);
    }
    Map map = (Map)recursionSet.get();
    map.clear();
    recursionSet.set(null);

    return retVal;
  }

  private static EntryValueNodeImpl createFromPrimitive(String fieldName, String type,
                                                       Object primitiveWrapper) {    
    EntryValueNodeImpl node = new EntryValueNodeImpl();
    node.name = fieldName;
    node.type = type;
    node.primitiveVal = primitiveWrapper;
    node.primitive = true;
    return node;
  }

  private static EntryValueNodeImpl createFromNullField(String fieldName, Class fieldType) {
    EntryValueNodeImpl node = new EntryValueNodeImpl();
    node.name = fieldName;
    if (fieldType.isArray()) {
      node.type = "array of" + fieldType.getComponentType().getName();
    } else {
      node.type = fieldType.getName();
    }
    node.primitiveVal = "null";
    node.primitive = true;
    return node;
  }

  private static EntryValueNodeImpl createFromArray(String fieldName, Object arrayObj,
                                                    Class arrayClass) {
    EntryValueNodeImpl node = new EntryValueNodeImpl();
    Map map = (Map)recursionSet.get();
    map.put(arrayObj, node);

    node.name = fieldName;
    Class compType = arrayClass.getComponentType();
    String elType = compType.getName();
    node.type = "array of " + elType;
    node.primitiveVal = arrayObj.toString();
    node.primitive = false;
//    if (arrayObj != null) (cannot be null) 
    {
      EntryValueNodeImpl[] children;
      if (arrayObj instanceof Object[]) {
        Object[] array = (Object[])arrayObj;
        children = new EntryValueNodeImpl[array.length];
        for (int i = 0; i" + constructKeyDisplay(key),
                                                key, logicalInspection));
                } else {
                  elements.add(createFromNullField("key->" + constructKeyDisplay(key),
                                                   Object.class));
                }
                if (value != null) {
                  elements.add(createFromObject("value->" + constructKeyDisplay(value),
                                                value, logicalInspection));
                } else {
                  elements.add(createFromNullField("value->" + constructKeyDisplay(value),
                                                   Object.class));
                }
              }
            }
          } else if (obj instanceof List) {
            java.util.List list = (List)obj;
            ListIterator it = list.listIterator();
            while (it.hasNext()) {
//               if (cancelled) { return; }
              Object element = it.next();
              elements.add(createFromObject(constructKeyDisplay(element),
                                            element, logicalInspection));
            }
          } else if (obj instanceof Collection) {
            Collection coll = (Collection)obj;
            Iterator it = coll.iterator();
            while (it.hasNext()) {
//               if (cancelled) { return; }
              Object element = it.next();
              elements.add(createFromObject(constructKeyDisplay(element),
                                            element, logicalInspection));
            }
          }
        } catch (ConcurrentModificationException ex) {
          elements = new ArrayList();
          retryCount++;
          if (retryCount <= 5) {
            retry = true;
          }
        }
      } while (retry);
//       if (cancelled) { return; }
      
      node.fields = (EntryValueNodeImpl[])elements.toArray(new EntryValueNodeImpl[0]);
      
    } else { //physical inspection

      Field[] fields = clazz.getDeclaredFields();
      try {
        AccessibleObject.setAccessible(fields, true);
      } catch (SecurityException se) {
        throw new InternalGemFireException(LocalizedStrings.EntryValueNodeImpl_UNABLE_TO_SET_ACCESSIBILITY_OF_FIELD_OBJECTS_DURING_CACHE_VALUE_DISPLAY_CONSTRUCTION.toLocalizedString(), se);
      }
      List fieldList = new ArrayList();
      for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy