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

com.gemstone.gemfire.codeAnalysis.ClassAndVariableDetails Maven / Gradle / Ivy

There is a newer version: 2.0-BETA
Show 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.codeAnalysis;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gemstone.gemfire.codeAnalysis.decode.CompiledClass;
import com.gemstone.gemfire.codeAnalysis.decode.CompiledField;


/**
 * A class used to store the names of dataserializable classes and the sizes
 * of their toData/fromData methods.
 * 
 * @author bruces
 *
 */
public class ClassAndVariableDetails {
  public String className;
  public boolean hasSerialVersionUID;
  public String serialVersionUID;
  public Map variables = new HashMap();
  
  public ClassAndVariableDetails(CompiledClass dclass) {
    this.className = dclass.fullyQualifiedName();
  }
  
  public ClassAndVariableDetails(String storedValues) throws IOException {
    String[] fields = storedValues.split(",");
    try {
      int fieldIndex = 2;
      className = fields[0];
      hasSerialVersionUID = Boolean.valueOf(fields[1]);
      if (hasSerialVersionUID) {
        serialVersionUID = fields[2];
        fieldIndex ++;
      }
      for (int i=fieldIndex; i entry: variables.entrySet()) {
      sb.append(',').append(entry.getKey()).append(':').append(entry.getValue());
    }
    return sb.toString();
  }
  
  /**
   * convert a ClassAndMethods into a string that can then be used to
   * instantiate a ClassAndVariableDetails
   */
  public static String convertForStoring(ClassAndVariables cam)  {
    StringBuilder sb = new StringBuilder(150);
    sb.append(cam.dclass.fullyQualifiedName());
    sb.append(',').append(cam.hasSerialVersionUID);
    if (cam.hasSerialVersionUID) {
      sb.append(',').append(cam.serialVersionUID);
    }
    
    List fields = new ArrayList(cam.variables.values());
    Collections.sort(fields);
    for (CompiledField field: fields) {
      sb.append(',').append(field.name())
        .append(':').append(field.descriptor());
    }
    return sb.toString();
  }
  
  @Override
  public String toString() {
    return valuesAsString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy