KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > AntModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Nico Seessle - bug 51332
11  *******************************************************************************/

12
13 package org.eclipse.ant.internal.ui.model;
14
15 import java.io.File JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.net.URLClassLoader JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Arrays JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Properties JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.Stack JavaDoc;
30
31 import org.apache.tools.ant.AntTypeDefinition;
32 import org.apache.tools.ant.BuildException;
33 import org.apache.tools.ant.ComponentHelper;
34 import org.apache.tools.ant.IntrospectionHelper;
35 import org.apache.tools.ant.Location;
36 import org.apache.tools.ant.Main;
37 import org.apache.tools.ant.Project;
38 import org.apache.tools.ant.RuntimeConfigurable;
39 import org.apache.tools.ant.Target;
40 import org.apache.tools.ant.Task;
41 import org.apache.tools.ant.TaskAdapter;
42 import org.apache.tools.ant.UnknownElement;
43 import org.eclipse.ant.core.AntCorePlugin;
44 import org.eclipse.ant.core.AntCorePreferences;
45 import org.eclipse.ant.core.AntSecurityException;
46 import org.eclipse.ant.core.Property;
47 import org.eclipse.ant.core.Type;
48 import org.eclipse.ant.internal.core.AntClassLoader;
49 import org.eclipse.ant.internal.core.AntCoreUtil;
50 import org.eclipse.ant.internal.core.AntSecurityManager;
51 import org.eclipse.ant.internal.core.IAntCoreConstants;
52 import org.eclipse.ant.internal.ui.AntUIPlugin;
53 import org.eclipse.ant.internal.ui.AntUtil;
54 import org.eclipse.ant.internal.ui.editor.DecayCodeCompletionDataStructuresThread;
55 import org.eclipse.ant.internal.ui.editor.outline.AntEditorMarkerUpdater;
56 import org.eclipse.ant.internal.ui.editor.utils.ProjectHelper;
57 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
58 import org.eclipse.core.resources.IFile;
59 import org.eclipse.core.resources.ResourcesPlugin;
60 import org.eclipse.core.runtime.CoreException;
61 import org.eclipse.core.runtime.IPath;
62 import org.eclipse.core.runtime.Preferences;
63 import org.eclipse.core.variables.VariablesPlugin;
64 import org.eclipse.jface.text.BadLocationException;
65 import org.eclipse.jface.text.DocumentEvent;
66 import org.eclipse.jface.text.IDocument;
67 import org.eclipse.jface.text.IDocumentListener;
68 import org.eclipse.jface.text.ISynchronizable;
69 import org.xml.sax.Attributes JavaDoc;
70 import org.xml.sax.SAXParseException JavaDoc;
71
72 import com.ibm.icu.text.MessageFormat;
73
74 public class AntModel implements IAntModel {
75
76     private static ClassLoader JavaDoc fgClassLoader;
77     private static int fgInstanceCount= 0;
78     
79     private IDocument fDocument;
80     private IProblemRequestor fProblemRequestor;
81     private LocationProvider fLocationProvider;
82
83     private AntProjectNode fProjectNode;
84     private AntTargetNode fCurrentTargetNode;
85     private AntElementNode fLastNode;
86     private AntElementNode fNodeBeingResolved;
87     private int fNodeBeingResolvedIndex= -1;
88     
89     private Map JavaDoc fEntityNameToPath;
90     
91      /**
92      * Stack of still open elements.
93      * <P>
94      * On top of the stack is the innermost element.
95      */

96     private Stack JavaDoc fStillOpenElements = new Stack JavaDoc();
97     
98     private Map JavaDoc fTaskToNode= new HashMap JavaDoc();
99
100     private List JavaDoc fTaskNodes= new ArrayList JavaDoc();
101
102     private final Object JavaDoc fDirtyLock= new Object JavaDoc();
103     private boolean fIsDirty= true;
104     private File JavaDoc fEditedFile= null;
105    
106     private ClassLoader JavaDoc fLocalClassLoader= null;
107     
108     private boolean fHasLexicalInfo= true;
109     private boolean fHasPositionInfo= true;
110     private boolean fHasTaskInfo= true;
111     
112     private IDocumentListener fListener;
113     private AntEditorMarkerUpdater fMarkerUpdater= null;
114     private List JavaDoc fNonStructuralNodes= new ArrayList JavaDoc(1);
115     
116     private Preferences.IPropertyChangeListener fCorePropertyChangeListener;
117     
118     private Preferences.IPropertyChangeListener fUIPropertyChangeListener;
119     
120     private Map JavaDoc fProperties= null;
121     private List JavaDoc fPropertyFiles= null;
122     
123     private Map JavaDoc fDefinersToText;
124     private Map JavaDoc fPreviousDefinersToText;
125     private Map JavaDoc fDefinerNodeIdentifierToDefinedTasks;
126     private Map JavaDoc fTaskNameToDefiningNode;
127     private Map JavaDoc fCurrentNodeIdentifiers;
128     
129     private boolean fReportingProblemsCurrent= false;
130     private boolean fDoNotReportProblems= false;
131     private boolean fShouldReconcile= true;
132     private HashMap JavaDoc fNamespacePrefixMappings;
133     
134     public AntModel(IDocument document, IProblemRequestor problemRequestor, LocationProvider locationProvider) {
135         init(document, problemRequestor, locationProvider);
136         
137         fMarkerUpdater= new AntEditorMarkerUpdater();
138         fMarkerUpdater.setModel(this);
139         fCorePropertyChangeListener= new Preferences.IPropertyChangeListener() {
140             /* (non-Javadoc)
141              * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
142              */

143             public void propertyChange(Preferences.PropertyChangeEvent event) {
144                 if (event.getProperty().equals(IAntCoreConstants.PREFERENCE_CLASSPATH_CHANGED)) {
145                     if (((Boolean JavaDoc)event.getNewValue()) == Boolean.TRUE) {
146                         reconcileForPropertyChange(true);
147                     }
148                 }
149             }
150         };
151         AntCorePlugin.getPlugin().getPluginPreferences().addPropertyChangeListener(fCorePropertyChangeListener);
152         
153         fUIPropertyChangeListener= new Preferences.IPropertyChangeListener() {
154             /* (non-Javadoc)
155              * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
156              */

157             public void propertyChange(Preferences.PropertyChangeEvent event) {
158                 String JavaDoc property= event.getProperty();
159                 if (property.equals(AntEditorPreferenceConstants.PROBLEM)) {
160                     AntUIPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(fUIPropertyChangeListener);
161                     reconcileForPropertyChange(false);
162                     AntUIPlugin.getDefault().getPluginPreferences().setToDefault(AntEditorPreferenceConstants.PROBLEM);
163                     AntUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(fUIPropertyChangeListener);
164                 } else if (property.equals(AntEditorPreferenceConstants.CODEASSIST_USER_DEFINED_TASKS)) {
165                     reconcileForPropertyChange(false);
166                 } else if (property.equals(AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE) || property.equals(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)) {
167                     fReportingProblemsCurrent= false;
168                     reconcileForPropertyChange(false);
169                 }
170             }
171         };
172         AntUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(fUIPropertyChangeListener);
173     }
174     
175     public AntModel(IDocument document, IProblemRequestor problemRequestor, LocationProvider locationProvider, boolean resolveLexicalInfo, boolean resolvePositionInfo, boolean resolveTaskInfo) {
176         init(document, problemRequestor, locationProvider);
177         
178         fHasLexicalInfo= resolveLexicalInfo;
179         fHasPositionInfo= resolvePositionInfo;
180         fHasTaskInfo= resolveTaskInfo;
181     }
182     
183     private void init(IDocument document, IProblemRequestor problemRequestor, LocationProvider locationProvider) {
184         fDocument= document;
185         fProblemRequestor= problemRequestor;
186         fLocationProvider= locationProvider;
187         if (fgInstanceCount == 0) {
188             //no other models are open to ensure that the classpath is up to date wrt the
189
//Ant preferences and start listening for breakpoint changes
190
AntDefiningTaskNode.setJavaClassPath();
191             AntModelCore.getDefault().startBreakpointListening();
192         }
193         fgInstanceCount++;
194         DecayCodeCompletionDataStructuresThread.cancel();
195     }
196     
197     /* (non-Javadoc)
198      * @see org.eclipse.ant.internal.ui.model.IAntModel#dispose()
199      */

200     public void dispose() {
201         synchronized (getLockObject()) {
202             if (fDocument != null && fListener != null) {
203                 fDocument.removeDocumentListener(fListener);
204             }
205             fDocument= null;
206             fLocationProvider= null;
207             ProjectHelper.setAntModel(null);
208         }
209         
210         if (fCorePropertyChangeListener != null) {
211             AntCorePlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(fCorePropertyChangeListener);
212         }
213         if (fUIPropertyChangeListener != null) {
214             AntUIPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(fUIPropertyChangeListener);
215         }
216         fgInstanceCount--;
217         if (fgInstanceCount == 0) {
218             fgClassLoader= null;
219             DecayCodeCompletionDataStructuresThread.getDefault().start();
220             AntModelCore.getDefault().stopBreakpointListening();
221             cleanup();
222         }
223     }
224     
225     private Object JavaDoc getLockObject() {
226         if (fDocument instanceof ISynchronizable) {
227             Object JavaDoc lock= ((ISynchronizable)fDocument).getLockObject();
228             if (lock != null) {
229                 return lock;
230             }
231         }
232         return this;
233     }
234
235     private void cleanup() {
236         AntProjectNode projectNode= getProjectNode();
237         if (projectNode != null) {
238             //cleanup the introspection helpers that may have been generated
239
IntrospectionHelper.getHelper(projectNode.getProject(), Small.class);
240             projectNode.getProject().fireBuildFinished(null);
241         }
242     }
243
244     /* (non-Javadoc)
245      * @see org.eclipse.ant.internal.ui.model.IAntModel#reconcile()
246      */

247     public void reconcile() {
248         synchronized (fDirtyLock) {
249             if (!fShouldReconcile || !fIsDirty) {
250                 return;
251             }
252             fIsDirty= false;
253         }
254
255         synchronized (getLockObject()) {
256             if (fLocationProvider == null) {
257                 // disposed
258
return;
259             }
260             
261             if (fDocument == null) {
262                 fProjectNode= null;
263             } else {
264                 reset();
265                 parseDocument(fDocument);
266                 reconcileTaskAndTypes();
267             }
268             AntModelCore.getDefault().notifyAntModelListeners(new AntModelChangeEvent(this));
269         }
270     }
271
272     private void reset() {
273         fCurrentTargetNode= null;
274         fStillOpenElements= new Stack JavaDoc();
275         fTaskToNode= new HashMap JavaDoc();
276         fTaskNodes= new ArrayList JavaDoc();
277         fNodeBeingResolved= null;
278         fNodeBeingResolvedIndex= -1;
279         fLastNode= null;
280         fCurrentNodeIdentifiers= null;
281         fNamespacePrefixMappings= null;
282         
283         fNonStructuralNodes= new ArrayList JavaDoc(1);
284         if (fDefinersToText != null) {
285             fPreviousDefinersToText= new HashMap JavaDoc(fDefinersToText);
286             fDefinersToText= null;
287         }
288     }
289     
290     private void parseDocument(IDocument input) {
291         boolean parsed= true;
292         if (input.getLength() == 0) {
293             fProjectNode= null;
294             parsed= false;
295             return;
296         }
297         ClassLoader JavaDoc originalClassLoader= Thread.currentThread().getContextClassLoader();
298         ClassLoader JavaDoc parsingClassLoader= getClassLoader(originalClassLoader);
299         Thread.currentThread().setContextClassLoader(parsingClassLoader);
300         Project project= null;
301         try {
302             ProjectHelper projectHelper= null;
303             String JavaDoc textToParse= input.get();
304             if (fProjectNode == null || !fProjectNode.hasChildren()) {
305                 fProjectNode= null;
306                 project = new AntModelProject();
307                 projectHelper= prepareForFullParse(project, parsingClassLoader);
308             } else {
309                 project= fProjectNode.getProject();
310                 projectHelper= (ProjectHelper)project.getReference("ant.projectHelper"); //$NON-NLS-1$
311
projectHelper.setBuildFile(getEditedFile());
312                 prepareForFullIncremental();
313             }
314             beginReporting();
315             Map JavaDoc references= project.getReferences();
316             references.remove("ant.parsing.context"); //$NON-NLS-1$
317
ProjectHelper.setAntModel(this);
318             projectHelper.parse(project, textToParse);
319             
320         } catch(BuildException e) {
321             handleBuildException(e, null);
322         } finally {
323             if (parsed) {
324                 SecurityManager JavaDoc origSM= System.getSecurityManager();
325                 processAntHome(true);
326                 try {
327                     //set a security manager to disallow system exit and system property setting
328
System.setSecurityManager(new AntSecurityManager(origSM, Thread.currentThread(), false));
329                     resolveBuildfile();
330                     endReporting();
331                 } catch (AntSecurityException e) {
332                 
333                 } finally {
334                     Thread.currentThread().setContextClassLoader(originalClassLoader);
335                     getClassLoader(null);
336                     System.setSecurityManager(origSM);
337                     project.fireBuildFinished(null); //cleanup (IntrospectionHelper)
338
}
339             }
340         }
341     }
342
343     private ProjectHelper prepareForFullParse(Project project, ClassLoader JavaDoc parsingClassLoader) {
344         initializeProject(project, parsingClassLoader);
345         // Ant's parsing facilities always works on a file, therefore we need
346
// to determine the actual location of the file. Though the file
347
// contents will not be parsed. We parse the passed document string
348
File JavaDoc file = getEditedFile();
349         String JavaDoc filePath= ""; //$NON-NLS-1$
350
if (file != null) {
351             filePath= file.getAbsolutePath();
352         }
353         project.setUserProperty("ant.file", filePath); //$NON-NLS-1$
354
project.setUserProperty("ant.version", Main.getAntVersion()); //$NON-NLS-1$
355

356         ProjectHelper projectHelper= new ProjectHelper(this);
357         projectHelper.setBuildFile(file);
358         project.addReference("ant.projectHelper", projectHelper); //$NON-NLS-1$
359
return projectHelper;
360     }
361     
362     private void prepareForFullIncremental() {
363         fProjectNode.reset();
364         fTaskToNode= new HashMap JavaDoc();
365         fTaskNodes= new ArrayList JavaDoc();
366     }
367
368     private void initializeProject(Project project, ClassLoader JavaDoc loader) {
369         processAntHome(false);
370         project.init();
371         setProperties(project);
372         setTasks(project, loader);
373         setTypes(project, loader);
374     }
375     
376     private void setTasks(Project project, ClassLoader JavaDoc loader) {
377         List JavaDoc tasks = AntCorePlugin.getPlugin().getPreferences().getTasks();
378         for (Iterator JavaDoc iterator = tasks.iterator(); iterator.hasNext();) {
379             org.eclipse.ant.core.Task task = (org.eclipse.ant.core.Task) iterator.next();
380             AntTypeDefinition def= new AntTypeDefinition();
381             def.setName(task.getTaskName());
382             def.setClassName(task.getClassName());
383             def.setClassLoader(loader);
384             def.setAdaptToClass(Task.class);
385             def.setAdapterClass(TaskAdapter.class);
386             ComponentHelper.getComponentHelper(project).addDataTypeDefinition(def);
387         }
388     }
389         
390     private void setTypes(Project project, ClassLoader JavaDoc loader) {
391         List JavaDoc types = AntCorePlugin.getPlugin().getPreferences().getTypes();
392         for (Iterator JavaDoc iterator = types.iterator(); iterator.hasNext();) {
393             Type type = (Type) iterator.next();
394              AntTypeDefinition def = new AntTypeDefinition();
395              def.setName(type.getTypeName());
396              def.setClassName(type.getClassName());
397              def.setClassLoader(loader);
398              ComponentHelper.getComponentHelper(project).addDataTypeDefinition(def);
399         }
400     }
401     
402     private void setProperties(Project project) {
403         setBuiltInProperties(project);
404         setExtraProperties(project);
405         setGlobalProperties(project);
406         loadExtraPropertyFiles(project);
407         loadPropertyFiles(project);
408     }
409
410     private void setExtraProperties(Project project) {
411         if (fProperties != null) {
412             for (Iterator JavaDoc iter = fProperties.keySet().iterator(); iter.hasNext();) {
413                 String JavaDoc name = (String JavaDoc) iter.next();
414                 String JavaDoc value= (String JavaDoc) fProperties.get(name);
415                 try {
416                     value= VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(value);
417                 } catch (CoreException e) {
418                 }
419                 if (value != null) {
420                     project.setUserProperty(name, value);
421                 }
422             }
423         }
424     }
425     
426     private void loadExtraPropertyFiles(Project project) {
427         if (fPropertyFiles != null) {
428             try {
429                 List JavaDoc allProperties= AntCoreUtil.loadPropertyFiles(fPropertyFiles, project.getUserProperty("basedir"), getEditedFile().getAbsolutePath()); //$NON-NLS-1$
430
setPropertiesFromFiles(project, allProperties);
431             } catch (IOException JavaDoc e1) {
432                 AntUIPlugin.log(e1);
433             }
434         }
435     }
436
437     /**
438      * Load all properties from the files
439      */

440     private void loadPropertyFiles(Project project) {
441         List JavaDoc fileNames= Arrays.asList(AntCorePlugin.getPlugin().getPreferences().getCustomPropertyFiles());
442         try {
443             List JavaDoc allProperties= AntCoreUtil.loadPropertyFiles(fileNames, project.getUserProperty("basedir"), getEditedFile().getAbsolutePath()); //$NON-NLS-1$
444
setPropertiesFromFiles(project, allProperties);
445         } catch (IOException JavaDoc e1) {
446             AntUIPlugin.log(e1);
447         }
448     }
449
450     private void setPropertiesFromFiles(Project project, List JavaDoc allProperties) {
451         Iterator JavaDoc iter= allProperties.iterator();
452         while (iter.hasNext()) {
453             Properties JavaDoc props = (Properties JavaDoc) iter.next();
454             Enumeration JavaDoc propertyNames = props.propertyNames();
455             while (propertyNames.hasMoreElements()) {
456                 String JavaDoc name = (String JavaDoc) propertyNames.nextElement();
457                 //do not override extra local properties with the global settings
458
if (project.getUserProperty(name) == null) {
459                     project.setUserProperty(name, props.getProperty(name));
460                 }
461             }
462         }
463     }
464
465     private void setBuiltInProperties(Project project) {
466         //set processAntHome for other properties set as system properties
467
project.setUserProperty("ant.file", getEditedFile().getAbsolutePath()); //$NON-NLS-1$
468
project.setUserProperty("ant.version", Main.getAntVersion()); //$NON-NLS-1$
469
}
470     
471     private void processAntHome(boolean finished) {
472         AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
473         String JavaDoc antHome= prefs.getAntHome();
474         if (finished) {
475             System.getProperties().remove("ant.home"); //$NON-NLS-1$
476
System.getProperties().remove("ant.library.dir"); //$NON-NLS-1$
477
} else {
478             System.setProperty("ant.home", antHome); //$NON-NLS-1$
479
File JavaDoc antLibDir= new File JavaDoc(antHome, "lib"); //$NON-NLS-1$
480
System.setProperty("ant.library.dir", antLibDir.getAbsolutePath()); //$NON-NLS-1$
481
}
482     }
483     
484     private void setGlobalProperties(Project project) {
485         List JavaDoc properties= AntCorePlugin.getPlugin().getPreferences().getProperties();
486         if (properties != null) {
487             for (Iterator JavaDoc iter = properties.iterator(); iter.hasNext();) {
488                 Property property = (Property) iter.next();
489                 String JavaDoc value= property.getValue(true);
490                 if (value != null) {
491                     project.setUserProperty(property.getName(), value);
492                 }
493             }
494         }
495     }
496
497     private void resolveBuildfile() {
498         Collection JavaDoc nodeCopy= new ArrayList JavaDoc(fTaskNodes);
499         Iterator JavaDoc iter= nodeCopy.iterator();
500         while (iter.hasNext()) {
501             AntTaskNode node = (AntTaskNode) iter.next();
502             fNodeBeingResolved= node;
503             fNodeBeingResolvedIndex= -1;
504             if (node.configure(false)) {
505                 //resolve any new elements that may have been added
506
resolveBuildfile();
507             }
508         }
509         fNodeBeingResolved= null;
510         fNodeBeingResolvedIndex= -1;
511         checkTargets();
512     }
513
514     /**
515      * Check that if a default target is specified it exists and that the
516      * target dependencies exist.
517      */

518     private void checkTargets() {
519         if (fProjectNode == null || doNotReportProblems()) {
520             return;
521         }
522         String JavaDoc defaultTargetName= fProjectNode.getDefaultTargetName();
523         if (defaultTargetName != null && fProjectNode.getProject().getTargets().get(defaultTargetName) == null) {
524             //no default target when one specified (default target does not have to be specified)
525
String JavaDoc message= MessageFormat.format(AntModelMessages.AntModel_43, new String JavaDoc[]{defaultTargetName});
526             IProblem problem= createProblem(message, fProjectNode.getOffset(), fProjectNode.getSelectionLength(), AntModelProblem.SEVERITY_ERROR);
527             acceptProblem(problem);
528             markHierarchy(fProjectNode, AntModelProblem.SEVERITY_ERROR, message);
529         }
530         if (!fProjectNode.hasChildren()) {
531             return;
532         }
533         List JavaDoc children= fProjectNode.getChildNodes();
534         Iterator JavaDoc iter= children.iterator();
535         boolean checkCircularDependencies= true;
536         while (iter.hasNext()) {
537             AntElementNode node = (AntElementNode) iter.next();
538             AntElementNode originalNode= node;
539             if (node instanceof AntTargetNode) {
540                 if (checkCircularDependencies) {
541                     checkCircularDependencies= false;
542                     checkCircularDependencies(node);
543                 }
544                 checkMissingDependencies(node, originalNode);
545             }
546         }
547     }
548
549     /**
550      * method assumes sendor has checked whether to report problems
551      */

552     private void checkMissingDependencies(AntElementNode node, AntElementNode originalNode) {
553         String JavaDoc missing= ((AntTargetNode)node).checkDependencies();
554         if (missing != null) {
555             String JavaDoc message= MessageFormat.format(AntModelMessages.AntModel_44, new String JavaDoc[]{missing});
556             AntElementNode importNode= node.getImportNode();
557             if (importNode != null) {
558                 node= importNode;
559             }
560             IProblem problem= createProblem(message, node.getOffset(), node.getSelectionLength(), AntModelProblem.SEVERITY_ERROR);
561             acceptProblem(problem);
562             markHierarchy(originalNode, AntModelProblem.SEVERITY_ERROR, message);
563         }
564     }
565
566     private boolean doNotReportProblems() {
567         if (fReportingProblemsCurrent) {
568             return fDoNotReportProblems;
569         }
570         
571         fReportingProblemsCurrent= true;
572         fDoNotReportProblems= false;
573         
574         if (AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)) {
575             fDoNotReportProblems= true;
576             return fDoNotReportProblems;
577         }
578         String JavaDoc buildFileNames= AntUIPlugin.getDefault().getCombinedPreferenceStore().getString(AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE);
579         if (buildFileNames.length() > 0) {
580             String JavaDoc[] names= AntUtil.parseString(buildFileNames, ","); //$NON-NLS-1$
581
String JavaDoc editedFileName= getEditedFile().getName();
582             for (int i = 0; i < names.length; i++) {
583                 String JavaDoc string = names[i];
584                 if (string.trim().equals(editedFileName)) {
585                     fDoNotReportProblems= true;
586                     return fDoNotReportProblems;
587                 }
588             }
589         }
590         
591         return fDoNotReportProblems;
592     }
593
594     /**
595      * method assumes sendor has checked whether to report problems
596      */

