KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > turbo > TurboProvider


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 package org.netbeans.modules.turbo;
20
21 import java.util.List JavaDoc;
22
23 /**
24  * SPI, extension point allowing third parties to redefine
25  * attribute reading and writing. Must be registered
26  * in default {@link org.openide.util.Lookup}.
27  * <p>
28  * It must generally deternime that they
29  * support given entity key and attribute pair
30  * and if so then perform action.
31  * <p>
32  * Two providers can theoreticaly clash and support
33  * the same attribute for the same entity key. The
34  * key point is that attribute meaning must be precisely
35  * defined guaranteeing that two independent providers
36  * respond with exactly same value hence making irrelevant
37  * which one is actually choosen.
38  * <p>
39  * Providers should not cache results.
40  *
41  * @author Petr Kuzel
42  */

43 public interface TurboProvider {
44
45     /**
46      * Reports if an attribute is supported by the implementation.
47      */

48     boolean recognizesAttribute(String JavaDoc name);
49
50     /**
51      * Reports if the entity identified by key is supported by the implementation.
52      */

53     boolean recognizesEntity(Object JavaDoc key);
54
55     /**
56      * Reads given attribute for given fileobject. No method
57      * parameter may be referenced after method execution finishes.
58      *
59      * @param key identifies source entity, never <code>null</code>
60      * @param name identifies requested attribute, never <code>null</code>
61      * @param memoryCache can store speculative results
62      * @return attribute value or <code>null</code> if it does not exist.
63      */

64     Object JavaDoc readEntry(Object JavaDoc key, String JavaDoc name, MemoryCache memoryCache);
65
66     /**
67      * Writes given attribute. No method
68      * parameter may be referenced after method execution finishes.
69      *
70      * @param key identifies target entity, never <code>null</code>
71      * @param name identifies attribute, never <code>null</code>
72      * @param value actual attribute value that should be stored or <code>null</code> for removing it
73      * @return <code>false</code> on write failure if provider denies the value. On I/O error it
74      * returns <code>true</code>.
75      */

76     boolean writeEntry(Object JavaDoc key, String JavaDoc name, Object JavaDoc value);
77
78     /**
79      * Provides direct access to memory layer (without
80      * delegating to providers layer, here source).
81      */

82     public static final class MemoryCache {
83
84         private final boolean enabled;
85
86         private final List JavaDoc speculative;
87
88         private final Memory memory;
89
90         private MemoryCache(boolean enabled) {
91             this.enabled = enabled;
92             speculative = null;
93             memory = null;
94         }
95
96         private MemoryCache(Memory memory, List JavaDoc speculative) {
97             enabled = true;
98             this.memory = memory;
99             this.speculative = speculative;
100         }
101
102         /**
103          * Creates instance intercepting speculative results.
104          * @param memory implementation
105          * @param speculative add()s speculative results into it
106          */

107         static MemoryCache createDefault(Memory memory, List JavaDoc speculative) {
108             return new MemoryCache(memory, speculative);
109         }
110
111         /** T9Y entry point. */
112         static MemoryCache getTest() {
113             return new MemoryCache(false);
114         }
115
116         /**
117          * Writes speculative entry into memory layer.
118          */

119         public void cacheEntry(Object JavaDoc key, String JavaDoc name, Object JavaDoc value) {
120             if (enabled == false) return;
121             memory.put(key, name, value);
122             if (speculative != null) speculative.add(new Object JavaDoc[] {key, name, value});
123         }
124
125         /** Return speculative results <code>[]{FileObject,String,Object}</code> silently inserted into memory */
126         List JavaDoc getSpeculative() {
127             return speculative;
128         }
129     }
130 }
131
Popular Tags