1 26 27 28 package org.objectweb.mobilitools.smi.api; 29 30 31 import java.lang.Comparable ; 32 import java.io.Serializable ; 33 34 35 40 public class Name implements Comparable , Serializable 41 { 42 byte[] my_authority; 43 byte[] my_identity; 44 short my_type; 45 46 47 51 public Name(Name name) 52 { 53 this(name.authority(), name.identity(), name.type()); 54 } 55 56 57 61 public Name(org.omg.CfMAF.Name name) 62 { 63 this(name.authority, name.identity, name.agent_system_type); 64 } 65 66 67 74 public Name(byte[] authority, byte[] identity, short type) 75 { 76 my_authority = authority; 77 my_identity = identity; 78 my_type = type; 79 } 80 81 82 89 public Name(String authority, String identity, short type) 90 { 91 this(authority.getBytes(), identity.getBytes(), type); 92 } 93 94 95 99 public Name(String str) 100 { 101 this( 102 new String (str.getBytes(), 1, str.getBytes()[0]), 103 new String (str.getBytes(), 2 + str.getBytes()[0], str.getBytes()[1 + str.getBytes()[0]]), 104 (short)Integer.parseInt(new String ( 105 str.getBytes(), 106 str.getBytes()[1+str.getBytes()[0]] + str.getBytes()[0] + 2, 107 str.getBytes().length - (str.getBytes()[1+str.getBytes()[0]] + str.getBytes()[0] + 2)))); 108 } 109 110 111 114 public org.omg.CfMAF.Name getmafname() 115 { 116 return new org.omg.CfMAF.Name(my_authority, my_identity, my_type); 117 } 118 119 120 123 public String identity() 124 { 125 return new String (my_identity); 126 } 127 128 129 132 public String authority() 133 { 134 return new String (my_authority); 135 } 136 137 138 141 public short type() 142 { 143 return my_type; 144 } 145 146 147 151 public String toString() 152 { 153 return identity() + " (" + authority() + ")"; 154 } 155 156 157 160 public String getStringRepresentation() 161 { 162 byte[] byteRep = new byte[1 + my_authority.length + 1 + my_identity.length]; 163 int i, j; 164 byteRep[0] = (byte) my_authority.length; 165 for (i=0, j=1 ; i<my_authority.length ; ++i, ++j) 166 { 167 byteRep[j] = my_authority[i]; 168 } 169 byteRep[j++] = (byte) my_identity.length; 170 for (i=0 ; i<my_identity.length ; ++i, ++j) 171 { 172 byteRep[j] = my_identity[i]; 173 } 174 return new String (byteRep) + String.valueOf(my_type); 175 } 176 177 178 public boolean equals(Object other) 179 { 180 Name otherName = null; 181 if (other instanceof Name) 182 { 183 otherName = (Name)other; 184 } 185 else if (other instanceof org.omg.CfMAF.Name) 186 { 187 otherName = new Name((org.omg.CfMAF.Name)other); 188 } 189 return 190 otherName != null && 191 identity().equals(otherName.identity()) && 192 authority().equals(otherName.authority()) && 193 my_type == otherName.type(); 194 } 195 196 197 public int hashCode() 198 { 199 return getStringRepresentation().hashCode(); 200 } 201 202 203 public int compareTo(Object other) 204 { 205 return getStringRepresentation().compareTo(((Name)other).getStringRepresentation()); 206 } 207 } 208 | Popular Tags |