Debian Codegraph @

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