KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > outline > AntModelProject


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
12 package org.eclipse.ant.internal.ui.editor.outline;
13
14 /*
15  * Copyright 2000-2004 The Apache Software Foundation
16  *
17  * Licensed under the Apache License, Version 2.0 (the "License");
18  * you may not use this file except in compliance with the License.
19  * You may obtain a copy of the License at
20  *
21  * http://www.apache.org/licenses/LICENSE-2.0
22  *
23  * Unless required by applicable law or agreed to in writing, software
24  * distributed under the License is distributed on an "AS IS" BASIS,
25  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  * See the License for the specific language governing permissions and
27  * limitations under the License.
28  *
29  */

30
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33
34 import org.apache.tools.ant.BuildException;
35 import org.apache.tools.ant.BuildListener;
36 import org.apache.tools.ant.Project;
37
38 /**
39  * Derived from the original Ant Project class
40  * This class allows property values to be written multiple times.
41  * This facilitates incremental parsing of the Ant build file
42  * It also attempts to ensure that we clean up after ourselves and allows
43  * more manipulation of properties resulting from incremental parsing
44  */

45 public class AntModelProject extends Project {
46     
47     private Hashtable JavaDoc fBaseProperties;
48     private Hashtable JavaDoc fCurrentProperties= new Hashtable JavaDoc();
49     
50     /* (non-Javadoc)
51      * @see org.apache.tools.ant.Project#setNewProperty(java.lang.String, java.lang.String)
52      */

53     public void setNewProperty(String JavaDoc name, String JavaDoc value) {
54         
55         if (fCurrentProperties.get(name) != null) {
56             return;
57         }
58         //always property values to be over-written for this parse session
59
//there is currently no way to remove properties from the Apache Ant project
60
//the project resets it properties for each parse...see reset()
61
fCurrentProperties.put(name, value);
62         super.setProperty(name, value);
63     }
64     
65     /* (non-Javadoc)
66      * @see org.apache.tools.ant.Project#fireBuildFinished(java.lang.Throwable)
67      */

68     public void fireBuildFinished(Throwable JavaDoc exception) {
69         super.fireBuildFinished(exception);
70         Enumeration JavaDoc e= getBuildListeners().elements();
71         while (e.hasMoreElements()) {
72             BuildListener listener = (BuildListener) e.nextElement();
73             removeBuildListener(listener);
74         }
75     }
76     
77     public void reset() {
78         getTargets().clear();
79         setDefault(null);
80         setDescription(null);
81         setName(""); //$NON-NLS-1$
82
//reset the properties to the initial set
83
fCurrentProperties= new Hashtable JavaDoc();
84         Enumeration JavaDoc e = fBaseProperties.keys();
85         while (e.hasMoreElements()) {
86             Object JavaDoc name = e.nextElement();
87             Object JavaDoc value = fBaseProperties.get(name);
88             fCurrentProperties.put(name, value);
89         }
90     }
91     
92     /* (non-Javadoc)
93      * @see org.apache.tools.ant.Project#getProperty(java.lang.String)
94      */

95     public String JavaDoc getProperty(String JavaDoc name) {
96         //override as we cannot remove properties from the Apache Ant project
97
return (String JavaDoc)fCurrentProperties.get(name);
98     }
99     
100     /* (non-Javadoc)
101      * @see org.apache.tools.ant.Project#getProperties()
102      */

103     public Hashtable JavaDoc getProperties() {
104         //override as we cannot remove properties from the Apache Ant project
105
return fCurrentProperties;
106     }
107     /* (non-Javadoc)
108      * @see org.apache.tools.ant.Project#init()
109      */

110     public void init() throws BuildException {
111         super.init();
112         fBaseProperties= super.getProperties();
113         fCurrentProperties= super.getProperties();
114     }
115 }
Popular Tags