KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > ProjectInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.core.internal.resources;
12
13 import java.util.HashMap JavaDoc;
14 import org.eclipse.core.internal.events.BuildCommand;
15 import org.eclipse.core.resources.ICommand;
16 import org.eclipse.core.resources.IProjectNature;
17 import org.eclipse.core.runtime.content.IContentTypeMatcher;
18
19 public class ProjectInfo extends ResourceInfo {
20
21     /** The description of this object */
22     protected ProjectDescription description = null;
23
24     /** The list of natures for this project */
25     protected HashMap JavaDoc natures = null;
26
27     /** The property store for this resource (used only by the compatibility fragment) */
28     protected Object JavaDoc propertyStore = null;
29
30     /** The content type matcher for this project. */
31     protected IContentTypeMatcher matcher = null;
32
33     /**
34      * Discards any stale state on this project after it has been moved. Builder
35      * instances must be cleared because they reference the old project handle.
36      */

37     public synchronized void fixupAfterMove() {
38         natures = null;
39         // note that the property store instance will be recreated lazily
40
propertyStore = null;
41         if (description != null) {
42             ICommand[] buildSpec = description.getBuildSpec(false);
43             for (int i = 0; i < buildSpec.length; i++)
44                 ((BuildCommand) buildSpec[i]).setBuilder(null);
45         }
46     }
47
48     /**
49      * Returns the description associated with this info. The return value may be null.
50      */

51     public ProjectDescription getDescription() {
52         return description;
53     }
54
55     /**
56      * Returns the content type matcher associated with this info. The return value may be null.
57      */

58     public IContentTypeMatcher getMatcher() {
59         return matcher;
60     }
61
62     public IProjectNature getNature(String JavaDoc natureId) {
63         // thread safety: (Concurrency001)
64
HashMap JavaDoc temp = natures;
65         if (temp == null)
66             return null;
67         return (IProjectNature) temp.get(natureId);
68     }
69
70     /**
71      * Returns the property store associated with this info. The return value may be null.
72      */

73     public Object JavaDoc getPropertyStore() {
74         return propertyStore;
75     }
76
77     /**
78      * Sets the description associated with this info. The value may be null.
79      */

80     public void setDescription(ProjectDescription value) {
81         if (description != null) {
82             //if we already have a description, assign the new
83
//build spec on top of the old one to ensure we maintain
84
//any existing builder instances in the old build commands
85
ICommand[] oldSpec = description.buildSpec;
86             ICommand[] newSpec = value.buildSpec;
87             value.buildSpec = oldSpec;
88             value.setBuildSpec(newSpec);
89         }
90         description = value;
91     }
92
93     /**
94      * Sets the content type matcher to be associated with this info. The value may be null.
95      */

96     public void setMatcher(IContentTypeMatcher matcher) {
97         this.matcher = matcher;
98     }
99
100     public synchronized void setNature(String JavaDoc natureId, IProjectNature value) {
101         // thread safety: (Concurrency001)
102
if (value == null) {
103             if (natures == null)
104                 return;
105             HashMap JavaDoc temp = (HashMap JavaDoc) natures.clone();
106             temp.remove(natureId);
107             if (temp.isEmpty())
108                 natures = null;
109             else
110                 natures = temp;
111         } else {
112             HashMap JavaDoc temp = natures;
113             if (temp == null)
114                 temp = new HashMap JavaDoc(5);
115             else
116                 temp = (HashMap JavaDoc) natures.clone();
117             temp.put(natureId, value);
118             natures = temp;
119         }
120     }
121
122     /**
123      * Sets the property store associated with this info. The value may be null.
124      */

125     public void setPropertyStore(Object JavaDoc value) {
126         propertyStore = value;
127     }
128 }
129
Popular Tags