001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: *
004: * The contents of this file are subject to the Mozilla Public License Version
005: * 1.1 (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS" basis,
010: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: * for the specific language governing rights and limitations under the
012: * License.
013: *
014: * The Original Code is Mozilla Communicator client code, released March 31, 1998.
015: *
016: * The Initial Developer of the Original Code is
017: * Netscape Communications Corporation.
018: * Portions created by Netscape are Copyright (C) 1998-1999
019: * Netscape Communications Corporation. All Rights Reserved.
020: *
021: * Contributor(s):
022: *
023: * IBM
024: * - Binding to permit interfacing between Mozilla and SWT
025: * - Copyright (C) 2003, 2004 IBM Corp. All Rights Reserved.
026: *
027: * ***** END LICENSE BLOCK ***** */
028: package org.eclipse.swt.internal.mozilla;
029:
030: public class nsID {
031:
032: public int m0;
033: public short m1;
034: public short m2;
035: public byte[] m3 = new byte[8];
036: public static final int sizeof = 16;
037:
038: public nsID() {
039: }
040:
041: public nsID(String id) {
042: Parse(id);
043: }
044:
045: public boolean Equals(nsID other) {
046: int /*long*/ptr = XPCOM.nsID_new();
047: XPCOM.memmove(ptr, this , nsID.sizeof);
048: int /*long*/otherPtr = XPCOM.nsID_new();
049: XPCOM.memmove(otherPtr, other, nsID.sizeof);
050: boolean result = XPCOM.nsID_Equals(ptr, otherPtr);
051: XPCOM.nsID_delete(ptr);
052: XPCOM.nsID_delete(otherPtr);
053: return result;
054: }
055:
056: public void Parse(String aIDStr) {
057: if (aIDStr == null)
058: throw new Error();
059: int i = 0;
060: for (; i < 8; i++)
061: m0 = (m0 << 4)
062: + Integer.parseInt(aIDStr.substring(i, i + 1), 16);
063: if (aIDStr.charAt(i++) != '-')
064: throw new Error();
065: for (; i < 13; i++)
066: m1 = (short) ((m1 << 4) + Integer.parseInt(aIDStr
067: .substring(i, i + 1), 16));
068: if (aIDStr.charAt(i++) != '-')
069: throw new Error();
070: for (; i < 18; i++)
071: m2 = (short) ((m2 << 4) + Integer.parseInt(aIDStr
072: .substring(i, i + 1), 16));
073: if (aIDStr.charAt(i++) != '-')
074: throw new Error();
075: for (; i < 21; i++)
076: m3[0] = (byte) ((m3[0] << 4) + Integer.parseInt(aIDStr
077: .substring(i, i + 1), 16));
078: for (; i < 23; i++)
079: m3[1] = (byte) ((m3[1] << 4) + Integer.parseInt(aIDStr
080: .substring(i, i + 1), 16));
081: if (aIDStr.charAt(i++) != '-')
082: throw new Error();
083: for (; i < 26; i++)
084: m3[2] = (byte) ((m3[2] << 4) + Integer.parseInt(aIDStr
085: .substring(i, i + 1), 16));
086: for (; i < 28; i++)
087: m3[3] = (byte) ((m3[3] << 4) + Integer.parseInt(aIDStr
088: .substring(i, i + 1), 16));
089: for (; i < 30; i++)
090: m3[4] = (byte) ((m3[4] << 4) + Integer.parseInt(aIDStr
091: .substring(i, i + 1), 16));
092: for (; i < 32; i++)
093: m3[5] = (byte) ((m3[5] << 4) + Integer.parseInt(aIDStr
094: .substring(i, i + 1), 16));
095: for (; i < 34; i++)
096: m3[6] = (byte) ((m3[6] << 4) + Integer.parseInt(aIDStr
097: .substring(i, i + 1), 16));
098: for (; i < 36; i++)
099: m3[7] = (byte) ((m3[7] << 4) + Integer.parseInt(aIDStr
100: .substring(i, i + 1), 16));
101: }
102:
103: }
|