3m9 compatible;
[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 is specific to their need and that
21  * they can pass in to various APIs (e.g. <code>IType.resolveType(String, WorkingCopyOwner)</code>.
22  * Clients can also override the default implementation of <code>createBuffer(ICompilationUnit)</code>.
23  * </p><p>
24  * Note: even though this class has no abstract method, which means that it provides functional default behvior,
25  * it is still an abstract class, as clients are intended to own their owner implementation.
26  * </p>
27  * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, org.eclipse.core.runtime.IProgressMonitor)
28  * @see ICompilationUnit#discardWorkingCopy()
29  * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
30  * @since 3.0
31  */
32 public abstract class WorkingCopyOwner {
33         
34         /**
35          * Sets the buffer provider of the primary working copy owner. Note that even if the
36          * buffer provider is a working copy owner, only its <code>createBuffer(ICompilationUnit)</code>
37          * method is used by the primary working copy owner. It doesn't replace the internal primary 
38          * working owner.
39          * <p>
40          * This method is for internal use by the jdt-related plug-ins.
41          * Clients outside of the jdt should not reference this method.
42          * </p>
43          * 
44          * @param primaryBufferProvider the primary buffer provider
45          */
46         public static void setPrimaryBufferProvider(WorkingCopyOwner primaryBufferProvider) {
47                 DefaultWorkingCopyOwner.PRIMARY.primaryBufferProvider = primaryBufferProvider;
48         }
49         
50         /**
51          * Creates a buffer for the given working copy.
52          * The new buffer will be initialized with the contents of the underlying file
53          * if and only if it was not already initialized by the compilation owner (a buffer is 
54          * uninitialized if its content is <code>null</code>).
55          * <p>
56          * Note: This buffer will be associated to the working copy for its entire life-cycle. Another
57          * working copy on same unit but owned by a different owner would not share the same buffer
58          * unless its owner decided to implement such a sharing behaviour.
59          * </p>
60          * 
61          * @param workingCopy the working copy of the buffer
62          * @return IBuffer the created buffer for the given working copy
63          * @see IBuffer
64          */
65         public IBuffer createBuffer(ICompilationUnit workingCopy) {
66
67                 return BufferManager.getDefaultBufferManager().createBuffer(workingCopy);
68         }
69
70 }