KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > build > BuildEntry


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.build;
12 import java.io.PrintWriter JavaDoc;
13 import java.util.StringTokenizer JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.pde.core.IModelChangedEvent;
18 import org.eclipse.pde.core.ModelChangedEvent;
19 import org.eclipse.pde.core.build.IBuildEntry;
20 import org.eclipse.pde.internal.core.util.PropertiesUtil;
21 public class BuildEntry extends BuildObject implements IBuildEntry {
22     private Vector JavaDoc tokens = new Vector JavaDoc();
23     private String JavaDoc name;
24     public BuildEntry(String JavaDoc name) {
25         this.name = name;
26     }
27     public void addToken(String JavaDoc token) throws CoreException {
28         ensureModelEditable();
29         tokens.add(token);
30         getModel().fireModelChanged(
31                 new ModelChangedEvent(getModel(), IModelChangedEvent.INSERT,
32                         new Object JavaDoc[]{token}, null));
33     }
34     public String JavaDoc getName() {
35         return name;
36     }
37     public String JavaDoc[] getTokens() {
38         String JavaDoc[] result = new String JavaDoc[tokens.size()];
39         tokens.copyInto(result);
40         return result;
41     }
42     public boolean contains(String JavaDoc token) {
43         return tokens.contains(token);
44     }
45     void processEntry(String JavaDoc value) {
46         StringTokenizer JavaDoc stok = new StringTokenizer JavaDoc(value, ","); //$NON-NLS-1$
47
while (stok.hasMoreTokens()) {
48             String JavaDoc token = stok.nextToken();
49             token = token.trim();
50             tokens.add(token);
51         }
52     }
53     public void removeToken(String JavaDoc token) throws CoreException {
54         ensureModelEditable();
55         tokens.remove(token);
56         getModel().fireModelChanged(
57                 new ModelChangedEvent(getModel(), IModelChangedEvent.REMOVE,
58                         new Object JavaDoc[]{token}, null));
59     }
60     public void renameToken(String JavaDoc oldName, String JavaDoc newName)
61             throws CoreException {
62         ensureModelEditable();
63         for (int i = 0; i < tokens.size(); i++) {
64             if (tokens.elementAt(i).toString().equals(oldName)) {
65                 tokens.setElementAt(newName, i);
66                 break;
67             }
68         }
69         getModel().fireModelChanged(
70                 new ModelChangedEvent(getModel(), IModelChangedEvent.CHANGE,
71                         new Object JavaDoc[]{oldName}, null));
72     }
73     public void setName(String JavaDoc name) throws CoreException {
74         ensureModelEditable();
75         String JavaDoc oldValue = this.name;
76         this.name = name;
77         getModel().fireModelObjectChanged(this, P_NAME, oldValue, name);
78     }
79     public String JavaDoc toString() {
80         return name;
81     }
82     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
83         PropertiesUtil.writeKeyValuePair(indent, name, tokens.elements(),
84                 writer);
85     }
86     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
87             throws CoreException {
88         if (name.equals(P_NAME)) {
89             setName(newValue != null ? newValue.toString() : null);
90         }
91     }
92 }
93
Popular Tags