KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > bridge > LangModel


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.java.bridge;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23
24 import org.openide.nodes.Node;
25
26 import org.openide.src.Element;
27 import org.openide.src.ClassElement;
28 import org.openide.src.SourceElement;
29 import org.openide.src.ElementProperties;
30 import org.openide.src.Identifier;
31 import org.openide.src.SourceException;
32 import org.openide.src.Type;
33
34 import org.netbeans.modules.java.ElementFactory;
35
36 /**
37  *
38  * @author sdedic
39  * @version
40  */

41 public interface LangModel extends ElementCreator {
42     /** Acquires a read lock on the model. There can be no changes until the
43      * lock is released. The same thread that has acquired the write lock may choose
44      * to acquire a read lock as well. The opposite is true as well, as long there's only
45      * a single reader - the current thread.
46      */

47     public void readLock();
48     
49     /** Releases the read lock.
50      */

51     public void releaseReadLock();
52     
53     /**
54      * Returns true, if the model is write-locked currently. However, this method does not
55      * guarantee, that, should it return false, writeLock called subsequently will not
56      * block.
57      */

58     public boolean isWriteLocked();
59
60     /**
61      * Adds a listener that will be notified before the commit phase is over - that is
62      * before the write lock is released. Please, use this type of listener with extreme
63      * caution and do not make global changes from it and avoid event firing if possible.
64      */

65     public void addPreCommitListener(CommitListener l);
66
67     /**
68      * Removes pre-commit listener from the model.
69      */

70     public void removePreCommitListener(CommitListener l);
71     
72     /**
73      * Attaches a CommitListener to the model. Post-commit listener gets a list of
74      * changes after the lock is released. The listener can make further operations on the model,
75      * risking that further events may be delayed.
76      */

77     public void addPostCommitListener(CommitListener l);
78
79     /**
80      * Removes the post-commit listener from the model.
81      */

82     public void removePostCommitListener(CommitListener l);
83     
84     /**
85      * Executes an atomic action.
86      */

87     public void runAtomic(Runnable JavaDoc r) throws SourceException;
88
89     /**
90      * @deprecated
91      */

92     public void commitChanges();
93     
94     /**
95      * Acquires a write lock on the model and returns an opaque handle. There may be
96      * at most *one* write lock active at any given time. Other threads asking for
97      * a lock will be blocked.
98      * @return handle for the write lock.
99      */

100     public Object JavaDoc writeLock();
101
102     /**
103      * Tries to acquire a write lock; if someone is holding the lock right now,
104      * the method returns immediately null. You can use this method as a nonblocking
105      * attempt to acquire the write lock.
106      *
107      * @return handle for the write lock, or null if the model is currently locked.
108      */

109     public Object JavaDoc tryWriteLock();
110     
111     /** Releases the write lock from the model. Requires the handle returned by
112      * the prior call to writeLock(). If the handle is invalid, the method does not
113      * unlock and throws IllegalArgumentException.
114      * @param handle for unlocking.
115      * @throws SourceException, if something goes wrong during the commit phase.
116      * @throws IllegalArgumentException if the lock handle is invalid.
117      */

118     public void releaseWriteLock(Object JavaDoc handle) throws SourceException;
119
120     /** Environmental interface that helps interaction between the model and its
121      * environment. Virtually any services required by the model from outside should
122      * be performed, or obtained from, this interface.
123      */

124     public static interface Env {
125         /**
126          * Callback function that will create a binding for an Element. The method can
127          * return null, in which case it can be invoked later for that particular Impl,
128          * or the Element will be assigned NullBinding, eventually.
129          * @param impl implementation instance of the model's Element.
130          * @return binding between the Element and its storage.
131          */

132         public BindingFactory getBindingFactory();
133         
134         /** Factory, that "wraps" element with the abstract layer fom the openide, optionally
135          * providing some levels of indirection to an element.
136          */

137         public WrapperFactory getWrapperFactory();
138         
139         /** Asks the environment to feed back information local to the given scope.
140          * Some Elements throughout the model support "lazy" evaluation. They will
141          * ask the environment for the informations to be filled on the first
142          * operation on the local data. The element can, if it chooses, keep the
143          * local data using WeakReferences, so it can ask for completion multiple
144          * times.
145          */

146         public void complete(Element scope, int informationKind);
147         
148         /** The environment is called to resolve type name according to the context it
149          * is used in.
150          */

151         public Type resolveType(Element context, Type original);
152         
153         /**
154          * This is called to resolve/transform a name of a type for this context.
155          */

156         public Identifier resolveTypeIdent(Element context, Identifier original);
157         
158         /**
159          * Since the model does not care for cookies, it needs to be supported by the
160          * environment if somebody asks for a cookie on the Element.
161          */

162         public Node.Cookie findCookie(Element el, Class JavaDoc requestedClass);
163         
164         /**
165          * Environment should remap the `markCurrent' call to some insertion
166          * strategy.
167         public void markCurrentElement(Element marker, boolean beforeAfter);
168          */

169     }
170     
171     public interface Updater extends LangModel, ElementProperties {
172         public void updateMembers(Element target, String JavaDoc propertyName,
173             Element[] els, int[] orderIndices, int[] optionalMap);
174
175         /**
176           * Updates members in a specified container of a target element. In general,
177           * container types correspond with indexed property names.
178           */

179         public void updateMemberOrder(Element target, String JavaDoc containerType,
180             Element[] orderedMembers);
181         
182         public Binding getElementBinding(Element target);
183         
184         /**
185          * Special method that explicitly makes an element active. Inactive elements do not
186          * fire property changes etc. Elements become automatically active, when inserted
187          * into active container or when the container is activated.
188          */

189         public void activate(Element target);
190         
191         /**
192          * Makes the whole model contents invalid.
193          */

194         public void invalidateModel(SourceElement el);
195
196         /**
197          * Runs the supplied runnable object in a special execution mode that can disable
198          * property veto checks
199          */

200         public boolean runUpdate(Runnable JavaDoc r, boolean disableVetos) throws SourceException;
201
202         /**
203          * Fires some property change event on behalf of some element managed by
204          * this model. Note that this <B>is a hack</B> method provided mostly
205          * for PROP_COOKIES property change as most of the properties are
206          * provided by the model's environment.
207          */

208         public void firePropertyChange(Element el, PropertyChangeEvent JavaDoc evt);
209         
210         /**
211          * Updates a body property on the specified element, firing a property change
212          * event when necessary.
213          * @param contentHash must be a CRC-32 hash of the body content.
214          */

215         public void updateBody(Element el, String JavaDoc bodyContent) throws UnsupportedOperationException JavaDoc;
216     }
217 }
218
Popular Tags