001: /**
002: * <copyright>
003: * </copyright>
004: *
005: * $Id: PicoBlackboardImpl.java 23326 2006-12-08 02:42:32Z jeichar $
006: */package net.refractions.udig.project.internal.impl;
007:
008: import java.util.concurrent.CopyOnWriteArraySet;
009:
010: import net.refractions.udig.project.BlackboardEvent;
011: import net.refractions.udig.project.IBlackboardListener;
012: import net.refractions.udig.project.internal.PicoBlackboard;
013: import net.refractions.udig.project.internal.ProjectPackage;
014: import net.refractions.udig.project.internal.ProjectPlugin;
015:
016: import org.eclipse.emf.ecore.EClass;
017: import org.eclipse.emf.ecore.EStructuralFeature;
018: import org.eclipse.emf.ecore.impl.EObjectImpl;
019: import org.picocontainer.ComponentAdapter;
020: import org.picocontainer.MutablePicoContainer;
021: import org.picocontainer.defaults.DefaultPicoContainer;
022:
023: /**
024: * TODO Purpose of net.refractions.udig.project.internal.impl
025: * <p>
026: * </p>
027: *
028: * @author Jesse
029: * @since 1.0.0
030: * @generated
031: */
032: public class PicoBlackboardImpl extends EObjectImpl implements
033: PicoBlackboard {
034: /**
035: * <!-- begin-user-doc --> <!-- end-user-doc -->
036: *
037: * @generated NOT
038: */
039: public static final String copyright = "uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details."; //$NON-NLS-1$
040:
041: /**
042: * The default value of the '{@link #getPicoContainer() <em>Pico Container</em>}' attribute.
043: * <!-- begin-user-doc --> <!-- end-user-doc -->
044: *
045: * @see #getPicoContainer()
046: * @generated NOT
047: * @ordered
048: */
049: protected static final MutablePicoContainer PICO_CONTAINER_EDEFAULT = new DefaultPicoContainer();
050:
051: /**
052: * The cached value of the '{@link #getPicoContainer() <em>Pico Container</em>}' attribute.
053: * <!-- begin-user-doc --> <!-- end-user-doc -->
054: * @see #getPicoContainer()
055: * @generated
056: * @ordered
057: */
058: protected MutablePicoContainer picoContainer = PICO_CONTAINER_EDEFAULT;
059:
060: /**
061: * <!-- begin-user-doc --> <!-- end-user-doc -->
062: * @generated
063: */
064: protected PicoBlackboardImpl() {
065: super ();
066: }
067:
068: /**
069: * <!-- begin-user-doc --> <!-- end-user-doc -->
070: * @generated
071: */
072: protected EClass eStaticClass() {
073: return ProjectPackage.eINSTANCE.getPicoBlackboard();
074: }
075:
076: /**
077: * <!-- begin-user-doc --> <!-- end-user-doc -->
078: * @generated
079: */
080: public MutablePicoContainer getPicoContainer() {
081: return picoContainer;
082: }
083:
084: /**
085: * <!-- begin-user-doc --> <!-- end-user-doc -->
086: * @generated
087: */
088: public Object eGet(EStructuralFeature eFeature, boolean resolve) {
089: switch (eDerivedStructuralFeatureID(eFeature)) {
090: case ProjectPackage.PICO_BLACKBOARD__PICO_CONTAINER:
091: return getPicoContainer();
092: }
093: return eDynamicGet(eFeature, resolve);
094: }
095:
096: /**
097: * <!-- begin-user-doc --> <!-- end-user-doc -->
098: * @generated
099: */
100: public boolean eIsSet(EStructuralFeature eFeature) {
101: switch (eDerivedStructuralFeatureID(eFeature)) {
102: case ProjectPackage.PICO_BLACKBOARD__PICO_CONTAINER:
103: return PICO_CONTAINER_EDEFAULT == null ? picoContainer != null
104: : !PICO_CONTAINER_EDEFAULT.equals(picoContainer);
105: }
106: return eDynamicIsSet(eFeature);
107: }
108:
109: /**
110: * <!-- begin-user-doc --> <!-- end-user-doc -->
111: * @generated
112: */
113: public String toString() {
114: if (eIsProxy())
115: return super .toString();
116:
117: StringBuffer result = new StringBuffer(super .toString());
118: result.append(" (picoContainer: "); //$NON-NLS-1$
119: result.append(picoContainer);
120: result.append(')');
121: return result.toString();
122: }
123:
124: /*
125: * (non-Javadoc)
126: *
127: * @see net.refractions.udig.project.IBlackboard#contains(java.lang.String)
128: */
129: public boolean contains(String key) {
130: return picoContainer.getComponentInstance(key) != null;
131: }
132:
133: /*
134: * (non-Javadoc)
135: *
136: * @see net.refractions.udig.project.IBlackboard#get(java.lang.String)
137: */
138: public Object get(String key) {
139: return picoContainer.getComponentInstance(key);
140: }
141:
142: /*
143: * (non-Javadoc)
144: *
145: * @see net.refractions.udig.project.IBlackboard#put(java.lang.String, java.lang.Object)
146: */
147: public void put(String key, Object value) {
148:
149: ComponentAdapter oldValue = picoContainer
150: .registerComponentInstance(key, value);
151:
152: BlackboardEvent event = new BlackboardEvent(this , key, oldValue
153: .getComponentInstance(picoContainer), value);
154: for (IBlackboardListener l : listeners) {
155: try {
156: l.blackBoardChanged(event);
157: } catch (Exception e) {
158: ProjectPlugin.log("", e); //$NON-NLS-1$
159: }
160: }
161: }
162:
163: /*
164: * (non-Javadoc)
165: *
166: * @see net.refractions.udig.project.IBlackboard#getFloat(java.lang.String)
167: */
168: public Float getFloat(String key) {
169: Object o = picoContainer.getComponentInstance(key);
170: if (o != null && o instanceof Float)
171: return (Float) o;
172:
173: return null;
174: }
175:
176: /*
177: * (non-Javadoc)
178: *
179: * @see net.refractions.udig.project.IBlackboard#getInteger(java.lang.String)
180: */
181: public Integer getInteger(String key) {
182: Object o = picoContainer.getComponentInstance(key);
183: if (o != null && o instanceof Integer)
184: return (Integer) o;
185:
186: return null;
187: }
188:
189: /*
190: * (non-Javadoc)
191: *
192: * @see net.refractions.udig.project.IBlackboard#getString(java.lang.String)
193: */
194: public String getString(String key) {
195: Object o = picoContainer.getComponentInstance(key);
196: if (o != null && o instanceof String)
197: return (String) o;
198:
199: return null;
200: }
201:
202: /*
203: * (non-Javadoc)
204: *
205: * @see net.refractions.udig.project.IBlackboard#putFloat(java.lang.String, float)
206: */
207: public void putFloat(String key, float value) {
208: put(key, new Float(value));
209: }
210:
211: /*
212: * (non-Javadoc)
213: *
214: * @see net.refractions.udig.project.IBlackboard#putInteger(java.lang.String, int)
215: */
216: public void putInteger(String key, int value) {
217: put(key, value);
218: }
219:
220: /*
221: * (non-Javadoc)
222: *
223: * @see net.refractions.udig.project.IBlackboard#putString(java.lang.String, java.lang.String)
224: */
225: public void putString(String key, String value) {
226: put(key, value);
227: }
228:
229: CopyOnWriteArraySet<IBlackboardListener> listeners = new CopyOnWriteArraySet<IBlackboardListener>();
230:
231: public boolean addListener(IBlackboardListener listener) {
232: return listeners.add(listener);
233: }
234:
235: public boolean removeListener(IBlackboardListener listener) {
236: return listeners.remove(listener);
237: }
238:
239: public void clear() {
240: // TODO: not sure if this is the correct way to clear, dispose is a
241: // lifecycle call
242: picoContainer.dispose();
243: picoContainer = new DefaultPicoContainer();
244:
245: for (IBlackboardListener l : listeners) {
246: try {
247: l.blackBoardCleared(this );
248: } catch (Exception e) {
249: ProjectPlugin.log("", e); //$NON-NLS-1$
250: }
251: }
252: }
253:
254: public void flush() {
255: // do nothing, does not support persistance
256: }
257:
258: } // PicoBlackboardImpl
|