1 17 package org.eclipse.emf.ecore.xml.type.impl; 18 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 22 import org.eclipse.emf.common.notify.Notification; 23 import org.eclipse.emf.common.notify.NotificationChain; 24 import org.eclipse.emf.ecore.EClass; 25 import org.eclipse.emf.ecore.EDataType; 26 import org.eclipse.emf.ecore.EStructuralFeature; 27 import org.eclipse.emf.ecore.InternalEObject; 28 import org.eclipse.emf.ecore.impl.ENotificationImpl; 29 import org.eclipse.emf.ecore.util.EcoreUtil; 30 import org.eclipse.emf.ecore.util.FeatureMap; 31 import org.eclipse.emf.ecore.util.InternalEList; 32 import org.eclipse.emf.ecore.xml.type.SimpleAnyType; 33 import org.eclipse.emf.ecore.xml.type.XMLTypePackage; 34 35 50 public class SimpleAnyTypeImpl extends AnyTypeImpl implements SimpleAnyType 51 { 52 60 protected static final String RAW_VALUE_EDEFAULT = null; 61 62 70 protected static final Object VALUE_EDEFAULT = null; 71 72 80 protected EDataType instanceType = null; 81 82 87 protected SimpleAnyTypeImpl() 88 { 89 super(); 90 } 91 92 97 protected EClass eStaticClass() 98 { 99 return XMLTypePackage.eINSTANCE.getSimpleAnyType(); 100 } 101 102 107 public String getRawValue() 108 { 109 StringBuffer value = new StringBuffer (); 110 for (Iterator i = getMixed().iterator(); i.hasNext(); ) 111 { 112 FeatureMap.Entry entry = (FeatureMap.Entry)i.next(); 113 if (entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text()) 114 { 115 value.append(entry.getValue()); 116 } 117 } 118 return value.toString(); 119 } 120 121 126 public void setRawValue(String newRawValue) 127 { 128 getMixed().clear(); 129 if (newRawValue != null) 130 { 131 getMixed().add(XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text(), newRawValue); 132 } 133 } 134 135 140 public Object getValue() 141 { 142 return EcoreUtil.createFromString(instanceType, getRawValue()); 143 } 144 145 150 public void setValue(Object newValue) 151 { 152 setRawValue(EcoreUtil.convertToString(instanceType, newValue)); 153 } 154 155 160 public EDataType getInstanceType() 161 { 162 return instanceType; 163 } 164 165 170 public void setInstanceType(EDataType newInstanceType) 171 { 172 EDataType oldInstanceType = instanceType; 173 instanceType = newInstanceType; 174 if (eNotificationRequired()) 175 eNotify(new ENotificationImpl(this, Notification.SET, XMLTypePackage.SIMPLE_ANY_TYPE__INSTANCE_TYPE, oldInstanceType, instanceType)); 176 } 177 178 183 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 184 { 185 if (featureID >= 0) 186 { 187 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 188 { 189 case XMLTypePackage.SIMPLE_ANY_TYPE__MIXED: 190 return ((InternalEList)getMixed()).basicRemove(otherEnd, msgs); 191 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY: 192 return ((InternalEList)getAny()).basicRemove(otherEnd, msgs); 193 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY_ATTRIBUTE: 194 return ((InternalEList)getAnyAttribute()).basicRemove(otherEnd, msgs); 195 default: 196 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 197 } 198 } 199 return eBasicSetContainer(null, featureID, msgs); 200 } 201 202 207 public Object eGet(EStructuralFeature eFeature, boolean resolve) 208 { 209 switch (eDerivedStructuralFeatureID(eFeature)) 210 { 211 case XMLTypePackage.SIMPLE_ANY_TYPE__MIXED: 212 return getMixed(); 213 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY: 214 return getAny(); 215 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY_ATTRIBUTE: 216 return getAnyAttribute(); 217 case XMLTypePackage.SIMPLE_ANY_TYPE__RAW_VALUE: 218 return getRawValue(); 219 case XMLTypePackage.SIMPLE_ANY_TYPE__VALUE: 220 return getValue(); 221 case XMLTypePackage.SIMPLE_ANY_TYPE__INSTANCE_TYPE: 222 return getInstanceType(); 223 } 224 return eDynamicGet(eFeature, resolve); 225 } 226 227 232 public void eSet(EStructuralFeature eFeature, Object newValue) 233 { 234 switch (eDerivedStructuralFeatureID(eFeature)) 235 { 236 case XMLTypePackage.SIMPLE_ANY_TYPE__MIXED: 237 getMixed().clear(); 238 getMixed().addAll((Collection )newValue); 239 return; 240 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY: 241 getAny().clear(); 242 getAny().addAll((Collection )newValue); 243 return; 244 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY_ATTRIBUTE: 245 getAnyAttribute().clear(); 246 getAnyAttribute().addAll((Collection )newValue); 247 return; 248 case XMLTypePackage.SIMPLE_ANY_TYPE__RAW_VALUE: 249 setRawValue((String )newValue); 250 return; 251 case XMLTypePackage.SIMPLE_ANY_TYPE__VALUE: 252 setValue((Object )newValue); 253 return; 254 case XMLTypePackage.SIMPLE_ANY_TYPE__INSTANCE_TYPE: 255 setInstanceType((EDataType)newValue); 256 return; 257 } 258 eDynamicSet(eFeature, newValue); 259 } 260 261 266 public void eUnset(EStructuralFeature eFeature) 267 { 268 switch (eDerivedStructuralFeatureID(eFeature)) 269 { 270 case XMLTypePackage.SIMPLE_ANY_TYPE__MIXED: 271 getMixed().clear(); 272 return; 273 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY: 274 getAny().clear(); 275 return; 276 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY_ATTRIBUTE: 277 getAnyAttribute().clear(); 278 return; 279 case XMLTypePackage.SIMPLE_ANY_TYPE__RAW_VALUE: 280 setRawValue(RAW_VALUE_EDEFAULT); 281 return; 282 case XMLTypePackage.SIMPLE_ANY_TYPE__VALUE: 283 setValue(VALUE_EDEFAULT); 284 return; 285 case XMLTypePackage.SIMPLE_ANY_TYPE__INSTANCE_TYPE: 286 setInstanceType((EDataType)null); 287 return; 288 } 289 eDynamicUnset(eFeature); 290 } 291 292 297 public boolean eIsSet(EStructuralFeature eFeature) 298 { 299 switch (eDerivedStructuralFeatureID(eFeature)) 300 { 301 case XMLTypePackage.SIMPLE_ANY_TYPE__MIXED: 302 return mixed != null && !mixed.isEmpty(); 303 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY: 304 return !getAny().isEmpty(); 305 case XMLTypePackage.SIMPLE_ANY_TYPE__ANY_ATTRIBUTE: 306 return anyAttribute != null && !anyAttribute.isEmpty(); 307 case XMLTypePackage.SIMPLE_ANY_TYPE__RAW_VALUE: 308 return RAW_VALUE_EDEFAULT == null ? getRawValue() != null : !RAW_VALUE_EDEFAULT.equals(getRawValue()); 309 case XMLTypePackage.SIMPLE_ANY_TYPE__VALUE: 310 return VALUE_EDEFAULT == null ? getValue() != null : !VALUE_EDEFAULT.equals(getValue()); 311 case XMLTypePackage.SIMPLE_ANY_TYPE__INSTANCE_TYPE: 312 return instanceType != null; 313 } 314 return eDynamicIsSet(eFeature); 315 } 316 317 } | Popular Tags |