Debian Codegraph @

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

raw
1 /**
2 * Copyright (c) 2002-2007 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 java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Comparator;
18 import java.util.List;
19
20 import org.w3c.dom.Element;
21 import org.w3c.dom.Node;
22
23 import org.eclipse.emf.common.notify.Notification;
24 import org.eclipse.emf.common.notify.NotificationChain;
25 import org.eclipse.emf.ecore.EAttribute;
26 import org.eclipse.emf.ecore.EClass;
27 import org.eclipse.emf.ecore.EReference;
28 import org.eclipse.emf.ecore.InternalEObject;
29 import org.eclipse.emf.ecore.impl.ENotificationImpl;
30 import org.eclipse.xsd.XSDAttributeDeclaration;
31 import org.eclipse.xsd.XSDAttributeUse;
32 import org.eclipse.xsd.XSDAttributeUseCategory;
33 import org.eclipse.xsd.XSDConcreteComponent;
34 import org.eclipse.xsd.XSDConstraint;
35 import org.eclipse.xsd.XSDDiagnosticSeverity;
36 import org.eclipse.xsd.XSDFactory;
37 import org.eclipse.xsd.XSDPackage;
38 import org.eclipse.xsd.XSDPlugin;
39 import org.eclipse.xsd.XSDSimpleTypeDefinition;
40 import org.eclipse.xsd.util.XSDConstants;
41
42
43 /**
44 * <!-- begin-user-doc -->
45 * An implementation of the model object '<em><b>Attribute Use</b></em>'.
46 * <!-- end-user-doc -->
47 * <p>
48 * The following features are implemented:
49 * </p>
50 * <ul>
51 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#isRequired <em>Required</em>}</li>
52 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#getValue <em>Value</em>}</li>
53 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#getConstraint <em>Constraint</em>}</li>
54 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#getUse <em>Use</em>}</li>
55 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#getLexicalValue <em>Lexical Value</em>}</li>
56 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#getAttributeDeclaration <em>Attribute Declaration</em>}</li>
57 * <li>{@link org.eclipse.xsd.impl.XSDAttributeUseImpl#getContent <em>Content</em>}</li>
58 * </ul>
59 *
60 * @generated
61 */
62 public class XSDAttributeUseImpl
63 extends XSDComponentImpl
64 implements XSDAttributeUse
65 {
66 /**
67 * The default value of the '{@link #isRequired() <em>Required</em>}' attribute.
68 * <!-- begin-user-doc -->
69 * <!-- end-user-doc -->
70 * @see #isRequired()
71 * @generated
72 * @ordered
73 */
74 protected static final boolean REQUIRED_EDEFAULT = false;
75
76 /**
77 * The flag representing the value of the '{@link #isRequired() <em>Required</em>}' attribute.
78 * <!-- begin-user-doc -->
79 * <!-- end-user-doc -->
80 * @see #isRequired()
81 * @generated
82 * @ordered
83 */
84 protected static final int REQUIRED_EFLAG = 1 << 8;
85
86 /**
87 * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
88 * <!-- begin-user-doc -->
89 * <!-- end-user-doc -->
90 * @see #getValue()
91 * @generated
92 * @ordered
93 */
94 protected static final Object VALUE_EDEFAULT = null;
95
96 /**
97 * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
98 * <!-- begin-user-doc -->
99 * <!-- end-user-doc -->
100 * @see #getValue()
101 * @generated
102 * @ordered
103 */
104 protected Object value = VALUE_EDEFAULT;
105
106 /**
107 * The default value of the '{@link #getConstraint() <em>Constraint</em>}' attribute.
108 * <!-- begin-user-doc -->
109 * <!-- end-user-doc -->
110 * @see #getConstraint()
111 * @generated
112 * @ordered
113 */
114 protected static final XSDConstraint CONSTRAINT_EDEFAULT = XSDConstraint.DEFAULT_LITERAL;
115
116 /**
117 * The offset of the flags representing the value of the '{@link #getConstraint() <em>Constraint</em>}' attribute.
118 * <!-- begin-user-doc -->
119 * <!-- end-user-doc -->
120 * @generated
121 * @ordered
122 */
123 protected static final int CONSTRAINT_EFLAG_OFFSET = 9;
124
125 /**
126 * The flags representing the default value of the '{@link #getConstraint() <em>Constraint</em>}' attribute.
127 * <!-- begin-user-doc -->
128 * <!-- end-user-doc -->
129 * @generated
130 * @ordered
131 */
132 protected static final int CONSTRAINT_EFLAG_DEFAULT = CONSTRAINT_EDEFAULT.ordinal() << CONSTRAINT_EFLAG_OFFSET;
133
134 /**
135 * The array of enumeration values for '{@link XSDConstraint Constraint}'
136 * <!-- begin-user-doc -->
137 * <!-- end-user-doc -->
138 * @generated
139 * @ordered
140 */
141 private static final XSDConstraint[] CONSTRAINT_EFLAG_VALUES = XSDConstraint.values();
142
143 /**
144 * The flag representing the value of the '{@link #getConstraint() <em>Constraint</em>}' attribute.
145 * <!-- begin-user-doc -->
146 * <!-- end-user-doc -->
147 * @see #getConstraint()
148 * @generated
149 * @ordered
150 */
151 protected static final int CONSTRAINT_EFLAG = 1 << CONSTRAINT_EFLAG_OFFSET;
152
153 /**
154 * The flag representing whether the Constraint attribute has been set.
155 * <!-- begin-user-doc -->
156 * <!-- end-user-doc -->
157 * @generated
158 * @ordered
159 */
160 protected static final int CONSTRAINT_ESETFLAG = 1 << 10;
161
162 /**
163 * The default value of the '{@link #getUse() <em>Use</em>}' attribute.
164 * <!-- begin-user-doc -->
165 * <!-- end-user-doc -->
166 * @see #getUse()
167 * @generated
168 * @ordered
169 */
170 protected static final XSDAttributeUseCategory USE_EDEFAULT = XSDAttributeUseCategory.OPTIONAL_LITERAL;
171
172 /**
173 * The offset of the flags representing the value of the '{@link #getUse() <em>Use</em>}' attribute.
174 * <!-- begin-user-doc -->
175 * <!-- end-user-doc -->
176 * @generated
177 * @ordered
178 */
179 protected static final int USE_EFLAG_OFFSET = 11;
180
181 /**
182 * The flags representing the default value of the '{@link #getUse() <em>Use</em>}' attribute.
183 * <!-- begin-user-doc -->
184 * <!-- end-user-doc -->
185 * @generated
186 * @ordered
187 */
188 protected static final int USE_EFLAG_DEFAULT = USE_EDEFAULT.ordinal() << USE_EFLAG_OFFSET;
189
190 /**
191 * The array of enumeration values for '{@link XSDAttributeUseCategory Attribute Use Category}'
192 * <!-- begin-user-doc -->
193 * <!-- end-user-doc -->
194 * @generated
195 * @ordered
196 */
197 private static final XSDAttributeUseCategory[] USE_EFLAG_VALUES = XSDAttributeUseCategory.values();
198
199 /**
200 * The flags representing the value of the '{@link #getUse() <em>Use</em>}' attribute.
201 * <!-- begin-user-doc -->
202 * <!-- end-user-doc -->
203 * @see #getUse()
204 * @generated
205 * @ordered
206 */
207 protected static final int USE_EFLAG = 0x3 << USE_EFLAG_OFFSET;
208
209 /**
210 * The flag representing whether the Use attribute has been set.
211 * <!-- begin-user-doc -->
212 * <!-- end-user-doc -->
213 * @generated
214 * @ordered
215 */
216 protected static final int USE_ESETFLAG = 1 << 13;
217
218 /**
219 * The default value of the '{@link #getLexicalValue() <em>Lexical Value</em>}' attribute.
220 * <!-- begin-user-doc -->
221 * <!-- end-user-doc -->
222 * @see #getLexicalValue()
223 * @generated
224 * @ordered
225 */
226 protected static final String LEXICAL_VALUE_EDEFAULT = null;
227
228 /**
229 * The cached value of the '{@link #getLexicalValue() <em>Lexical Value</em>}' attribute.
230 * <!-- begin-user-doc -->
231 * <!-- end-user-doc -->
232 * @see #getLexicalValue()
233 * @generated
234 * @ordered
235 */
236 protected String lexicalValue = LEXICAL_VALUE_EDEFAULT;
237
238 /**
239 * The cached value of the '{@link #getAttributeDeclaration() <em>Attribute Declaration</em>}' reference.
240 * <!-- begin-user-doc -->
241 * <!-- end-user-doc -->
242 * @see #getAttributeDeclaration()
243 * @generated
244 * @ordered
245 */
246 protected XSDAttributeDeclaration attributeDeclaration;
247
248 /**
249 * The cached value of the '{@link #getContent() <em>Content</em>}' containment reference.
250 * <!-- begin-user-doc -->
251 * <!-- end-user-doc -->
252 * @see #getContent()
253 * @generated
254 * @ordered
255 */
256 protected XSDAttributeDeclaration content;
257
258 public static XSDAttributeUse createAttributeUse(Node node)
259 {
260 if (XSDConstants.nodeType(node) == XSDConstants.ATTRIBUTE_ELEMENT)
261 {
262 XSDAttributeUse xsdAttributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse();
263 xsdAttributeUse.setElement((Element)node);
264
265 XSDAttributeDeclaration xsdAttributeDeclaration = XSDAttributeDeclarationImpl.createAttributeDeclaration(node);
266 xsdAttributeUse.setContent(xsdAttributeDeclaration);
267 return xsdAttributeUse;
268 }
269
270 return null;
271 }
272
273 public static List<XSDAttributeUse> sortAttributeUses(Collection<XSDAttributeUse> xsdAttributeUses)
274 {
275 XSDAttributeUse [] objects = new XSDAttributeUse[xsdAttributeUses.size()];
276 objects = xsdAttributeUses.toArray(objects);
277 Arrays.sort
278 (objects,
279 new Comparator<XSDAttributeUse>()
280 {
281 Comparator<String> collator = XSDPlugin.INSTANCE.getComparator();
282
283 @Override
284 public boolean equals(Object that)
285 {
286 return this == that;
287 }
288
289 public int compare(XSDAttributeUse o1, XSDAttributeUse o2)
290 {
291 String name1 = o1.getContent().getResolvedAttributeDeclaration().getName();
292 String name2 = o2.getContent().getResolvedAttributeDeclaration().getName();
293 if (name1 == null && name2 == null)
294 {
295 return 0;
296 }
297 else if (name1 == null)
298 {
299 return 1;
300 }
301 else if (name2 == null)
302 {
303 return -1;
304 }
305 else
306 {
307 return collator.compare(name1, name2);
308 }
309 }
310 });
311
312 return Arrays.asList(objects);
313 }
314
315 /**
316 * <!-- begin-user-doc -->
317 * <!-- end-user-doc -->
318 * @generated
319 */
320 protected XSDAttributeUseImpl()
321 {
322 super();
323 }
324
325 /**
326 * <!-- begin-user-doc -->
327 * <!-- end-user-doc -->
328 * @generated
329 */
330 @Override
331 protected EClass eStaticClass()
332 {
333 return XSDPackage.Literals.XSD_ATTRIBUTE_USE;
334 }
335
336 /**
337 * <!-- begin-user-doc -->
338 * <!-- end-user-doc -->
339 * @generated
340 */
341 @Override
342 public boolean isRequired()
343 {
344 return (eFlags & REQUIRED_EFLAG) != 0;
345 }
346
347 /**
348 * <!-- begin-user-doc -->
349 * <!-- end-user-doc -->
350 * @generated
351 */
352 @Override
353 public void setRequired(boolean newRequired)
354 {
355 boolean oldRequired = (eFlags & REQUIRED_EFLAG) != 0;
356 if (newRequired) eFlags |= REQUIRED_EFLAG; else eFlags &= ~REQUIRED_EFLAG;
357 if (eNotificationRequired())
358 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__REQUIRED, oldRequired, newRequired));
359 }
360
361 /**
362 * <!-- begin-user-doc -->
363 * <!-- end-user-doc -->
364 * @generated
365 */
366 @Override
367 public Object getValue()
368 {
369 return value;
370 }
371
372 /**
373 * <!-- begin-user-doc -->
374 * <!-- end-user-doc -->
375 * @generated
376 */
377 @Override
378 public void setValue(Object newValue)
379 {
380 Object oldValue = value;
381 value = newValue;
382 if (eNotificationRequired())
383 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__VALUE, oldValue, value));
384 }
385
386 /**
387 * <!-- begin-user-doc -->
388 * <!-- end-user-doc -->
389 * @generated
390 */
391 @Override
392 public XSDConstraint getConstraint()
393 {
394 return CONSTRAINT_EFLAG_VALUES[(eFlags & CONSTRAINT_EFLAG) >>> CONSTRAINT_EFLAG_OFFSET];
395 }
396
397 /**
398 * <!-- begin-user-doc -->
399 * <!-- end-user-doc -->
400 * @generated
401 */
402 @Override
403 public void setConstraint(XSDConstraint newConstraint)
404 {
405 XSDConstraint oldConstraint = CONSTRAINT_EFLAG_VALUES[(eFlags & CONSTRAINT_EFLAG) >>> CONSTRAINT_EFLAG_OFFSET];
406 if (newConstraint == null) newConstraint = CONSTRAINT_EDEFAULT;
407 eFlags = eFlags & ~CONSTRAINT_EFLAG | newConstraint.ordinal() << CONSTRAINT_EFLAG_OFFSET;
408 boolean oldConstraintESet = (eFlags & CONSTRAINT_ESETFLAG) != 0;
409 eFlags |= CONSTRAINT_ESETFLAG;
410 if (eNotificationRequired())
411 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__CONSTRAINT, oldConstraint, newConstraint, !oldConstraintESet));
412 }
413
414 /**
415 * <!-- begin-user-doc -->
416 * <!-- end-user-doc -->
417 * @generated
418 */
419 @Override
420 public void unsetConstraint()
421 {
422 XSDConstraint oldConstraint = CONSTRAINT_EFLAG_VALUES[(eFlags & CONSTRAINT_EFLAG) >>> CONSTRAINT_EFLAG_OFFSET];
423 boolean oldConstraintESet = (eFlags & CONSTRAINT_ESETFLAG) != 0;
424 eFlags = eFlags & ~CONSTRAINT_EFLAG | CONSTRAINT_EFLAG_DEFAULT;
425 eFlags &= ~CONSTRAINT_ESETFLAG;
426 if (eNotificationRequired())
427 eNotify(new ENotificationImpl(this, Notification.UNSET, XSDPackage.XSD_ATTRIBUTE_USE__CONSTRAINT, oldConstraint, CONSTRAINT_EDEFAULT, oldConstraintESet));
428 }
429
430 /**
431 * <!-- begin-user-doc -->
432 * <!-- end-user-doc -->
433 * @generated
434 */
435 @Override
436 public boolean isSetConstraint()
437 {
438 return (eFlags & CONSTRAINT_ESETFLAG) != 0;
439 }
440
441 /**
442 * <!-- begin-user-doc -->
443 * <!-- end-user-doc -->
444 * @generated
445 */
446 @Override
447 public XSDAttributeUseCategory getUse()
448 {
449 return USE_EFLAG_VALUES[(eFlags & USE_EFLAG) >>> USE_EFLAG_OFFSET];
450 }
451
452 /**
453 * <!-- begin-user-doc -->
454 * <!-- end-user-doc -->
455 * @generated
456 */
457 @Override
458 public void setUse(XSDAttributeUseCategory newUse)
459 {
460 XSDAttributeUseCategory oldUse = USE_EFLAG_VALUES[(eFlags & USE_EFLAG) >>> USE_EFLAG_OFFSET];
461 if (newUse == null) newUse = USE_EDEFAULT;
462 eFlags = eFlags & ~USE_EFLAG | newUse.ordinal() << USE_EFLAG_OFFSET;
463 boolean oldUseESet = (eFlags & USE_ESETFLAG) != 0;
464 eFlags |= USE_ESETFLAG;
465 if (eNotificationRequired())
466 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__USE, oldUse, newUse, !oldUseESet));
467 }
468
469 /**
470 * <!-- begin-user-doc -->
471 * <!-- end-user-doc -->
472 * @generated
473 */
474 @Override
475 public void unsetUse()
476 {
477 XSDAttributeUseCategory oldUse = USE_EFLAG_VALUES[(eFlags & USE_EFLAG) >>> USE_EFLAG_OFFSET];
478 boolean oldUseESet = (eFlags & USE_ESETFLAG) != 0;
479 eFlags = eFlags & ~USE_EFLAG | USE_EFLAG_DEFAULT;
480 eFlags &= ~USE_ESETFLAG;
481 if (eNotificationRequired())
482 eNotify(new ENotificationImpl(this, Notification.UNSET, XSDPackage.XSD_ATTRIBUTE_USE__USE, oldUse, USE_EDEFAULT, oldUseESet));
483 }
484
485 /**
486 * <!-- begin-user-doc -->
487 * <!-- end-user-doc -->
488 * @generated
489 */
490 @Override
491 public boolean isSetUse()
492 {
493 return (eFlags & USE_ESETFLAG) != 0;
494 }
495
496 /**
497 * <!-- begin-user-doc -->
498 * <!-- end-user-doc -->
499 * @generated
500 */
501 @Override
502 public String getLexicalValue()
503 {
504 return lexicalValue;
505 }
506
507 /**
508 * <!-- begin-user-doc -->
509 * <!-- end-user-doc -->
510 * @generated
511 */
512 @Override
513 public void setLexicalValue(String newLexicalValue)
514 {
515 String oldLexicalValue = lexicalValue;
516 lexicalValue = newLexicalValue;
517 if (eNotificationRequired())
518 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__LEXICAL_VALUE, oldLexicalValue, lexicalValue));
519 }
520
521 /**
522 * <!-- begin-user-doc -->
523 * <!-- end-user-doc -->
524 * @generated
525 */
526 @Override
527 public XSDAttributeDeclaration getAttributeDeclaration()
528 {
529 return attributeDeclaration;
530 }
531
532 /**
533 * <!-- begin-user-doc -->
534 * <!-- end-user-doc -->
535 * @generated
536 */
537 @Override
538 public void setAttributeDeclaration(XSDAttributeDeclaration newAttributeDeclaration)
539 {
540 XSDAttributeDeclaration oldAttributeDeclaration = attributeDeclaration;
541 attributeDeclaration = newAttributeDeclaration;
542 if (eNotificationRequired())
543 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__ATTRIBUTE_DECLARATION, oldAttributeDeclaration, attributeDeclaration));
544 }
545
546 /**
547 * <!-- begin-user-doc -->
548 * <!-- end-user-doc -->
549 * @generated
550 */
551 @Override
552 public XSDAttributeDeclaration getContent()
553 {
554 return content;
555 }
556
557 /**
558 * <!-- begin-user-doc -->
559 * <!-- end-user-doc -->
560 * @generated
561 */
562 @Override
563 public void setContent(XSDAttributeDeclaration newContent)
564 {
565 if (newContent != content)
566 {
567 NotificationChain msgs = null;
568 if (content != null)
569 msgs = ((InternalEObject)content).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_ATTRIBUTE_USE__CONTENT, null, msgs);
570 if (newContent != null)
571 msgs = ((InternalEObject)newContent).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_ATTRIBUTE_USE__CONTENT, null, msgs);
572 msgs = basicSetContent(newContent, msgs);
573 if (msgs != null) msgs.dispatch();
574 }
575 else if (eNotificationRequired())
576 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__CONTENT, newContent, newContent));
577 }
578
579 /**
580 * <!-- begin-user-doc -->
581 * <!-- end-user-doc -->
582 * @generated
583 */
584 @Override
585 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
586 {
587 switch (featureID)
588 {
589 case XSDPackage.XSD_ATTRIBUTE_USE__CONTENT:
590 return basicSetContent(null, msgs);
591 }
592 return super.eInverseRemove(otherEnd, featureID, msgs);
593 }
594
595 /**
596 * <!-- begin-user-doc -->
597 * <!-- end-user-doc -->
598 * @generated
599 */
600 public NotificationChain basicSetContent(XSDAttributeDeclaration newContent, NotificationChain msgs)
601 {
602 XSDAttributeDeclaration oldContent = content;
603 content = newContent;
604 if (eNotificationRequired())
605 {
606 ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_ATTRIBUTE_USE__CONTENT, oldContent, newContent);
607 if (msgs == null) msgs = notification; else msgs.add(notification);
608 }
609 return msgs;
610 }
611
612 /**
613 * <!-- begin-user-doc -->
614 * <!-- end-user-doc -->
615 * @generated
616 */
617 @Override
618 public Object eGet(int featureID, boolean resolve, boolean coreType)
619 {
620 switch (featureID)
621 {
622 case XSDPackage.XSD_ATTRIBUTE_USE__REQUIRED:
623 return isRequired();
624 case XSDPackage.XSD_ATTRIBUTE_USE__VALUE:
625 return getValue();
626 case XSDPackage.XSD_ATTRIBUTE_USE__CONSTRAINT:
627 return getConstraint();
628 case XSDPackage.XSD_ATTRIBUTE_USE__USE:
629 return getUse();
630 case XSDPackage.XSD_ATTRIBUTE_USE__LEXICAL_VALUE:
631 return getLexicalValue();
632 case XSDPackage.XSD_ATTRIBUTE_USE__ATTRIBUTE_DECLARATION:
633 return getAttributeDeclaration();
634 case XSDPackage.XSD_ATTRIBUTE_USE__CONTENT:
635 return getContent();
636 }
637 return super.eGet(featureID, resolve, coreType);
638 }
639
640 /**
641 * <!-- begin-user-doc -->
642 * <!-- end-user-doc -->
643 * @generated
644 */
645 @Override
646 public void eSet(int featureID, Object newValue)
647 {
648 switch (featureID)
649 {
650 case XSDPackage.XSD_ATTRIBUTE_USE__REQUIRED:
651 setRequired((Boolean)newValue);
652 return;
653 case XSDPackage.XSD_ATTRIBUTE_USE__VALUE:
654 setValue(newValue);
655 return;
656 case XSDPackage.XSD_ATTRIBUTE_USE__CONSTRAINT:
657 setConstraint((XSDConstraint)newValue);
658 return;
659 case XSDPackage.XSD_ATTRIBUTE_USE__USE:
660 setUse((XSDAttributeUseCategory)newValue);
661 return;
662 case XSDPackage.XSD_ATTRIBUTE_USE__LEXICAL_VALUE:
663 setLexicalValue((String)newValue);
664 return;
665 case XSDPackage.XSD_ATTRIBUTE_USE__ATTRIBUTE_DECLARATION:
666 setAttributeDeclaration((XSDAttributeDeclaration)newValue);
667 return;
668 case XSDPackage.XSD_ATTRIBUTE_USE__CONTENT:
669 setContent((XSDAttributeDeclaration)newValue);
670 return;
671 }
672 super.eSet(featureID, newValue);
673 }
674
675 /**
676 * <!-- begin-user-doc -->
677 * <!-- end-user-doc -->
678 * @generated
679 */
680 @Override
681 public void eUnset(int featureID)
682 {
683 switch (featureID)
684 {
685 case XSDPackage.XSD_ATTRIBUTE_USE__REQUIRED:
686 setRequired(REQUIRED_EDEFAULT);
687 return;
688 case XSDPackage.XSD_ATTRIBUTE_USE__VALUE:
689 setValue(VALUE_EDEFAULT);
690 return;
691 case XSDPackage.XSD_ATTRIBUTE_USE__CONSTRAINT:
692 unsetConstraint();
693 return;
694 case XSDPackage.XSD_ATTRIBUTE_USE__USE:
695 unsetUse();
696 return;
697 case XSDPackage.XSD_ATTRIBUTE_USE__LEXICAL_VALUE:
698 setLexicalValue(LEXICAL_VALUE_EDEFAULT);
699 return;
700 case XSDPackage.XSD_ATTRIBUTE_USE__ATTRIBUTE_DECLARATION:
701 setAttributeDeclaration((XSDAttributeDeclaration)null);
702 return;
703 case XSDPackage.XSD_ATTRIBUTE_USE__CONTENT:
704 setContent((XSDAttributeDeclaration)null);
705 return;
706 }
707 super.eUnset(featureID);
708 }
709
710 /**
711 * <!-- begin-user-doc -->
712 * <!-- end-user-doc -->
713 * @generated
714 */
715 @Override
716 public boolean eIsSet(int featureID)
717 {
718 switch (featureID)
719 {
720 case XSDPackage.XSD_ATTRIBUTE_USE__REQUIRED:
721 return ((eFlags & REQUIRED_EFLAG) != 0) != REQUIRED_EDEFAULT;
722 case XSDPackage.XSD_ATTRIBUTE_USE__VALUE:
723 return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value);
724 case XSDPackage.XSD_ATTRIBUTE_USE__CONSTRAINT:
725 return isSetConstraint();
726 case XSDPackage.XSD_ATTRIBUTE_USE__USE:
727 return isSetUse();
728 case XSDPackage.XSD_ATTRIBUTE_USE__LEXICAL_VALUE:
729 return LEXICAL_VALUE_EDEFAULT == null ? lexicalValue != null : !LEXICAL_VALUE_EDEFAULT.equals(lexicalValue);
730 case XSDPackage.XSD_ATTRIBUTE_USE__ATTRIBUTE_DECLARATION:
731 return attributeDeclaration != null;
732 case XSDPackage.XSD_ATTRIBUTE_USE__CONTENT:
733 return content != null;
734 }
735 return super.eIsSet(featureID);
736 }
737
738 /**
739 * <!-- begin-user-doc -->
740 * <!-- end-user-doc -->
741 * @generated
742 */
743 @Override
744 public String toString()
745 {
746 if (eIsProxy()) return super.toString();
747
748 StringBuilder result = new StringBuilder(super.toString());
749 result.append(" (required: ");
750 result.append((eFlags & REQUIRED_EFLAG) != 0);
751 result.append(", value: ");
752 result.append(value);
753 result.append(", constraint: ");
754 if ((eFlags & CONSTRAINT_ESETFLAG) != 0) result.append(CONSTRAINT_EFLAG_VALUES[(eFlags & CONSTRAINT_EFLAG) >>> CONSTRAINT_EFLAG_OFFSET]); else result.append("<unset>");
755 result.append(", use: ");
756 if ((eFlags & USE_ESETFLAG) != 0) result.append(USE_EFLAG_VALUES[(eFlags & USE_EFLAG) >>> USE_EFLAG_OFFSET]); else result.append("<unset>");
757 result.append(", lexicalValue: ");
758 result.append(lexicalValue);
759 result.append(')');
760 return result.toString();
761 }
762
763 @Override
764 public Element createElement()
765 {
766 Element newElement = null;
767 XSDAttributeDeclaration theContent = getContent();
768 if (theContent != null)
769 {
770 newElement = ((XSDConcreteComponentImpl)theContent).createElement();
771 setElement(newElement);
772 }
773 return newElement;
774 }
775
776 @Override
777 protected void patch()
778 {
779 super.patch();
780 patchHelper();
781 }
782
783 protected void patchHelper()
784 {
785 XSDAttributeDeclaration newAttributeDeclaration = getContent();
786 if (newAttributeDeclaration != null)
787 {
788 newAttributeDeclaration = newAttributeDeclaration.getResolvedAttributeDeclaration();
789 }
790
791 if (newAttributeDeclaration != getAttributeDeclaration())
792 {
793 setAttributeDeclaration(newAttributeDeclaration);
794 }
795 }
796
797 @Override
798 protected boolean analyze()
799 {
800 super.analyze();
801 Object newValue = null;
802 XSDSimpleTypeDefinition xsdSimpleTypeDefinition = getAttributeDeclaration().getTypeDefinition();
803 if (xsdSimpleTypeDefinition != null)
804 {
805 String theLexicalValue = getLexicalValue();
806 if (theLexicalValue != null)
807 {
808 try
809 {
810 newValue = xsdSimpleTypeDefinition.getValue(getElement(), theLexicalValue);
811 }
812 catch (RuntimeException exception)
813 {
814 // Ignore.
815 }
816 }
817 }
818
819 if (newValue == null ? getValue() != null : !newValue.equals(getValue()))
820 {
821 setValue(newValue);
822 }
823
824 return true;
825 }
826
827 @Override
828 public void validate()
829 {
830 super.validate();
831
832 if (getLexicalValue() != null)
833 {
834 XSDAttributeDeclaration theAttributeDeclaration = getAttributeDeclaration();
835 XSDSimpleTypeDefinition theTypeDefinition = theAttributeDeclaration.getTypeDefinition();
836 Element theElement = getElement();
837 if (theTypeDefinition != null)
838 {
839 if (XSDConstants.isOrIsDerivedFromID(theTypeDefinition))
840 {
841 createDiagnostic(XSDDiagnosticSeverity.ERROR_LITERAL, "coss-attribute.3");
842 }
843 else
844 {
845 checkSimpleTypeConstraint
846 (theTypeDefinition,
847 getLexicalValue(),
848 XSDConstants.PART1,
849 "element-attribute",
850 theElement,
851 getConstraint() == XSDConstraint.FIXED_LITERAL ? XSDConstants.FIXED_ATTRIBUTE : XSDConstants.DEFAULT_ATTRIBUTE,
852 false);
853 }
854 }
855
856 if (theAttributeDeclaration.getConstraint() == XSDConstraint.FIXED_LITERAL &&
857 theAttributeDeclaration.getLexicalValue() != null &&
858 (getConstraint() != XSDConstraint.FIXED_LITERAL ||
859 theTypeDefinition != null && !theTypeDefinition.equalLiterals(theAttributeDeclaration.getElement(), theAttributeDeclaration.getLexicalValue(), theElement, getLexicalValue())))
860 {
861 createDiagnostic
862 (XSDDiagnosticSeverity.ERROR_LITERAL, "coss-attruse.2", getLexicalValue(), theAttributeDeclaration.getLexicalValue());
863 }
864
865 if (getConstraint() == XSDConstraint.DEFAULT_LITERAL &&
866 isSetUse() && getUse() != XSDAttributeUseCategory.OPTIONAL_LITERAL)
867 {
868 createDiagnostic(XSDDiagnosticSeverity.ERROR_LITERAL, "src-attribute.2");
869 }
870 }
871 }
872
873 @Override
874 protected Collection<Element> getContentNodes(Element changedElement)
875 {
876 return Collections.singleton(getElement());
877 }
878
879 @Override
880 protected void reconcileAttributes(Element changedElement)
881 {
882 super.reconcileAttributes(changedElement);
883
884 if (changedElement == getElement())
885 {
886 XSDAttributeUseCategory newUse = null;
887 if (getElement().hasAttributeNS(null, XSDConstants.USE_ATTRIBUTE))
888 {
889 newUse = XSDAttributeUseCategory.get(getElement().getAttributeNS(null, XSDConstants.USE_ATTRIBUTE));
890 }
891
892 boolean newRequired = false;
893 XSDConstraint newConstraint = null;
894 String newLexicalValue = null;
895
896 if (newUse != XSDAttributeUseCategory.PROHIBITED_LITERAL)
897 {
898 newRequired = newUse == XSDAttributeUseCategory.REQUIRED_LITERAL;
899 if (getElement().hasAttributeNS(null, XSDConstants.FIXED_ATTRIBUTE))
900 {
901 newLexicalValue = getElement().getAttributeNS(null, XSDConstants.FIXED_ATTRIBUTE);
902 if (newLexicalValue != null)
903 {
904 newConstraint = XSDConstraint.FIXED_LITERAL;
905 }
906 }
907 else if (getElement().hasAttributeNS(null, XSDConstants.DEFAULT_ATTRIBUTE))
908 {
909 newLexicalValue = getElement().getAttributeNS(null, XSDConstants.DEFAULT_ATTRIBUTE);
910 if (newLexicalValue != null)
911 {
912 newConstraint = XSDConstraint.DEFAULT_LITERAL;
913 }
914 }
915 }
916
917 if (newUse == null)
918 {
919 if (isSetUse())
920 {
921 unsetUse();
922 }
923 }
924 else if (!isSetUse() || newUse != getUse())
925 {
926 setUse(newUse);
927 }
928
929 if (newRequired != isRequired())
930 {
931 setRequired(newRequired);
932 }
933
934 if (newConstraint == null)
935 {
936 if (isSetConstraint())
937 {
938 unsetConstraint();
939 }
940 }
941 else if (!isSetConstraint() || newConstraint != getConstraint())
942 {
943 setConstraint(newConstraint);
944 }
945
946 if (newLexicalValue == null ? getLexicalValue() != null : !newLexicalValue.equals(getLexicalValue()))
947 {
948 setLexicalValue(newLexicalValue);
949 }
950
951 XSDAttributeDeclaration theContent = getContent();
952 if (theContent != null)
953 {
954 theContent.elementAttributesChanged(changedElement);
955 }
956 }
957 }
958
959 @Override
960 protected void reconcileContents(Element changedElement)
961 {
962 super.reconcileContents(changedElement);
963 if (changedElement == getElement())
964 {
965 XSDAttributeDeclaration theContent = getContent();
966 if (theContent != null)
967 {
968 theContent.elementContentsChanged(changedElement);
969 XSDAttributeDeclaration newAttributeDeclaration = theContent.getResolvedAttributeDeclaration();
970 if (newAttributeDeclaration != getAttributeDeclaration())
971 {
972 setAttributeDeclaration(newAttributeDeclaration);
973 }
974 }
975 }
976 }
977
978 @Override
979 protected void changeAttribute(EAttribute eAttribute)
980 {
981 if (isReconciling)
982 {
983 return;
984 }
985
986 super.changeAttribute(eAttribute);
987 Element theElement = getElement();
988 if (theElement != null)
989 {
990 if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_ATTRIBUTE_USE__USE)
991 {
992 niceSetAttribute(theElement, XSDConstants.USE_ATTRIBUTE, isSetUse() ? getUse().getName() : null);
993 }
994
995 if (eAttribute == null ||
996 eAttribute == XSDPackage.Literals.XSD_FEATURE__LEXICAL_VALUE ||
997 eAttribute == XSDPackage.Literals.XSD_ATTRIBUTE_USE__CONSTRAINT)
998 {
999 if (getLexicalValue() != null)
1000 {
1001 switch (getConstraint().getValue())
1002 {
1003 case XSDConstraint.FIXED:
1004 {
1005 niceSetAttribute(theElement, XSDConstants.FIXED_ATTRIBUTE, getLexicalValue());
1006 if (theElement.hasAttributeNS(null, XSDConstants.DEFAULT_ATTRIBUTE))
1007 {
1008 niceSetAttribute(theElement, XSDConstants.DEFAULT_ATTRIBUTE, null);
1009 }
1010 break;
1011 }
1012 case XSDConstraint.DEFAULT:
1013 {
1014 niceSetAttribute(theElement, XSDConstants.DEFAULT_ATTRIBUTE, getLexicalValue());
1015 if (theElement.hasAttributeNS(null, XSDConstants.FIXED_ATTRIBUTE))
1016 {
1017 niceSetAttribute(theElement, XSDConstants.FIXED_ATTRIBUTE, null);
1018 }
1019 break;
1020 }
1021 }
1022 }
1023 else
1024 {
1025 if (theElement.hasAttributeNS(null, XSDConstants.FIXED_ATTRIBUTE))
1026 {
1027 niceSetAttribute(theElement, XSDConstants.FIXED_ATTRIBUTE, null);
1028 }
1029 if (theElement.hasAttributeNS(null, XSDConstants.DEFAULT_ATTRIBUTE))
1030 {
1031 niceSetAttribute(theElement, XSDConstants.DEFAULT_ATTRIBUTE, null);
1032 }
1033 }
1034 }
1035 }
1036 }
1037
1038 @Override
1039 protected void adoptContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent)
1040 {
1041 super.adoptContent(eReference, xsdConcreteComponent);
1042 if (eReference == XSDPackage.Literals.XSD_ATTRIBUTE_USE__CONTENT)
1043 {
1044 patchHelper();
1045 traverseToRootForPatching();
1046 }
1047 }
1048
1049 @Override
1050 protected void orphanContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent)
1051 {
1052 super.orphanContent(eReference, xsdConcreteComponent);
1053 if (eReference == XSDPackage.Literals.XSD_ATTRIBUTE_USE__CONTENT)
1054 {
1055 patchHelper();
1056 traverseToRootForPatching();
1057 }
1058 }
1059
1060 @Override
1061 public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM)
1062 {
1063 XSDAttributeUseImpl clonedAttributeUse =
1064 (XSDAttributeUseImpl)getXSDFactory().createXSDAttributeUse();
1065 clonedAttributeUse.isReconciling = true;
1066
1067 if (isSetUse())
1068 {
1069 clonedAttributeUse.setUse(getUse());
1070 }
1071
1072 clonedAttributeUse.setRequired(isRequired());
1073
1074 if (isSetConstraint())
1075 {
1076 clonedAttributeUse.setConstraint(getConstraint());
1077 }
1078 if (getLexicalValue() != null)
1079 {
1080 clonedAttributeUse.setLexicalValue(getLexicalValue());
1081 }
1082
1083 clonedAttributeUse.setContent((XSDAttributeDeclaration)getContent().cloneConcreteComponent(deep, shareDOM));
1084
1085 if (shareDOM && getElement() != null)
1086 {
1087 clonedAttributeUse.setElement(getElement());
1088 }
1089
1090 clonedAttributeUse.isReconciling = shareDOM;
1091 return clonedAttributeUse;
1092 }
1093 }