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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.options;

import java.io.*;
import java.util.Collection;

import org.openide.ErrorManager;
import org.openide.TopManager;
import org.openide.util.Lookup;
import org.openide.util.io.NbObjectInputStream;
import org.openide.util.io.NbObjectOutputStream;
import org.openide.util.io.SafeException;


/** Singleton pool with a list of options for the entire IDE.
* Provides "safe" serialization of options
* (i.e. failures are per-property, not per-option nor per-pool).
*
* @author Jaroslav Tulach, Petr Hamernik
* @deprecated With the use of services and XML layers, this class is not useful.
*/
public class ControlPanel extends Object implements java.io.Serializable {
    /** generated Serialized Version UID */
    static final long serialVersionUID = 6242888199364119241L;
    /** Result of the query with ManifestSection.OptionSection. */
    private Lookup.Result result = null;

    /** Default constructor, not to be called by user code.
    * @see TopManager#getControlPanel
    */
    public ControlPanel() {}

    /** Add a new option to the pool.
    * @param so the option to add
    * @return true if the object was added; false if it was already there
    * @deprecated Use a declaration in a manifest file.
    */
    public synchronized boolean add (SystemOption so) {
        return false;
    }

    /** Remove an option from the pool.
    * @param so the option to remove
    * @return true if the option was removed; false if it was not there anyway
    * @deprecated Use a declaration in a manifest file.
    */
    public synchronized boolean remove (SystemOption so) {
        return false;
    }

    /** Get all options in the pool.
    * @return the options
    */
    public SystemOption[] getSystemOptions() {
        if (result == null) {
            result = Lookup.getDefault().lookup(
                new Lookup.Template(SystemOption.class)
            );
        }
        
        Collection options = result.allInstances();
        
        return (SystemOption[]) options.toArray(new SystemOption[options.size()]);
    }

    /* Stores content of the pool. Uses safe serialization for each options.
    */
    public void writeExternal (ObjectOutput oo) throws IOException {
        SystemOption[] arr = getSystemOptions ();
        oo.writeInt (arr.length);
        for (int i = 0; i < arr.length; i++) {
            // XXX should this be arr[i].getClass ().getName () ???
            oo.writeUTF (arr.getClass ().getName ());
            try {
                NbObjectOutputStream.writeSafely (oo, arr[i]);
            } catch (SafeException ex) {
                Exception e = ex.getException ();
                ErrorManager.getDefault ().annotate (e, ErrorManager.INFORMATIONAL, arr[i].getClass ().getName (), null, null, null);
                ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, e);
            }
        }
    }

    /* Reads content of the pool.
    */
    public void readExternal (ObjectInput oi) throws IOException, ClassNotFoundException {
        int len = oi.readInt ();
        while (len-- > 0) {
            /*String name = */oi.readUTF ();
            try {
                NbObjectInputStream.readSafely (oi);
            } catch (SafeException ex) {
                ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ex.getException ());
            }
        }
    }

    /* Creates replaces for this panel that stores and read data to the
    * default control panel
    */
    public final Object writeReplace () {
        return new Replace ();
    }

    /** Replace class */
    private static final class Replace implements java.io.Serializable {
        /** SUID */
        static final long serialVersionUID = -1956267184272888393L;

	Replace() {}

        private void writeObject (ObjectOutputStream oos) throws IOException {
            TopManager.getDefault ().getControlPanel ().writeExternal (oos);
        }

        private void readObject (ObjectInputStream ois)
        throws IOException, ClassNotFoundException {
            TopManager.getDefault ().getControlPanel ().readExternal (ois);
        }

        /** @return the default pool */
        public Object readResolve () {
            return TopManager.getDefault ().getControlPanel ();
        }
    }
}
... 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.