This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 120724
Collapse All | Expand All

(-)a/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java (+8 lines)
Lines 376-381 Link Here
376
                attr = attrs.get(attrName.substring(6));
376
                attr = attrs.get(attrName.substring(6));
377
                return attr == null ? null : attr.getType(this);
377
                return attr == null ? null : attr.getType(this);
378
            }
378
            }
379
            if (attr == null && attrName.startsWith("raw:")) { // NOI18N
380
                attr = attrs.get(attrName.substring(4));
381
                try {
382
                    return attr == null || attr.index != 10 ? null : attr.methodValue(attr.value, this, attrName).getMethod();
383
                } catch (Exception ex) {
384
                    return null;
385
                }
386
            }
379
            if (attr == null && attrName.equals("layers")) { // NOI18N
387
            if (attr == null && attrName.equals("layers")) { // NOI18N
380
                return getLayersAttr();
388
                return getLayersAttr();
381
            }
389
            }
(-)a/openide.filesystems/apichanges.xml (+20 lines)
Lines 46-51 Link Here
46
        <apidef name="filesystems">Filesystems API</apidef>
46
        <apidef name="filesystems">Filesystems API</apidef>
47
    </apidefs>
47
    </apidefs>
48
    <changes>
48
    <changes>
49
        <change id="attribute.methodvalue">
50
            <api name="filesystems"/>
51
            <summary>setAttribute("methodvalue:attrname", method)</summary>
52
            <version major="7" minor="39"/>
53
            <date day="4" month="5" year="2010"/>
54
            <author login="jtulachs"/>
55
            <compatibility addition="yes"/>
56
            <description>
57
                <p>
58
                    You can use prefix <code>"methodvalue:"</code> to set
59
                    an attribute of type <a href="@JDK@/java/lang/reflect/Method.html">Method</a>.
60
                    When the attribute is queried (without the prefix), the
61
                    method is called as is common in
62
                    <a href="@TOP@/org/openide/filesystems/XMLFileSystem.html">XMLFileSystem</a>
63
                    attributes.
64
                </p>
65
            </description>
66
            <class package="org.openide.filesystems" name="FileUtil"/>
67
            <issue number="131951"/>
68
        </change>
49
        <change id="addRecursiveListenerStop">
69
        <change id="addRecursiveListenerStop">
50
            <api name="filesystems"/>
70
            <api name="filesystems"/>
51
            <summary>Interruptable addRecursiveListener</summary>
71
            <summary>Interruptable addRecursiveListener</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 7.38
5
OpenIDE-Module-Specification-Version: 7.39
6
6
(-)a/openide.filesystems/src/org/openide/filesystems/AbstractFileObject.java (-1 / +1 lines)
Lines 324-330 Link Here
324
324
325
    /** performance hack */
325
    /** performance hack */
326
    final Object getAttribute(String attrName, String path) {
326
    final Object getAttribute(String attrName, String path) {
327
        return getAbstractFileSystem().attr.readAttribute(path, attrName);
327
        return XMLMapAttr.readAttribute(this, getAbstractFileSystem().attr, path, attrName);
328
    }
328
    }
