KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > spi > project > support > rake > ExtensibleMetadataProviderImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ruby.spi.project.support.rake;
21
22 import java.io.IOException JavaDoc;
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 JavaDoc;
28
29 /**
30  * Manages extensible (freeform) metadata in an Ant-based project.
31  * @author Jesse Glick
32  */

33 final class ExtensibleMetadataProviderImpl implements AuxiliaryConfiguration, CacheDirectoryProvider {
34
35     /**
36      * Relative path from project directory to the required private cache directory.
37      */

38     private static final String JavaDoc CACHE_PATH = "nbproject/private/cache"; // NOI18N
39

40     private final RakeProjectHelper helper;
41     
42     ExtensibleMetadataProviderImpl(RakeProjectHelper helper) {
43         this.helper = helper;
44     }
45     
46     public FileObject getCacheDirectory() throws IOException JavaDoc {
47         return FileUtil.createFolder(helper.getProjectDirectory(), CACHE_PATH);
48     }
49     
50     public Element JavaDoc getConfigurationFragment(String JavaDoc elementName, String JavaDoc namespace, boolean shared) {
51         if (elementName == null || elementName.indexOf(':') != -1 || namespace == null) {
52             throw new IllegalArgumentException JavaDoc("Illegal elementName and/or namespace"); // NOI18N
53
}
54         return helper.getConfigurationFragment(elementName, namespace, shared);
55     }
56     
57     public void putConfigurationFragment(Element JavaDoc fragment, boolean shared) throws IllegalArgumentException JavaDoc {
58         if (fragment.getNamespaceURI() == null || fragment.getNamespaceURI().length() == 0) {
59             throw new IllegalArgumentException JavaDoc("Illegal elementName and/or namespace"); // NOI18N
60
}
61         if (fragment.getLocalName().equals(helper.getType().getPrimaryConfigurationDataElementName(shared)) &&
62                 fragment.getNamespaceURI().equals(helper.getType().getPrimaryConfigurationDataElementNamespace(shared))) {
63             throw new IllegalArgumentException JavaDoc("elementName + namespace reserved for project's primary configuration data"); // NOI18N
64
}
65         helper.putConfigurationFragment(fragment, shared);
66     }
67     
68     public boolean removeConfigurationFragment(String JavaDoc elementName, String JavaDoc namespace, boolean shared) throws IllegalArgumentException JavaDoc {
69         if (elementName == null || elementName.indexOf(':') != -1 || namespace == null) {
70             throw new IllegalArgumentException JavaDoc("Illegal elementName and/or namespace"); // NOI18N
71
}
72         if (elementName.equals(helper.getType().getPrimaryConfigurationDataElementName(shared)) &&
73                 namespace.equals(helper.getType().getPrimaryConfigurationDataElementNamespace(shared))) {
74             throw new IllegalArgumentException JavaDoc("elementName + namespace reserved for project's primary configuration data"); // NOI18N
75
}
76         return helper.removeConfigurationFragment(elementName, namespace, shared);
77     }
78     
79 }
80
Popular Tags