597     private void checkCircularDependencies(AntElementNode node) {
598         Target target= ((AntTargetNode)node).getTarget();
599         String JavaDoc name= target.getName();
600         if (name == null) {
601             return;
602         }
603         try {
604             target.getProject().topoSort(name, target.getProject().getTargets());
605         } catch (BuildException be) {
606             //possible circular dependency
607
String JavaDoc message = be.getMessage();
608             if (message.startsWith("Circular")) { //$NON-NLS-1$ //we do our own checking for missing dependencies
609
IProblem problem= createProblem(message, node.getProjectNode().getOffset(), node.getProjectNode().getSelectionLength(), AntModelProblem.SEVERITY_ERROR);
610                 acceptProblem(problem);
611                 markHierarchy(node.getProjectNode(), AntModelProblem.SEVERITY_ERROR, message);
612             }
613         }
614     }
615
616     /* (non-Javadoc)
617      * @see org.eclipse.ant.internal.ui.model.IAntModel#handleBuildException(org.apache.tools.ant.BuildException, org.eclipse.ant.internal.ui.model.AntElementNode, int)
618      */

619     public void handleBuildException(BuildException e, AntElementNode node, int severity) {
620         try {
621             if (node != null) {
622                 markHierarchy(node, severity, e.getMessage());
623             }
624             Location location= e.getLocation();
625             int line= 0;
626             int originalOffset= 0;
627             int nonWhitespaceOffset= 0;
628             int length= 0;
629             if (location == Location.UNKNOWN_LOCATION && node != null) {
630                 if (node.getImportNode() != null) {
631                     node= node.getImportNode();
632                 }
633                 nonWhitespaceOffset= node.getOffset();
634                 length= node.getLength();
635             } else {
636                 line= location.getLineNumber();
637                 if (line == 0) {
638                     AntProjectNode projectNode= getProjectNode();
639                     if (projectNode != null) {
640                         length= projectNode.getSelectionLength();
641                         nonWhitespaceOffset= projectNode.getOffset();
642                         if (severity == AntModelProblem.SEVERITY_ERROR) {
643                             projectNode.setProblemSeverity(AntModelProblem.NO_PROBLEM);
644                             projectNode.setProblemMessage(null);
645                         }
646                     } else {
647                         return;
648                     }
649                 } else {
650                     if (node == null) {
651                         originalOffset= getOffset(line, 1);
652                         nonWhitespaceOffset= originalOffset;
653                         try {
654                             nonWhitespaceOffset= getNonWhitespaceOffset(line, 1);
655                         } catch (BadLocationException be) {
656                         }
657                         length= getLastCharColumn(line) - (nonWhitespaceOffset - originalOffset);
658                     } else {
659                         if (node.getImportNode() != null) {
660                             node= node.getImportNode();
661                         }
662                         nonWhitespaceOffset= node.getOffset();
663                         length= node.getLength();
664                     }
665                 }
666             }
667             notifyProblemRequestor(e, nonWhitespaceOffset, length, severity);
668         } catch (BadLocationException e1) {
669         }
670     }
671
672     public void handleBuildException(BuildException e, AntElementNode node) {
673         handleBuildException(e, node, AntModelProblem.SEVERITY_ERROR);
674     }
675
676     /* (non-Javadoc)
677      * @see org.eclipse.ant.internal.ui.model.IAntModel#getEditedFile()
678      */

