1 19 20 package org.netbeans.spi.project.support.ant; 21 22 import java.io.IOException ; 23 import org.netbeans.spi.project.AuxiliaryConfiguration; 24 import org.netbeans.spi.project.CacheDirectoryProvider; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileUtil; 27 import org.w3c.dom.Element ; 28 29 33 final class ExtensibleMetadataProviderImpl implements AuxiliaryConfiguration, CacheDirectoryProvider { 34 35 38 private static final String CACHE_PATH = "nbproject/private/cache"; 40 private final AntProjectHelper helper; 41 42 ExtensibleMetadataProviderImpl(AntProjectHelper helper) { 43 this.helper = helper; 44 } 45 46 public FileObject getCacheDirectory() throws IOException { 47 return FileUtil.createFolder(helper.getProjectDirectory(), CACHE_PATH); 48 } 49 50 public Element getConfigurationFragment(String elementName, String namespace, boolean shared) { 51 if (elementName == null || elementName.indexOf(':') != -1 || namespace == null) { 52 throw new IllegalArgumentException ("Illegal elementName and/or namespace"); } 54 return helper.getConfigurationFragment(elementName, namespace, shared); 55 } 56 57 public void putConfigurationFragment(Element fragment, boolean shared) throws IllegalArgumentException { 58 if (fragment.getNamespaceURI() == null || fragment.getNamespaceURI().length() == 0) { 59 throw new IllegalArgumentException ("Illegal elementName and/or namespace"); } 61 if (fragment.getLocalName().equals(helper.getType().getPrimaryConfigurationDataElementName(shared)) && 62 fragment.getNamespaceURI().equals(helper.getType().getPrimaryConfigurationDataElementNamespace(shared))) { 63 throw new IllegalArgumentException ("elementName + namespace reserved for project's primary configuration data"); } 65 helper.putConfigurationFragment(fragment, shared); 66 } 67 68 public boolean removeConfigurationFragment(String elementName, String namespace, boolean shared) throws IllegalArgumentException { 69 if (elementName == null || elementName.indexOf(':') != -1 || namespace == null) { 70 throw new IllegalArgumentException ("Illegal elementName and/or namespace"); } 72 if (elementName.equals(helper.getType().getPrimaryConfigurationDataElementName(shared)) && 73 namespace.equals(helper.getType().getPrimaryConfigurationDataElementNamespace(shared))) { 74 throw new IllegalArgumentException ("elementName + namespace reserved for project's primary configuration data"); } 76 return helper.removeConfigurationFragment(elementName, namespace, shared); 77 } 78 79 } 80 | Popular Tags |