329
329
330
    /* Set the file attribute with the specified name.
330
    /* Set the file attribute with the specified name.
(-)a/openide.filesystems/src/org/openide/filesystems/DefaultAttributes.java (+1 lines)
Lines 67-72 Link Here
67
import java.util.TreeSet;
67
import java.util.TreeSet;
68
import javax.xml.parsers.FactoryConfigurationError;
68
import javax.xml.parsers.FactoryConfigurationError;
69
import javax.xml.parsers.ParserConfigurationException;
69
import javax.xml.parsers.ParserConfigurationException;
70
import org.openide.filesystems.AbstractFileSystem.Attr;
70
import org.openide.util.Enumerations;
71
import org.openide.util.Enumerations;
71
import org.openide.util.NbBundle;
72
import org.openide.util.NbBundle;
72
import org.openide.util.Utilities;
73
import org.openide.util.Utilities;
(-)a/openide.filesystems/src/org/openide/filesystems/FileUtil.java (-2 / +9 lines)
Lines 49-54 Link Here
49
import java.io.OutputStream;
49
import java.io.OutputStream;
50
import java.io.SyncFailedException;
50
import java.io.SyncFailedException;
51
import java.lang.ref.WeakReference;
51
import java.lang.ref.WeakReference;
52
import java.lang.reflect.Method;
52
import java.net.MalformedURLException;
53
import java.net.MalformedURLException;
53
import java.net.URI;
54
import java.net.URI;
54
import java.net.URL;
55
import java.net.URL;
Lines 68-73 Link Here
68
import java.util.StringTokenizer;
69
import java.util.StringTokenizer;
69
import java.util.WeakHashMap;
70
import java.util.WeakHashMap;
70
import java.util.concurrent.Callable;
71
import java.util.concurrent.Callable;
72
import java.util.concurrent.atomic.AtomicBoolean;
71
import java.util.jar.JarEntry;
73
import java.util.jar.JarEntry;
72
import java.util.jar.JarInputStream;
74
import java.util.jar.JarInputStream;
73
import java.util.logging.Level;
75
import java.util.logging.Level;
Lines 1088-1101 Link Here
1088
                continue;
1090
                continue;
1089
            }
1091
            }
1090
1092
1091
            Object value = source.getAttribute(key);
1093
            AtomicBoolean isRawValue = new AtomicBoolean();
1094
            Object value = XMLMapAttr.getRawAttribute(source, key, isRawValue);
1092
1095
1093
            // #132801 and #16761 - don't set attributes where value is 
1096
            // #132801 and #16761 - don't set attributes where value is 
1094
            // instance of VoidValue because these attributes were previously written 
1097
            // instance of VoidValue because these attributes were previously written 
1095
            // by mistake in code. So it should happen only if you import some
1098
            // by mistake in code. So it should happen only if you import some
1096
            // settings from old version.
1099
            // settings from old version.
1097
            if (value != null && !(value instanceof MultiFileObject.VoidValue)) {
1100
            if (value != null && !(value instanceof MultiFileObject.VoidValue)) {
1098
                dest.setAttribute(key, value);
1101
                if (isRawValue.get() && value instanceof Method) {
1102
                    dest.setAttribute("methodvalue:" + key, value); // NOI18N
1103
                } else {
1104
                    dest.setAttribute(key, value);
1105
                }
1099
            }
1106
            }
1100
        }
1107
        }
1101
    }
1108
    }
(-)a/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java (-12 / +43 lines)
Lines 58-63 Link Here
58
import java.util.Set;
58
import java.util.Set;
59
import java.util.SortedSet;
59
import java.util.SortedSet;
60
import java.util.TreeSet;
60
import java.util.TreeSet;
61
import java.util.concurrent.atomic.AtomicBoolean;
61
import org.openide.util.SharedClassObject;
62
import org.openide.util.SharedClassObject;
62
import org.openide.util.Utilities;
63
import org.openide.util.Utilities;
63
import org.openide.util.io.NbMarshalledObject;
64
import org.openide.util.io.NbMarshalledObject;
Lines 146-151 Link Here
146
        return new Attr(index, value);
147
        return new Attr(index, value);
147
    }
148
    }
148
149
150
    static Object getRawAttribute(FileObject fo, String name, AtomicBoolean ab) {
151
        Object raw = fo.getAttribute("raw:" + name); // NOI18N
152
        if (raw != null) {
153
            if (ab != null) {
154
                ab.set(true);
155
            }
156
            return raw;
157
        }
158
        if (ab != null) {
159
            ab.set(false);
160
        }
161
        return fo.getAttribute(name);
162
    }
163
    private static ThreadLocal<FileObject> ATTR_FOR = new ThreadLocal<FileObject>();
164
    static Object readAttribute(FileObject forFO, AbstractFileSystem.Attr attr, String path, String attrName) {
165
        FileObject prev = ATTR_FOR.get();
166
        try {
167
            ATTR_FOR.set(forFO);
168
            return attr.readAttribute(path, attrName);
169
        } finally {
170
            ATTR_FOR.set(prev);
171
        }
172
    }
149
    /** According to name of attribute returns attribute as object
173
    /** According to name of attribute returns attribute as object
150
    * @param p1 is name of attribute
174
    * @param p1 is name of attribute
151
    * @return attribute, which is hold in XMLMapAttr.Attr or null if such attribute doesn`t exist or isn`t able to construct form String representation
175
    * @return attribute, which is hold in XMLMapAttr.Attr or null if such attribute doesn`t exist or isn`t able to construct form String representation
Lines 183-189 Link Here
183
    /** implementation of Map.get. But fires Exception to have chance in
207
    /** implementation of Map.get. But fires Exception to have chance in
184
     * DefaultAttributes to catch and annotate*/
208
     * DefaultAttributes to catch and annotate*/
