KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > browser > PromptServiceFactory


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.browser;
12
13 import org.eclipse.swt.internal.C;
14 import org.eclipse.swt.internal.mozilla.*;
15
16 class PromptServiceFactory {
17     XPCOMObject supports;
18     XPCOMObject factory;
19     int refCount = 0;
20
21 public PromptServiceFactory () {
22     createCOMInterfaces ();
23 }
24
25 int AddRef () {
26     refCount++;
27     return refCount;
28 }
29
30 void createCOMInterfaces () {
31     /* Create each of the interfaces that this object implements */
32     supports = new XPCOMObject (new int[] {2, 0, 0}) {
33         public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
34         public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
35         public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
36     };
37     
38     factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) {
39         public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
40         public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
41         public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
42         public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);}
43         public int /*long*/ method4 (int /*long*/[] args) {return LockFactory (args[0]);}
44     };
45 }
46
47 void disposeCOMInterfaces () {
48     if (supports != null) {
49         supports.dispose ();
50         supports = null;
51     }
52     if (factory != null) {
53         factory.dispose ();
54         factory = null;
55     }
56 }
57
58 int /*long*/ getAddress () {
59     return factory.getAddress ();
60 }
61
62 int /*long*/ QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
63     if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE;
64     nsID guid = new nsID ();
65     XPCOM.memmove (guid, riid, nsID.sizeof);
66     
67     if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) {
68         XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF);
69         AddRef ();
70         return XPCOM.NS_OK;
71     }
72     if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) {
73         XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF);
74         AddRef ();
75         return XPCOM.NS_OK;
76     }
77     
78     XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
79     return XPCOM.NS_ERROR_NO_INTERFACE;
80 }
81             
82 int Release () {
83     refCount--;
84     if (refCount == 0) disposeCOMInterfaces ();
85     return refCount;
86 }
87     
88 /* nsIFactory */
89
90 public int /*long*/ CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) {
91     PromptService promptService = new PromptService ();
92     promptService.AddRef ();
93     XPCOM.memmove (result, new int /*long*/[] {promptService.getAddress ()}, C.PTR_SIZEOF);
94     return XPCOM.NS_OK;
95 }
96
97 public int /*long*/ LockFactory (int /*long*/ lock) {
98     return XPCOM.NS_OK;
99 }
100 }
101
Popular Tags