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
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>.
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.
32 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor,
33 * org.eclipse.core.runtime.IProgressMonitor)
34 * @see ICompilationUnit#discardWorkingCopy()
35 * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor)
38 public abstract class WorkingCopyOwner {
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
47 * This method is for internal use by the jdt-related plug-ins. Clients
48 * outside of the jdt should not reference this method.
51 * @param primaryBufferProvider
52 * the primary buffer provider
54 public static void setPrimaryBufferProvider(
55 WorkingCopyOwner primaryBufferProvider) {
56 DefaultWorkingCopyOwner.PRIMARY.primaryBufferProvider = primaryBufferProvider;
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>).
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.
72 * the working copy of the buffer
73 * @return IBuffer the created buffer for the given working copy
76 public IBuffer createBuffer(ICompilationUnit workingCopy) {
78 return BufferManager.getDefaultBufferManager()
79 .createBuffer(workingCopy);