# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/work/trunk/nb_all # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: core/settings/api/doc/changes/apichanges.xml *** /home/work/trunk/nb_all/core/settings/api/doc/changes/apichanges.xml Base (1.6) --- /home/work/trunk/nb_all/core/settings/api/doc/changes/apichanges.xml Locally Modified (Based On 1.6) *************** *** 79,84 **** --- 79,99 ---- + Added new attribute for provider registration + + + + + New file attribute can be used if the registered convertor + is capable of handling subclasses of the registered class. The + attribute name is "settings.subclasses" and it can be set on + the same file object under "xml/memory" as "settings.providerPath". + The value of the attribute must be boolean. Defaults to false. + + + + + Added DOMConvertor supporting composed content Index: core/settings/src/org/netbeans/modules/settings/Env.java *** /home/work/trunk/nb_all/core/settings/src/org/netbeans/modules/settings/Env.java Base (1.4) --- /home/work/trunk/nb_all/core/settings/src/org/netbeans/modules/settings/Env.java Locally Modified (Based On 1.4) *************** *** 62,67 **** --- 62,72 ---- * */ public final static String EA_INSTANCE_CREATE = "settings.instanceCreate"; //NOI18N + /** file attribute determining whether the registration works also for subclasses of the registering + * class. Use of this attribute is optional. The default is false, the value must be boolean, example: + * <attr name="settings.subclasses" boolvalue="true"/> + */ + public static final String EA_SUBCLASSES = "settings.subclasses"; // NOI18N private final FileObject providerFO; *************** *** 101,123 **** /** look up appropriate provider according to clazz */ public static FileObject findProvider(Class clazz) throws IOException { String prefix = "xml/memory/"; //NOI18N - String name = clazz.getName().replace('.', '/'); FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); FileObject memContext = sfs.findResource(prefix); if (memContext == null) throw new java.io.FileNotFoundException("SFS/xml/memory/"); //NOI18N ! String convertorPath = new StringBuffer(200).append(prefix). append(name).toString(); // NOI18N FileObject fo = sfs.findResource(convertorPath); if (fo != null) { String providerPath = (String) fo.getAttribute(EA_PROVIDER_PATH); if (providerPath != null) { return sfs.findResource(providerPath); } } return null; } --- 106,139 ---- /** look up appropriate provider according to clazz */ public static FileObject findProvider(Class clazz) throws IOException { String prefix = "xml/memory/"; //NOI18N FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); FileObject memContext = sfs.findResource(prefix); if (memContext == null) throw new java.io.FileNotFoundException("SFS/xml/memory/"); //NOI18N ! Class c = clazz; ! while (c != null) { ! String name = c.getName().replace('.', '/'); String convertorPath = new StringBuffer(200).append(prefix). append(name).toString(); // NOI18N FileObject fo = sfs.findResource(convertorPath); if (fo != null) { String providerPath = (String) fo.getAttribute(EA_PROVIDER_PATH); if (providerPath != null) { + if (c.equals(clazz)) { return sfs.findResource(providerPath); + } else { + // check the special subclasses attribute + Object inheritAttribute = fo.getAttribute(EA_SUBCLASSES); + if (inheritAttribute instanceof Boolean) { + boolean subclasses = ((Boolean)inheritAttribute).booleanValue(); + if (subclasses) { + return sfs.findResource(providerPath); } } + } + } + } + c = c.getSuperclass(); + } return null; } Index: core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar2Setting.java *** /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar2Setting.java No Base Revision --- /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar2Setting.java Locally New *************** *** 1,0 **** --- 1,27 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 2002 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.netbeans.modules.settings.convertors; + + /** + * + * @author David Strupl + */ + public class Bar2Setting { + + /** + * Creates a new instance of Bar2Setting + */ + public Bar2Setting() { + } + + } Index: core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar3Setting.java *** /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar3Setting.java No Base Revision --- /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar3Setting.java Locally New *************** *** 1,0 **** --- 1,25 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 2002 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.netbeans.modules.settings.convertors; + + /** + * + * @author David Strupl + */ + public class Bar3Setting extends Bar1Setting { + + /** Creates a new instance of BarBarSetting */ + public Bar3Setting() { + } + + } Index: core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar1Setting.java *** /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar1Setting.java No Base Revision --- /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar1Setting.java Locally New *************** *** 1,0 **** --- 1,27 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 2002 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.netbeans.modules.settings.convertors; + + /** + * + * @author David Strupl + */ + public class Bar1Setting { + + /** + * Creates a new instance of Bar1Setting + */ + public Bar1Setting() { + } + + } Index: core/settings/manifest.mf *** /home/work/trunk/nb_all/core/settings/manifest.mf Base (1.18) --- /home/work/trunk/nb_all/core/settings/manifest.mf Locally Modified (Based On 1.18) *************** *** 1,6 **** Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.settings/1 ! OpenIDE-Module-Specification-Version: 1.11 OpenIDE-Module-Layer: org/netbeans/modules/settings/resources/mf-layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/settings/resources/Bundle.properties --- 1,6 ---- Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.settings/1 ! OpenIDE-Module-Specification-Version: 1.12 OpenIDE-Module-Layer: org/netbeans/modules/settings/resources/mf-layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/settings/resources/Bundle.properties Index: core/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml *** /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml Base (1.9) --- /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml Locally Modified (Based On 1.9) *************** *** 130,135 **** --- 130,144 ---- + + + + + + + Index: core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar4Setting.java *** /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar4Setting.java No Base Revision --- /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/convertors/Bar4Setting.java Locally New *************** *** 1,0 **** --- 1,25 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 2002 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.netbeans.modules.settings.convertors; + + /** + * + * @author David Strupl + */ + public class Bar4Setting extends Bar2Setting { + + /** Creates a new instance of BarBarSetting */ + public Bar4Setting() { + } + + } Index: core/settings/test/unit/src/org/netbeans/modules/settings/EnvTest.java *** /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/EnvTest.java Base (1.4) --- /home/work/trunk/nb_all/core/settings/test/unit/src/org/netbeans/modules/settings/EnvTest.java Locally Modified (Based On 1.4) *************** *** 51,57 **** --- 51,70 ---- FileObject fo = Env.findProvider(clazz); assertNotNull("xml/memory registration not found: " + clazz.getName(), fo); } + + public void testFindProviderFromSuperClass() throws Exception { + Class clazz = org.netbeans.modules.settings.convertors.Bar3Setting.class; + FileObject fo = Env.findProvider(clazz); + assertNotNull("xml/memory registration not found: " + clazz.getName(), fo); } + + public void testFindProviderFromSuperClass2() throws Exception { + Class clazz = org.netbeans.modules.settings.convertors.Bar4Setting.class; + FileObject fo = Env.findProvider(clazz); + assertNull("xml/memory registration found: " + clazz.getName(), fo); + } + } Index: openide/loaders/src/org/openide/loaders/InstanceDataObject.java *** /home/work/trunk/nb_all/openide/loaders/src/org/openide/loaders/InstanceDataObject.java Base (1.29) --- /home/work/trunk/nb_all/openide/loaders/src/org/openide/loaders/InstanceDataObject.java Locally Modified (Based On 1.29) *************** *** 1476,1481 **** --- 1476,1482 ---- /** path where to find convertor/provider definition */ private final static String EA_PROVIDER_PATH = "settings.providerPath"; // NOI18N + private static final String EA_SUBCLASSES = "settings.subclasses"; // NOI18N /** look up appropriate convertor according to obj */ private static FileObject resolveConvertor(Object obj) throws IOException { *************** *** 1485,1511 **** FileObject memContext = sfs.findResource(prefix); if (memContext == null) throw new FileNotFoundException("SFS:xml/memory while converting a " + obj.getClass().getName()); //NOI18N ! String[] classes = new String[] {obj.getClass().getName(), Object.class.getName()}; ! for (int i = 0; i < classes.length; i++) { String convertorPath = new StringBuffer(200).append(prefix).append('/'). ! append(classes[i].replace('.', '/')).toString(); // NOI18N FileObject fo = sfs.findResource(convertorPath); if (fo != null) { String providerPath = (String) fo.getAttribute(EA_PROVIDER_PATH); ! if (providerPath == null) break; FileObject ret = sfs.findResource(providerPath); if (ret == null) { ! throw new FileNotFoundException("Invalid settings.providerPath under SFS/xml/memory/ for " + obj.getClass()); // NOI18N } else { return ret; } } } - throw new FileNotFoundException("None convertor was found under SFS/xml/memory/ for " + obj.getClass()); //NOI18N } private void attachToConvertor(Object obj) throws IOException { --- 1486,1531 ---- FileObject memContext = sfs.findResource(prefix); if (memContext == null) throw new FileNotFoundException("SFS:xml/memory while converting a " + obj.getClass().getName()); //NOI18N ! Class clazz = obj.getClass(); ! Class c = clazz; ! while (c != null) { ! String className = c.getName(); String convertorPath = new StringBuffer(200).append(prefix).append('/'). ! append(className.replace('.', '/')).toString(); // NOI18N FileObject fo = sfs.findResource(convertorPath); if (fo != null) { String providerPath = (String) fo.getAttribute(EA_PROVIDER_PATH); ! if (providerPath == null) { ! c = c.getSuperclass(); ! continue; ! } ! if (c.equals(clazz) || Object.class.equals(c)) { FileObject ret = sfs.findResource(providerPath); if (ret == null) { ! throw new FileNotFoundException("Invalid settings.providerPath under SFS/xml/memory/ for " + clazz); // NOI18N } else { return ret; } + } else { + // check the special subclasses attribute + Object inheritAttribute = fo.getAttribute(EA_SUBCLASSES); + if (inheritAttribute instanceof Boolean) { + boolean subclasses = ((Boolean)inheritAttribute).booleanValue(); + if (subclasses) { + FileObject ret = sfs.findResource(providerPath); + if (ret == null) { + throw new FileNotFoundException("Invalid settings.providerPath under SFS/xml/memory/ for " + clazz); // NOI18N + } else { + return ret; } } } + } + } + c = c.getSuperclass(); + } + throw new FileNotFoundException("None convertor was found under SFS/xml/memory/ for " + clazz); //NOI18N + } private void attachToConvertor(Object obj) throws IOException { attachToConvertor (obj, false); Index: core/settings/api/doc/org/netbeans/spi/settings/doc-files/api.html *** /home/work/trunk/nb_all/core/settings/api/doc/org/netbeans/spi/settings/doc-files/api.html Base (1.11) --- /home/work/trunk/nb_all/core/settings/api/doc/org/netbeans/spi/settings/doc-files/api.html Locally Modified (Based On 1.11) *************** *** 160,165 **** --- 160,194 ---- look up the provider registration for the exact class of the object passed into the method. +

If you have a special setting convertor capable of converting of objects + of its class and of all of its superclasses you might want to specify also + attribute settings.subclasses with boolean value set to true like this: + +

+ <folder name="xml">
+   <folder name="memory">
+     <folder name="org">
+       <folder name="netbeans">
+         <folder name="modules">
+           <folder name="foo">
+             <!--allows to create .settings file from memory via InstanceDataObject.create-->
+             <file name="FooSetting">
+               <attr name="settings.providerPath"
+                  stringvalue="xml/lookups/Vendor_org_netbeans_modules_foo/DTD_FooSetting_1_0.instance"/>
+               <attr name="settings.subclasses"
+                  boolvalue="true"/>
+             </file>
+           </folder>
+         </folder>
+       </folder>
+     </folder>
+   </folder>
+ </folder>
+ 
+ +

Please use the attribute settings.subclasses only in case + you are sure your convertor can handle all subclasses! +

Composed Content

In order to allow to reuse existing convertors and to put their output together into one XML document