1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / WorkingCopyOwner.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core;
12
13 import net.sourceforge.phpdt.internal.core.BufferManager;
14 import net.sourceforge.phpdt.internal.core.DefaultWorkingCopyOwner;
15
16 /**
17  * The owner of an <code>ICompilationUnit</code> handle in working copy mode.
18  * An owner is used to identify a working copy and to create its buffer.
19  * <p>
20  * Clients should subclass this class to instantiate a working copy owner that
21  * is specific to their need and that they can pass in to various APIs (e.g.
22  * <code>IType.resolveType(String, WorkingCopyOwner)</code>. Clients can also
23  * override the default implementation of
24  * <code>createBuffer(ICompilationUnit)</code>.
25  * </p>
26  * <p>
27  * Note: even though this class has no abstract method, which means that it
28  * provides functional default behvior, it is still an abstract class, as
29  * clients are intended to own their owner implementation.
30  * </p>
31  * 
32  * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor,
33  *      org.eclipse.core.runtime.IProgressMonitor)
34  * @see ICompilationUnit#discardWorkingCopy()
35  * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
36  * @since 3.0
37  */
38 public abstract class WorkingCopyOwner {
39
40         /**
41          * Sets the buffer provider of the primary working copy owner. Note that
42          * even if the buffer provider is a working copy owner, only its
43          * <code>createBuffer(ICompilationUnit)</code> method is used by the
44          * primary working copy owner. It doesn't replace the internal primary
45          * working owner.
46          * <p>
47          * This method is for internal use by the jdt-related plug-ins. Clients
48          * outside of the jdt should not reference this method.
49          * </p>
50          * 
51          * @param primaryBufferProvider
52          *            the primary buffer provider
53          */
54         public static void setPrimaryBufferProvider(
55                         WorkingCopyOwner primaryBufferProvider) {
56                 DefaultWorkingCopyOwner.PRIMARY.primaryBufferProvider = primaryBufferProvider;
57         }
58
59         /**
60          * Creates a buffer for the given working copy. The new buffer will be
61          * initialized with the contents of the underlying file if and only if it
62          * was not already initialized by the compilation owner (a buffer is
63          * uninitialized if its content is <code>null</code>).
64          * <p>
65          * Note: This buffer will be associated to the working copy for its entire
66          * life-cycle. Another working copy on same unit but owned by a different
67          * owner would not share the same buffer unless its owner decided to
68          * implement such a sharing behaviour.
69          * </p>
70          * 
71          * @param workingCopy
72          *            the working copy of the buffer
73          * @return IBuffer the created buffer for the given working copy
74          * @see IBuffer
75          */
76         public IBuffer createBuffer(ICompilationUnit workingCopy) {
77
78                 return BufferManager.getDefaultBufferManager()
79                                 .createBuffer(workingCopy);
80         }
81
82 }