// vim: ts=4 sw=4 filetype=javascript expandtab cindent foldmethod=marker
//
// BEGIN FLOCK GPL
// 
// Copyright Flock Inc. 2005-2006
// http://flock.com
// 
// This file may be used under the terms of of the
// GNU General Public License Version 2 or later (the "GPL"),
// http://www.gnu.org/licenses/gpl.html
// 
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
// 
// END FLOCK GPL
//


const FLOCK_CLUSTER_CONTRACTID = '@flock.com/cluster;1'
const FLOCK_CLUSTER_CID = '{17052c97-f78e-4e23-961a-68cc16b005f8}';
const FLOCK_CLUSTER_DESC = 'A cluster of RSS posts.';

const flockICluster                 = Components.interfaces.flockICluster;
const nsISupports                   = Components.interfaces.nsISupports;
const nsIClassInfo                  = Components.interfaces.nsIClassInfo;
const nsITimer                      = Components.interfaces.nsITimer;

// flockICluster implementation /*{{{*/
function flockCluster()
{
    this.mKeyword = null;
    this.mKeyword2 = null;
    this.mPosts = null;
}

// the nsISupports implementation /*{{{*/
flockCluster.prototype.QueryInterface =
function (iid) {
    if (!iid.equals(flockICluster) && 
        !iid.equals(nsITimer) &&
        !iid.equals(nsIClassInfo) &&
        !iid.equals(nsISupports))
        throw Components.results.NS_ERROR_NO_INTERFACE;
    return this;
} /*}}}*/
// the nsIClassInfo implementation /*{{{*/
flockCluster.prototype.flags = nsIClassInfo.SINGLETON;
flockCluster.prototype.classDescription = FLOCK_CLUSTER_DESC;
flockCluster.prototype.getInterfaces = function (count) {
    var interfaceList = [flockICluster, nsIClassInfo];
    count.value = interfaceList.length;
    return interfaceList;
}
flockCluster.prototype.getHelperForLanguage = function (count) {return null;}
/*}}}*/


flockCluster.prototype.getKeyword =
function() {
    return this.mKeyword;
}
flockCluster.prototype.setKeyword =
function(aKeyword) {
    this.mKeyword = aKeyword;
}
flockCluster.prototype.getKeyword2 =
function() {
    return this.mKeyword2;
}
flockCluster.prototype.setKeyword2 =
function(aKeyword2) {
    this.mKeyword2 = aKeyword2;
}
flockCluster.prototype.getPosts =
function() {
    return this.mPosts;
}
flockCluster.prototype.setPosts =
function(aPosts) {
    this.mPosts = aPosts;
}
/*}}}*/


// JavaScript XPCOM Boilerplate /*{{{*/
function clusterModule (aCID, aContractId, aComponentName, aConstructor) {
    this.mCID = Components.ID (aCID);
    this.mContractId = aContractId;
    this.mComponentName = aComponentName;
    this.mConstructor = aConstructor;

    // factory object
    this.mFactory = {
        constructor: this.mConstructor,
        createInstance: function (aOuter, aIID) {
            if (aOuter != null) {
                throw Components.results.NS_ERROR_NO_AGGREGATION;
            }

            return (new (this.constructor) ()).QueryInterface (aIID);
        }
    };
}
clusterModule.prototype = {
    // the module should register itself
    registerSelf: function (aCompMgr, aLocation, aLoaderStr, aType) {
        aCompMgr = aCompMgr.QueryInterface (
                Components.interfaces.nsIComponentRegistrar);
        aCompMgr.registerFactoryLocation (this.mCID, this.mComponentName, 
                this.mContractId, aLocation, aLoaderStr, aType);
    },

    // get the factory                  
    getClassObject: function (aCompMgr, aCID, aIID) {
        if (!aCID.equals (this.mCID)) {
            throw Components.results.NS_ERROR_NO_INTERFACE;
        }

        if (!aIID.equals (Components.interfaces.nsIFactory)) {
            throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
        }

        return this.mFactory;
    },

    canUnload: function(compMgr) {
        return true;
    }
};
/* entrypoint */
function NSGetModule(compMgr, fileSpec) {
    return new clusterModule(FLOCK_CLUSTER_CID, FLOCK_CLUSTER_CONTRACTID,
                             FLOCK_CLUSTER_DESC, flockCluster);
}
/*}}}*/

