alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.catalog.settings;

import java.io.*;
import java.util.*;
import java.beans.*;
import org.netbeans.modules.xml.catalog.lib.IteratorIterator;

import org.openide.*;
import org.openide.util.HelpCtx;
import org.openide.util.io.NbMarshalledObject;

import org.netbeans.modules.xml.catalog.spi.*;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.Repository;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.loaders.FolderLookup;
import org.openide.util.Lookup;
import org.openide.util.LookupListener;
import org.openide.util.LookupEvent;
import org.openide.util.lookup.Lookups;


/** 
 * The pool holding mounted catalogs both at per project basics
 * and at at global basics. Project scope catalogs are always considered a higher
 * priority ones.
 * 

* Global scope catalogs are intended to be used by semantics modules for * which one can assume that if an user enabled such module then the user * really wants to have enabled module catalog. It can be done declarativelly * at module layer as InstanceCookie providers of {@link CatalogReader}: *

 * 
 * 
 *   
 *      
 *      
 *   
 * 
 * 
 * 
*

* Project scope settings are currently only accesible by this class addCatalog * and removeCatalog methods. It's persistent for Serializable * implementations. * * @deprecated Modules are highly suggested to use declarative registrations * of global catalogs. Project scope catalogs should be managed by user via UI only. * * @thread implementation is thread safe * * @author Petr Kuzel */ public final class CatalogSettings implements Externalizable { /** Serial Version UID */ private static final long serialVersionUID = 7895789034L; public static final int VERSION_1 = 1; //my externalization protocol version /** Identifies property holding mounted catalogs */ public static final String PROP_MOUNTED_CATALOGS = "catalogs"; // NOI18N // folder at SFS holding global registrations private static final String REGISTRATIONS = "Plugins/XML/UserCatalogs"; /** * Project has changed. You MUST switch to new settings instance. * It is fired at the old instance. * @deprecated It is hack for NetBeans 3.X lacking project system */ public static final String PROP_PRJ_INSTANCE = "cat-prj-in"; // cached instance private static Lookup userCatalogLookup; // ordered set of mounted catalogs private List mountedCatalogs = new ArrayList(5); private PropertyChangeSupport listeners = null; private final CatalogListener catalogListener = new CL(); private static ErrorManager err = null; // active result of lookup for this setting private static Lookup.Result result = null; // the only active instance in current project private static CatalogSettings instance = null; /** * Just for externalization purposes. * It MUST NOT be called directly by a user code. */ public CatalogSettings() { init(); } /** * Initialized the instance from externalization. */ private void init() { listeners = new PropertyChangeSupport(this); } /** * Return active settings instance in the only one active project. * @deprecated does not allow multiple opened projects */ public static synchronized CatalogSettings getDefault() { if (result == null) { result = Lookup.getDefault().lookup(new Lookup.Template(CatalogSettings.class)); // listen at project "switch", we are project setting result.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent e) { CatalogSettings oldSettings = instance; synchronized (CatalogSettings.class) { instance = (CatalogSettings) Lookup.getDefault().lookup(CatalogSettings.class); } if (oldSettings != null) { oldSettings.firePropertyChange(PROP_PRJ_INSTANCE, oldSettings, instance); } } }); // start result listening instance = (CatalogSettings) result.allInstances().iterator().next(); } return instance; } /** * Register mounted catalog at project scope level. * @param provider to be registered. Must not be null. */ public final void addCatalog(CatalogReader provider) { synchronized (this) { if (provider == null) throw new IllegalArgumentException("null provider not permited"); // NOI18N if (mountedCatalogs.contains(provider) == false) { mountedCatalogs.add(provider); } } firePropertyChange(PROP_MOUNTED_CATALOGS, null, null); // add listener to the catalog try { provider.addCatalogListener(catalogListener); } catch (UnsupportedOperationException ex) { // ignore it, we just can not listen at it and save it on change // it is fully OK until the catalog instance supports data source // change } } /** * Deregister given catalog at project scope level. */ public final void removeCatalog(CatalogReader provider) { synchronized (this) { mountedCatalogs.remove(provider); } firePropertyChange(PROP_MOUNTED_CATALOGS, null, null); // remove listener to the catalog try { provider.removeCatalogListener(catalogListener); } catch (UnsupportedOperationException ex) { // ignore it } } /** * Return iterator of providers of given class. * * @param providerClasses returned providers will be assignable to it * e.g. CatalogReader class or null * as a wildcard. * @return providers of given class or all if passed null/code> argument. * It never returns null. */ public final synchronized Iterator getCatalogs(Class[] providerClasses) { // compose global registrations and local(project) registrations IteratorIterator it = new IteratorIterator(); it.add(mountedCatalogs.iterator()); Lookup.Template template = new Lookup.Template(CatalogReader.class); Lookup.Result result = getUserCatalogsLookup().lookup(template); it.add(result.allInstances().iterator()); if (providerClasses == null) return it; ArrayList list = new ArrayList(); try_next_provider: while (it.hasNext()) { Object next = it.next(); // provider test for (int i=0; i

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.