KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > GenericIdentifiable


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
8 package com.sun.corba.se.impl.ior;
9
10 import java.util.Arrays JavaDoc ;
11
12 import org.omg.CORBA_2_3.portable.InputStream JavaDoc;
13 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc;
14
15 import com.sun.corba.se.spi.ior.Identifiable ;
16
17 /**
18  * @author
19  * This is used for unknown components and profiles. A TAG_MULTICOMPONENT_PROFILE will be represented this way.
20  */

21 public abstract class GenericIdentifiable implements Identifiable
22 {
23     private int id;
24     private byte data[];
25     
26     public GenericIdentifiable(int id, InputStream JavaDoc is)
27     {
28     this.id = id ;
29     data = EncapsulationUtility.readOctets( is ) ;
30     }
31     
32     public int getId()
33     {
34     return id ;
35     }
36     
37     public void write(OutputStream JavaDoc os)
38     {
39     os.write_ulong( data.length ) ;
40     os.write_octet_array( data, 0, data.length ) ;
41     }
42     
43     public String JavaDoc toString()
44     {
45     return "GenericIdentifiable[id=" + getId() + "]" ;
46     }
47     
48     public boolean equals(Object JavaDoc obj)
49     {
50     if (obj == null)
51         return false ;
52
53     if (!(obj instanceof GenericIdentifiable))
54         return false ;
55
56     GenericIdentifiable encaps = (GenericIdentifiable)obj ;
57
58     return (getId() == encaps.getId()) &&
59         Arrays.equals( getData(), encaps.getData() ) ;
60     }
61    
62     public int hashCode()
63     {
64     int result = 17 ;
65     for (int ctr=0; ctr<data.length; ctr++ )
66         result = 37*result + data[ctr] ;
67     return result ;
68     }
69
70     public GenericIdentifiable(int id, byte[] data)
71     {
72     this.id = id ;
73     this.data = (byte[])(data.clone()) ;
74     }
75     
76     public byte[] getData()
77     {
78     return data ;
79     }
80 }
81
Popular Tags