01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.build;
11:
12: import java.io.PrintWriter;
13: import java.util.ArrayList;
14:
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.pde.core.IModelChangedEvent;
17: import org.eclipse.pde.core.ModelChangedEvent;
18: import org.eclipse.pde.core.build.IBuild;
19: import org.eclipse.pde.core.build.IBuildEntry;
20:
21: public class Build extends BuildObject implements IBuild {
22: protected ArrayList fEntries = new ArrayList();
23:
24: public void add(IBuildEntry entry) throws CoreException {
25: ensureModelEditable();
26: fEntries.add(entry);
27: ((BuildEntry) entry).setInTheModel(true);
28: getModel().fireModelChanged(
29: new ModelChangedEvent(getModel(),
30: IModelChangedEvent.INSERT,
31: new Object[] { entry }, null));
32: }
33:
34: public IBuildEntry[] getBuildEntries() {
35: return (IBuildEntry[]) fEntries
36: .toArray(new IBuildEntry[fEntries.size()]);
37: }
38:
39: public IBuildEntry getEntry(String name) {
40: for (int i = 0; i < fEntries.size(); i++) {
41: IBuildEntry entry = (IBuildEntry) fEntries.get(i);
42: if (entry.getName().equals(name))
43: return entry;
44: }
45: return null;
46: }
47:
48: public void processEntry(String name, String value) {
49: BuildEntry entry = (BuildEntry) getModel().getFactory()
50: .createEntry(name);
51: fEntries.add(entry);
52: entry.processEntry(value);
53: }
54:
55: public void remove(IBuildEntry entry) throws CoreException {
56: ensureModelEditable();
57: fEntries.remove(entry);
58: getModel().fireModelChanged(
59: new ModelChangedEvent(getModel(),
60: IModelChangedEvent.REMOVE,
61: new Object[] { entry }, null));
62: }
63:
64: public void reset() {
65: fEntries.clear();
66: }
67:
68: public void write(String indent, PrintWriter writer) {
69: for (int i = 0; i < fEntries.size(); i++) {
70: IBuildEntry entry = (IBuildEntry) fEntries.get(i);
71: entry.write("", writer); //$NON-NLS-1$
72: }
73: }
74: }
|