KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > internal > mozilla > nsID


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Mozilla Communicator client code, released March 31, 1998.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corporation.
18  * Portions created by Netscape are Copyright (C) 1998-1999
19  * Netscape Communications Corporation. All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * IBM
24  * - Binding to permit interfacing between Mozilla and SWT
25  * - Copyright (C) 2003, 2004 IBM Corp. All Rights Reserved.
26  *
27  * ***** END LICENSE BLOCK ***** */

28 package org.eclipse.swt.internal.mozilla;
29
30 public class nsID {
31     
32     public int m0;
33     public short m1;
34     public short m2;
35     public byte[] m3 = new byte[8];
36     public static final int sizeof = 16;
37
38 public nsID() {
39 }
40
41 public nsID(String JavaDoc id) {
42     Parse(id);
43 }
44
45 public boolean Equals(nsID other) {
46     int /*long*/ ptr = XPCOM.nsID_new();
47     XPCOM.memmove(ptr, this, nsID.sizeof);
48     int /*long*/ otherPtr = XPCOM.nsID_new();
49     XPCOM.memmove(otherPtr, other, nsID.sizeof);
50     boolean result = XPCOM.nsID_Equals(ptr, otherPtr);
51     XPCOM.nsID_delete(ptr);
52     XPCOM.nsID_delete(otherPtr);
53     return result;
54 }
55
56 public void Parse (String JavaDoc aIDStr) {
57     if(aIDStr == null) throw new Error JavaDoc ();
58     int i = 0;
59     for (; i < 8; i++) m0 = (m0 << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16);
60     if (aIDStr.charAt (i++) != '-') throw new Error JavaDoc ();
61     for (; i < 13; i++) m1 = (short)((m1 << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
62     if (aIDStr.charAt (i++) != '-') throw new Error JavaDoc ();
63     for (; i < 18; i++) m2 = (short)((m2 << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
64     if (aIDStr.charAt (i++) != '-') throw new Error JavaDoc ();
65     for (; i < 21; i++) m3[0] = (byte)((m3[0] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
66     for (; i < 23; i++) m3[1] = (byte)((m3[1] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
67     if (aIDStr.charAt (i++) != '-') throw new Error JavaDoc ();
68     for (; i < 26; i++) m3[2] = (byte)((m3[2] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
69     for (; i < 28; i++) m3[3] = (byte)((m3[3] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
70     for (; i < 30; i++) m3[4] = (byte)((m3[4] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
71     for (; i < 32; i++) m3[5] = (byte)((m3[5] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
72     for (; i < 34; i++) m3[6] = (byte)((m3[6] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
73     for (; i < 36; i++) m3[7] = (byte)((m3[7] << 4) + Integer.parseInt (aIDStr.substring (i, i + 1), 16));
74 }
75
76 }
Popular Tags