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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core;
13 import net.sourceforge.phpdt.internal.core.BufferManager;
14 import net.sourceforge.phpdt.internal.core.DefaultWorkingCopyOwner;
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.
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>.
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.
27 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, org.eclipse.core.runtime.IProgressMonitor)
28 * @see ICompilationUnit#discardWorkingCopy()
29 * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
32 public abstract class WorkingCopyOwner {
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
40 * This method is for internal use by the jdt-related plug-ins.
41 * Clients outside of the jdt should not reference this method.
44 * @param primaryBufferProvider the primary buffer provider
46 public static void setPrimaryBufferProvider(WorkingCopyOwner primaryBufferProvider) {
47 DefaultWorkingCopyOwner.PRIMARY.primaryBufferProvider = primaryBufferProvider;
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>).
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.
61 * @param workingCopy the working copy of the buffer
62 * @return IBuffer the created buffer for the given working copy
65 public IBuffer createBuffer(ICompilationUnit workingCopy) {
67 return BufferManager.getDefaultBufferManager().createBuffer(workingCopy);