1. /*
  2. * @(#)GenericIdentifiable.java 1.18 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.ior;
  8. import java.util.Arrays ;
  9. import org.omg.CORBA_2_3.portable.InputStream;
  10. import org.omg.CORBA_2_3.portable.OutputStream;
  11. import com.sun.corba.se.spi.ior.Identifiable ;
  12. /**
  13. * @author
  14. * This is used for unknown components and profiles. A TAG_MULTICOMPONENT_PROFILE will be represented this way.
  15. */
  16. public abstract class GenericIdentifiable implements Identifiable
  17. {
  18. private int id;
  19. private byte data[];
  20. public GenericIdentifiable(int id, InputStream is)
  21. {
  22. this.id = id ;
  23. data = EncapsulationUtility.readOctets( is ) ;
  24. }
  25. public int getId()
  26. {
  27. return id ;
  28. }
  29. public void write(OutputStream os)
  30. {
  31. os.write_ulong( data.length ) ;
  32. os.write_octet_array( data, 0, data.length ) ;
  33. }
  34. public String toString()
  35. {
  36. return "GenericIdentifiable[id=" + getId() + "]" ;
  37. }
  38. public boolean equals(Object obj)
  39. {
  40. if (obj == null)
  41. return false ;
  42. if (!(obj instanceof GenericIdentifiable))
  43. return false ;
  44. GenericIdentifiable encaps = (GenericIdentifiable)obj ;
  45. return (getId() == encaps.getId()) &&
  46. Arrays.equals( getData(), encaps.getData() ) ;
  47. }
  48. public int hashCode()
  49. {
  50. int result = 17 ;
  51. for (int ctr=0; ctr<data.length; ctr++ )
  52. result = 37*result + data[ctr] ;
  53. return result ;
  54. }
  55. public GenericIdentifiable(int id, byte[] data)
  56. {
  57. this.id = id ;
  58. this.data = (byte[])(data.clone()) ;
  59. }
  60. public byte[] getData()
  61. {
  62. return data ;
  63. }
  64. }