001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.mapper.model;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023: import java.util.concurrent.locks.Lock;
024: import java.util.concurrent.locks.ReentrantReadWriteLock;
025: import org.netbeans.modules.xml.axi.AXIComponent;
026: import org.netbeans.modules.xml.xam.Model;
027:
028: /**
029: *
030: * @author Vitaly Bychkov
031: * @version 1.0
032: */
033: public class MapperContextChangeSupport {
034: private Lock writeLock = new ReentrantReadWriteLock().writeLock();
035: private List<MapperContextChangeListener> myListeners = new ArrayList<MapperContextChangeListener>();
036:
037: public MapperContextChangeSupport() {
038: }
039:
040: public void addPropertyChangeListener(
041: MapperContextChangeListener changeListener) {
042: assert changeListener != null : "Try to add null listener."; // NOI18N
043: writeLock.lock();
044: try {
045: myListeners.add(changeListener);
046: } finally {
047: writeLock.unlock();
048: }
049: }
050:
051: public void removePropertyChangeListener(
052: MapperContextChangeListener changeListener) {
053: assert changeListener != null : "Try to remove null listener."; // NOI18N
054: writeLock.lock();
055: try {
056: myListeners.remove(changeListener);
057: } finally {
058: writeLock.unlock();
059: }
060: }
061:
062: /**
063: * Invoked when something changed.
064: * In complex cases ChangeEvent could be passed as newObject.
065: * In this case the oldObject is null.
066: * @param oldValue
067: * @param newValue
068: */
069: public void fireMapperContextChanged(Object oldValue,
070: Object newValue) {
071: MapperContextChangeListener[] tmp = new MapperContextChangeListener[myListeners
072: .size()];
073: synchronized (myListeners) {
074: tmp = myListeners.toArray(tmp);
075: }
076:
077: for (MapperContextChangeListener listener : tmp) {
078: listener.mapperContextChanged(oldValue, newValue);
079: }
080: }
081:
082: public void fireXslModelStateChanged(Model.State oldValue,
083: Model.State newValue) {
084: MapperContextChangeListener[] tmp = new MapperContextChangeListener[myListeners
085: .size()];
086: synchronized (myListeners) {
087: tmp = myListeners.toArray(tmp);
088: }
089:
090: for (MapperContextChangeListener listener : tmp) {
091: listener.mapperContextChanged(oldValue, newValue);
092:
093: listener.xslModelStateChanged(oldValue, newValue);
094: }
095: }
096:
097: public void fireTMapModelStateChanged(Model.State oldValue,
098: Model.State newValue) {
099: MapperContextChangeListener[] tmp = new MapperContextChangeListener[myListeners
100: .size()];
101: synchronized (myListeners) {
102: tmp = myListeners.toArray(tmp);
103: }
104:
105: for (MapperContextChangeListener listener : tmp) {
106: listener.mapperContextChanged(oldValue, newValue);
107:
108: listener.tMapModelStateChanged(oldValue, newValue);
109: }
110: }
111:
112: public void fireSourceTypeChanged(AXIComponent oldComponent,
113: AXIComponent newComponent) {
114: MapperContextChangeListener[] tmp = new MapperContextChangeListener[myListeners
115: .size()];
116: synchronized (myListeners) {
117: tmp = myListeners.toArray(tmp);
118: }
119:
120: for (MapperContextChangeListener listener : tmp) {
121: listener.mapperContextChanged(oldComponent, newComponent);
122:
123: listener.sourceTypeChanged(oldComponent, newComponent);
124: }
125: }
126:
127: public void fireTargetTypeChanged(AXIComponent oldComponent,
128: AXIComponent newComponent) {
129: MapperContextChangeListener[] tmp = new MapperContextChangeListener[myListeners
130: .size()];
131: synchronized (myListeners) {
132: tmp = myListeners.toArray(tmp);
133: }
134:
135: for (MapperContextChangeListener listener : tmp) {
136: listener.mapperContextChanged(oldComponent, newComponent);
137:
138: listener.targetTypeChanged(oldComponent, newComponent);
139: }
140: }
141:
142: public void fireMapperContextChanged(MapperContext oldContext,
143: MapperContext newContext) {
144: throw new UnsupportedOperationException();
145: }
146: }
|