679     public File JavaDoc getEditedFile() {
680         if (fLocationProvider != null && fEditedFile == null) {
681             fEditedFile= fLocationProvider.getLocation().toFile();
682         }
683         return fEditedFile;
684     }
685
686     private void markHierarchy(AntElementNode openElement, int severity, String JavaDoc message) {
687         if (doNotReportProblems()) {
688             return;
689         }
690         while (openElement != null) {
691             openElement.setProblemSeverity(severity);
692             openElement.setProblemMessage(message);
693             openElement= openElement.getParentNode();
694         }
695     }
696     
697     /* (non-Javadoc)
698      * @see org.eclipse.ant.internal.ui.model.IAntModel#getLocationProvider()
699      */

700     public LocationProvider getLocationProvider() {
701         return fLocationProvider;
702     }
703
704     /* (non-Javadoc)
705      * @see org.eclipse.ant.internal.ui.model.IAntModel#addTarget(org.apache.tools.ant.Target, int, int)
706      */

707     public void addTarget(Target newTarget, int line, int column) {
708         AntTargetNode targetNode= new AntTargetNode(newTarget);
709         fProjectNode.addChildNode(targetNode);
710         fCurrentTargetNode= targetNode;
711         fStillOpenElements.push(targetNode);
712         if (fNodeBeingResolved instanceof AntImportNode) {
713             targetNode.setImportNode(fNodeBeingResolved);
714             targetNode.setExternal(true);
715             targetNode.setFilePath(newTarget.getLocation().getFileName());
716         } else {
717            String JavaDoc targetFileName= newTarget.getLocation().getFileName();
718            boolean external= isNodeExternal(targetFileName);
719            targetNode.setExternal(external);
720            if (external) {
721                targetNode.setFilePath(targetFileName);
722            }
723         }
724         computeOffset(targetNode, line, column);
725     }
726     
727     /* (non-Javadoc)
728      * @see org.eclipse.ant.internal.ui.model.IAntModel#addProject(org.apache.tools.ant.Project, int, int)
729      */

