4
* Copyright Ericsson AB 1997-2009. All Rights Reserved.
6
* The contents of this file are subject to the Erlang Public License,
7
* Version 1.1, (the "License"); you may not use this file except in
8
* compliance with the License. You should have received a copy of the
9
* Erlang Public License along with this software. If not, it can be
10
* retrieved online at http://www.erlang.org/.
12
* Software distributed under the License is distributed on an "AS IS"
13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
* the License for the specific language governing rights and limitations
21
* InitialReference is a class which generates the INIT reference
22
* which can be used by the InitialReferences interface.
26
public class InitialReference
32
public InitialReference(){;}
35
* Returns the stringified objectreference to the initial reference server
37
public String stringified_ior(String host, int port)
43
// byte_order followed by ' {"", [{0, '
44
// char iorBytesFirstPart[] = {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0};
45
char iorBytesFirstPart[] = {0,0,0,0,0,0,0,32,73,68,76,58,79,114,98,101,114,47,73,110,105,116,105,97,108,82,101,102,101,114,101,110,99,101,115,58,49,46,48,0,0,0,0,1,0,0,0,0};
46
// the objectkey "INIT
47
char iorBytesLastPart[] = {0,0,0,4,73,78,73,84};
49
// Fix the ProfileData struct.
50
char pdPrefix[] = {0,1,0,0};
51
char nullbyte[] = {0};
52
profileData = new String(pdPrefix) + enc_ulong(host.length() + 1) + host + new String(nullbyte);
53
profileData = align(profileData, 2);
54
profileData += enc_ushort(port);
55
profileData = align(profileData, 4);
56
profileData += new String(iorBytesLastPart);
58
iorByteString = new String(iorBytesFirstPart) + enc_ulong(profileData.length()) +
61
// System.out.print("Start[" + profileData.length() + "]");
62
// System.out.print("[");
63
// for(int x = 0; x < iorByteString.length(); x++)
65
// System.out.print((int) iorByteString.charAt(x) + ",");
67
// System.out.println("]");
69
iorString = createIOR(iorByteString);
70
// System.out.println(iorString);
75
private String enc_ushort(int s)
77
char byteArray[] = {(char) ((s >>> 8) & 0xFF),
78
(char) ((s >>> 0) & 0xFF)};
80
return new String(byteArray);
83
private String enc_ulong(int l)
85
char byteArray[] = {(char) ((l >>> 24) & 0xFF),
86
(char) ((l >>> 16) & 0xFF),
87
(char) ((l >>> 8) & 0xFF),
88
(char) ((l >>> 0) & 0xFF)};
90
return new String(byteArray);
94
private String createIOR(String bytes)
97
StringBuffer sb = new StringBuffer("IOR:");
99
for(i = 0; i < bytes.length(); i++)
101
int b = bytes.charAt(i);
105
int c1 = (n1 < 10) ? ('0' + n1) : ('a' + (n1 - 10));
106
int c2 = (n2 < 10) ? ('0' + n2) : ('a' + (n2 - 10));
111
return sb.toString();
114
private String align(String buffer, int alignment)
117
char nullbyte[] = {0};
119
int remainder = alignment - (buffer.length() % alignment);
120
if (remainder == alignment) return s;
122
for (int i = 0; i < remainder; i++)
124
s += new String(nullbyte);