185
    Object getAttribute(Object attrName) throws Exception {
209
    Object getAttribute(Object attrName) throws Exception {
186
        return getAttribute(attrName, null);
210
        return getAttribute(attrName, new Object[] { ATTR_FOR.get(), attrName });
187
    }
211
    }
188
212
189
    private Object getAttribute(Object attrName, Object[] params)
213
    private Object getAttribute(Object attrName, Object[] params)
Lines 201-206 Link Here
201
        if (attr == null && origAttrName.startsWith("class:")) { // NOI18N
225
        if (attr == null && origAttrName.startsWith("class:")) { // NOI18N
202
            attr = (Attr) map.get(origAttrName.substring(6));
226
            attr = (Attr) map.get(origAttrName.substring(6));
203
            retVal = attr != null ? attr.getType(params) : null;
227
            retVal = attr != null ? attr.getType(params) : null;
228
        } else if (attr == null && origAttrName.startsWith("raw:")) { // NOI18N
229
            attr = (Attr) map.get(origAttrName.substring(4));
230
            if (attr != null && attr.keyIndex == 9) {
231
                return attr.methodValue(attr.value, params).getMethod();
232
            }
204
        } else {
233
        } else {
205
            try {
234
            try {
206
                retVal = (attr == null) ? attr : attr.get(params);
235
                retVal = (attr == null) ? attr : attr.get(params);
Lines 241-248 Link Here
241
        Object[] keyValuePair = ModifiedAttribute.translateInto((String) p1, p2);
270
        Object[] keyValuePair = ModifiedAttribute.translateInto((String) p1, p2);
242
        String key = (String) keyValuePair[0];
271
        String key = (String) keyValuePair[0];
243
        Object value = keyValuePair[1];
272
        Object value = keyValuePair[1];
244
        Object toStore = ((value == null) || value instanceof Attr) ? value : new Attr(value);
273
        Object toStore;
245
274
        if (value == null) {
275
            toStore = null;
276
        } else if (value instanceof Attr) {
277
            toStore = value;
278
        } else if (value instanceof Method && key.startsWith("methodvalue:")) { // NOI18N
279
            Method m = (Method)value;
280
            key = key.substring("methodvalue:".length()); // NOI18N
281
            toStore = new Attr("methodvalue", m.getDeclaringClass().getName() + '.' + m.getName()); // NOI18N
282
        } else {
283
            toStore = new Attr(value);
284
        }
246
        if (decode) {
285
        if (decode) {
247
            key = Attr.decode(key).intern();
286
            key = Attr.decode(key).intern();
248
        }
287
        }
Lines 618-636 Link Here
618
        }
657
        }
619
658
620
        /**
659
        /**
621
        * Constructs new attribute as Object. Used for static creation from literal or serialValue.
622
        * @return new attribute as Object
623
        */
624
        private Object get() throws Exception {
625
            return getObject(null); //getObject is ready to aobtain null
626
        }
627
628
        /**
629
         * Constructs new attribute as Object. Used for dynamic creation: methodvalue .
660
         * Constructs new attribute as Object. Used for dynamic creation: methodvalue .
630
         * @param objs has sense only for methodvalue invocation; and only 2 parametres will be used
661
         * @param objs has sense only for methodvalue invocation; and only 2 parametres will be used
631
         *@return new attribute as Object
662
         *@return new attribute as Object
632
         */
663
         */
633
        private Object get(Object[] objs) throws Exception {
664
        final Object get(Object[] objs) throws Exception {
634
            return getObject(objs);
665
            return getObject(objs);
635
        }
666
        }
636
667
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java (+48 lines)
Lines 44-49 Link Here
44
44
45
import java.util.*;
45
import java.util.*;
46
import java.io.*;
46
import java.io.*;
47
import java.lang.reflect.Method;
48
import org.xml.sax.SAXException;
47
49
48
/**
50
/**
49
 *
51
 *
Lines 281-286 Link Here
281
        assertTrue (TEST_ERR,testedFS != null);                    
283
        assertTrue (TEST_ERR,testedFS != null);                    
282
    }*/
284
    }*/
283
285
286
    public void testFileUtilCopyAttributes() throws Exception {
287
        assertTrue(TEST_ERR, testedFS != null);
288
        if (testedFS.isReadOnly()) {
289
            return;
290
        }
291
292
        File f = new File(getWorkDir(), "sample.xml");
293
        FileOutputStream fos = new FileOutputStream(f);
294
        fos.write(("<?xml version='1.0' encoding='UTF-8'?>" +
295
                "<!DOCTYPE filesystem PUBLIC '-//NetBeans//DTD Filesystem 1.2//EN' 'http://www.netbeans.org/dtds/filesystem-1_2.dtd'>" +
296
                "<filesystem>" +
297
                "<folder name='Templates'>" +
298
                "<folder name='Other'>" +
299
                "<file name='special'>" +
300
                "  <attr name='ii' methodvalue='" + AttributesTestHidden.class.getName() + ".hello'/>" +
301
                "  <attr name='temp' boolvalue='true'/>" +
302
                "</file></folder></folder></filesystem>"
303
        ).getBytes());
304
        fos.close();
305
306
        XMLFileSystem xfs = new XMLFileSystem(f.toURI().toURL());
307
        FileObject template = xfs.findResource("Templates/Other/special");
308
        assertNotNull("template found", template);
309
        FileObject foTested = testedFS.getRoot().createData("copiedTemplate");
310
        FileUtil.copyAttributes(template, foTested);
311
        assertEquals("template copied too", Boolean.TRUE, foTested.getAttribute("temp"));
312
        assertEquals("instantiatingIterator called", "Hello ii@copiedTemplate", foTested.getAttribute("ii"));
313
    }
314
315
    public static String hello(FileObject obj, String attr) {
316
        return "Hello " + attr + "@" + obj.getNameExt();
317
    }
318
319
    public void testSetMethodGetResult() throws Exception {
320
        assertTrue(TEST_ERR, testedFS != null);
321
        if (testedFS.isReadOnly()) {
322
            return;
323
        }
324
325
        FileObject foTested = testedFS.getRoot().createData("copiedTemplate");
326
        Method m = AttributesTestHidden.class.getDeclaredMethod("hello", FileObject.class, String.class);
327
        foTested.setAttribute("methodvalue:ii", m);
328
329
        assertEquals("instantiatingIterator called", "Hello ii@copiedTemplate", foTested.getAttribute("ii"));
330
    }
331
284
}
332
}
285
333
286
334
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java (-1 / +31 lines)
Lines 47-52 Link Here
47
import java.io.FileWriter;
47
import java.io.FileWriter;
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.io.File;
49
import java.io.File;
50
import java.io.FileOutputStream;
50
import java.io.InputStream;
51
import java.io.InputStream;
51
import java.io.OutputStream;
52
import java.io.OutputStream;
52
import java.net.URL;
53
import java.net.URL;
Lines 781-787 Link Here
781
        
