1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.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 Oracle Corporation code.
15 *
16 * The Initial Developer of the Original Code is
17 * Oracle Corporation
18 * Portions created by the Initial Developer are Copyright (C) 2004
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
23 * Philipp Kewisch <mozilla@kewis.ch>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 // nsIFactory
40 const calMemoryCalendarFactory = {
QueryInterface
41 QueryInterface: function (aIID) {
42 if (!aIID.equals(Components.interfaces.nsISupports) &&
43 !aIID.equals(Components.interfaces.nsIFactory)) {
44 throw Components.results.NS_ERROR_NO_INTERFACE;
45 }
46 return this;
47 },
48
createInstance
49 createInstance: function (outer, iid) {
50 if (outer != null)
51 throw Components.results.NS_ERROR_NO_AGGREGATION;
52 return (new calMemoryCalendar()).QueryInterface(iid);
53 }
54 };
55
56 /****
57 **** module registration
58 ****/
59
60 var calMemoryCalendarModule = {
61 mCID: Components.ID("{bda0dd7f-0a2f-4fcf-ba08-5517e6fbf133}"),
62 mContractID: "@mozilla.org/calendar/calendar;1?type=memory",
63
64 mUtilsLoaded: false,
cMCM_loadUtils
65 loadUtils: function cMCM_loadUtils() {
66 if (this.mUtilsLoaded) {
67 return;
68 }
69
70 const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
71 const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
72
73 const iosvcContractID = "@mozilla.org/network/io-service;1";
74 const iosvcIID = Components.interfaces.nsIIOService;
75
76 var loader = Components.classes[jssslContractID].getService(jssslIID);
77 var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
78
79 // Note that unintuitively, __LOCATION__.parent == .
80 // We expect to find utils in ./../js
81 var appdir = __LOCATION__.parent.parent;
82 appdir.append("js");
83 const scripts = ["calUtils.js", "calProviderBase.js",
84 "calMemoryCalendar.js" ];
85
86 for each (var scriptName in scripts) {
87 var f = appdir.clone();
88 f.append(scriptName);
89
90 try {
91 var fileurl = iosvc.newFileURI(f);
92 loader.loadSubScript(fileurl.spec, null);
93 } catch (e) {
94 Components.utils.reportError("Error while loading " + fileurl.spec);
95 throw e;
96 }
97 }
98
99 this.mUtilsLoaded = true;
100 },
101
registerSelf
102 registerSelf: function (compMgr, fileSpec, location, type) {
103 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
104 compMgr.registerFactoryLocation(this.mCID,
105 "Calendar in-memory back-end",
106 this.mContractID,
107 fileSpec,
108 location,
109 type);
110 },
111
getClassObject
112 getClassObject: function (compMgr, cid, iid) {
113 if (!cid.equals(this.mCID))
114 throw Components.results.NS_ERROR_NO_INTERFACE;
115
116 if (!iid.equals(Components.interfaces.nsIFactory))
117 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
118
119 this.loadUtils();
120
121 return calMemoryCalendarFactory;
122 },
123
canUnload
124 canUnload: function(compMgr) {
125 return true;
126 }
127 };
128
NSGetModule
129 function NSGetModule(compMgr, fileSpec) {
130 return calMemoryCalendarModule;
131 }