KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > impl > AXIModelListener


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.axi.impl;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.xml.axi.AXIComponent;
26
27 /**
28  * Listener to listen to this model changes. Used by code generator.
29  *
30  * @author Ayub
31  */

32 public class AXIModelListener implements PropertyChangeListener JavaDoc {
33     List JavaDoc<PropertyChangeEvent JavaDoc> events = new ArrayList JavaDoc<PropertyChangeEvent JavaDoc>();
34     
35     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
36         
37         //filter events if not intended for code generator.
38
if(!validatePropertyChangeEvent(evt))
39             return;
40         
41         //add event to the event queue.
42
events.add(evt);
43     }
44     
45     public List JavaDoc<PropertyChangeEvent JavaDoc> getEvents() {
46         return events;
47     }
48     
49     public void clearEvents() { events.clear();}
50     
51     /**
52      * Checks the validity of this event. Certain events shouldn't go to
53      * the code generator. For example events coming from proxy components.
54      * There are certain other cases as well.
55      */

56     private boolean validatePropertyChangeEvent(PropertyChangeEvent JavaDoc evt) {
57         Object JavaDoc source = evt.getSource();
58         //events coming from model are valid
59
if( !(source instanceof AXIComponent) )
60             return true;
61                 
62         //ignore proxy related events
63
if(proxyRelated(evt))
64             return false;
65                         
66         
67         return true;
68     }
69     
70     private boolean proxyRelated(PropertyChangeEvent JavaDoc evt) {
71         if(evt.getSource() instanceof AXIComponentProxy)
72             return true;
73         
74         Object JavaDoc oldValue = evt.getOldValue();
75         Object JavaDoc newValue = evt.getNewValue();
76         //proxy child added
77
if( (newValue != null) && (oldValue == null) &&
78             (newValue instanceof AXIComponentProxy) )
79             return true;
80         //proxy child removed
81
if( (oldValue != null) && (newValue == null) &&
82             (oldValue instanceof AXIComponentProxy) )
83             return true;
84         
85         return false;
86     }
87     
88 }
89
Popular Tags