782
        
782
        assertAttr("Imutable value is still nochange", nochange, "value", "nochange");
783
        assertAttr("Imutable value is still nochange", nochange, "value", "nochange");
783
        assertEquals("No change in this attribute: "  + no.events, 0, no.events.size());
784
        assertEquals("No change in this attribute: "  + no.events, 0, no.events.size());
784
    }    
785
    }
786
787
    public void testFileUtilCopyAttributesOnOwnLayer() throws Exception {
788
        File f = new File(getWorkDir(), "sample.xml");
789
        FileOutputStream fos = new FileOutputStream(f);
790
        fos.write(("<?xml version='1.0' encoding='UTF-8'?>" +
791
                "<!DOCTYPE filesystem PUBLIC '-//NetBeans//DTD Filesystem 1.2//EN' 'http://www.netbeans.org/dtds/filesystem-1_2.dtd'>" +
792
                "<filesystem>" +
793
                "<folder name='Templates'>" +
794
                "<folder name='Other'>" +
795
                "<file name='special'>" +
796
                "  <attr name='ii' methodvalue='" + AttributesTestHidden.class.getName() + ".hello'/>" +
797
                "  <attr name='temp' boolvalue='true'/>" +
798
                "</file></folder></folder></filesystem>"
799
        ).getBytes());
800
        fos.close();
801
802
        File r = new File(getWorkDir(), "root");
803
        r.mkdirs();
804
        LocalFileSystem target = new LocalFileSystem();
805
        target.setRootDirectory(r);
806
807
        FileSystem source = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURI().toURL());
808
        FileObject template = source.findResource("Templates/Other/special");
809
        assertNotNull("template found", template);
810
        FileObject foTested = target.getRoot().createData("copiedTemplate");
811
        FileUtil.copyAttributes(template, foTested);
812
        assertEquals("template copied too", Boolean.TRUE, foTested.getAttribute("temp"));
813
        assertEquals("instantiatingIterator called", "Hello ii@copiedTemplate", foTested.getAttribute("ii"));
814
    }
785
815
786
    private static Image icon;
816
    private static Image icon;
787
817

Return to bug 120724