001// 002// Name 003// $RCSfile: ManagedObjectStreamClass.java,v $ 004// 005// Copyright 006// Confidential Property of Kabira Technologies, Inc. 007// Copyright 2011 by Kabira Technologies, Inc. 008// All rights reserved. 009// 010// History 011// $Revision: 1.1.2.2 $ $Date: 2011/10/05 23:45:09 $ 012// 013package com.kabira.platform; 014 015import java.io.ObjectStreamField; 016import java.io.ObjectOutput; 017import java.io.IOException; 018 019/** 020 * Class used to manage managed object streams. 021 */ 022public final class ManagedObjectStreamClass 023{ 024 ManagedObjectStreamClass(long offset) 025 throws IOException 026 { 027 m_td = TypeDescriptor.getDescriptor(offset); 028 loadStreamFields(); 029 } 030 031 /** 032 * Get a field of this managed class by name. 033 */ 034 public ObjectStreamField getField(String name) 035 { 036 for (int i = 0; i < m_streamFields.length; i++) 037 { 038 if (m_streamFields[i].getName().equals(name)) 039 { 040 return m_streamFields[i]; 041 } 042 } 043 return null; 044 } 045 046 /** 047 * Return an array of the fields of this managed class. 048 */ 049 public ObjectStreamField[] getFields() 050 { 051 return m_streamFields; 052 } 053 054 /** 055 * Returns the name of the class described by this descriptor. 056 */ 057 public String getName() 058 { 059 return m_td.m_className; 060 } 061 062 /** 063 * Return the serialVersionUID for this class. 064 * 065 * If there was no serialVersionUID defined in 066 * the class a value of 0L is returned. 067 */ 068 public long getSerialVersionUID() 069 { 070 return m_td.m_serialVersionUID; 071 } 072 073 // 074 // FIX THIS: If we want to support offsets, we need to subclass 075 // ObjectStreamField and implement setOffset(). 076 // 077 private void loadStreamFields() throws IOException 078 { 079 m_streamFields = new ObjectStreamField[m_td.m_fields.size()]; 080 081 int idx = 0; 082 083 try 084 { 085 for (TypeDescriptor.FieldDescriptor fd : m_td.m_fields) 086 { 087 Class cls = m_td.forName(fd); 088 m_streamFields[idx] = new ObjectStreamField( 089 fd.m_name, m_td.forName(fd)); 090 idx++; 091 } 092 } 093 catch (ClassNotFoundException ex) 094 { 095 throw new IOException(ex); 096 } 097 } 098 099 TypeDescriptor m_td; 100 ObjectStreamField [] m_streamFields; 101}