730     public void addProject(Project project, int line, int column) {
731         fProjectNode= new AntProjectNode((AntModelProject)project, this);
732         fStillOpenElements.push(fProjectNode);
733         computeOffset(fProjectNode, line, column);
734     }
735     
736     /* (non-Javadoc)
737      * @see org.eclipse.ant.internal.ui.model.IAntModel#addDTD(java.lang.String, int, int)
738      */

739     public void addDTD(String JavaDoc name, int line, int column) {
740         AntDTDNode node= new AntDTDNode(name);
741         fStillOpenElements.push(node);
742         int offset= -1;
743         try {
744             if (column <= 0) {
745                 offset= getOffset(line, 0);
746                 int lastCharColumn= getLastCharColumn(line);
747                 offset= computeOffsetUsingPrefix(line, offset, "<!DOCTYPE", lastCharColumn); //$NON-NLS-1$
748
} else {
749                 offset= getOffset(line, column);
750             }
751         } catch (BadLocationException e) {
752             AntUIPlugin.log(e);
753         }
754         node.setOffset(offset);
755         fNonStructuralNodes.add(node);
756     }
757
758     /* (non-Javadoc)
759      * @see org.eclipse.ant.internal.ui.model.IAntModel#addTask(org.apache.tools.ant.Task, org.apache.tools.ant.Task, org.xml.sax.Attributes, int, int)
760      */

761     public void addTask(Task newTask, Task parentTask, Attributes JavaDoc attributes, int line, int column) {
762         if (!canGetTaskInfo()) {
763             //need to add top level tasks so imports are executed even when
764
//the model is not interested in task level resolution
765
Target owningTarget= newTask.getOwningTarget();
766             String JavaDoc name= owningTarget.getName();
767             if (name == null || name.length() != 0 ) {
768                 //not the top level implicit target
769
return;
770             }
771         }
772         AntTaskNode taskNode= null;
773         if (parentTask == null) {
774             taskNode= newTaskNode(newTask, attributes);
775             if (fCurrentTargetNode == null) {
776                 fProjectNode.addChildNode(taskNode);
777             } else {
778                 fCurrentTargetNode.addChildNode(taskNode);
779             }
780         } else {
781             taskNode= newNotWellKnownTaskNode(newTask, attributes);
782             AntTaskNode parentNode= (AntTaskNode)fTaskToNode.get(parentTask);
783             parentNode.addChildNode(taskNode);
784         }
785         fTaskToNode.put(newTask, taskNode);
786         
787         fStillOpenElements.push(taskNode);
788         computeOffset(taskNode, line, column);
789         if (fNodeBeingResolved instanceof AntImportNode) {
790             taskNode.setImportNode(fNodeBeingResolved);
791             //place the node in the collection right after the import node
792
if (fNodeBeingResolvedIndex == -1) {
793                 fNodeBeingResolvedIndex= fTaskNodes.indexOf(fNodeBeingResolved);
794             }
795             fNodeBeingResolvedIndex++;
796             fTaskNodes.add(fNodeBeingResolvedIndex, taskNode);
797         } else {
798             fTaskNodes.add(taskNode);
799         }
800     }
801     
802     /* (non-Javadoc)
803      * @see org.eclipse.ant.internal.ui.model.IAntModel#addEntity(java.lang.String, java.lang.String)
804      */

805     public void addEntity(String JavaDoc entityName, String JavaDoc entityPath) {
806         if (fEntityNameToPath == null) {
807             fEntityNameToPath= new HashMap JavaDoc();
808         }
809         fEntityNameToPath.put(entityName, entityPath);
810     }
811
812     private AntTaskNode newTaskNode(Task newTask, Attributes JavaDoc attributes) {
813         AntTaskNode newNode= null;
814         String JavaDoc taskName= newTask.getTaskName();
815         if (newTask instanceof UnknownElement) {
816             //attempt to handle namespaces
817
taskName= ((UnknownElement) newTask).getTag();
818         }
819         
820         if (isPropertySettingTask(taskName)) {
821             newNode= new AntPropertyNode(newTask, attributes);
822         } else if (taskName.equalsIgnoreCase("import")) { //$NON-NLS-1$
823
newNode= new AntImportNode(newTask, attributes);
824         } else if (taskName.equalsIgnoreCase("macrodef") //$NON-NLS-1$
825
|| taskName.equalsIgnoreCase("presetdef") //$NON-NLS-1$
826
|| taskName.equalsIgnoreCase("typedef") //$NON-NLS-1$
827
|| taskName.equalsIgnoreCase("taskdef")) { //$NON-NLS-1$
828
newNode= new AntDefiningTaskNode(newTask, attributes);
829         } else if(taskName.equalsIgnoreCase("antcall")) { //$NON-NLS-1$
830
newNode= new AntTaskNode(newTask, generateLabel(taskName, attributes, IAntModelConstants.ATTR_TARGET));
831         } else if(taskName.equalsIgnoreCase("mkdir")) { //$NON-NLS-1$
832
newNode= new AntTaskNode(newTask, generateLabel(taskName, attributes, IAntModelConstants.ATTR_DIR));
833         } else if(taskName.equalsIgnoreCase("copy")) { //$NON-NLS-1$
834
newNode= new AntTaskNode(newTask, generateLabel(taskName, attributes, IAntModelConstants.ATTR_DESTFILE));
835         } else if(taskName.equalsIgnoreCase("tar") //$NON-NLS-1$
836
|| taskName.equalsIgnoreCase("jar") //$NON-NLS-1$
837
|| taskName.equalsIgnoreCase("war") //$NON-NLS-1$
838
|| taskName.equalsIgnoreCase("zip")) { //$NON-NLS-1$
839
newNode= new AntTaskNode(newTask, generateLabel(newTask.getTaskName(), attributes, IAntModelConstants.ATTR_DESTFILE));
840         } else if(taskName.equalsIgnoreCase("untar") //$NON-NLS-1$
841
|| taskName.equalsIgnoreCase("unjar") //$NON-NLS-1$
842
|| taskName.equalsIgnoreCase("unwar") //$NON-NLS-1$
843
|| taskName.equalsIgnoreCase("gunzip") //$NON-NLS-1$
844
|| taskName.equalsIgnoreCase("bunzip2") //$NON-NLS-1$
845
|| taskName.equalsIgnoreCase("unzip")) { //$NON-NLS-1$
846
newNode= new AntTaskNode(newTask, generateLabel(newTask.getTaskName(), attributes, IAntModelConstants.ATTR_SRC));
847         } else if(taskName.equalsIgnoreCase("gzip") //$NON-NLS-1$
848
|| taskName.equalsIgnoreCase("bzip2")) { //$NON-NLS-1$
849
newNode= new AntTaskNode(newTask, generateLabel(newTask.getTaskName(), attributes, IAntModelConstants.ATTR_ZIPFILE));
850         } else if(taskName.equalsIgnoreCase("exec")) { //$NON-NLS-1$
851
String JavaDoc label = "exec "; //$NON-NLS-1$
852
String JavaDoc command = attributes.getValue(IAntModelConstants.ATTR_COMMAND);
853             if(command != null) {
854                 label += command;
855             }
856             command = attributes.getValue(IAntModelConstants.ATTR_EXECUTABLE);
857             if(command != null) {
858                 label += command;
859             }
860             newNode= new AntTaskNode(newTask, label);
861         } else if(taskName.equalsIgnoreCase("ant")) { //$NON-NLS-1$
862
newNode= new AntAntNode(newTask, attributes);
863         } else if(taskName.equalsIgnoreCase("delete")) { //$NON-NLS-1$
864
String JavaDoc label = "delete "; //$NON-NLS-1$
865
String JavaDoc file = attributes.getValue(IAntModelConstants.ATTR_FILE);
866             if(file != null) {
867                 label+= file;
868             } else {
869                 file = attributes.getValue(IAntModelConstants.ATTR_DIR);
870                 if(file != null) {
871                     label+= file;
872                 }
873             }
874             newNode= new AntTaskNode(newTask, label);
875         } else {
876             newNode = newNotWellKnownTaskNode(newTask, attributes);
877         }
878         setExternalInformation(newTask, newNode);
879         return newNode;
880     }
881             
882     /**
883      * @param taskName the name of the task to check
884      * @return whether or not a task with this name sets properties
885      */

