1 11 package org.eclipse.core.internal.resources; 12 13 import java.util.ArrayList ; 14 import org.eclipse.core.internal.utils.Messages; 15 import org.eclipse.core.resources.IProjectNatureDescriptor; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 20 22 public class ProjectNatureDescriptor implements IProjectNatureDescriptor { 23 protected String id; 24 protected String label; 25 protected String [] requiredNatures; 26 protected String [] natureSets; 27 protected String [] builderIds; 28 protected String [] contentTypeIds; 29 protected boolean allowLinking = true; 30 31 protected boolean hasCycle = false; 33 protected byte colour = 0; 35 36 40 protected ProjectNatureDescriptor(IExtension natureExtension) throws CoreException { 41 readExtension(natureExtension); 42 } 43 44 protected void fail() throws CoreException { 45 fail(NLS.bind(Messages.natures_invalidDefinition, id)); 46 } 47 48 protected void fail(String reason) throws CoreException { 49 throw new ResourceException(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, 1, reason, null)); 50 } 51 52 56 public String [] getBuilderIds() { 57 return builderIds; 58 } 59 60 64 public String [] getContentTypeIds() { 65 return contentTypeIds; 66 } 67 68 71 public String getNatureId() { 72 return id; 73 } 74 75 78 public String getLabel() { 79 return label; 80 } 81 82 85 public String [] getRequiredNatureIds() { 86 return requiredNatures; 87 } 88 89 92 public String [] getNatureSetIds() { 93 return natureSets; 94 } 95 96 99 public boolean isLinkingAllowed() { 100 return allowLinking; 101 } 102 103 106 protected void readExtension(IExtension natureExtension) throws CoreException { 107 id = natureExtension.getUniqueIdentifier(); 109 if (id == null) { 110 fail(Messages.natures_missingIdentifier); 111 } 112 label = natureExtension.getLabel(); 113 IConfigurationElement[] elements = natureExtension.getConfigurationElements(); 114 int count = elements.length; 115 ArrayList requiredList = new ArrayList (count); 116 ArrayList setList = new ArrayList (count); 117 ArrayList builderList = new ArrayList (count); 118 ArrayList contentTypeList = new ArrayList (count); 119 for (int i = 0; i < count; i++) { 120 IConfigurationElement element = elements[i]; 121 String name = element.getName(); 122 if (name.equalsIgnoreCase("requires-nature")) { String attribute = element.getAttribute("id"); if (attribute == null) 125 fail(); 126 requiredList.add(attribute); 127 } else if (name.equalsIgnoreCase("one-of-nature")) { String attribute = element.getAttribute("id"); if (attribute == null) 130 fail(); 131 setList.add(attribute); 132 } else if (name.equalsIgnoreCase("builder")) { String attribute = element.getAttribute("id"); if (attribute == null) 135 fail(); 136 builderList.add(attribute); 137 } else if (name.equalsIgnoreCase("content-type")) { String attribute = element.getAttribute("id"); if (attribute == null) 140 fail(); 141 contentTypeList.add(attribute); 142 } else if (name.equalsIgnoreCase("options")) { String attribute = element.getAttribute("allowLinking"); allowLinking = !Boolean.FALSE.toString().equalsIgnoreCase(attribute); 146 } 147 } 148 requiredNatures = (String []) requiredList.toArray(new String [requiredList.size()]); 149 natureSets = (String []) setList.toArray(new String [setList.size()]); 150 builderIds = (String []) builderList.toArray(new String [builderList.size()]); 151 contentTypeIds = (String []) contentTypeList.toArray(new String [contentTypeList.size()]); 152 } 153 154 157 public String toString() { 158 return "ProjectNatureDescriptor(" + id + ")"; } 160 } 161 | Popular Tags |