KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
24 import org.openide.src.*;
25 import org.netbeans.modules.java.ElementFactory.Item;
26 import org.netbeans.modules.java.JavaDataObject;
27 import org.netbeans.jmi.javamodel.JavaClass;
28 import org.netbeans.jmi.javamodel.Constructor;
29 import org.netbeans.jmi.javamodel.Method;
30 import org.netbeans.jmi.javamodel.Initializer;
31 import org.netbeans.jmi.javamodel.Field;
32 import org.netbeans.jmi.javamodel.Import;
33 import org.netbeans.api.mdr.MDRepository;
34 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
35 import org.netbeans.modules.javacore.JMManager;
36 import org.openide.ErrorManager;
37
38 /**
39  * This is the root point of the source text model. This object creates individual
40  * model's elements and performs model-related tasks. All elements in the model have
41  * (indirect) references to this object so they can contact it.
42  * @author svata
43  * @version
44  */

45 public class DefaultLangModel implements LangModel, LangModel.Updater, Runnable JavaDoc {
46     private static boolean initialized;
47     
48     private static Class JavaDoc CLASS_MEMBER_IMPL;
49     
50     private static Class JavaDoc CLASS_INITIALIZER_IMPL;
51     
52     static final Positioner DEFAULT_POSITIONER = new DefaultInsertStrategy();
53     
54     /** Mutex object for the whole model. The lock is obtained during model updates so
55      * change detection and property changes are really atomic.
56      */

57     private Object JavaDoc locked;
58     
59     private Env env;
60     
61     private Object JavaDoc writerNotify;
62     
63     private Thread JavaDoc writingThread;
64     
65     private int readerCount;
66     
67     private Thread JavaDoc reader;
68     
69     // derived attributes:
70
private BindingFactory bindingFactory;
71     
72     private WrapperFactory wrapperFactory;
73     
74     /** Event queue map for individual elements in the model. The map is keyed by
75      * element instances, values maps <property_name> -> <property change event>
76      */

77     private EventQueue eventQueue;
78     
79     /** Number of nested atomic locks.
80      */

81     private int writeLocks;
82     
83     private int masterLocks;
84     
85     /**
86      * True, if all changes made in the transaction should be commited upon lock
87      * release.
88      */

89     private boolean transactionCommited;
90     
91     /**
92      * True, if the transaction is constrained - changes are consulted with
93      * VetoableChangeListeners and checked for consistency.
94      */

95     private boolean transactionConstrained;
96     
97     /**
98      * True, if the model is currently dispatching events.
99      */

100     private boolean eventDispatch;
101
102     /**
103      * List of currently registered pre-commit listners.
104      */

105     Collection preCommitListeners;
106     
107     /**
108      * List of currently registered post-commit listeners.
109      */

110     Collection postCommitListeners;
111     
112     /**
113      * Holds top-level EventQueues in the order of dispatching. New queues are appened
114      * during unlock to preserve the order of event generation.
115      */

116     LinkedList outputQueue;
117     
118     boolean firingEvents;
119     
120     private JavaDataObject javaDataObject;
121     
122     public DefaultLangModel(JavaDataObject jdo) {
123         this (new LangEnvImpl (jdo), jdo);
124     }
125      
126     public DefaultLangModel(Env env, JavaDataObject jdo) {
127         this.env = env;
128         this.javaDataObject = jdo;
129         writerNotify = new Object JavaDoc();
130         this.eventQueue = new EventQueue(null);
131     }
132     
133     public JavaDataObject getJavaDataObject () {
134         return javaDataObject;
135     }
136     
137     private static void initializeClasses() {
138         if (initialized)
139             return;
140         try {
141             CLASS_MEMBER_IMPL = Class.forName("org.netbeans.modules.java.bridge.MemberElementImpl"); // NOI18N
142
CLASS_INITIALIZER_IMPL = Class.forName("org.netbeans.modules.java.bridge.InitializerElementImpl"); // NOI18N
143
} catch (ClassNotFoundException JavaDoc ex) {
144             // warn -- the class was not found.
145
}
146         initialized = true;
147     }
148     
149     /** Clone the model object; the method does not clone the whole model, it rather clones
150      * the management object so that objects created by the clone are compatible with
151      * the original one. Usable mainly for paralel analysis of two sources and matching
152      * them up.
153      */

154     public Object JavaDoc clone() {
155         return null;
156     }
157     
158     /*----------------------------------------------------------------
159      * Factory methods for creating implementations of
160      * model pieces
161      *----------------------------------------------------------------*/

162     
163     public ClassElementImpl createTopClass(SourceElement src, JavaClass javaClass) {
164     ClassElementImpl c = new ClassElementImpl(this, javaClass);
165         getWrapper().wrapClass(c, src);
166         c.setParent(src);
167         return c;
168     }
169     
170     public ClassElementImpl createInnerClass(ClassElement parent, JavaClass javaClass) {
171     ClassElementImpl c = new ClassElementImpl(this, javaClass);
172         getWrapper().wrapClass(c, parent);
173         c.setParent(parent);
174         return c;
175     }
176     
177     public FieldElementImpl createField(ClassElement parent, Field field) {
178         FieldElementImpl impl = new FieldElementImpl(this, field);
179         getWrapper().wrapField(impl, parent);
180         impl.setParent(parent);
181         return impl;
182     }
183     
184     public ConstructorElementImpl createConstructor(ClassElement parent, Constructor constructor) {
185         ConstructorElementImpl impl = new ConstructorElementImpl(this, constructor);
186         getWrapper().wrapConstructor(impl, parent);
187         impl.setParent(parent);
188         return impl;
189     }
190     
191     public MethodElementImpl createMethod(ClassElement parent, Method method) {
192         MethodElementImpl impl = new MethodElementImpl(this, method);
193         getWrapper().wrapMethod(impl, parent);
194         impl.setParent(parent);
195         return impl;
196     }
197     
198     public ImportImpl createImport(SourceElement parent, Import imp) {
199         ImportImpl impl = new ImportImpl(this, imp);
200         getWrapper().wrapImport(impl, parent);
201         impl.setParent(parent);
202         return impl;
203     }
204     
205     public InitializerElementImpl createInitializer(ClassElement parent, Initializer initializer) {
206         InitializerElementImpl impl = new InitializerElementImpl(this, initializer);
207         getWrapper().wrapInitializer(impl, parent);
208         impl.setParent(parent);
209         return impl;
210     }
211     
212     // ..........................................................................
213

214     public SourceElementImpl createSource() {
215         MDRepository repo = JavaMetamodel.getDefaultRepository();
216         repo.beginTrans(false);
217         try {
218             return new SourceElementImpl(this, null, null);
219         } finally {
220             repo.endTrans();
221         }
222     }
223     
224     public ClassElementImpl createTopClass(SourceElement src) {
225     ClassElementImpl c = new ClassElementImpl(this, null);
226         getWrapper().wrapClass(c, src);
227         c.setParent(src);
228         return c;
229     }
230     
231     public ClassElementImpl createInnerClass(ClassElement parent) {
232     ClassElementImpl c = new ClassElementImpl(this, null);
233         getWrapper().wrapClass(c, parent);
234         c.setParent(parent);
235         return c;
236     }
237     
238     public FieldElementImpl createField(ClassElement parent) {
239         FieldElementImpl impl = new FieldElementImpl(this, null);
240         getWrapper().wrapField(impl, parent);
241         impl.setParent(parent);
242         return impl;
243     }
244     
245     public ConstructorElementImpl createConstructor(ClassElement parent) {
246         ConstructorElementImpl impl = new ConstructorElementImpl(this, null);
247         getWrapper().wrapConstructor(impl, parent);
248         impl.setParent(parent);
249         return impl;
250     }
251     
252     public MethodElementImpl createMethod(ClassElement parent) {
253         MethodElementImpl impl = new MethodElementImpl(this, null);
254         getWrapper().wrapMethod(impl, parent);
255         impl.setParent(parent);
256         return impl;
257     }
258     
259     public ImportImpl createImport(SourceElement parent) {
260         ImportImpl impl = new ImportImpl(this, null);
261         getWrapper().wrapImport(impl, parent);
262         impl.setParent(parent);
263         return impl;
264     }
265     
266     public InitializerElementImpl createInitializer(ClassElement parent) {
267         InitializerElementImpl impl = new InitializerElementImpl(this, null);
268         getWrapper().wrapInitializer(impl, parent);
269         impl.setParent(parent);
270         return impl;
271     }
272     
273     // ..........................................................................
274

275     final Identifier resolveIdent(Element context, Identifier original) {
276         return env.resolveTypeIdent(context, original);
277     }
278     
279     final Type resolveType(Element context, Type t) {
280         return env.resolveType(context, t);
281     }
282     
283     public void addPreCommitListener(CommitListener l) {
284         synchronized (this) {
285             if (preCommitListeners == null)
286                 preCommitListeners = new LinkedList();
287         }
288         synchronized (preCommitListeners) {
289             preCommitListeners.add(l);
290         }
291     }
292     
293     public void addPostCommitListener(CommitListener l) {
294         synchronized (this) {
295             if (postCommitListeners == null)
296                 postCommitListeners = new LinkedList();
297         }
298         synchronized (postCommitListeners) {
299             postCommitListeners.add(l);
300         }
301     }
302     
303     public void removePreCommitListener(CommitListener l) {
304         if (preCommitListeners == null)
305             return;
306         synchronized (preCommitListeners) {
307             preCommitListeners.remove(l);
308         }
309     }
310     
311     public void removePostCommitListener(CommitListener l) {
312         if (postCommitListeners == null)
313             return;
314         synchronized (postCommitListeners) {
315             postCommitListeners.remove(l);
316         }
317     }
318     
319     final void notifyEventsDispatched(boolean dispatchOn) {
320         this.eventDispatch = dispatchOn;
321     }
322     
323     public final Object JavaDoc writeLock() {
324         return null;
325         /*
326         Object l = doWriteLock();
327         if (masterLocks == -1)
328             createEventQueue();
329         return l;
330          */

331     }
332     
333     private void createEventQueue() {
334         eventQueue = new EventQueue(eventQueue);
335     }
336     
337     /**
338      * The method obtains a write lock, but integrates all messages to the outside
339      * queue instead of creating a local one.
340      */

341     final Object JavaDoc masterWriteLock() {
342         /*
343         Object l = doWriteLock();
344         if (masterLocks > 0) {
345             try {
346                 releaseWriteLock(l);
347             } catch (SourceException ex) {
348                 // should NOT happen.
349             }
350             throw new IllegalStateException("Nested master locks!!"); // NOI18N
351         }
352         masterLocks = writeLocks;
353         eventQueue = new EventQueue(eventQueue);
354         return l;
355          */

356         return null;
357     }
358     
359     public Object JavaDoc tryWriteLock() {
360         return tryWriteLock(false);
361     }
362     
363     private Object JavaDoc tryWriteLock(boolean master) {
364         /*
365         synchronized (writerNotify) {
366             if (locked == null ||
367                 writingThread == Thread.currentThread())
368                 return master ?
369                     masterWriteLock() :
370                     writeLock();
371         }
372         return null;
373          */

374         return null;
375     }
376     
377     public final Object JavaDoc doWriteLock() {
378         /*
379         synchronized (writerNotify) {
380             if (writingThread == Thread.currentThread()) {
381                 if (eventDispatch) {
382                     throw new IllegalStateException(
383                         "Modification from inside the event handler are banned"); // NOI18N
384                 }
385                 writeLocks++;
386                 return locked;
387             }
388             if (locked != null) {
389                 try {
390                     writerNotify.wait();
391                 } catch (InterruptedException ex) {
392                     throw new IllegalStateException("Interrupted"); // NOI18N
393                 }
394             }
395             // new lock - constrain the transaction.
396             transactionConstrained = true;
397             writeLocks++;
398             locked = writerNotify;
399             this.writingThread = Thread.currentThread();
400             return locked;
401         }
402          */

403         return null;
404     }
405     
406     /**
407      * Releases the write lock held on the model. If there are any outstanding
408      * events, the CommitListener events are fired prior to releasing the lock.
409      * If the operation is not aborted, write lock is released and queued
410      * PropertyChangeEvents are fired out.
411      */

412     public final void releaseWriteLock(Object JavaDoc handle) {
413         releaseWriteLock(handle, false);
414     }
415     
416     final void releaseWriteLock(Object JavaDoc handle, boolean forkThread) {
417         /*
418         if (handle == null)
419             throw new IllegalArgumentException("Invalid lock: " + handle); // NOI18N
420         if (locked == null)
421             throw new IllegalStateException("Model not locked."); // NOI18N
422         synchronized (writerNotify) {
423             if (handle != locked)
424                 throw new IllegalArgumentException("Invalid unlock attempt."); // NOI18N
425         }
426         
427         EventQueue result = null;
428         
429         if (masterLocks == -1)
430             result = mergeEventQueues();
431         else if (masterLocks >= writeLocks) {
432             result = mergeEventQueues();
433             masterLocks = -1;
434         }
435         if (--writeLocks > 0) {
436             return;
437         }
438         eventQueue = null;
439
440         // fix change events so they contain snapshots of
441         // new state in addition to the live reference.
442         
443         // PENDING
444         if (result != null) {
445             result.fixupChanges();
446             // can throw SourceException
447             firePreCommitEvents(result);
448             enqueue(result);
449         }
450         
451         synchronized (writerNotify) {
452             this.writingThread = null;
453             locked = null;
454             writerNotify.notifyAll();
455         }
456         if (forkThread) {
457             org.openide.util.RequestProcessor.getDefault().post(this);
458         } else {
459             processOutputQueue();
460         }
461          */

462     }
463     
464     /**
465      * This method operates under a write lock -- nobody else can modify or create the queue,
466      * but somebody may be reading it.
467      */

468     private void enqueue(EventQueue q) {
469         /*
470         if (outputQueue == null)
471             outputQueue = new LinkedList();
472         synchronized (outputQueue) {
473             outputQueue.addLast(q);
474         }
475          */

476     }
477     
478     public void run() {
479         // processOutputQueue();
480
}
481     
482     private void processOutputQueue() {
483         /*
484         if (this.outputQueue == null)
485             return;
486         
487         EventQueue bit;
488         synchronized (outputQueue) {
489             if (firingEvents)
490                 return;
491             firingEvents = true;
492         }
493         try {
494             while (true) {
495                 synchronized (outputQueue) {
496                     if (outputQueue.isEmpty()) {
497                         return;
498                     }
499                     bit = (EventQueue)outputQueue.removeFirst();
500                 }
501                 bit.fireEvents();
502                 firePostCommitEvents(bit);
503             }
504         } finally {
505             synchronized (outputQueue) {
506                 firingEvents = false;
507             }
508         }
509          */

510     }
511     
512     private void firePreCommitEvents(EventQueue q) {
513         fireCommitEvents(preCommitListeners, q);
514     }
515     
516     private void firePostCommitEvents(EventQueue what) {
517         fireCommitEvents(postCommitListeners, what);
518     }
519
520     private void fireCommitEvents(Collection origListeners, EventQueue data) {
521         /*
522         if (origListeners == null || data == null || data.isEmpty())
523             return;
524         
525         Collection listeners;
526         
527         synchronized (origListeners) {
528             listeners = new Vector(origListeners);
529         }
530         
531         Set removed = data.getRemovedElements();
532         Set created = data.getCreatedElements();
533         Map changed = data.getChangedElements();
534
535         // if the lock will be released after this operation, fire summary events
536         // to watchers as well.
537         for (Iterator it = listeners.iterator(); it.hasNext(); ) {
538             CommitListener l = (CommitListener)it.next();
539             l.changesCommited(created, removed, changed);
540         }
541          */

542     }
543     
544     private EventQueue mergeEventQueues() {
545         /*
546         EventQueue parent = eventQueue.getParent();
547         if (parent != null) {
548             if (transactionCommited) {
549                 eventQueue.mergeToParent();
550             } else {
551                 // PENDING: cancel ordinary events in the queue,
552                 // backfire all vetoable changes.
553             }
554             eventQueue = parent;
555         }
556         transactionCommited = false;
557         return eventQueue;
558          */

559         return null;
560     }
561     
562     public void commitChanges() {
563         /*
564         if (locked == null || this.writingThread != Thread.currentThread()) {
565             throw new IllegalStateException("Sanity check: commit outside lock"); // NOI18N
566         }
567         if (masterLocks > 0 && masterLocks < writeLocks)
568             return;
569         this.transactionCommited = true;
570          */

571     }
572     
573     public void runAtomic(Runnable JavaDoc r) throws SourceException {
574         Object JavaDoc token = writeLock();
575         try {
576             r.run();
577             commitChanges();
578         } finally {
579             releaseWriteLock(token);
580         }
581     }
582     
583     protected boolean isConstrained() {
584         return this.transactionConstrained;
585     }
586     
587     protected final org.openide.nodes.Node.Cookie findElementCookie(Element el, Class JavaDoc clazz) {
588         return env.findCookie(el, clazz);
589     }
590
591     /**
592      * Enters a special locked mode with disabled constraint and veto
593      * checking.
594      */

595     public boolean runUpdate(Runnable JavaDoc r, boolean disableConstraints)
596     throws SourceException {
597         Object JavaDoc token = tryWriteLock(true);
598         if (token == null)
599             return false;
600         boolean saveConstraint = this.transactionConstrained;
601         
602         try {
603             this.transactionConstrained = !disableConstraints;
604             r.run();
605             /*
606         } catch (SourceException ex) {
607             throw ex;
608              */

609             commitChanges();
610             return true;
611         } catch (Exception JavaDoc ex) {
612             ex.printStackTrace();
613             throw new SourceException("Unexpected implementation error"); // NOI18N
614
} finally {
615             this.transactionConstrained = saveConstraint;
616             releaseWriteLock(token, true);
617         }
618     }
619     
620     private void doRunAtomic(ExceptionRunnable r) throws SourceException {
621         // nothing done here (for now).
622
try {
623             r.run();
624         } catch (SourceException ex) {
625             throw ex;
626         } catch (Exception JavaDoc ex) {
627             throw new SourceException("Unexpected implementation error."); // NOI18N
628
}
629     }
630     
631     public void runAtomic(ExceptionRunnable r) throws SourceException {
632         boolean fire = false;
633         boolean ok = false;
634         Object JavaDoc token = null;
635
636         token = writeLock();
637         try {
638             doRunAtomic(r);
639             commitChanges();
640         } finally {
641             releaseWriteLock(token);
642         }
643     }
644     
645     public Object JavaDoc getManagementLock() {
646         return writerNotify;
647     }
648     
649     public final void readLock() {
650         /*
651         synchronized (writerNotify) {
652             if (writingThread != null) {
653                 if (writingThread == Thread.currentThread()) {
654                     readerCount++;
655                     return;
656                 }
657             }
658             try {
659                 writerNotify.wait();
660             } catch (InterruptedException ex) {
661                 // PENDING: rethrow another (Runtime) exception.
662             }
663             if (locked == null) {
664                 locked = Thread.currentThread();
665             }
666             readerCount++;
667         }
668          */

669     }
670
671     public final void releaseReadLock() {
672         /*
673         synchronized (writerNotify) {
674             if (--readerCount == 0) {
675                 if (writingThread == null) {
676                     locked = null;
677                     writerNotify.notifyAll();
678                 }
679             }
680         }
681          */

682     }
683     
684     protected EventQueue getEventQueue() {
685         return this.eventQueue;
686     }
687     
688     public boolean isWriteLocked() {
689         return this.writingThread != null;
690     }
691     
692     public Item createImport(Import im, int from, int to) {
693         return null;
694     }
695     
696     public void notifyElementChanged(Element ref, Element old) {
697         eventQueue.elementChanged(ref, old);
698     }
699     
700     public void notifyElementCreated(Element ref) {
701         eventQueue.elementCreated(ref);
702     }
703     
704     public void notifyElementRemoved(Element ref) {
705         eventQueue.elementRemoved(ref);
706     }
707     
708     public void fireModelElementChange(ElementImpl bean, PropertyChangeEvent JavaDoc evt) {
709         queuePropertyChange(bean, evt.getPropertyName(), evt);
710     }
711     
712     public void fireModelElementChange(Element.Impl bean, PropertyChangeEvent JavaDoc evt) {
713         queuePropertyChange((ElementImpl)bean, evt.getPropertyName(), evt);
714     }
715     
716     // Model-private protocol
717
///////////////////////////////////////////////////////////////////////////////
718

719     protected BindingFactory getBindingFactory() {
720         if (this.bindingFactory != null) {
721             return this.bindingFactory;
722         }
723         return this.bindingFactory = env.getBindingFactory();
724     }
725     
726     public WrapperFactory getWrapper() {
727         if (this.wrapperFactory != null) {
728             return this.wrapperFactory;
729         }
730         synchronized (this) {
731             if (this.wrapperFactory == null) {
732                 this.wrapperFactory = env.getWrapperFactory();
733             }
734             return this.wrapperFactory;
735         }
736     }
737     
738     // Implementation:
739
///////////////////////////////////////////////////////////////////////////////
740
private void queuePropertyChange(ElementImpl bean, String JavaDoc name, PropertyChangeEvent JavaDoc evt) {
741         eventQueue.addPropertyChange(bean, evt);
742     }
743     
744     private ElementImpl getElementImpl(Element el) {
745         return (ElementImpl)el.getCookie(ElementImpl.class);
746     }
747     
748     public void updateMembers(Element target, String JavaDoc propertyName, Element[] els,
749         int[] orderIndices,
750         int[] optMap) {
751         if (target instanceof ClassElement) {
752             ClassElementImpl impl = (ClassElementImpl)getElementImpl(target);
753             impl.updateMembers(propertyName, els, orderIndices, optMap);
754         } else {
755             SourceElementImpl impl = (SourceElementImpl)getElementImpl(target);
756             impl.updateMembers(propertyName, els, optMap);
757         }
758     }
759     
760     public void updateMemberOrder(Element target, String JavaDoc id,
761         Element[] orderedMembers) {
762         ClassElementImpl impl = (ClassElementImpl)getElementImpl(target);
763         impl.updateMemberOrder(orderedMembers);
764     }
765     
766     public void activate(Element target) {
767         ElementImpl impl = getElementImpl(target);
768         impl.notifyCreate();
769     }
770     
771     public Binding getElementBinding(Element target) {
772         ElementImpl impl = getElementImpl(target);
773         return impl.getRawBinding();
774     }
775     
776     public boolean isSameContext(Element context, Identifier id) {
777         ElementImpl impl = getElementImpl(context);
778         if (impl == null)
779             return false;
780         return impl.checkIdentifierContext(id);
781     }
782     
783     public Identifier createLocalIdentifier(Element context, Identifier id, int status) {
784         ElementImpl impl = getElementImpl(context);
785         if (impl == null)
786             throw new IllegalArgumentException JavaDoc("Unknown context class: " + context.getClass()); // NOI18N
787
return impl.createLocalIdentifier(id, status);
788     }
789     
790     public Identifier createLocalIdentifier(Element context, String JavaDoc full, String JavaDoc source,
791     int status) {
792         Identifier id = Identifier.create(full, source);
793         return createLocalIdentifier(context, id, status);
794     }
795     
796     // methods related to commit listener
797

798     private void doFire (Set removed, Set created, Map changed) {
799         if (postCommitListeners != null) {
800             synchronized (postCommitListeners) {
801                 for (Iterator it = postCommitListeners.iterator(); it.hasNext();) {
802                     CommitListener l = (CommitListener)it.next();
803                     l.changesCommited(created, removed, changed);
804                 }
805             }
806         }
807     }
808     
809     public void fireElementChanged (Element oldElem, Element newElem) {
810         Map changed = new HashMap ();
811         changed.put (newElem, new Element [] {oldElem, newElem});
812         
813         doFire (new HashSet (), new HashSet (), changed);
814     }
815
816     public void fireElementRemoved (Element elem) {
817         Set removed = new HashSet ();
818         removed.add (elem);
819         
820         doFire (removed, new HashSet (), new HashMap ());
821     }
822     
823     public void fireElementAdded (Element elem) {
824         Set created = new HashSet ();
825         created.add (elem);
826              
827         doFire (new HashSet (), created, new HashMap ());
828     }
829      
830     public void fireElementSet (Element oldElem, Element newElem) {
831         Set removed = new HashSet ();
832         removed.add (oldElem);
833         Set created = new HashSet ();
834         created.add (newElem);
835          
836         doFire (removed, created, new HashMap ());
837     }
838     
839     public Element findElement(Element.Impl impl) {
840         if (!(impl instanceof ElementImpl))
841             return null;
842         return ((ElementImpl)impl).getElement();
843     }
844     
845     public void firePropertyChange(Element el, PropertyChangeEvent JavaDoc evt) {
846         ElementImpl impl = getElementImpl(el);
847         if (impl == null) {
848             // [PENDING]
849
JMManager.getLog().log(ErrorManager.INFORMATIONAL, "DefaultLangModel.firePropertyChange(): impl == null"); // NOI18N
850
return;
851         }
852         impl.fireOwnPropertyChange(evt);
853     }
854     
855     public void updateBody(Element el, String JavaDoc bodyContent) throws UnsupportedOperationException JavaDoc {
856         /*
857         ElementImpl impl = getElementImpl(el);
858         if (impl instanceof CallableImpl)
859             ((CallableImpl)impl).updateBody(bodyContent);
860         else if (impl instanceof InitializerElementImpl)
861             ((InitializerElementImpl)impl).updateBody(bodyContent);
862         else
863             throw new UnsupportedOperationException();
864          */

865     }
866  
867     public void invalidateModel(SourceElement el) {
868         SourceElementImpl impl = (SourceElementImpl)getElementImpl(el);
869         Object JavaDoc token = writeLock();
870         try {
871             if (impl == null)
872                 return;
873             impl.notifyRemove();
874             commitChanges();
875         } finally {
876             releaseWriteLock(token);
877         }
878     }
879 }
880
Popular Tags