886     private boolean isPropertySettingTask(String JavaDoc taskName) {
887         return taskName.equalsIgnoreCase("property") //$NON-NLS-1$
888
|| taskName.equalsIgnoreCase("available") //$NON-NLS-1$
889
|| taskName.equalsIgnoreCase("basename") //$NON-NLS-1$
890
|| taskName.equalsIgnoreCase("condition") //$NON-NLS-1$
891
|| taskName.equalsIgnoreCase("dirname") //$NON-NLS-1$
892
|| taskName.equalsIgnoreCase("loadfile") //$NON-NLS-1$
893
|| taskName.equalsIgnoreCase("pathconvert") //$NON-NLS-1$
894
|| taskName.equalsIgnoreCase("uptodate") //$NON-NLS-1$
895
|| taskName.equalsIgnoreCase("xmlproperty") //$NON-NLS-1$
896
|| taskName.equalsIgnoreCase("loadproperties"); //$NON-NLS-1$
897
}
898
899     private boolean isNodeExternal(String JavaDoc fileName) {
900         File JavaDoc taskFile= new File JavaDoc(fileName);
901         return !taskFile.equals(getEditedFile());
902     }
903
904     private AntTaskNode newNotWellKnownTaskNode(Task newTask, Attributes JavaDoc attributes) {
905         AntTaskNode newNode= new AntTaskNode(newTask);
906         String JavaDoc id= attributes.getValue("id"); //$NON-NLS-1$
907
if (id != null) {
908             newNode.setId(id);
909         }
910         String JavaDoc taskName= newTask.getTaskName();
911         if ("attribute".equals(taskName) || "element".equals(taskName)) { //$NON-NLS-1$ //$NON-NLS-2$
912
String JavaDoc name= attributes.getValue("name"); //$NON-NLS-1$
913
if (name != null) {
914                 newNode.setBaseLabel(name);
915             }
916         }
917         
918         setExternalInformation(newTask, newNode);
919         return newNode;
920     }
921
922     private void setExternalInformation(Task newTask, AntTaskNode newNode) {
923         String JavaDoc taskFileName= newTask.getLocation().getFileName();
924         boolean external= isNodeExternal(taskFileName);
925         newNode.setExternal(external);
926         if (external) {
927             newNode.setFilePath(taskFileName);
928         }
929     }
930
931     private String JavaDoc generateLabel(String JavaDoc taskName, Attributes JavaDoc attributes, String JavaDoc attributeName) {
932         StringBuffer JavaDoc label = new StringBuffer JavaDoc(taskName);
933         String JavaDoc srcFile = attributes.getValue(attributeName);
934         if(srcFile != null) {
935             label.append(' ');
936             label.append(srcFile);
937         }
938         return label.toString();
939     }
940
941     private void computeLength(AntElementNode element, int line, int column) {
942         if (element.isExternal()) {
943             element.setExternalInfo(line, column);
944             return;
945         }
946         try {
947             int length;
948             int offset;
949             if (column <= 0) {
950                 column= getLastCharColumn(line);
951                 String JavaDoc lineText= fDocument.get(fDocument.getLineOffset(line - 1), column);
952                 StringBuffer JavaDoc searchString= new StringBuffer JavaDoc("</"); //$NON-NLS-1$
953
searchString.append(element.getName());
954                 searchString.append('>');
955                 int index= lineText.indexOf(searchString.toString());
956                 if (index == -1) {
957                     index= lineText.indexOf("/>"); //$NON-NLS-1$
958
if (index == -1 ) {
959                         index= column; //set to the end of line
960
} else {
961                         index= index + 3;
962                     }
963                 } else {
964                     index= index + searchString.length() + 1;
965                 }
966                 offset= getOffset(line, index);
967             } else {
968                 offset= getOffset(line, column);
969             }
970             
971             length= offset - element.getOffset();
972             element.setLength(length);
973         } catch (BadLocationException e) {
974             //ignore as the parser may be out of sync with the document during reconciliation
975
}
976     }
977     
978     private void computeOffset(AntElementNode element, int line, int column) {
979         if (!canGetPositionInfo()) {
980             return;
981         }
982         if (element.isExternal()) {
983             element.setExternalInfo(line - 1, column);
984             return;
985         }
986         try {
987             String JavaDoc prefix= "<" + element.getName(); //$NON-NLS-1$
988
int offset = computeOffset(line, column, prefix);
989             element.setOffset(offset + 1);
990             element.setSelectionLength(element.getName().length());
991         } catch (BadLocationException e) {
992             //ignore as the parser may be out of sync with the document during reconciliation
993
}
994     }
995     
996     private int computeOffset(int line, int column, String JavaDoc prefix) throws BadLocationException {
997         int offset;
998         if (column <= 0) {
999             offset= getOffset(line, 0);
1000            int lastCharColumn= getLastCharColumn(line);
1001            offset= computeOffsetUsingPrefix(line, offset, prefix, lastCharColumn);
1002        } else {
1003            column= column -1;
1004            offset= getOffset(line, column);
1005            offset= computeOffsetUsingPrefix(line, offset, prefix, column);
1006        }
1007        return offset;
1008    }
1009
1010    private int computeOffsetUsingPrefix(int line, int offset, String JavaDoc prefix, int column) throws BadLocationException {
1011        String JavaDoc lineText= fDocument.get(fDocument.getLineOffset(line - 1), column);
1012        int lastIndex= lineText.indexOf(prefix);
1013        if (lastIndex > -1) {
1014            offset= getOffset(line, lastIndex + 1);
1015        } else {
1016            return computeOffsetUsingPrefix(line - 1, offset, prefix, getLastCharColumn(line - 1));
1017        }
1018        return offset;
1019    }
1020
1021    /* (non-Javadoc)
1022     * @see org.eclipse.ant.internal.ui.model.IAntModel#getOffset(int, int)
1023     */

1024    public int getOffset(int line, int column) throws BadLocationException {
1025        return fDocument.getLineOffset(line - 1) + column - 1;
1026    }
1027    
1028    private int getNonWhitespaceOffset(int line, int column) throws BadLocationException {
1029        int offset= fDocument.getLineOffset(line - 1) + column - 1;
1030        while(Character.isWhitespace(fDocument.getChar(offset))) {
1031            offset++;
1032        }
1033        return offset;
1034    }
1035    
1036    public int getLine(int offset) {
1037        try {
1038            return fDocument.getLineOfOffset(offset) + 1;
1039        } catch (BadLocationException be) {
1040            return -1;
1041        }
1042    }
1043    
1044    private int getLastCharColumn(int line) throws BadLocationException {
1045        String JavaDoc lineDelimiter= fDocument.getLineDelimiter(line - 1);
1046        int lineDelimiterLength= lineDelimiter != null ? lineDelimiter.length() : 0;
1047        return fDocument.getLineLength(line - 1) - lineDelimiterLength;
1048    }
1049
1050    /* (non-Javadoc)
1051     * @see org.eclipse.ant.internal.ui.model.IAntModel#setCurrentElementLength(int, int)
1052     */

1053    public void setCurrentElementLength(int lineNumber, int column) {
1054        fLastNode= (AntElementNode)fStillOpenElements.pop();
1055        if (fLastNode == fCurrentTargetNode) {
1056            fCurrentTargetNode= null; //the current target element has been closed
1057
}
1058        if (canGetPositionInfo()) {
1059            computeLength(fLastNode, lineNumber, column);
1060        }
1061    }
1062    
1063    private void acceptProblem(IProblem problem) {
1064        if (fProblemRequestor != null) {
1065            fProblemRequestor.acceptProblem(problem);
1066        }
1067        if (fMarkerUpdater != null) {
1068            fMarkerUpdater.acceptProblem(problem);
1069        }
1070    }
1071    
1072    /* (non-Javadoc)
1073     * @see org.eclipse.ant.internal.ui.model.IAntModel#getFile()
1074     */

1075    public IFile getFile() {
1076        IPath location= fLocationProvider.getLocation();
1077        if (location == null) {
1078            return null;
1079        }
1080        IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
1081        if (files.length > 0) {
1082            return files[0];
1083        }
1084        return null;
1085    }
1086
1087    private void beginReporting() {
1088        if (fProblemRequestor != null) {
1089            fProblemRequestor.beginReporting();
1090        }
1091        if (fMarkerUpdater != null) {
1092            fMarkerUpdater.beginReporting();
1093        }
1094    }
1095    
1096    private void endReporting() {
1097        if (fProblemRequestor != null) {
1098            fProblemRequestor.endReporting();
1099        }
1100    }
1101
1102    private IProblem createProblem(Exception JavaDoc exception, int offset, int length, int severity) {
1103        return createProblem(exception.getMessage(), offset, length, severity);
1104    }
1105    
1106    private IProblem createProblem(String JavaDoc message, int offset, int length, int severity) {
1107        return new AntModelProblem(message, severity, offset, length, getLine(offset));
1108    }
1109
1110    private void notifyProblemRequestor(Exception JavaDoc exception, AntElementNode element, int severity) {
1111        if (doNotReportProblems()) {
1112            return;
1113        }
1114        AntElementNode importNode= element.getImportNode();
1115        if (importNode != null) {
1116            element= importNode;
1117        }
1118        IProblem problem= createProblem(exception, element.getOffset(), element.getLength(), severity);
1119        acceptProblem(problem);
1120        element.associatedProblem(problem);
1121    }
1122    
1123    private void notifyProblemRequestor(Exception JavaDoc exception, int offset, int length, int severity) {
1124        if (doNotReportProblems()) {
1125            return;
1126        }
1127        if (fProblemRequestor != null) {
1128            IProblem problem= createProblem(exception, offset, length, severity);
1129            acceptProblem(problem);
1130        }
1131    }
1132
1133    /* (non-Javadoc)
1134     * @see org.eclipse.ant.internal.ui.model.IAntModel#warning(java.lang.Exception)
1135     */

