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

package org.netbeans.core.deprecated;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import org.openide.*;
import org.openide.cookies.*;
import org.openide.loaders.*;
import org.openide.filesystems.*;
import org.openide.util.NbBundle;
import org.openide.util.io.*;
import org.openide.util.Lookup;
import org.openide.nodes.*;
import org.openide.windows.WindowManager;


/** Default implementation of a project.
*
* @author Jaroslav Tulach
*/
final class NbProject extends Object implements ProjectCookie {
    /** serial version UID */
    static final long serialVersionUID=8726895988034807614L;

    //
    // implementation of the default project
    //

    private static byte SAVE_CONTROL_PANEL = 1;
    private static byte SAVE_REPOSITORY = 2;
    private static byte SAVE_WORKSPACES = 4;
    private static byte SAVE_SERVICES = 8;

    // ----------------------------------------------------------------------------------------
    // Default simple ProjectCookie implementation

    /** Opens the project by loading its settings to the IDE. This method is
     * here for backward compatibility only. Since Nb 3.3 no parts of the system
     * need explicit saving/loading by projects subsystem.
     *
     * @exception IOException if an error occured during opening the project
     */
    public void projectOpen () throws IOException {
        // remove project layer
        org.netbeans.core.projects.SessionManager.getDefault ().setProjectLayer (null);

        FileObject projectFile = getSerializedProjectFile (false);
        if (projectFile == null) return; // project does not exist

        ObjectInputStream ois = null;
        try {
            ois = new NbObjectInputStream (
		new BufferedInputStream (projectFile.getInputStream (), 16384));

            // A. load info about what is stored in the project
            byte loadFlags = ois.readByte ();

            // B. load all items that are to be loaded
            // 1. Repository
            try {
                if ((loadFlags & SAVE_REPOSITORY) != 0) NbObjectInputStream.readSafely (ois);
            } catch (SafeException exc) {
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
            }

            // 2. Control panel
            try {
                if ((loadFlags & SAVE_CONTROL_PANEL) != 0) NbObjectInputStream.readSafely (ois);
            } catch (SafeException exc) {
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
            }

            // 3. Workspaces
            // PENDING What all this does mean?
//            WindowManagerImpl wmImpl = (WindowManagerImpl)WindowManager.getDefault();
            WindowManager.getDefault(); // replaces above ??
            if (((loadFlags & SAVE_WORKSPACES) != 0) && (System.getProperty ("netbeans.workspaces.noload") == null)) {
                try {
                    NbObjectInputStream.readSafely (ois);
                } catch (SafeException exc) {
                    ErrorManager.getDefault().annotate(exc, NbBundle.getMessage(NbProject.class, "EXC_WorkspaceLoadFail"));
                    ErrorManager.getDefault().notify(exc);
                    // create default
//                    if (!wmImpl.isCreated())
//                        WindowManagerImpl.createFromScratch();
                }
            } else {
                if ((loadFlags & SAVE_WORKSPACES) != 0) {
                    NbObjectInputStream.skipSafely (ois); // when the workspaces are saved but should not be loaded, skip it
                }
//                if (!wmImpl.isCreated())
//                    WindowManagerImpl.createFromScratch();
            }

            // 4. Executors
            try {
                if ((loadFlags & SAVE_SERVICES) != 0) NbObjectInputStream.readSafely (ois);
            } catch (SafeException exc) {
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
            }
        }
        finally {
            if (ois != null)
                ois.close();
        }
    }

    /** Since Nb 3.3 there is nothing to save explicitly, all System Options,
     * ServiceTypes, Repository, Window System persist automaticaly on the disk.
     * Note: For window system it is still not true.
     * See also 
     *
     * @exception IOException if an error occurs during saving
     */
    public void projectSave () throws IOException {
//        // XXX #29159 winsys has to be saved from here.
//        NbTopManager.WindowSystem windowSystem = (NbTopManager.WindowSystem)Lookup
//            .getDefault().lookup(NbTopManager.WindowSystem.class);
//        if(windowSystem != null) {
//            windowSystem.save();
//        } // TEMP
    }

    /** Close the project. This method instructs the project that another project
     * is becoming the active project and that the project can drop allocated 
     * resources.
     *
     * @exception IOException if an error occurs during saving
     */
    public void projectClose () throws IOException {
    }

    public synchronized Node projectDesktop () {
        return null;
    }

    /** name and extension for basic serialized project file */
    private static final String SERIALIZED_PROJECT_NAME = "project"; // NOI18N
    private static final String SERIALIZED_PROJECT_EXT = "basic"; // NOI18N

    /** Returns file object (file) where the current project is serialized.
    * @param create true if the file should be created
    * @return the file object
    */
    private static FileObject getSerializedProjectFile (boolean create) throws java.io.IOException {
        org.openide.filesystems.FileSystem def =
            Repository.getDefault().getDefaultFileSystem ();

        FileObject fo = def.getRoot().getFileObject(SERIALIZED_PROJECT_NAME, SERIALIZED_PROJECT_EXT); // NOI18N
        if (fo == null && create) {
            fo = def.getRoot ().createData (SERIALIZED_PROJECT_NAME, SERIALIZED_PROJECT_EXT);
        }
        return fo;
    }
}
... 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.