Debian Codegraph @

plugins/org.eclipse.xsd/src/org/eclipse/xsd/impl/XSDXPathDefinitionImpl.java

raw
1 /**
2 * Copyright (c) 2002-2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.xsd.impl;
12
13
14 import org.w3c.dom.Element;
15 import org.w3c.dom.Node;
16
17 import org.eclipse.emf.common.notify.Notification;
18 import org.eclipse.emf.common.notify.NotificationChain;
19 import org.eclipse.emf.ecore.EAttribute;
20 import org.eclipse.emf.ecore.EClass;
21 import org.eclipse.emf.ecore.InternalEObject;
22 import org.eclipse.emf.ecore.impl.ENotificationImpl;
23 import org.eclipse.xsd.XSDAnnotation;
24 import org.eclipse.xsd.XSDComplexTypeDefinition;
25 import org.eclipse.xsd.XSDConcreteComponent;
26 import org.eclipse.xsd.XSDFactory;
27 import org.eclipse.xsd.XSDPackage;
28 import org.eclipse.xsd.XSDXPathDefinition;
29 import org.eclipse.xsd.XSDXPathVariety;
30 import org.eclipse.xsd.util.XSDConstants;
31
32
33 /**
34 * <!-- begin-user-doc -->
35 * An implementation of the model object '<em><b>XPath Definition</b></em>'.
36 * <!-- end-user-doc -->
37 * <p>
38 * The following features are implemented:
39 * </p>
40 * <ul>
41 * <li>{@link org.eclipse.xsd.impl.XSDXPathDefinitionImpl#getVariety <em>Variety</em>}</li>
42 * <li>{@link org.eclipse.xsd.impl.XSDXPathDefinitionImpl#getValue <em>Value</em>}</li>
43 * <li>{@link org.eclipse.xsd.impl.XSDXPathDefinitionImpl#getAnnotation <em>Annotation</em>}</li>
44 * </ul>
45 *
46 * @generated
47 */
48 public class XSDXPathDefinitionImpl
49 extends XSDComponentImpl
50 implements XSDXPathDefinition
51 {
52 /**
53 * The default value of the '{@link #getVariety() <em>Variety</em>}' attribute.
54 * <!-- begin-user-doc -->
55 * <!-- end-user-doc -->
56 * @see #getVariety()
57 * @generated
58 * @ordered
59 */
60 protected static final XSDXPathVariety VARIETY_EDEFAULT = XSDXPathVariety.SELECTOR_LITERAL;
61
62 /**
63 * The offset of the flags representing the value of the '{@link #getVariety() <em>Variety</em>}' attribute.
64 * <!-- begin-user-doc -->
65 * <!-- end-user-doc -->
66 * @generated
67 * @ordered
68 */
69 protected static final int VARIETY_EFLAG_OFFSET = 8;
70
71 /**
72 * The flags representing the default value of the '{@link #getVariety() <em>Variety</em>}' attribute.
73 * <!-- begin-user-doc -->
74 * <!-- end-user-doc -->
75 * @generated
76 * @ordered
77 */
78 protected static final int VARIETY_EFLAG_DEFAULT = VARIETY_EDEFAULT.ordinal() << VARIETY_EFLAG_OFFSET;
79
80 /**
81 * The array of enumeration values for '{@link XSDXPathVariety XPath Variety}'
82 * <!-- begin-user-doc -->
83 * <!-- end-user-doc -->
84 * @generated
85 * @ordered
86 */
87 private static final XSDXPathVariety[] VARIETY_EFLAG_VALUES = XSDXPathVariety.values();
88
89 /**
90 * The flag representing the value of the '{@link #getVariety() <em>Variety</em>}' attribute.
91 * <!-- begin-user-doc -->
92 * <!-- end-user-doc -->
93 * @see #getVariety()
94 * @generated
95 * @ordered
96 */
97 protected static final int VARIETY_EFLAG = 1 << VARIETY_EFLAG_OFFSET;
98
99 /**
100 * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
101 * <!-- begin-user-doc -->
102 * <!-- end-user-doc -->
103 * @see #getValue()
104 * @generated
105 * @ordered
106 */
107 protected static final String VALUE_EDEFAULT = null;
108
109 /**
110 * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
111 * <!-- begin-user-doc -->
112 * <!-- end-user-doc -->
113 * @see #getValue()
114 * @generated
115 * @ordered
116 */
117 protected String value = VALUE_EDEFAULT;
118
119 /**
120 * The cached value of the '{@link #getAnnotation() <em>Annotation</em>}' containment reference.
121 * <!-- begin-user-doc -->
122 * <!-- end-user-doc -->
123 * @see #getAnnotation()
124 * @generated
125 * @ordered
126 */
127 protected XSDAnnotation annotation;
128
129 public static XSDXPathDefinition createXPathDefinition(Node node)
130 {
131 switch (XSDConstants.nodeType(node))
132 {
133 case XSDConstants.SELECTOR_ELEMENT:
134 case XSDConstants.FIELD_ELEMENT:
135 {
136 XSDXPathDefinition xsdXPathDefinition = XSDFactory.eINSTANCE.createXSDXPathDefinition();
137 xsdXPathDefinition.setElement((Element)node);
138 return xsdXPathDefinition;
139 }
140 }
141
142 return null;
143 }
144
145 /**
146 * <!-- begin-user-doc -->
147 * <!-- end-user-doc -->
148 * @generated
149 */
150 protected XSDXPathDefinitionImpl()
151 {
152 super();
153 }
154
155 /**
156 * <!-- begin-user-doc -->
157 * <!-- end-user-doc -->
158 * @generated
159 */
160 @Override
161 protected EClass eStaticClass()
162 {
163 return XSDPackage.Literals.XSD_XPATH_DEFINITION;
164 }
165
166 /**
167 * <!-- begin-user-doc -->
168 * <!-- end-user-doc -->
169 * @generated
170 */
171 @Override
172 public XSDXPathVariety getVariety()
173 {
174 return VARIETY_EFLAG_VALUES[(eFlags & VARIETY_EFLAG) >>> VARIETY_EFLAG_OFFSET];
175 }
176
177 /**
178 * <!-- begin-user-doc -->
179 * <!-- end-user-doc -->
180 * @generated
181 */
182 @Override
183 public void setVariety(XSDXPathVariety newVariety)
184 {
185 XSDXPathVariety oldVariety = VARIETY_EFLAG_VALUES[(eFlags & VARIETY_EFLAG) >>> VARIETY_EFLAG_OFFSET];
186 if (newVariety == null) newVariety = VARIETY_EDEFAULT;
187 eFlags = eFlags & ~VARIETY_EFLAG | newVariety.ordinal() << VARIETY_EFLAG_OFFSET;
188 if (eNotificationRequired())
189 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_XPATH_DEFINITION__VARIETY, oldVariety, newVariety));
190 }
191
192 /**
193 * <!-- begin-user-doc -->
194 * <!-- end-user-doc -->
195 * @generated
196 */
197 @Override
198 public String getValue()
199 {
200 return value;
201 }
202
203 /**
204 * <!-- begin-user-doc -->
205 * <!-- end-user-doc -->
206 * @generated
207 */
208 @Override
209 public void setValue(String newValue)
210 {
211 String oldValue = value;
212 value = newValue;
213 if (eNotificationRequired())
214 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_XPATH_DEFINITION__VALUE, oldValue, value));
215 }
216
217 /**
218 * <!-- begin-user-doc -->
219 * <!-- end-user-doc -->
220 * @generated
221 */
222 @Override
223 public XSDAnnotation getAnnotation()
224 {
225 return annotation;
226 }
227
228 /**
229 * <!-- begin-user-doc -->
230 * <!-- end-user-doc -->
231 * @generated
232 */
233 @Override
234 public void setAnnotation(XSDAnnotation newAnnotation)
235 {
236 if (newAnnotation != annotation)
237 {
238 NotificationChain msgs = null;
239 if (annotation != null)
240 msgs = ((InternalEObject)annotation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION, null, msgs);
241 if (newAnnotation != null)
242 msgs = ((InternalEObject)newAnnotation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION, null, msgs);
243 msgs = basicSetAnnotation(newAnnotation, msgs);
244 if (msgs != null) msgs.dispatch();
245 }
246 else if (eNotificationRequired())
247 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION, newAnnotation, newAnnotation));
248 }
249
250 /**
251 * <!-- begin-user-doc -->
252 * <!-- end-user-doc -->
253 * @generated
254 */
255 @Override
256 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
257 {
258 switch (featureID)
259 {
260 case XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION:
261 return basicSetAnnotation(null, msgs);
262 }
263 return super.eInverseRemove(otherEnd, featureID, msgs);
264 }
265
266 /**
267 * <!-- begin-user-doc -->
268 * <!-- end-user-doc -->
269 * @generated
270 */
271 public NotificationChain basicSetAnnotation(XSDAnnotation newAnnotation, NotificationChain msgs)
272 {
273 XSDAnnotation oldAnnotation = annotation;
274 annotation = newAnnotation;
275 if (eNotificationRequired())
276 {
277 ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION, oldAnnotation, newAnnotation);
278 if (msgs == null) msgs = notification; else msgs.add(notification);
279 }
280 return msgs;
281 }
282
283 /**
284 * <!-- begin-user-doc -->
285 * <!-- end-user-doc -->
286 * @generated
287 */
288 @Override
289 public Object eGet(int featureID, boolean resolve, boolean coreType)
290 {
291 switch (featureID)
292 {
293 case XSDPackage.XSD_XPATH_DEFINITION__VARIETY:
294 return getVariety();
295 case XSDPackage.XSD_XPATH_DEFINITION__VALUE:
296 return getValue();
297 case XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION:
298 return getAnnotation();
299 }
300 return super.eGet(featureID, resolve, coreType);
301 }
302
303 /**
304 * <!-- begin-user-doc -->
305 * <!-- end-user-doc -->
306 * @generated
307 */
308 @Override
309 public void eSet(int featureID, Object newValue)
310 {
311 switch (featureID)
312 {
313 case XSDPackage.XSD_XPATH_DEFINITION__VARIETY:
314 setVariety((XSDXPathVariety)newValue);
315 return;
316 case XSDPackage.XSD_XPATH_DEFINITION__VALUE:
317 setValue((String)newValue);
318 return;
319 case XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION:
320 setAnnotation((XSDAnnotation)newValue);
321 return;
322 }
323 super.eSet(featureID, newValue);
324 }
325
326 /**
327 * <!-- begin-user-doc -->
328 * <!-- end-user-doc -->
329 * @generated
330 */
331 @Override
332 public void eUnset(int featureID)
333 {
334 switch (featureID)
335 {
336 case XSDPackage.XSD_XPATH_DEFINITION__VARIETY:
337 setVariety(VARIETY_EDEFAULT);
338 return;
339 case XSDPackage.XSD_XPATH_DEFINITION__VALUE:
340 setValue(VALUE_EDEFAULT);
341 return;
342 case XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION:
343 setAnnotation((XSDAnnotation)null);
344 return;
345 }
346 super.eUnset(featureID);
347 }
348
349 /**
350 * <!-- begin-user-doc -->
351 * <!-- end-user-doc -->
352 * @generated
353 */
354 @Override
355 public boolean eIsSet(int featureID)
356 {
357 switch (featureID)
358 {
359 case XSDPackage.XSD_XPATH_DEFINITION__VARIETY:
360 return (eFlags & VARIETY_EFLAG) != VARIETY_EFLAG_DEFAULT;
361 case XSDPackage.XSD_XPATH_DEFINITION__VALUE:
362 return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value);
363 case XSDPackage.XSD_XPATH_DEFINITION__ANNOTATION:
364 return annotation != null;
365 }
366 return super.eIsSet(featureID);
367 }
368
369 /**
370 * <!-- begin-user-doc -->
371 * <!-- end-user-doc -->
372 * @generated
373 */
374 @Override
375 public String toString()
376 {
377 if (eIsProxy()) return super.toString();
378
379 StringBuilder result = new StringBuilder(super.toString());
380 result.append(" (variety: ");
381 result.append(VARIETY_EFLAG_VALUES[(eFlags & VARIETY_EFLAG) >>> VARIETY_EFLAG_OFFSET]);
382 result.append(", value: ");
383 result.append(value);
384 result.append(')');
385 return result.toString();
386 }
387
388 @Override
389 public Element createElement()
390 {
391 Element newElement =
392 createElement
393 (XSDXPathVariety.SELECTOR_LITERAL == getVariety() ?
394 XSDConstants.SELECTOR_ELEMENT :
395 XSDConstants.FIELD_ELEMENT);
396 if (newElement != null)
397 {
398 newElement.setAttributeNS(null, XSDConstants.XPATH_ATTRIBUTE, getValue());
399
400 setElement(newElement);
401 }
402 return newElement;
403 }
404
405 @Override
406 public void validate()
407 {
408 super.validate();
409
410 String anchor = null;
411 String elementName = null;
412 switch (getVariety().getValue())
413 {
414 case XSDXPathVariety.FIELD:
415 {
416 anchor = "element-field";
417 elementName = "field";
418 break;
419 }
420 case XSDXPathVariety.SELECTOR:
421 {
422 anchor = "element-selector";
423 elementName = "selector";
424 break;
425 }
426 }
427
428 Element theElement = getElement();
429 if (theElement != null)
430 {
431 checkAttributes
432 (XSDConstants.PART1,
433 anchor,
434 theElement,
435 new String []
436 {
437 XSDConstants.ID_ATTRIBUTE,
438 XSDConstants.XPATH_ATTRIBUTE
439 });
440
441 checkBuiltInTypeConstraint
442 ("ID",
443 null,
444 XSDConstants.PART1,
445 anchor,
446 theElement,
447 XSDConstants.ID_ATTRIBUTE,
448 false);
449
450 checkComplexContent("annotated", XSDConstants.PART1, anchor, theElement);
451 }
452
453 checkAttributeTypeConstraint
454 ((XSDComplexTypeDefinition)getSchema().getSchemaForSchema().resolveElementDeclaration(elementName).getTypeDefinition(),
455 XSDConstants.XPATH_ATTRIBUTE,
456 getValue(),
457 XSDConstants.PART1,
458 anchor,
459 theElement,
460 XSDConstants.XPATH_ATTRIBUTE,
461 true);
462 }
463
464 @Override
465 protected void reconcileAttributes(Element changedElement)
466 {
467 super.reconcileAttributes(changedElement);
468
469 if (changedElement == getElement())
470 {
471 XSDXPathVariety newVariety = XSDXPathVariety.get(changedElement.getLocalName());
472 if (newVariety != getVariety())
473 {
474 setVariety(newVariety);
475 }
476
477 if (changedElement.hasAttributeNS(null, XSDConstants.XPATH_ATTRIBUTE))
478 {
479 String newValue = changedElement.getAttributeNS(null, XSDConstants.XPATH_ATTRIBUTE);
480 if (newValue == null || !newValue.equals(getValue()))
481 {
482 setValue(newValue);
483 }
484 }
485 else if (getValue() != null)
486 {
487 setValue(null);
488 }
489 }
490 }
491
492 @Override
493 protected void changeAttribute(EAttribute eAttribute)
494 {
495 super.changeAttribute(eAttribute);
496 Element theElement = getElement();
497 if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_XPATH_DEFINITION__VARIETY)
498 {
499 if (theElement != null && eAttribute != null && !isReconciling)
500 {
501 Element newElement =
502 createElement
503 (XSDXPathVariety.SELECTOR_LITERAL == getVariety() ?
504 XSDConstants.SELECTOR_ELEMENT :
505 XSDConstants.FIELD_ELEMENT);
506
507 forceReplace(newElement, theElement);
508 setElement(newElement);
509 }
510 }
511 }
512
513 @Override
514 public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM)
515 {
516 XSDXPathDefinitionImpl clonedXPathDefinition =
517 (XSDXPathDefinitionImpl)getXSDFactory().createXSDXPathDefinition();
518 clonedXPathDefinition.isReconciling = true;
519
520 clonedXPathDefinition.setVariety(getVariety());
521 clonedXPathDefinition.setValue(getValue());
522
523 if (deep)
524 {
525 if (getAnnotation() != null)
526 {
527 clonedXPathDefinition.setAnnotation((XSDAnnotation)getAnnotation().cloneConcreteComponent(deep, shareDOM));
528 }
529 }
530
531 if (shareDOM && getElement() != null)
532 {
533 clonedXPathDefinition.setElement(getElement());
534 }
535
536 clonedXPathDefinition.isReconciling = shareDOM;
537 return clonedXPathDefinition;
538 }
539 }