1 19 package org.netbeans.mdr.handlers; 20 21 import javax.jmi.model.*; 22 import javax.jmi.reflect.*; 23 24 import java.util.*; 25 26 import org.netbeans.api.mdr.events.*; 27 28 import org.netbeans.mdr.util.DebugException; 29 import org.netbeans.mdr.storagemodel.*; 30 import org.netbeans.mdr.persistence.StorageException; 31 32 37 public abstract class FeaturedHandler extends BaseObjectHandler implements RefFeatured { 38 39 40 41 42 43 44 protected FeaturedHandler(StorableFeatured storable) { 45 super(storable); 46 } 47 48 49 50 51 52 private StorableFeatured getFeaturedDelegate() { 53 return (StorableFeatured) _getDelegate(); 54 } 55 56 57 58 59 60 protected final Object _preGet(String featureName) { 61 _lock(false); 62 return featureName; 63 } 64 65 protected final void _postGet(Object result, Object extraInfo, boolean fail) { 66 try { 67 if (result instanceof AttrCollWrapper) { 68 ((AttrCollWrapper) result).setAttrName((String ) extraInfo); 69 } 70 } finally { 71 _unlock(); 72 } 73 } 74 75 protected final Object _preSet(String featureName, Object newValue) { 76 boolean fail = true; 77 _lock(true); 78 try { 79 if (_getMdrStorage().eventsEnabled()) { 80 Object oldValue = _getAttribute(featureName); 81 AttributeEvent event = new AttributeEvent( 85 this, 86 AttributeEvent.EVENT_ATTRIBUTE_SET, 87 featureName, 88 oldValue, 89 newValue, 90 AttributeEvent.POSITION_NONE 91 ); 92 if (this instanceof RefObject) { 93 _getMdrStorage().getEventNotifier().INSTANCE.firePlannedChange(this, event); 94 } else { 95 _getMdrStorage().getEventNotifier().CLASS.firePlannedChange(this, event); 96 } 97 fail = false; 98 return event; 99 } 100 fail = false; 101 return null; 102 } finally { 103 if (fail) _unlock(true); 104 } 105 } 107 108 protected final void _postSet(Object extraInfo, boolean fail) { 109 _unlock(fail); 110 } 111 112 113 115 public final Object refInvokeOperation(String operationName, List args) throws RefException { 116 return _invokeOperation(operationName, args.toArray()); 117 } 118 119 public final Object refInvokeOperation(RefObject requestedOperation, List args) throws RefException { 120 return _invokeOperation(((Operation) requestedOperation).getName(), args.toArray()); 121 } 122 123 public void refSetValue(String featureName, java.lang.Object value) { 124 _lock(true); 125 try { 126 _setAttribute(featureName, value); 127 } finally { 128 _unlock(); 129 } 130 } 131 132 public void refSetValue(RefObject feature, Object value) { 133 _lock(true); 134 try { 135 143 _setAttribute(((Attribute) feature).getName(), value); 144 } catch (InvalidNameException e) { 145 throw new InvalidCallException(null, feature); 146 } catch (ClassCastException e) { 147 throw new InvalidCallException(null, feature); 148 } finally { 151 _unlock(); 152 } 153 } 154 155 public Object refGetValue(String featureName) { 156 _lock(false); 157 try { 158 return _getAttribute(featureName); 159 } finally { 160 _unlock(); 161 } 162 } 163 164 public Object refGetValue(RefObject feature) { 165 _lock(false); 166 try { 167 176 return _getAttribute(((Attribute) feature).getName()); 177 } catch (InvalidNameException e) { 178 throw new InvalidCallException(null, feature); 179 } catch (ClassCastException e) { 180 throw new InvalidCallException(null, feature); 181 185 } finally { 186 _unlock(); 187 } 188 } 189 190 191 192 193 194 public abstract void _setAttribute(String attrName, Object newValue); 195 public abstract Object _getAttribute(String attrName); 196 197 public abstract Object _invokeOperation(String operName, Object [] params); 198 } 199 | Popular Tags |