1136    public void warning(Exception JavaDoc exception) {
1137        handleError(exception, AntModelProblem.SEVERITY_WARNING);
1138    }
1139    
1140    /* (non-Javadoc)
1141     * @see org.eclipse.ant.internal.ui.model.IAntModel#error(java.lang.Exception)
1142     */

1143    public void error(Exception JavaDoc exception) {
1144        handleError(exception, AntModelProblem.SEVERITY_ERROR);
1145    }
1146    
1147    /* (non-Javadoc)
1148     * @see org.eclipse.ant.internal.ui.model.IAntModel#errorFromElementText(java.lang.Exception, int, int)
1149     */

1150    public void errorFromElementText(Exception JavaDoc exception, int start, int count) {
1151        AntElementNode node= fLastNode;
1152        if (node == null) {
1153            if (!fStillOpenElements.empty()) {
1154                node= (AntElementNode)fStillOpenElements.peek();
1155            }
1156        }
1157        if (node == null) {
1158            return;
1159        }
1160        computeEndLocationForErrorNode(node, start, count);
1161        notifyProblemRequestor(exception, start, count, AntModelProblem.SEVERITY_ERROR);
1162        markHierarchy(fLastNode, AntModelProblem.SEVERITY_ERROR, exception.getMessage());
1163    }
1164    
1165    /* (non-Javadoc)
1166     * @see org.eclipse.ant.internal.ui.model.IAntModel#errorFromElement(java.lang.Exception, org.eclipse.ant.internal.ui.model.AntElementNode, int, int)
1167     */

1168    public void errorFromElement(Exception JavaDoc exception, AntElementNode node, int lineNumber, int column) {
1169        if (node == null) {
1170            if (!fStillOpenElements.empty()) {
1171                node= (AntElementNode)fStillOpenElements.peek();
1172            } else {
1173                node= fLastNode;
1174            }
1175        }
1176        computeEndLocationForErrorNode(node, lineNumber, column);
1177        notifyProblemRequestor(exception, node, AntModelProblem.SEVERITY_ERROR);
1178        markHierarchy(node, AntModelProblem.SEVERITY_ERROR, exception.getMessage());
1179    }
1180
1181    private AntElementNode createProblemElement(SAXParseException JavaDoc exception) {
1182        int lineNumber= exception.getLineNumber();
1183        StringBuffer JavaDoc message= new StringBuffer JavaDoc(exception.getMessage());
1184        if (lineNumber != -1){
1185            message.append(AntModelMessages.AntModel_1 + lineNumber);
1186        }
1187
1188        AntElementNode errorNode= new AntElementNode(message.toString());
1189        errorNode.setFilePath(exception.getSystemId());
1190        errorNode.setProblemSeverity(AntModelProblem.SEVERITY_ERROR);
1191        errorNode.setProblemMessage(exception.getMessage());
1192        computeErrorLocation(errorNode, exception);
1193        return errorNode;
1194    }
1195    
1196    private void computeErrorLocation(AntElementNode element, SAXParseException JavaDoc exception) {
1197        if (element.isExternal()) {
1198            return;
1199        }
1200        
1201        int line= exception.getLineNumber();
1202        int startColumn= exception.getColumnNumber();
1203        computeEndLocationForErrorNode(element, line, startColumn);
1204    }
1205    
1206    private void computeEndLocationForErrorNode(AntElementNode element, int line, int startColumn) {
1207        try {
1208            if (line <= 0) {
1209                line= 1;
1210            }
1211            int endColumn;
1212            if (startColumn <= 0) {
1213                if (element.getOffset() > -1) {
1214                    startColumn= element.getOffset() + 1;
1215                } else {
1216                    startColumn= 1;
1217                }
1218                endColumn= getLastCharColumn(line) + 1;
1219            } else {
1220                if (startColumn > 1) {
1221                    --startColumn;
1222                }
1223                
1224                endColumn= startColumn;
1225                if (startColumn <= getLastCharColumn(line)) {
1226                    ++endColumn;
1227                }
1228            }
1229            
1230            int correction= 0;
1231            if (element.getOffset() == -1) {
1232                int originalOffset= getOffset(line, startColumn);
1233                int nonWhitespaceOffset= originalOffset;
1234                try {
1235                    nonWhitespaceOffset= getNonWhitespaceOffset(line, startColumn);
1236                } catch (BadLocationException be) {
1237                }
1238                element.setOffset(nonWhitespaceOffset);
1239                correction= nonWhitespaceOffset - originalOffset;
1240            }
1241            if (endColumn - startColumn == 0) {
1242                int offset= getOffset(line, startColumn);
1243                element.setLength(offset - element.getOffset() - correction);
1244            } else {
1245                element.setLength(endColumn - startColumn - correction);
1246            }
1247        } catch (BadLocationException e) {
1248            //ignore as the parser may be out of sync with the document during reconciliation
1249
}
1250    }
1251
1252    private void handleError(Exception JavaDoc exception, int severity) {
1253        AntElementNode node= null;
1254        if (fStillOpenElements.isEmpty()) {
1255            if (exception instanceof SAXParseException JavaDoc) {
1256                node= createProblemElement((SAXParseException JavaDoc)exception);
1257            }
1258        } else {
1259            node= (AntElementNode)fStillOpenElements.peek();
1260        }
1261        if (node == null) {
1262            return;
1263        }
1264        markHierarchy(node, severity, exception.getMessage());
1265        
1266        if (exception instanceof SAXParseException JavaDoc) {
1267            SAXParseException JavaDoc parseException= (SAXParseException JavaDoc)exception;
1268            if (node.getOffset() == -1) {
1269                computeEndLocationForErrorNode(node, parseException.getLineNumber() - 1, parseException.getColumnNumber());
1270            } else {
1271                int lineNumber= parseException.getLineNumber();
1272                int columnNumber= parseException.getColumnNumber();
1273                if (columnNumber == -1) {
1274                    columnNumber= 1;
1275                }
1276                try {
1277                    AntElementNode childNode= node.getNode(getNonWhitespaceOffset(lineNumber, columnNumber) + 1);
1278                    if (childNode != null && childNode != node) {
1279                        node= childNode;
1280                        node.setProblemSeverity(severity);
1281                        node.setProblemMessage(exception.getMessage());
1282                    } else {
1283                        node= createProblemElement(parseException);
1284                    }
1285                } catch (BadLocationException be) {
1286                    node= createProblemElement(parseException);
1287                }
1288            }
1289        }
1290        
1291        notifyProblemRequestor(exception, node, severity);
1292        
1293        if (node != null) {
1294            while (node.getParentNode() != null) {
1295                AntElementNode parentNode= node.getParentNode();
1296                if (parentNode.getLength() == -1) {
1297                    parentNode.setLength(node.getOffset() - parentNode.getOffset() + node.getLength());
1298                }
1299                node= parentNode;
1300            }
1301        }
1302    }
1303    
1304    /* (non-Javadoc)
1305     * @see org.eclipse.ant.internal.ui.model.IAntModel#fatalError(java.lang.Exception)
1306     */

1307    public void fatalError(Exception JavaDoc exception) {
1308        handleError(exception, AntModelProblem.SEVERITY_FATAL_ERROR);
1309    }
1310    
1311    public AntElementNode getOpenElement() {
1312        if (fStillOpenElements.isEmpty()) {
1313            return null;
1314        }
1315        return (AntElementNode)fStillOpenElements.peek();
1316    }
1317
1318    /* (non-Javadoc)
1319     * @see org.eclipse.ant.internal.ui.model.IAntModel#getEntityName(java.lang.String)
1320     */

