001// 002// Name 003// $RCSfile: ManagedObjectStreamClass.java,v $ 004// 005// Copyright 006// Copyright 2011-2015 Cloud Software Group, Inc. ALL RIGHTS RESERVED. 007// Cloud Software Group, Inc. Confidential Information 008// 009// History 010// $Revision: 1.1.2.4 $ $Date: 2015/01/27 03:24:39 $ 011// 012package com.kabira.platform; 013 014import java.io.ObjectStreamField; 015import java.io.ObjectOutput; 016import java.io.IOException; 017 018/** 019 * Class used to manage managed object streams. 020 */ 021public final class ManagedObjectStreamClass 022{ 023 ManagedObjectStreamClass(long offset) 024 throws IOException 025 { 026 m_td = TypeDescriptor.getDescriptor(offset); 027 loadStreamFields(); 028 } 029 030 ManagedObjectStreamClass(int domainId, int typeId) 031 throws IOException 032 { 033 m_td = TypeDescriptor.getDescriptor(domainId, typeId); 034 loadStreamFields(); 035 } 036 037 /** 038 * Get a field of this managed class by name. 039 * @param name Field name to get. 040 * @return ObjectStreamField instance or null if name not found. 041 */ 042 public ObjectStreamField getField(String name) 043 { 044 for (int i = 0; i < m_streamFields.length; i++) 045 { 046 if (m_streamFields[i].getName().equals(name)) 047 { 048 return m_streamFields[i]; 049 } 050 } 051 return null; 052 } 053 054 /** 055 * Return an array of the fields of this managed class. 056 * @return Array of ObjectStreamField instances. 057 */ 058 public ObjectStreamField[] getFields() 059 { 060 return m_streamFields; 061 } 062 063 /** 064 * Returns the name of the class described by this descriptor. 065 * @return Name of class. 066 */ 067 public String getName() 068 { 069 return m_td.m_className; 070 } 071 072 /** 073 * Return the serialVersionUID for this class. 074 * <p> 075 * If there was no serialVersionUID defined in 076 * the class a value of 0L is returned. 077 * @return Serial version id. 078 */ 079 public long getSerialVersionUID() 080 { 081 return m_td.m_serialVersionUID; 082 } 083 084 // 085 // FIX THIS: If we want to support offsets, we need to subclass 086 // ObjectStreamField and implement setOffset(). 087 // 088 private void loadStreamFields() throws IOException 089 { 090 m_streamFields = new ObjectStreamField[m_td.m_fields.size()]; 091 092 int idx = 0; 093 094 try 095 { 096 for (TypeDescriptor.FieldDescriptor fd : m_td.m_fields) 097 { 098 Class<?> cls = TypeDescriptor.forName(fd); 099 m_streamFields[idx] = new ObjectStreamField( 100 fd.m_name, 101 TypeDescriptor.forName(fd)); 102 idx++; 103 } 104 } 105 catch (ClassNotFoundException ex) 106 { 107 throw new IOException(ex); 108 } 109 } 110 111 TypeDescriptor m_td; 112 ObjectStreamField [] m_streamFields; 113}