1321    public String JavaDoc getEntityName(String JavaDoc path) {
1322        if (fEntityNameToPath != null) {
1323            Iterator JavaDoc itr= fEntityNameToPath.keySet().iterator();
1324            String JavaDoc entityPath;
1325            String JavaDoc name;
1326            while (itr.hasNext()) {
1327                name= (String JavaDoc) itr.next();
1328                entityPath= (String JavaDoc) fEntityNameToPath.get(name);
1329                if (entityPath.equals(path)) {
1330                    return name;
1331                }
1332            }
1333        }
1334        return null;
1335    }
1336
1337    private ClassLoader JavaDoc getClassLoader(ClassLoader JavaDoc contextClassLoader) {
1338        if (fLocalClassLoader != null) {
1339            ((AntClassLoader) fLocalClassLoader).setPluginContextClassloader(contextClassLoader);
1340            return fLocalClassLoader;
1341        }
1342        if (fgClassLoader == null) {
1343            fgClassLoader= AntCorePlugin.getPlugin().getNewClassLoader(true);
1344        }
1345        if (fgClassLoader instanceof AntClassLoader) {
1346            ((AntClassLoader) fgClassLoader).setPluginContextClassloader(contextClassLoader);
1347        }
1348        return fgClassLoader;
1349    }
1350    
1351    public String JavaDoc getTargetDescription(String JavaDoc targetName) {
1352        AntTargetNode target= getTargetNode(targetName);
1353        if (target != null) {
1354            return target.getTarget().getDescription();
1355        }
1356        return null;
1357    }
1358    
1359    public AntTargetNode getTargetNode(String JavaDoc targetName ) {
1360        AntProjectNode projectNode= getProjectNode();
1361        if (projectNode == null) {
1362            return null;
1363        }
1364        if (projectNode.hasChildren()) {
1365            List JavaDoc possibleTargets= projectNode.getChildNodes();
1366            Iterator JavaDoc iter= possibleTargets.iterator();
1367            while (iter.hasNext()) {
1368                AntElementNode node = (AntElementNode) iter.next();
1369                if (node instanceof AntTargetNode) {
1370                    AntTargetNode targetNode = (AntTargetNode) node;
1371                    if (targetName.equalsIgnoreCase(targetNode.getTarget().getName())) {
1372                        return targetNode;
1373                    }
1374                }
1375            }
1376        }
1377        return null;
1378    }
1379    
1380    /* (non-Javadoc)
1381     * @see org.eclipse.ant.internal.ui.model.IAntModel#getProjectNode(boolean)
1382     */

1383    public AntProjectNode getProjectNode(boolean doReconcile) {
1384        if (doReconcile) {
1385            synchronized (getLockObject()) { //ensure to wait for any current synchronization
1386
reconcile();
1387            }
1388        }
1389        return fProjectNode;
1390    }
1391    
1392    /* (non-Javadoc)
1393     * @see org.eclipse.ant.internal.ui.model.IAntModel#getProjectNode()
1394     */

1395    public AntProjectNode getProjectNode() {
1396        return getProjectNode(true);
1397    }
1398    
1399    public AntElementNode getNode(int offset, boolean waitForReconcile) {
1400        if (getProjectNode(waitForReconcile) != null) {
1401            return getProjectNode(waitForReconcile).getNode(offset);
1402        }
1403        return null;
1404    }
1405    
1406    /**
1407     * Removes any type definitions that no longer exist in the buildfile
1408     */

1409    private void reconcileTaskAndTypes() {
1410        if (fCurrentNodeIdentifiers == null || fDefinerNodeIdentifierToDefinedTasks == null) {
1411            return;
1412        }
1413        Iterator JavaDoc iter= fDefinerNodeIdentifierToDefinedTasks.keySet().iterator();
1414        ComponentHelper helper= ComponentHelper.getComponentHelper(fProjectNode.getProject());
1415        while (iter.hasNext()) {
1416            String JavaDoc key = (String JavaDoc) iter.next();
1417            if (fCurrentNodeIdentifiers.get(key) == null) {
1418                removeDefinerTasks(key, helper.getAntTypeTable());
1419            }
1420        }
1421    }
1422
1423    protected void removeDefinerTasks(String JavaDoc definerIdentifier, Hashtable JavaDoc typeTable) {
1424        if (fDefinerNodeIdentifierToDefinedTasks == null) {
1425            return;
1426        }
1427        List JavaDoc tasks= (List JavaDoc) fDefinerNodeIdentifierToDefinedTasks.get(definerIdentifier);
1428        if (tasks == null) {
1429            return;
1430        }
1431        Iterator JavaDoc iterator= tasks.iterator();
1432        while (iterator.hasNext()) {
1433            typeTable.remove(iterator.next());
1434        }
1435    }
1436
1437    /* (non-Javadoc)
1438     * @see org.eclipse.ant.internal.ui.model.IAntModel#addComment(int, int, int)
1439     */

1440    public void addComment(int lineNumber, int columnNumber, int length) {
1441        AntCommentNode commentNode= new AntCommentNode();
1442        int offset= -1;
1443        try {
1444            offset= computeOffset(lineNumber, columnNumber, "-->"); //$NON-NLS-1$
1445
} catch (BadLocationException e) {
1446            commentNode.setExternal(true);
1447            commentNode.setExternalInfo(lineNumber, columnNumber);
1448            offset= length-1;
1449        }
1450        commentNode.setOffset(offset - length);
1451        commentNode.setLength(length);
1452        fNonStructuralNodes.add(commentNode);
1453    }
1454
1455    /* (non-Javadoc)
1456     * @see org.eclipse.ant.internal.ui.model.IAntModel#needsTaskResolution()
1457     */

1458    public boolean canGetTaskInfo() {
1459        return fHasTaskInfo;
1460    }
1461
1462    /* (non-Javadoc)
1463     * @see org.eclipse.ant.internal.ui.model.IAntModel#needsLexicalResolution()
1464     */

1465    public boolean canGetLexicalInfo() {
1466        return fHasLexicalInfo;
1467    }
1468    
1469    /* (non-Javadoc)
1470     * @see org.eclipse.ant.internal.ui.model.IAntModel#setClassLoader(java.net.URLClassLoader)
1471     */

1472    public void setClassLoader(URLClassLoader JavaDoc loader) {
1473        AntDefiningTaskNode.setJavaClassPath(loader.getURLs());
1474        fLocalClassLoader= loader;
1475    }
1476
1477    /* (non-Javadoc)
1478     * @see org.eclipse.ant.internal.ui.model.IAntModel#needsPositionResolution()
1479     */

1480    public boolean canGetPositionInfo() {
1481        return fHasPositionInfo;
1482    }
1483
1484    public String JavaDoc getPath(String JavaDoc text, int offset) {
1485        if (fEntityNameToPath != null) {
1486            String JavaDoc path= (String JavaDoc)fEntityNameToPath.get(text);
1487            if (path != null) {
1488                return path;
1489            }
1490        }
1491        AntElementNode node= getNode(offset, true);
1492        if (node != null) {
1493            return node.getReferencedElement(offset);
1494        }
1495        return null;
1496    }
1497    
1498    /* (non-Javadoc)
1499     * @see org.eclipse.ant.internal.ui.model.IAntModel#getText(int, int)
1500     */

1501    public String JavaDoc getText(int offset, int length) {
1502        try {
1503            return fDocument.get(offset, length);
1504        } catch (BadLocationException e) {
1505        }
1506        return null;
1507    }
1508
1509    private AntElementNode findPropertyNode(String JavaDoc text, List JavaDoc children) {
1510        Iterator JavaDoc iter= children.iterator();
1511        while (iter.hasNext()) {
1512            AntElementNode element = (AntElementNode) iter.next();
1513            if (element instanceof AntPropertyNode) {
1514                if (((AntPropertyNode)element).getProperty(text) != null){
1515                    return element;
1516                }
1517            } else if (element.hasChildren()) {
1518                AntElementNode found= findPropertyNode(text, element.getChildNodes());
1519                if (found != null) {
1520                    return found;
1521                }
1522            }
1523        }
1524        return null;
1525    }
1526
1527    public AntElementNode getPropertyNode(String JavaDoc text) {
1528        AntProjectNode node= getProjectNode();
1529        if (node == null || !node.hasChildren()) {
1530            return null;
1531        }
1532        
1533        return findPropertyNode(text, node.getChildNodes());
1534    }
1535
1536    public List JavaDoc getNonStructuralNodes() {
1537        return fNonStructuralNodes;
1538    }
1539
1540    public void updateForInitialReconcile() {
1541        fMarkerUpdater.updateMarkers();
1542        fShouldReconcile= AntUIPlugin.getDefault().getPreferenceStore().getBoolean(AntEditorPreferenceConstants.EDITOR_RECONCILE);
1543    }
1544
1545    public void updateMarkers() {
1546        boolean temp= fShouldReconcile;
1547        try {
1548            fShouldReconcile= true;
1549            reconcile();
1550            fMarkerUpdater.updateMarkers();
1551        } finally {
1552            fShouldReconcile= temp;
1553        }
1554    }
1555
1556    public AntElementNode getReferenceNode(String JavaDoc text) {
1557        Object JavaDoc reference = getReferenceObject(text);
1558        if (reference == null) {
1559            return null;
1560        }
1561        
1562        Collection JavaDoc nodes = fTaskToNode.keySet();
1563        Iterator JavaDoc iter = nodes.iterator();
1564        while (iter.hasNext()) {
1565            Object JavaDoc original = iter.next();
1566            Object JavaDoc object = original;
1567            if (object instanceof UnknownElement) {
1568                UnknownElement element = (UnknownElement) object;
1569                RuntimeConfigurable wrapper = element.getWrapper();
1570                Map JavaDoc attributes = wrapper.getAttributeMap();
1571                String JavaDoc id = (String JavaDoc) attributes.get("id"); //$NON-NLS-1$
1572
if (text.equals(id)) {
1573                    return (AntElementNode)fTaskToNode.get(original);
1574                }
1575            }
1576        }
1577        return null;
1578    }
1579
1580    public Object JavaDoc getReferenceObject(String JavaDoc refId) {
1581        AntProjectNode projectNode= getProjectNode();
1582        if (projectNode == null) {
1583            return null;
1584        }
1585        try {
1586            Project project= projectNode.getProject();
1587            Object JavaDoc ref= project.getReference(refId);
1588            return ref;
1589            
1590        } catch (BuildException be) {
1591            handleBuildException(be, null);
1592        }
1593        return null;
1594    }
1595
1596    public String JavaDoc getPropertyValue(String JavaDoc propertyName) {
1597        AntProjectNode projectNode= getProjectNode();
1598        if (projectNode == null) {
1599            return null;
1600        }
1601        return projectNode.getProject().getProperty(propertyName);
1602    }
1603
1604    /**
1605     * Only called if the AntModel is associated with an AntEditor
1606     */

1607    public void install() {
1608        fListener= new IDocumentListener() {
1609            public void documentAboutToBeChanged(DocumentEvent event) {
1610                synchronized (fDirtyLock) {
1611                    fIsDirty= true;
1612                }
1613            }
1614            public void documentChanged(DocumentEvent event) {}
1615        };
1616        fDocument.addDocumentListener(fListener);
1617    }
1618
1619    private void reconcileForPropertyChange(boolean classpathChanged) {
1620        if (classpathChanged) {
1621            fProjectNode= null; //need to reset tasks, types and properties
1622
fgClassLoader= null;
1623            AntDefiningTaskNode.setJavaClassPath();
1624            ProjectHelper.reset();
1625        }
1626        fIsDirty= true;
1627        reconcile();
1628        AntModelCore.getDefault().notifyAntModelListeners(new AntModelChangeEvent(this, true));
1629        fMarkerUpdater.updateMarkers();
1630    }
1631
1632    /* (non-Javadoc)
1633     * @see org.eclipse.ant.internal.ui.model.IAntModel#setProperties(java.util.Map)
1634     */

1635    public void setProperties(Map JavaDoc properties) {
1636       fProperties= properties;
1637    }
1638
1639    /* (non-Javadoc)
1640     * @see org.eclipse.ant.internal.ui.model.IAntModel#setPropertyFiles(java.util.List)
1641     */

1642    public void setPropertyFiles(String JavaDoc[] propertyFiles) {
1643        if (propertyFiles != null) {
1644            fPropertyFiles= Arrays.asList(propertyFiles);
1645        }
1646    }
1647    
1648    public void setDefiningTaskNodeText(AntDefiningTaskNode node) {
1649        if (fDefinersToText == null) {
1650            fDefinersToText= new HashMap JavaDoc();
1651            fCurrentNodeIdentifiers= new HashMap JavaDoc();
1652        }
1653        
1654        Object JavaDoc nodeIdentifier= node.getIdentifier();
1655        String JavaDoc nodeText= null;
1656        if (fPreviousDefinersToText != null) {
1657            nodeText= (String JavaDoc) fPreviousDefinersToText.get(nodeIdentifier);
1658        }
1659        String JavaDoc newNodeText= getText(node.getOffset(), node.getLength());
1660        if (nodeText != null) {
1661            if (nodeText.equals(newNodeText)) {
1662                node.setNeedsToBeConfigured(false);
1663                //update the data structures for the new node as the offset may have changed.
1664
List JavaDoc tasks= (List JavaDoc) fDefinerNodeIdentifierToDefinedTasks.get(nodeIdentifier);
1665                if (tasks != null) {
1666                    for (Iterator JavaDoc iter = tasks.iterator(); iter.hasNext(); ) {
1667                        String JavaDoc taskName = (String JavaDoc) iter.next();
1668                        fTaskNameToDefiningNode.put(taskName, node);
1669                    }
1670                }
1671            }
1672        }
1673        
1674        if (newNodeText != null) {
1675            fDefinersToText.put(nodeIdentifier, newNodeText);
1676        }
1677        fCurrentNodeIdentifiers.put(nodeIdentifier, nodeIdentifier);
1678    }
1679    
1680    protected void removeDefiningTaskNodeInfo(AntDefiningTaskNode node) {
1681        Object JavaDoc identifier= node.getIdentifier();
1682        if (identifier != null && fCurrentNodeIdentifiers != null) {
1683            fCurrentNodeIdentifiers.remove(identifier);
1684            fDefinersToText.remove(identifier);
1685        }
1686    }
1687    
1688    protected void addDefinedTasks(List JavaDoc newTasks, AntDefiningTaskNode node) {
1689        if (fTaskNameToDefiningNode == null) {
1690            fTaskNameToDefiningNode= new HashMap JavaDoc();
1691            fDefinerNodeIdentifierToDefinedTasks= new HashMap JavaDoc();
1692        }
1693
1694        Object JavaDoc identifier= node.getIdentifier();
1695        if (identifier == null) {
1696            return;
1697        }
1698        if (newTasks.isEmpty() && fCurrentNodeIdentifiers != null) {
1699            fCurrentNodeIdentifiers.remove(identifier);
1700        }
1701        fDefinerNodeIdentifierToDefinedTasks.put(identifier, newTasks);
1702        Iterator JavaDoc iter= newTasks.iterator();
1703        while (iter.hasNext()) {
1704            String JavaDoc name = (String JavaDoc) iter.next();
1705            fTaskNameToDefiningNode.put(name, node);
1706        }
1707    }
1708    
1709    public AntDefiningTaskNode getDefininingTaskNode(String JavaDoc nodeName) {
1710        if (fTaskNameToDefiningNode != null) {
1711            AntDefiningTaskNode node= (AntDefiningTaskNode)fTaskNameToDefiningNode.get(nodeName);
1712            if (node == null) {
1713                nodeName = getNamespaceCorrectName(nodeName);
1714                node= (AntDefiningTaskNode)fTaskNameToDefiningNode.get(nodeName);
1715            }
1716            return node;
1717        }
1718        return null;
1719    }
1720
1721    public String JavaDoc getNamespaceCorrectName(String JavaDoc nodeName) {
1722        String JavaDoc prefix= org.apache.tools.ant.ProjectHelper.extractUriFromComponentName(nodeName);
1723        String JavaDoc uri= getPrefixMapping(prefix);
1724        nodeName= org.apache.tools.ant.ProjectHelper.genComponentName(uri, org.apache.tools.ant.ProjectHelper.extractNameFromComponentName(nodeName));
1725        return nodeName;
1726    }
1727    
1728    public String JavaDoc getUserNamespaceCorrectName(String JavaDoc nodeName) {
1729        String JavaDoc prefix= org.apache.tools.ant.ProjectHelper.extractUriFromComponentName(nodeName);
1730        if (prefix.length() > 0) {
1731            String JavaDoc uri= getUserPrefixMapping(prefix);
1732            nodeName= org.apache.tools.ant.ProjectHelper.genComponentName(uri, org.apache.tools.ant.ProjectHelper.extractNameFromComponentName(nodeName));
1733        }
1734        return nodeName;
1735    }
1736    
1737    public AntTaskNode getMacroDefAttributeNode(String JavaDoc macroDefAttributeName) {
1738        if (fTaskNameToDefiningNode == null) {
1739            return null;
1740        }
1741        Iterator JavaDoc iter = fTaskNameToDefiningNode.values().iterator();
1742        while(iter.hasNext()) {
1743            AntDefiningTaskNode definingNode = (AntDefiningTaskNode) iter.next();
1744            List JavaDoc attributes= definingNode.getChildNodes();
1745            if (attributes != null) {
1746                Iterator JavaDoc attributeItr= attributes.iterator();
1747                while (attributeItr.hasNext()) {
1748                    AntTaskNode attributeNode= (AntTaskNode) attributeItr.next();
1749                    if (macroDefAttributeName.equals(attributeNode.getLabel())) {
1750                        return attributeNode;
1751                    }
1752                }
1753            }
1754        }
1755        return null;
1756    }
1757
1758    /**
1759     * Sets whether the AntModel should reconcile if it become dirty.
1760     * If set to reconcile, a reconcile is triggered if the model is dirty.
1761     * @param shouldReconcile
1762     */

1763    public void setShouldReconcile(boolean shouldReconcile) {
1764        fShouldReconcile= shouldReconcile;
1765        if (fShouldReconcile) {
1766            reconcile();
1767        }
1768    }
1769
1770    /* (non-Javadoc)
1771     * @see org.eclipse.ant.internal.ui.model.IAntModel#addPrefixMapping(java.lang.String, java.lang.String)
1772     */

1773    public void addPrefixMapping(String JavaDoc prefix, String JavaDoc uri) {
1774        if (fNamespacePrefixMappings == null) {
1775            fNamespacePrefixMappings= new HashMap JavaDoc();
1776        }
1777        fNamespacePrefixMappings.put(prefix, uri);
1778    }
1779    
1780    private String JavaDoc getPrefixMapping(String JavaDoc prefix) {
1781        if (fNamespacePrefixMappings != null) {
1782            return (String JavaDoc) fNamespacePrefixMappings.get(prefix);
1783        }
1784        return null;
1785    }
1786    
1787    private String JavaDoc getUserPrefixMapping(String JavaDoc prefix) {
1788        if (fNamespacePrefixMappings != null) {
1789            Set JavaDoc entrySet= fNamespacePrefixMappings.entrySet();
1790            Iterator JavaDoc entries= entrySet.iterator();
1791            while (entries.hasNext()) {
1792                Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entries.next();
1793                if (entry.getValue().equals(prefix)) {
1794                    return (String JavaDoc) entry.getKey();
1795                }
1796            }
1797        }
1798        return null;
1799    }
1800    
1801    /**
1802     * @see AntModel#cleanup()
1803     */

1804    class Small {
1805    }
1806}
Popular Tags