Debian Codegraph @

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

raw
1 /**
2 * Copyright (c) 2002-2009 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.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.ListIterator;
21 import java.util.Map;
22 import java.util.StringTokenizer;
23
24 import org.w3c.dom.Attr;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
27 import org.w3c.dom.NamedNodeMap;
28 import org.w3c.dom.Node;
29 import org.w3c.dom.Text;
30
31 import org.eclipse.emf.common.notify.Notification;
32 import org.eclipse.emf.common.notify.NotificationChain;
33 import org.eclipse.emf.common.util.BasicEList;
34 import org.eclipse.emf.common.util.EList;
35 import org.eclipse.emf.ecore.EAttribute;
36 import org.eclipse.emf.ecore.EClass;
37 import org.eclipse.emf.ecore.EObject;
38 import org.eclipse.emf.ecore.EReference;
39 import org.eclipse.emf.ecore.EStructuralFeature;
40 import org.eclipse.emf.ecore.InternalEObject;
41 import org.eclipse.emf.ecore.impl.ENotificationImpl;
42 import org.eclipse.emf.ecore.impl.EObjectImpl;
43 import org.eclipse.emf.ecore.util.EContentsEList;
44 import org.eclipse.emf.ecore.util.EObjectContainmentEList;
45 import org.eclipse.emf.ecore.util.EcoreUtil;
46 import org.eclipse.emf.ecore.util.InternalEList;
47 import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;
48
49 import org.eclipse.xsd.XSDAnnotation;
50 import org.eclipse.xsd.XSDAttributeDeclaration;
51 import org.eclipse.xsd.XSDAttributeGroupDefinition;
52 import org.eclipse.xsd.XSDAttributeUse;
53 import org.eclipse.xsd.XSDComplexTypeDefinition;
54 import org.eclipse.xsd.XSDCompositor;
55 import org.eclipse.xsd.XSDConcreteComponent;
56 import org.eclipse.xsd.XSDDiagnostic;
57 import org.eclipse.xsd.XSDDiagnosticSeverity;
58 import org.eclipse.xsd.XSDElementDeclaration;
59 import org.eclipse.xsd.XSDFactory;
60 import org.eclipse.xsd.XSDIdentityConstraintCategory;
61 import org.eclipse.xsd.XSDIdentityConstraintDefinition;
62 import org.eclipse.xsd.XSDModelGroup;
63 import org.eclipse.xsd.XSDModelGroupDefinition;
64 import org.eclipse.xsd.XSDNotationDeclaration;
65 import org.eclipse.xsd.XSDPackage;
66 import org.eclipse.xsd.XSDParticle;
67 import org.eclipse.xsd.XSDPlugin;
68 import org.eclipse.xsd.XSDSchema;
69 import org.eclipse.xsd.XSDSimpleTypeDefinition;
70 import org.eclipse.xsd.XSDTypeDefinition;
71 import org.eclipse.xsd.XSDVariety;
72 import org.eclipse.xsd.util.XSDConstants;
73 import org.eclipse.xsd.util.XSDUtil;
74
75
76 /**
77 * <!-- begin-user-doc -->
78 * An implementation of the model object '<em><b>Concrete Component</b></em>'.
79 * <!-- end-user-doc -->
80 * <p>
81 * The following features are implemented:
82 * </p>
83 * <ul>
84 * <li>{@link org.eclipse.xsd.impl.XSDConcreteComponentImpl#getElement <em>Element</em>}</li>
85 * <li>{@link org.eclipse.xsd.impl.XSDConcreteComponentImpl#getContainer <em>Container</em>}</li>
86 * <li>{@link org.eclipse.xsd.impl.XSDConcreteComponentImpl#getRootContainer <em>Root Container</em>}</li>
87 * <li>{@link org.eclipse.xsd.impl.XSDConcreteComponentImpl#getSchema <em>Schema</em>}</li>
88 * <li>{@link org.eclipse.xsd.impl.XSDConcreteComponentImpl#getDiagnostics <em>Diagnostics</em>}</li>
89 * </ul>
90 *
91 * @generated
92 */
93 public abstract class XSDConcreteComponentImpl
94 extends EObjectImpl
95 implements XSDConcreteComponent
96 {
97 /**
98 * The default value of the '{@link #getElement() <em>Element</em>}' attribute.
99 * <!-- begin-user-doc -->
100 * <!-- end-user-doc -->
101 * @see #getElement()
102 * @generated
103 * @ordered
104 */
105 protected static final Element ELEMENT_EDEFAULT = null;
106
107 /**
108 * The cached value of the '{@link #getElement() <em>Element</em>}' attribute.
109 * <!-- begin-user-doc -->
110 * <!-- end-user-doc -->
111 * @see #getElement()
112 * @generated
113 * @ordered
114 */
115 protected Element element = ELEMENT_EDEFAULT;
116
117 /**
118 * The cached value of the '{@link #getDiagnostics() <em>Diagnostics</em>}' containment reference list.
119 * <!-- begin-user-doc -->
120 * <!-- end-user-doc -->
121 * @see #getDiagnostics()
122 * @generated
123 * @ordered
124 */
125 protected EList<XSDDiagnostic> diagnostics;
126
127 protected static final int FATAL=0;
128 protected static final int ERROR=1;
129 protected static final int WARNING=2;
130 protected static final int INFORMATION=3;
131
132 protected boolean updatingDOM;
133 protected boolean isReconciling;
134 protected boolean forceResolve;
135 protected EList<XSDConcreteComponent> xsdContents;
136
137 /**
138 * <!-- begin-user-doc -->
139 * <!-- end-user-doc -->
140 * @generated
141 */
142 protected XSDConcreteComponentImpl()
143 {
144 super();
145 }
146
147 /**
148 * <!-- begin-user-doc -->
149 * <!-- end-user-doc -->
150 * @generated
151 */
152 @Override
153 protected EClass eStaticClass()
154 {
155 return XSDPackage.Literals.XSD_CONCRETE_COMPONENT;
156 }
157
158 protected XSDFactory getXSDFactory()
159 {
160 return getXSDPackage().getXSDFactory();
161 }
162
163 protected XSDPackage getXSDPackage()
164 {
165 return (XSDPackage)eClass().getEPackage();
166 }
167
168 public static class XSDContentsEList extends EContentsEList<XSDConcreteComponent>
169 {
170 XSDContentsEList(EObject eObject, EStructuralFeature [] eStructuralFeatures)
171 {
172 super(eObject, eStructuralFeatures);
173 }
174
175 @Override
176 protected ListIterator<XSDConcreteComponent> newListIterator()
177 {
178 return new FeatureIteratorImpl(eObject, eStructuralFeatures);
179 }
180
181 @Override
182 protected boolean isIncluded(EStructuralFeature eStructuralFeature)
183 {
184 EReference eReference = (EReference)eStructuralFeature;
185 return !eReference.isTransient();
186 }
187
188 @Override
189 public List<XSDConcreteComponent> basicList()
190 {
191 return new XSDContentsEList(eObject, eStructuralFeatures);
192 }
193
194 @Override
195 public Iterator<XSDConcreteComponent> basicIterator()
196 {
197 return new FeatureIteratorImpl(eObject, eStructuralFeatures);
198 }
199
200 public static class FeatureIteratorImpl extends EContentsEList.FeatureIteratorImpl<XSDConcreteComponent>
201 {
202 public FeatureIteratorImpl(EObject eObject)
203 {
204 super(eObject, (EStructuralFeature [])((BasicEList<?>)eObject.eClass().getEAllReferences()).data());
205 }
206
207 public FeatureIteratorImpl(EObject eObject, EStructuralFeature [] eStructuralFeatures)
208 {
209 super(eObject, eStructuralFeatures);
210 }
211
212 @Override
213 protected boolean isIncluded(EStructuralFeature eStructuralFeature)
214 {
215 EReference eReference = (EReference)eStructuralFeature;
216 return !eReference.isTransient();
217 }
218 }
219 }
220
221 public EList<XSDConcreteComponent> getXSDContents()
222 {
223 if (xsdContents == null)
224 {
225 xsdContents =
226 new XSDContentsEList
227 (this,
228 (EStructuralFeature [])((BasicEList<?>)eClass().getEAllContainments()).data());
229 }
230
231 return xsdContents;
232 }
233
234 @SuppressWarnings("unchecked")
235 protected EList<XSDConcreteComponentImpl> getXSDConcreteComponentImpls()
236 {
237 return (EList<XSDConcreteComponentImpl>)(EList<?>)getXSDContents();
238 }
239
240 public void reset()
241 {
242 for (XSDConcreteComponentImpl content : getXSDConcreteComponentImpls())
243 {
244 content.reset();
245 }
246 }
247
248 protected final Element createElement(int nodeType)
249 {
250 XSDSchema xsdSchema = getSchema();
251
252 if (xsdSchema == null)
253 {
254 return null;
255 }
256
257 Document document = null;
258 Element element = null;
259
260 LOOP:
261 for (XSDConcreteComponent container = getContainer(); container != null; container = container.getContainer())
262 {
263 element = container.getElement();
264 if (element != null)
265 {
266 for (Node root = element.getParentNode(); root != null; root = root.getParentNode())
267 {
268 if (root.getNodeType() == Node.DOCUMENT_NODE)
269 {
270 document = (Document)root;
271 break LOOP;
272 }
273 }
274 }
275 }
276 if (document == null)
277 {
278 document = xsdSchema.getDocument();
279 if (document == null)
280 {
281 document = xsdSchema.updateDocument();
282 }
283 }
284
285 String qualifier = xsdSchema.getSchemaForSchemaQNamePrefix();
286 String schemaForSchemaNamespace = xsdSchema.getSchemaForSchemaNamespace();
287
288 Element newElement =
289 document.createElementNS
290 (schemaForSchemaNamespace, (qualifier == null ? "" : qualifier + ":") + XSDConstants.ELEMENT_TAGS[nodeType]);
291
292 if (document.getDocumentElement() == null)
293 {
294 document.appendChild(newElement);
295 }
296
297 if (nodeType == XSDConstants.SCHEMA_ELEMENT)
298 {
299 for (Map.Entry<String, String> entry : xsdSchema.getQNamePrefixToNamespaceMap().entrySet())
300 {
301 String key = entry.getKey();
302 newElement.setAttributeNS(XSDConstants.XMLNS_URI_2000, key == null ? "xmlns" : "xmlns:" + key, entry.getValue());
303 }
304
305 String xmlnsAttribute = "xmlns";
306 if (qualifier != null)
307 {
308 xmlnsAttribute += ":" + qualifier;
309 }
310 newElement.setAttributeNS(XSDConstants.XMLNS_URI_2000, xmlnsAttribute, schemaForSchemaNamespace);
311 }
312
313 return newElement;
314 }
315
316 public Element createElement()
317 {
318 return null;
319 }
320
321 public void updateElement(boolean deep)
322 {
323 if (deep || getElement() == null)
324 {
325 updateElement();
326 }
327 else
328 {
329 changeAttribute(null);
330 changeReference(null);
331 }
332 }
333
334 public void updateElement()
335 {
336 if (getElement() == null)
337 {
338 XSDConcreteComponent container = getContainer();
339 if (container == null)
340 {
341 if (!(this instanceof XSDSchema))
342 {
343 return;
344 }
345 }
346 else if (container.getElement() == null)
347 {
348 container.updateElement();
349 return;
350 }
351
352 isReconciling = true;
353 createElement();
354 isReconciling = false;
355 }
356
357 changeAttribute(null);
358 changeReference(null);
359
360 for (EReference eReference : eClass().getEAllContainments())
361 {
362 if (!eReference.isTransient())
363 {
364 if (eReference.isMany())
365 {
366 @SuppressWarnings("unchecked")
367 Collection<XSDConcreteComponent> xsdConcreteComponents = ((Collection<XSDConcreteComponent>)eGet(eReference));
368 for (XSDConcreteComponent xsdConcreteComponent : xsdConcreteComponents)
369 {
370 handleElementForAdopt(eReference, xsdConcreteComponent);
371 xsdConcreteComponent.updateElement();
372 }
373 }
374 else
375 {
376 XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent)eGet(eReference);
377 if (xsdConcreteComponent != null)
378 {
379 handleElementForAdopt(eReference, xsdConcreteComponent);
380 xsdConcreteComponent.updateElement();
381 }
382 }
383 }
384 }
385 }
386
387 protected void updatePrefix(Node node, String namespace, String oldPrefix, String newPrefix)
388 {
389 if ((namespace == null ? node.getNamespaceURI() == null : namespace.equals(node.getNamespaceURI())) &&
390 (oldPrefix == null ? node.getPrefix() == null : oldPrefix.equals(node.getPrefix())))
391 {
392 node.setPrefix(newPrefix);
393 }
394
395 for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
396 {
397 updatePrefix(child, namespace, oldPrefix, newPrefix);
398 }
399 }
400
401 protected boolean isUpdatingDOM()
402 {
403 return updatingDOM;
404 }
405
406 public void elementChanged(Element changedElement)
407 {
408 if (!isUpdatingDOM())
409 {
410 if (!isReconciling)
411 {
412 // System.out.println("**** changeFor " + eClass().getName());
413
414 isReconciling = true;
415 reconcile(changedElement);
416
417 XSDConcreteComponent theContainer = getContainer();
418 if (theContainer != null && theContainer.getElement() == changedElement)
419 {
420 theContainer.elementChanged(changedElement);
421 }
422
423 isReconciling = false;
424 traverseToRootForPatching();
425 }
426 else
427 {
428 // System.out.println("**** cyclic internal reconcile avoided " + eClass().getName());
429 }
430 }
431 else
432 {
433 // System.out.println("**** cyclic DOM reconcile avoided " + eClass().getName());
434 }
435 }
436
437 public void elementAttributesChanged(Element changedElement)
438 {
439 if (!isUpdatingDOM())
440 {
441 if (!isReconciling)
442 {
443 // System.out.println("**** changeFor " + eClass().getName());
444
445 isReconciling = true;
446 reconcileAttributes(changedElement);
447
448 XSDConcreteComponent theContainer = getContainer();
449 if (theContainer != null && theContainer.getElement() == changedElement)
450 {
451 theContainer.elementAttributesChanged(changedElement);
452 }
453
454 isReconciling = false;
455 traverseToRootForPatching();
456 }
457 else
458 {
459 // System.out.println("**** cyclic internal reconcile avoided " + eClass().getName());
460 }
461 }
462 else
463 {
464 // System.out.println("**** cyclic DOM reconcile avoided " + eClass().getName());
465 }
466 }
467
468 public void elementContentsChanged(Element changedElement)
469 {
470 if (!isUpdatingDOM())
471 {
472 if (!isReconciling)
473 {
474 // System.out.println("**** changeFor " + eClass().getName());
475
476 isReconciling = true;
477 reconcileContents(changedElement);
478
479 XSDConcreteComponent theContainer = getContainer();
480 if (theContainer != null && theContainer.getElement() == changedElement)
481 {
482 theContainer.elementContentsChanged(changedElement);
483 }
484
485 isReconciling = false;
486 traverseToRootForPatching();
487 }
488 else
489 {
490 // System.out.println("**** cyclic internal reconcile avoided " + eClass().getName());
491 }
492 }
493 else
494 {
495 // System.out.println("**** cyclic DOM reconcile avoided " + eClass().getName());
496 }
497 }
498
499 protected void traverseToRootForPatching()
500 {
501 if (!isReconciling)
502 {
503 XSDConcreteComponentImpl container = (XSDConcreteComponentImpl)getContainer();
504 if (container != null)
505 {
506 container.traverseToRootForPatching();
507 }
508 }
509 }
510
511 protected void traverseToRootForAnalysis()
512 {
513 if (!isReconciling)
514 {
515 XSDConcreteComponentImpl container = (XSDConcreteComponentImpl)getContainer();
516 if (container != null)
517 {
518 container.traverseToRootForAnalysis();
519 }
520 }
521 }
522
523 protected void patch()
524 {
525 for (XSDConcreteComponentImpl content : getXSDConcreteComponentImpls())
526 {
527 content.forceResolve = forceResolve;
528 content.isReconciling = true;
529 content.patch();
530 content.isReconciling = false;
531 content.forceResolve = false;
532 }
533 }
534
535 protected final int UNANALYZED = 0;
536 protected final int ANALYZING = 1;
537 protected final int ANALYZED = 2;
538 protected final int CIRCULAR = 3;
539
540 protected boolean analyze()
541 {
542 boolean result = true;
543 for (XSDConcreteComponentImpl content : getXSDConcreteComponentImpls())
544 {
545 content.isReconciling = true;
546 if (!content.analyze())
547 {
548 result = false;
549 }
550 content.isReconciling = false;
551 }
552 return result;
553 }
554
555 public void validate()
556 {
557 for (XSDConcreteComponentImpl content : getXSDConcreteComponentImpls())
558 {
559 content.validate();
560 }
561 }
562
563 public void clearDiagnostics()
564 {
565 Collection<XSDDiagnostic> theDiagnostics = getDiagnostics();
566 if (!theDiagnostics.isEmpty())
567 {
568 theDiagnostics.clear();
569 }
570 for (XSDConcreteComponent content : getXSDContents())
571 {
572 content.clearDiagnostics();
573 }
574 }
575
576 protected XSDDiagnostic reportConstraintViolation
577 (String part, String anchor, Element element, String attributeName, Object [] substitutions)
578 {
579 XSDDiagnostic xsdDiagnostic = getXSDFactory().createXSDDiagnostic();
580 xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL);
581 xsdDiagnostic.setMessage
582 (XSDPlugin.INSTANCE.getString("_UI_XSDError_message", new Object [] { populateDiagnostic(xsdDiagnostic, anchor, substitutions) }));
583 xsdDiagnostic.setPrimaryComponent(this);
584 Node node = element;
585 if (attributeName != null)
586 {
587 Attr attr = element.getAttributeNodeNS(null, attributeName);
588 if (attr != null)
589 {
590 node = attr;
591 }
592 }
593 xsdDiagnostic.setNode(node);
594
595 getDiagnostics().add(xsdDiagnostic);
596 return xsdDiagnostic;
597 }
598
599 protected XSDDiagnostic checkElementComplexContent
600 (String elementName,
601 String part,
602 String anchor,
603 Element element)
604 {
605 XSDElementDeclaration xsdElementDeclaration = getSchema().getSchemaForSchema().resolveElementDeclaration(elementName);
606 return checkComplexContent((XSDComplexTypeDefinition)xsdElementDeclaration.getTypeDefinition(), part, anchor, element);
607 }
608
609 protected void printDFA(XSDParticle.DFA dfa)
610 {
611 ((XSDParticleImpl.XSDNFA)dfa).dump(System.err);
612 }
613
614 protected XSDDiagnostic checkComplexContent
615 (String builtInTypeName,
616 String part,
617 String anchor,
618 Element element)
619 {
620 XSDComplexTypeDefinition xsdComplexTypeDefinition = getSchema().getSchemaForSchema().resolveComplexTypeDefinition(builtInTypeName);
621 return checkComplexContent(xsdComplexTypeDefinition, part, anchor, element);
622 }
623
624 protected XSDDiagnostic checkComplexContent
625 (XSDComplexTypeDefinition xsdComplexTypeDefinition,
626 String part,
627 String anchor,
628 Element element)
629 {
630 List<XSDDiagnostic> xsdDiagnostics = XSDUtil.checkComplexContent(xsdComplexTypeDefinition, part, anchor, element);
631 for (XSDDiagnostic xsdDiagnostic : xsdDiagnostics)
632 {
633 xsdDiagnostic.setPrimaryComponent(this);
634 }
635 getDiagnostics().addAll(xsdDiagnostics);
636 return xsdDiagnostics.isEmpty() ? null : xsdDiagnostics.get(xsdDiagnostics.size() - 1);
637 }
638
639 protected XSDDiagnostic checkAttributeTypeConstraint
640 (String builtInTypeName,
641 String builtInAttributeName,
642 String value,
643 String part,
644 String anchor,
645 Element element,
646 String attributeName,
647 boolean isRequired)
648 {
649 XSDComplexTypeDefinition xsdComplexTypeDefinition = getSchema().getSchemaForSchema().resolveComplexTypeDefinition(builtInTypeName);
650 return checkAttributeTypeConstraint
651 (xsdComplexTypeDefinition,
652 builtInAttributeName,
653 value,
654 part,
655 anchor,
656 element,
657 attributeName,
658 isRequired);
659 }
660
661 protected XSDDiagnostic checkAttributeTypeConstraint
662 (XSDComplexTypeDefinition xsdComplexTypeDefinition,
663 String builtInAttributeName,
664 String value,
665 String part,
666 String anchor,
667 Element element,
668 String attributeName,
669 boolean isRequired)
670 {
671 for (XSDAttributeUse xsdAttributeUse : xsdComplexTypeDefinition.getAttributeUses())
672 {
673 XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();
674 if (builtInAttributeName.equals(xsdAttributeDeclaration.getName()))
675 {
676 XSDDiagnostic result =
677 checkSimpleTypeConstraint
678 (xsdAttributeDeclaration.getTypeDefinition(), value, part, anchor, element, attributeName, isRequired);
679 return result;
680 }
681 }
682
683 return null;
684 }
685
686 protected XSDDiagnostic checkBuiltInTypeConstraint
687 (String builtInTypeName, String value, String part, String anchor, Element element, String attributeName, boolean isRequired)
688 {
689 XSDSimpleTypeDefinition builtInType = getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(builtInTypeName);
690 return checkSimpleTypeConstraint(builtInType, value, part, anchor, element, attributeName, isRequired);
691 }
692
693 protected XSDDiagnostic checkSimpleTypeConstraint
694 (XSDSimpleTypeDefinition xsdTypeDefinition,
695 String value,
696 String part,
697 String anchor,
698 Element element,
699 String attributeName,
700 boolean isRequired)
701 {
702 XSDDiagnostic result = null;
703 if (element != null && value == null && element.hasAttributeNS(null, attributeName))
704 {
705 value = element.getAttributeNS(null, attributeName);
706 }
707
708 if (value == null)
709 {
710 if (isRequired)
711 {
712 result = createRequiredAttributeDiagnostic(part, anchor, element, attributeName);
713 }
714 }
715 else
716 {
717 XSDSimpleTypeDefinition.Assessment assessment = xsdTypeDefinition.assess(element, value);
718 Collection<XSDDiagnostic> allDiagnostics = assessment.getDiagnostics();
719 if (!allDiagnostics.isEmpty())
720 {
721 ((XSDSimpleTypeDefinitionImpl.AssessmentImpl)assessment).assignDiagnostics(this, element, attributeName);
722 getDiagnostics().addAll(allDiagnostics);
723 result = allDiagnostics.iterator().next();
724 result.setAnnotationURI(part + "#" + anchor);
725 }
726 }
727
728 return result;
729 }
730
731 protected Collection<XSDDiagnostic> checkAttributes(String part, String anchor, Element element, String [] allowedAttributeNames)
732 {
733 Collection<XSDDiagnostic> result = null;
734 if (element != null)
735 {
736 NamedNodeMap attributes = element.getAttributes();
737 LOOP:
738 for (int i = 0, length = attributes.getLength(); i < length; ++i)
739 {
740 Attr attr = (Attr)attributes.item(i);
741 if (attr.getNamespaceURI() == null)
742 {
743 String localName = attr.getLocalName();
744
745 for (int j = 0; j < allowedAttributeNames.length; ++j)
746 {
747 if (allowedAttributeNames[j].equals(localName))
748 {
749 continue LOOP;
750 }
751 }
752
753 XSDDiagnostic xsdDiagnostic = getXSDFactory().createXSDDiagnostic();
754 xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL);
755 xsdDiagnostic.setMessage
756 (XSDPlugin.INSTANCE.getString
757 ("_UI_XSDError_message",
758 new Object []
759 {
760 populateDiagnostic(xsdDiagnostic, "cvc-complex-type.3", new Object [] { localName })
761 }));
762 xsdDiagnostic.setAnnotationURI(part + "#" + anchor);
763 xsdDiagnostic.setPrimaryComponent(this);
764 xsdDiagnostic.setNode(attr);
765 getDiagnostics().add(xsdDiagnostic);
766 if (result == null)
767 {
768 result = new ArrayList<XSDDiagnostic>();
769 }
770 result.add(xsdDiagnostic);
771 }
772 }
773 }
774
775 return result;
776 }
777
778 protected XSDDiagnostic createRequiredAttributeDiagnostic(String part, String anchor, Element element, String attributeName)
779 {
780 XSDDiagnostic result = getXSDFactory().createXSDDiagnostic();
781 result.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL);
782 result.setMessage
783 (XSDPlugin.INSTANCE.getString
784 ("_UI_XSDError_message",
785 new Object []
786 {
787 populateDiagnostic(result, "cvc-complex-type.4", new Object [] { attributeName })
788 }));
789 result.setAnnotationURI(part + "#" + anchor);
790 result.setPrimaryComponent(this);
791 result.setNode(element);
792 getDiagnostics().add(result);
793 return result;
794 }
795
796 protected XSDConcreteComponentImpl getDiagnosticTarget(XSDConcreteComponent xsdConcreteComponent)
797 {
798 return
799 EcoreUtil.isAncestor(this, xsdConcreteComponent) &&
800 !xsdConcreteComponent.eContainmentFeature().isTransient() ?
801 (XSDConcreteComponentImpl)xsdConcreteComponent :
802 this;
803 }
804
805 protected XSDDiagnostic createDiagnostic(XSDDiagnosticSeverity severity, String key)
806 {
807 XSDDiagnostic xsdDiagnostic = getXSDFactory().createXSDDiagnostic();
808 xsdDiagnostic.setSeverity(severity);
809 xsdDiagnostic.setMessage
810 (XSDPlugin.INSTANCE.getString
811 ("_UI_XSDError_message", new Object [] { populateDiagnostic(xsdDiagnostic, key, null) }));
812 xsdDiagnostic.setPrimaryComponent(this);
813 xsdDiagnostic.setNode(getElement());
814
815 Element theElement = getElement();
816 xsdDiagnostic.setNode(theElement);
817
818 getDiagnostics().add(xsdDiagnostic);
819 return xsdDiagnostic;
820 }
821
822 protected XSDDiagnostic createDiagnostic(XSDDiagnosticSeverity severity, String key, Object s1)
823 {
824 XSDDiagnostic xsdDiagnostic = getXSDFactory().createXSDDiagnostic();
825 xsdDiagnostic.setSeverity(severity);
826 xsdDiagnostic.setMessage
827 (XSDPlugin.INSTANCE.getString
828 ("_UI_XSDError_message", new Object [] { populateDiagnostic(xsdDiagnostic, key, new Object [] { s1 }) }));
829 xsdDiagnostic.setPrimaryComponent(this);
830 xsdDiagnostic.setNode(getElement());
831
832 Element theElement = getElement();
833 xsdDiagnostic.setNode(theElement);
834
835 getDiagnostics().add(xsdDiagnostic);
836 return xsdDiagnostic;
837 }
838
839 protected XSDDiagnostic createDiagnostic(XSDDiagnosticSeverity severity, String key, Object s1, Object s2)
840 {
841 XSDDiagnostic xsdDiagnostic = getXSDFactory().createXSDDiagnostic();
842 xsdDiagnostic.setSeverity(severity);
843 xsdDiagnostic.setMessage
844 (XSDPlugin.INSTANCE.getString
845 ("_UI_XSDError_message", new Object [] { populateDiagnostic(xsdDiagnostic, key, new Object [] { s1, s2 }) }));
846 xsdDiagnostic.setPrimaryComponent(this);
847 xsdDiagnostic.setNode(getElement());
848
849 Element theElement = getElement();
850 xsdDiagnostic.setNode(theElement);
851
852 getDiagnostics().add(xsdDiagnostic);
853 return xsdDiagnostic;
854 }
855
856 protected XSDDiagnostic createDiagnostic(XSDDiagnosticSeverity severity, String key, Object s1, Object s2, Object s3)
857 {
858 XSDDiagnostic xsdDiagnostic = getXSDFactory().createXSDDiagnostic();
859 xsdDiagnostic.setSeverity(severity);
860 xsdDiagnostic.setMessage
861 (XSDPlugin.INSTANCE.getString
862 ("_UI_XSDError_message", new Object [] { populateDiagnostic(xsdDiagnostic, key, new Object [] { s1, s2, s3 }) }));
863 xsdDiagnostic.setPrimaryComponent(this);
864 xsdDiagnostic.setNode(getElement());
865
866 Element theElement = getElement();
867 xsdDiagnostic.setNode(theElement);
868
869 getDiagnostics().add(xsdDiagnostic);
870 return xsdDiagnostic;
871 }
872
873 protected static String populateDiagnostic(XSDDiagnostic xsdDiagnostic, String key, Object [] substitutions)
874 {
875 xsdDiagnostic.setKey(key);
876 if (substitutions != null)
877 {
878 List<String> values = xsdDiagnostic.getSubstitutions();
879 for (int i = 0; i < substitutions.length; ++i)
880 {
881 Object value = substitutions[i];
882 values.add(value == null ? null : value.toString());
883 }
884 return XSDPlugin.INSTANCE.getString(key, substitutions);
885 }
886 else
887 {
888 return XSDPlugin.INSTANCE.getString(key);
889 }
890 }
891
892 protected void reconcile(Element changedElement)
893 {
894 reconcileAttributes(changedElement);
895 reconcileContents(changedElement);
896 }
897
898 protected void reconcileAttributes(Element changedElement)
899 {
900 // Do nothing.
901 }
902
903 protected Collection<Element> getContentNodes(Element changedElement)
904 {
905 Collection<Element> result = new ArrayList<Element>();
906 for (Node child = getElement().getFirstChild(); child != null; child = child.getNextSibling())
907 {
908 if (child.getNodeType() == Node.ELEMENT_NODE)
909 {
910 result.add((Element)child);
911 }
912 }
913 return result;
914 }
915
916 protected void reconcileContents(Element changedElement)
917 {
918 XSDSchemaImpl xsdSchema = (XSDSchemaImpl)getSchema();
919 List<XSDConcreteComponent> newContents = new ArrayList<XSDConcreteComponent>();
920 List<XSDConcreteComponent> remainingContents = new ArrayList<XSDConcreteComponent>(getXSDContents());
921 Collection<Element> contentNodes = getContentNodes(changedElement);
922 LOOP:
923 for (Node child : contentNodes)
924 {
925 if (child.getNodeType() == Node.ELEMENT_NODE && (xsdSchema == null || child != xsdSchema.getDeletionNode()))
926 {
927 for (Iterator<XSDConcreteComponent> contents = remainingContents.iterator(); contents.hasNext(); )
928 {
929 XSDConcreteComponent remainingConcreteComponent = contents.next();
930 if (remainingConcreteComponent.getElement() == child)
931 {
932 newContents.add(remainingConcreteComponent);
933 contents.remove();
934 continue LOOP;
935 }
936 }
937
938 if (!remainingContents.isEmpty())
939 {
940 XSDConcreteComponent potentialReplacement = remainingContents.get(0);
941 Element potentialReplacedElement = potentialReplacement.getElement();
942 if (potentialReplacedElement != null &&
943 potentialReplacedElement.getParentNode() != changedElement &&
944 potentialReplacedElement.getLocalName().equals(child.getLocalName()))
945 {
946 remainingContents.remove(0);
947 potentialReplacement.setElement((Element)child);
948 newContents.add(potentialReplacement);
949 continue;
950 }
951 }
952
953 handleUnreconciledElement((Element)child, newContents, remainingContents);
954 }
955 }
956
957 handleReconciliation(newContents, remainingContents);
958 }
959
960 protected void handleUnreconciledElement(Element child, List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
961 {
962 // Do nothing.
963 }
964
965 protected void handleReconciliation(List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
966 {
967 // Do nothing.
968 }
969
970 protected void handleAnnotationReconciliation
971 (EReference eReference, List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
972 {
973 XSDAnnotation newAnnotation = null;
974 XSDAnnotation oldAnnotation = (XSDAnnotation)eGet(eReference);
975 if (!newContents.isEmpty())
976 {
977 XSDConcreteComponent xsdConcreteComponent = newContents.get(0);
978 if (xsdConcreteComponent instanceof XSDAnnotation)
979 {
980 newAnnotation = (XSDAnnotation)xsdConcreteComponent;
981 newContents.remove(0);
982 }
983 }
984
985 if (newAnnotation != oldAnnotation)
986 {
987 eSet(eReference, newAnnotation);
988 }
989
990 if (oldAnnotation != null)
991 {
992 remainingContents.remove(oldAnnotation);
993 }
994 }
995
996 @Override
997 public void eNotify(Notification msg)
998 {
999 int eventType = msg.getEventType();
1000 Object feature = msg.getFeature();
1001 Object oldValue = msg.getOldValue();
1002 Object newValue = msg.getNewValue();
1003 if (eClass().getEAllReferences().contains(feature))
1004 {
1005 EReference eReference = (EReference)feature;
1006 if (feature == XSDPackage.Literals.XSD_CONCRETE_COMPONENT__DIAGNOSTICS)
1007 {
1008 switch (eventType)
1009 {
1010 case Notification.ADD:
1011 {
1012 adoptDiagnostic((XSDDiagnostic)newValue);
1013 break;
1014 }
1015 case Notification.ADD_MANY:
1016 {
1017 @SuppressWarnings("unchecked") Collection<XSDDiagnostic> xsdDiagnostics = ((Collection<XSDDiagnostic>)newValue);
1018 for (XSDDiagnostic xsdDiagnostic : xsdDiagnostics)
1019 {
1020 adoptDiagnostic(xsdDiagnostic);
1021 }
1022 break;
1023 }
1024 case Notification.REMOVE:
1025 {
1026 if (oldValue != null)
1027 {
1028 orphanDiagnostic((XSDDiagnostic)oldValue);
1029 }
1030 break;
1031 }
1032 case Notification.REMOVE_MANY:
1033 {
1034 @SuppressWarnings("unchecked") Collection<XSDDiagnostic> xsdDiagnostics = ((Collection<XSDDiagnostic>)oldValue);
1035 for (XSDDiagnostic xsdDiagnostic : xsdDiagnostics)
1036 {
1037 orphanDiagnostic(xsdDiagnostic);
1038 }
1039 break;
1040 }
1041 case Notification.MOVE:
1042 {
1043 // Don't care.
1044 //
1045 break;
1046 }
1047 case Notification.SET:
1048 case Notification.UNSET:
1049 {
1050 if (oldValue != null)
1051 {
1052 orphanDiagnostic((XSDDiagnostic)oldValue);
1053 }
1054 if (newValue != null)
1055 {
1056 adoptDiagnostic((XSDDiagnostic)newValue);
1057 }
1058 break;
1059 }
1060 }
1061 }
1062 else if (eReference.isContainment() && !eReference.isTransient())
1063 {
1064 switch (eventType)
1065 {
1066 case Notification.ADD:
1067 {
1068 adoptContent(eReference, (XSDConcreteComponent)newValue);
1069 break;
1070 }
1071 case Notification.ADD_MANY:
1072 {
1073 @SuppressWarnings("unchecked") Collection<XSDConcreteComponent> xsdConcreteComponents = ((Collection<XSDConcreteComponent>)newValue);
1074 for (XSDConcreteComponent xsdConcreteComponent : xsdConcreteComponents)
1075 {
1076 adoptContent(eReference, xsdConcreteComponent);
1077 }
1078 break;
1079 }
1080 case Notification.REMOVE:
1081 {
1082 if (oldValue != null)
1083 {
1084 orphanContent(eReference, (XSDConcreteComponent)oldValue);
1085 }
1086 break;
1087 }
1088 case Notification.REMOVE_MANY:
1089 {
1090 @SuppressWarnings("unchecked") Collection<XSDConcreteComponent> xsdConcreteComponents = ((Collection<XSDConcreteComponent>)oldValue);
1091 for (XSDConcreteComponent xsdConcreteComponent : xsdConcreteComponents)
1092 {
1093 orphanContent(eReference, xsdConcreteComponent);
1094 }
1095 break;
1096 }
1097 case Notification.MOVE:
1098 {
1099 moveContent(eReference, (XSDConcreteComponent)newValue);
1100 break;
1101 }
1102 case Notification.SET:
1103 case Notification.UNSET:
1104 {
1105 if (oldValue != null)
1106 {
1107 orphanContent(eReference, (XSDConcreteComponent)oldValue);
1108 }
1109 if (newValue != null)
1110 {
1111 adoptContent(eReference, (XSDConcreteComponent)newValue);
1112 }
1113 break;
1114 }
1115 }
1116 }
1117 else
1118 {
1119 switch (eventType)
1120 {
1121 case Notification.ADD:
1122 case Notification.ADD_MANY:
1123 case Notification.REMOVE:
1124 case Notification.REMOVE_MANY:
1125 case Notification.MOVE:
1126 case Notification.SET:
1127 case Notification.UNSET:
1128 {
1129 changeReference(eReference);
1130 break;
1131 }
1132 }
1133 }
1134 }
1135 else if (eClass().getEAllAttributes().contains(feature))
1136 {
1137 EAttribute eAttribute = (EAttribute)feature;
1138 switch (eventType)
1139 {
1140 case Notification.ADD:
1141 case Notification.ADD_MANY:
1142 case Notification.REMOVE:
1143 case Notification.REMOVE_MANY:
1144 case Notification.MOVE:
1145 case Notification.SET:
1146 case Notification.UNSET:
1147 {
1148 changeAttribute(eAttribute);
1149 break;
1150 }
1151 }
1152 }
1153 super.eNotify(msg);
1154 }
1155
1156 protected void changeAttribute(EAttribute eAttribute)
1157 {
1158 if (eAttribute == XSDPackage.Literals.XSD_CONCRETE_COMPONENT__ELEMENT)
1159 {
1160 Element theElement = getElement();
1161 if (theElement != null && !isReconciling)
1162 {
1163 for (Node rootDocument = theElement.getParentNode(); rootDocument != null; rootDocument = rootDocument.getParentNode())
1164 {
1165 if (rootDocument.getNodeType() == Node.DOCUMENT_NODE)
1166 {
1167 isReconciling = true;
1168 if (getSchema() == null)
1169 {
1170 reconcileAttributes(getElement());
1171 isReconciling = false;
1172 }
1173 else
1174 {
1175 reconcile(getElement());
1176 isReconciling = false;
1177 traverseToRootForPatching();
1178 }
1179 break;
1180 }
1181 }
1182 }
1183 }
1184 }
1185
1186 protected void changeReference(EReference eReference)
1187 {
1188 // Do nothing.
1189 }
1190
1191 protected Node getAdoptionParentNode(EReference eReference)
1192 {
1193 return getElement();
1194 }
1195
1196 protected void handleElementForAdopt(EReference eReference, XSDConcreteComponent xsdConcreteComponent)
1197 {
1198 Node adoptionParent = getAdoptionParentNode(eReference);
1199 Element childElement = xsdConcreteComponent.getElement();
1200 Element referencedElement = null;
1201 for (Iterator<XSDConcreteComponent> contents = getXSDContents().iterator(); contents.hasNext(); )
1202 {
1203 if (contents.next() == xsdConcreteComponent)
1204 {
1205 if (contents.hasNext())
1206 {
1207 referencedElement = contents.next().getElement();
1208 while (referencedElement != null)
1209 {
1210 Node parent = referencedElement.getParentNode();
1211 if (parent == null )
1212 {
1213 referencedElement = null;
1214 break;
1215 }
1216 else if (parent == adoptionParent)
1217 {
1218 break;
1219 }
1220 else if (parent.getNodeType() == Node.ELEMENT_NODE)
1221 {
1222 referencedElement = (Element)parent;
1223 }
1224 else
1225 {
1226 break;
1227 }
1228 }
1229 }
1230 break;
1231 }
1232 }
1233
1234 XSDConcreteComponentImpl xsdConcreteComponentImpl = (XSDConcreteComponentImpl)xsdConcreteComponent;
1235 boolean newChild = childElement == null;
1236 if (newChild)
1237 {
1238 xsdConcreteComponentImpl.isReconciling = true;
1239 childElement = xsdConcreteComponentImpl.createElement();
1240 xsdConcreteComponentImpl.isReconciling = false;
1241 if (childElement == null)
1242 {
1243 System.out.println("not created! " + xsdConcreteComponent);
1244 }
1245 }
1246
1247 boolean isAttached = false;
1248 for (Node rootDocument = childElement; rootDocument != null; rootDocument = rootDocument.getParentNode())
1249 {
1250 if (XSDConstants.nodeType(rootDocument) == XSDConstants.SCHEMA_ELEMENT)
1251 {
1252 isAttached = true;
1253 break;
1254 }
1255 }
1256
1257 if (!isAttached)
1258 {
1259 // Special rule for annotations that must appear first,
1260 // or facets of simple types within a restriction which must appear before any attributes.
1261 //
1262 if (referencedElement == null)
1263 {
1264 if (eReference == XSDPackage.Literals.XSD_SIMPLE_TYPE_DEFINITION__FACET_CONTENTS &&
1265 XSDConstants.nodeType(adoptionParent) == XSDConstants.RESTRICTION_ELEMENT)
1266 {
1267 for (Node child = adoptionParent.getFirstChild(); child != null; child = child.getNextSibling())
1268 {
1269 int nodeType = XSDConstants.nodeType(child);
1270 if (nodeType == XSDConstants.ATTRIBUTE_ELEMENT ||
1271 nodeType == XSDConstants.ATTRIBUTEGROUP_ELEMENT ||
1272 nodeType == XSDConstants.ANYATTRIBUTE_ELEMENT)
1273 {
1274 referencedElement = (Element)child;
1275 break;
1276 }
1277 }
1278 }
1279 else if (XSDConstants.nodeType(childElement) == XSDConstants.ANNOTATION_ELEMENT && !eReference.isMany())
1280 {
1281 for (Node child = adoptionParent.getFirstChild(); child != null; child = child.getNextSibling())
1282 {
1283 if (child.getNodeType() == Node.ELEMENT_NODE)
1284 {
1285 referencedElement = (Element)child;
1286 break;
1287 }
1288 }
1289 }
1290 }
1291
1292 niceInsertBefore(adoptionParent, childElement, referencedElement);
1293 if (!newChild)
1294 {
1295 xsdConcreteComponentImpl.isReconciling = true;
1296 xsdConcreteComponentImpl.reconcile(childElement);
1297 xsdConcreteComponentImpl.isReconciling = false;
1298 }
1299 }
1300 else
1301 {
1302 // System.out.println("bad adoption " + xsdConcreteComponent);
1303 }
1304 }
1305
1306 protected void adoptContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent)
1307 {
1308 if (isReconciling)
1309 {
1310 if (xsdConcreteComponent.getElement() != null)
1311 {
1312 xsdConcreteComponent.elementChanged(xsdConcreteComponent.getElement());
1313 }
1314 }
1315 else
1316 {
1317 Element childElement = xsdConcreteComponent.getElement();
1318 if (getElement() != null && (childElement == null || childElement.getParentNode() == null))
1319 {
1320 if (childElement != null && childElement.getOwnerDocument() != getElement().getOwnerDocument())
1321 {
1322 xsdConcreteComponent.setElement(null);
1323 childElement = null;
1324 }
1325
1326 handleElementForAdopt(eReference, xsdConcreteComponent);
1327 xsdConcreteComponent.updateElement();
1328 }
1329 }
1330
1331 XSDSchema xsdSchema = getSchema();
1332 if (xsdSchema != null)
1333 {
1334 ((XSDConcreteComponentImpl)xsdConcreteComponent).adoptBy(xsdSchema);
1335 }
1336 }
1337
1338 protected void adoptBy(XSDSchema xsdSchema)
1339 {
1340 List<XSDDiagnostic> theDiagnostics = getDiagnostics();
1341 if (!theDiagnostics.isEmpty())
1342 {
1343 xsdSchema.getDiagnostics().addAll(theDiagnostics);
1344 }
1345
1346 for (XSDConcreteComponentImpl childXSDConcreteComponent : getXSDConcreteComponentImpls())
1347 {
1348 childXSDConcreteComponent.adoptBy(xsdSchema);
1349 }
1350 }
1351
1352 protected void adoptDiagnostic(XSDDiagnostic xsdDiagnostic)
1353 {
1354 XSDSchema xsdSchema = getSchema();
1355 if (xsdSchema != null)
1356 {
1357 xsdSchema.getAllDiagnostics().add(xsdDiagnostic);
1358 }
1359 }
1360
1361
1362 protected void orphanContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent)
1363 {
1364 if (!isReconciling)
1365 {
1366 Element parent = getElement();
1367 if (parent != null)
1368 {
1369 Element contentElement = xsdConcreteComponent.getElement();
1370 if (contentElement != null)
1371 {
1372 if (parent == contentElement)
1373 {
1374 XSDConcreteComponentImpl parentComponent = (XSDConcreteComponentImpl)getContainer();
1375 boolean oldParentUpdatingDOM = parentComponent.updatingDOM;
1376 parentComponent.updatingDOM = true;
1377 niceRemoveChild(contentElement.getParentNode(), contentElement);
1378 parentComponent.updatingDOM = oldParentUpdatingDOM;
1379 }
1380 else
1381 {
1382 niceRemoveChild(contentElement.getParentNode(), contentElement);
1383 }
1384 }
1385 }
1386 }
1387
1388 XSDSchema xsdSchema = getSchema();
1389 if (xsdSchema != null)
1390 {
1391 ((XSDConcreteComponentImpl)xsdConcreteComponent).orphanBy(xsdSchema);
1392 }
1393 }
1394
1395 protected void orphanBy(XSDSchema xsdSchema)
1396 {
1397 List<XSDDiagnostic> theDiagnostics = getDiagnostics();
1398 if (!theDiagnostics.isEmpty())
1399 {
1400 xsdSchema.getAllDiagnostics().removeAll(theDiagnostics);
1401 }
1402 for (XSDConcreteComponentImpl childXSDConcreteComponent : getXSDConcreteComponentImpls())
1403 {
1404 childXSDConcreteComponent.orphanBy(xsdSchema);
1405 }
1406 }
1407
1408 protected void orphanDiagnostic(XSDDiagnostic xsdDiagnostic)
1409 {
1410 XSDSchema xsdSchema = getSchema();
1411 if (xsdSchema != null)
1412 {
1413 xsdSchema.getAllDiagnostics().remove(xsdDiagnostic);
1414 }
1415 }
1416
1417
1418 public void moveContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent)
1419 {
1420 if (isReconciling)
1421 {
1422 // System.out.println("**** cyclic dom writeback avoided " + eClass().getName());
1423 return;
1424 }
1425 //System.out.println("moving " + xsdConcreteComponent);
1426 Node parent = getAdoptionParentNode(eReference);
1427 if (parent != null)
1428 {
1429 Element child = xsdConcreteComponent.getElement();
1430 if (child != null)
1431 {
1432 List<XSDConcreteComponent> contents = getXSDContents();
1433 int index = contents.indexOf(xsdConcreteComponent);
1434 niceRemoveChild(parent, child);
1435 niceInsertBefore
1436 (parent,
1437 child,
1438 ++index == contents.size() ?
1439 null :
1440 contents.get(index).getElement());
1441 }
1442 }
1443 //System.out.println("moved " + xsdConcreteComponent);
1444 }
1445
1446 public void niceInsertBefore(Node parent, Node newChild, Node referenceChild)
1447 {
1448 if (isReconciling || parent == newChild)
1449 {
1450 // System.out.println("**** cyclic dom writeback avoided " + eClass().getName());
1451 return;
1452 }
1453
1454 forceNiceInsertBefore(parent, newChild, referenceChild);
1455 }
1456
1457 public void forceNiceInsertBefore(Node parent, Node newChild, Node referenceChild)
1458 {
1459 updatingDOM = true;
1460
1461 LOOP:
1462 for (Node child = referenceChild == null ? parent.getLastChild() : referenceChild.getPreviousSibling();
1463 child != null;
1464 child = child.getPreviousSibling())
1465 {
1466 switch (child.getNodeType())
1467 {
1468 case Node.TEXT_NODE:
1469 {
1470 Text text = (Text)child;
1471 String data = text.getData();
1472
1473 /*
1474 System.out.print("xx " + data.length() + ":: ");
1475 for (int i = 0; i < data.length(); ++i)
1476 {
1477 System.out.print(" " + Integer.toHexString((int)data.charAt(i)));
1478 }
1479 System.out.println();
1480 */
1481
1482 int index = data.lastIndexOf('\n');
1483 if (index != -1)
1484 {
1485 // System.out.println("In here");
1486
1487 StringBuffer indent = new StringBuffer();
1488 for (Node ancestor = parent.getParentNode();
1489 ancestor != null && ancestor.getNodeType() != Node.DOCUMENT_NODE;
1490 ancestor = ancestor.getParentNode())
1491 {
1492 indent.append(" ");
1493 }
1494
1495 if (index + 1 < data.length() && data.charAt(index + 1) == '\r')
1496 {
1497 ++index;
1498 }
1499 if (index + 1 == data.length())
1500 {
1501 text.appendData(indent + " ");
1502 }
1503 else
1504 {
1505 text.replaceData(index + 1, data.length() - index - 1, indent + " ");
1506 }
1507
1508 // setCorrectIndentation(indent, newText);
1509 if (referenceChild != null)
1510 {
1511 indent.append(" ");
1512 }
1513 Text newText = parent.getOwnerDocument().createTextNode("\n" + indent);
1514 // System.out.println("Inserted..." + newText);
1515 parent.insertBefore(newText, referenceChild);
1516 referenceChild = newText;
1517 break LOOP;
1518 }
1519
1520 break;
1521 }
1522 case Node.ELEMENT_NODE:
1523 {
1524 break LOOP;
1525 }
1526 }
1527 }
1528
1529 // System.out.println("Inserted..." + newChild);
1530 parent.insertBefore(newChild, referenceChild);
1531
1532 updatingDOM = false;
1533 }
1534
1535 public void niceRemoveChild(Node parent, Node child)
1536 {
1537 if (isReconciling)
1538 {
1539 // System.out.println("**** cyclic dom writeback avoided " + eClass().getName());
1540 return;
1541 }
1542 forceNiceRemoveChild(parent, child);
1543 }
1544
1545 public void forceNiceRemoveChild(Node parent, Node child)
1546 {
1547 updatingDOM = true;
1548
1549 boolean done = false;
1550
1551 // System.out.println("?*");
1552 Node previous = child.getPreviousSibling();
1553 if (previous != null && previous.getNodeType() == Node.TEXT_NODE)
1554 {
1555 Text text = (Text)previous;
1556 String data = text.getData();
1557 int index = data.lastIndexOf('\n');
1558 if (index != -1)
1559 {
1560 if (index - 1 > 0 && data.charAt(index - 1) == '\r')
1561 {
1562 //System.out.println("1*");
1563 text.deleteData(index - 1, data.length() - index + 1);
1564 }
1565 else
1566 {
1567 //System.out.println("2*");
1568 text.deleteData(index, data.length() - index);
1569 }
1570 done = true;
1571 }
1572 else
1573 {
1574 //System.out.println("No return before!");
1575 }
1576 }
1577 else
1578 {
1579 // System.out.println("No text node before!");
1580 }
1581
1582
1583 if (!done)
1584 {
1585 for (Node next = child.getNextSibling(); next != null; next = next.getNextSibling())
1586 {
1587 if (next.getNodeType() == Node.TEXT_NODE)
1588 {
1589 Text text = (Text)next;
1590 String data = text.getData();
1591 /*
1592 System.out.print("xx " + data.length() + ":: ");
1593 for (int i = 0; i < data.length(); ++i)
1594 {
1595 System.out.print(" " + Integer.toHexString((int)data.charAt(i)));
1596 }
1597 System.out.println();
1598 */
1599
1600 int index = data.indexOf('\n');
1601 if (index != -1)
1602 {
1603 if (index + 1 < data.length() && data.charAt(index + 1) == '\r')
1604 {
1605 // System.out.println("3*");
1606 text.deleteData(0, index + 2);
1607 }
1608 else
1609 {
1610 //System.out.println("4*");
1611 text.deleteData(0, index + 1);
1612 }
1613 break;
1614 }
1615 else
1616 {
1617 // System.out.println("No return after!");
1618 }
1619 }
1620 else if (next.getNodeType() == Node.ELEMENT_NODE)
1621 {
1622 break;
1623 }
1624 }
1625 }
1626
1627 // System.out.println("Removing from--------\n " + parent);
1628 //System.out.println("Removing--------\n " + child);
1629 parent.removeChild(child);
1630
1631 updatingDOM=false;
1632 }
1633
1634 public void forceReplace(Element replacementElement, Element referenceElement)
1635 {
1636 isReconciling = true;
1637 updatingDOM = true;
1638
1639 XSDConcreteComponentImpl container = (XSDConcreteComponentImpl)getContainer();
1640 container.isReconciling = true;
1641 container.updatingDOM = true;
1642
1643 Node parent = referenceElement.getParentNode();
1644 XSDConcreteComponentImpl containerOfContainer =
1645 parent != container.getElement() ?
1646 (XSDConcreteComponentImpl)container.getContainer() :
1647 null;
1648 if (containerOfContainer != null)
1649 {
1650 containerOfContainer.isReconciling = true;
1651 containerOfContainer.updatingDOM = true;
1652 }
1653
1654 for (Node child = referenceElement.getFirstChild(); child != null; )
1655 {
1656 Node node = child;
1657 child = child.getNextSibling();
1658 referenceElement.removeChild(node);
1659 replacementElement.appendChild(node);
1660 }
1661
1662 org.w3c.dom.NamedNodeMap attributes = referenceElement.getAttributes();
1663 for (int i = 0, length = attributes.getLength(); i < length; ++i)
1664 {
1665 replacementElement.setAttributeNode((org.w3c.dom.Attr)attributes.item(i).cloneNode(true));
1666 }
1667
1668 forceNiceInsertBefore(parent, replacementElement, referenceElement);
1669 forceNiceRemoveChild(parent, referenceElement);
1670
1671 updatingDOM = false;
1672 isReconciling = false;
1673
1674 container.updatingDOM = false;
1675 container.isReconciling = false;
1676
1677 if (containerOfContainer != null)
1678 {
1679 containerOfContainer.updatingDOM = false;
1680 containerOfContainer.isReconciling = false;
1681 }
1682 }
1683
1684 public void forceEngulf(Element newElement, Element engulfingElement, Element referenceElement, Node referenceChild)
1685 {
1686 isReconciling = true;
1687 updatingDOM = true;
1688
1689 forceNiceInsertBefore(referenceElement, newElement, referenceChild);
1690
1691 for (Node child = referenceChild; child != null; )
1692 {
1693 Node node = child;
1694 child = child.getNextSibling();
1695 forceNiceRemoveChild(referenceElement, node);
1696 forceNiceInsertBefore(engulfingElement, node, null);
1697 }
1698
1699 updatingDOM = false;
1700 isReconciling = false;
1701 }
1702
1703 public void forceEngulf(Node firstAdoptee, Element engulfingElement, Node referenceChild)
1704 {
1705 isReconciling = true;
1706 updatingDOM = true;
1707
1708 Node parent = firstAdoptee.getParentNode();
1709 for (Node child = firstAdoptee; child != null; )
1710 {
1711 Node node = child;
1712 child = child.getNextSibling();
1713 forceNiceRemoveChild(parent, node);
1714 forceNiceInsertBefore(engulfingElement, node, referenceChild);
1715 }
1716
1717 updatingDOM = false;
1718 isReconciling = false;
1719 }
1720
1721 protected void niceSetAttribute(Element element, String attribute, String value)
1722 {
1723 if (isReconciling)
1724 {
1725 // System.out.println("**** cyclic dom attribute writeback avoided " + eClass().getName());
1726 return;
1727 }
1728
1729 if (value == null)
1730 {
1731 if (element.hasAttributeNS(null, attribute))
1732 {
1733 updatingDOM = true;
1734 element.removeAttribute(attribute);
1735 updatingDOM=false;
1736 }
1737 }
1738 else if (!element.hasAttributeNS(null, attribute) || !element.getAttributeNS(null, attribute).equals(value))
1739 {
1740 updatingDOM = true;
1741 element.setAttributeNS(null, attribute, value);
1742 updatingDOM=false;
1743 }
1744 }
1745
1746 protected String niceCreateNamespaceAttribute(String namespace)
1747 {
1748 XSDSchema xsdSchema = getSchema();
1749 if (namespace == null)
1750 {
1751 namespace = "";
1752 }
1753 if (xsdSchema != null && xsdSchema.getElement() != null)
1754 {
1755 Element schemaElement = xsdSchema.getElement();
1756 if (XSDConstants.isSchemaForSchemaNamespace(namespace))
1757 {
1758 if (!schemaElement.hasAttributeNS(XSDConstants.XMLNS_URI_2000, "xsd"))
1759 {
1760 schemaElement.setAttributeNS(XSDConstants.XMLNS_URI_2000, "xmlns:xsd", namespace);
1761 xsdSchema.getQNamePrefixToNamespaceMap().put("xsd", namespace);
1762 return "xsd";
1763 }
1764 }
1765
1766 String qualifier = "Q";
1767 String result;
1768 int count = 1;
1769 while (schemaElement.hasAttributeNS(XSDConstants.XMLNS_URI_2000, result = qualifier + count))
1770 {
1771 ++count;
1772 }
1773 schemaElement.setAttributeNS(XSDConstants.XMLNS_URI_2000, "xmlns:" + result, namespace);
1774 xsdSchema.getQNamePrefixToNamespaceMap().put(result, namespace);
1775 return result;
1776 }
1777 else
1778 {
1779 return null;
1780 }
1781 }
1782
1783 protected void niceSetAttributeURIValue(Element element, String attribute, String uriList)
1784 {
1785 if (isReconciling)
1786 {
1787 // System.out.println("**** cyclic dom attribute writeback avoided " + eClass().getName());
1788 return;
1789 }
1790
1791 if (uriList == null)
1792 {
1793 updatingDOM = true;
1794 element.removeAttribute(attribute);
1795 updatingDOM=false;
1796 }
1797 else
1798 {
1799 StringBuffer value = new StringBuffer();
1800 for (StringTokenizer stringTokenizer = new StringTokenizer(uriList, " "); stringTokenizer.hasMoreElements(); )
1801 {
1802 String uri = stringTokenizer.nextToken();
1803 String namespace = null;
1804 String localName = uri;
1805 int index = uri.lastIndexOf("#");
1806 if (index != -1)
1807 {
1808 if (index > 0)
1809 {
1810 namespace = uri.substring(0, index);
1811 }
1812 localName = uri.substring(index + 1);
1813 }
1814 String qualifier = XSDConstants.lookupQualifier(element, namespace);
1815 if (qualifier == null)
1816 {
1817 qualifier = niceCreateNamespaceAttribute(namespace);
1818 }
1819
1820 String qName = qualifier == null || qualifier.length() == 0 ? localName : qualifier + ":" + localName;
1821
1822 if (value.length() != 0)
1823 {
1824 value.append(' ');
1825 }
1826 value.append(qName);
1827 }
1828
1829 if (!element.hasAttributeNS(null, attribute) || !element.getAttributeNS(null, attribute).equals(value.toString()))
1830 {
1831 updatingDOM = true;
1832 element.setAttributeNS(null, attribute, value.toString());
1833 updatingDOM=false;
1834 }
1835 }
1836 }
1837
1838 public XSDConcreteComponent getContainer()
1839 {
1840 return
1841 eContainer instanceof XSDConcreteComponent ?
1842 (XSDConcreteComponent)eContainer :
1843 null;
1844 }
1845
1846 public XSDConcreteComponent getRootContainer()
1847 {
1848 for (XSDConcreteComponent root = this;;)
1849 {
1850 XSDConcreteComponent parent = root.getContainer();
1851 if (parent == null)
1852 {
1853 return root;
1854 }
1855 root = parent;
1856 }
1857 }
1858
1859 public boolean contains(XSDConcreteComponent xsdConcreteComponent)
1860 {
1861 while (xsdConcreteComponent != null)
1862 {
1863 if (xsdConcreteComponent == this)
1864 {
1865 return true;
1866 }
1867 xsdConcreteComponent = xsdConcreteComponent.getContainer();
1868 }
1869 return false;
1870 }
1871
1872 public XSDSchema getSchema()
1873 {
1874 for (XSDConcreteComponent container = this; container != null; container = container.getContainer())
1875 {
1876 if (container instanceof XSDSchema)
1877 {
1878 return (XSDSchema)container;
1879 }
1880 }
1881
1882 return null;
1883 }
1884
1885 /**
1886 * <!-- begin-user-doc -->
1887 * <!-- end-user-doc -->
1888 * @generated
1889 */
1890 @Override
1891 public EList<XSDDiagnostic> getDiagnostics()
1892 {
1893 if (diagnostics == null)
1894 {
1895 diagnostics = new EObjectContainmentEList<XSDDiagnostic>(XSDDiagnostic.class, this, XSDPackage.XSD_CONCRETE_COMPONENT__DIAGNOSTICS);
1896 }
1897 return diagnostics;
1898 }
1899
1900 /**
1901 * <!-- begin-user-doc -->
1902 * <!-- end-user-doc -->
1903 * @generated
1904 */
1905 @Override
1906 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
1907 {
1908 switch (featureID)
1909 {
1910 case XSDPackage.XSD_CONCRETE_COMPONENT__DIAGNOSTICS:
1911 return ((InternalEList<?>)getDiagnostics()).basicRemove(otherEnd, msgs);
1912 }
1913 return super.eInverseRemove(otherEnd, featureID, msgs);
1914 }
1915
1916 /**
1917 * <!-- begin-user-doc -->
1918 * <!-- end-user-doc -->
1919 * @generated
1920 */
1921 @Override
1922 public Object eGet(int featureID, boolean resolve, boolean coreType)
1923 {
1924 switch (featureID)
1925 {
1926 case XSDPackage.XSD_CONCRETE_COMPONENT__ELEMENT:
1927 return getElement();
1928 case XSDPackage.XSD_CONCRETE_COMPONENT__CONTAINER:
1929 return getContainer();
1930 case XSDPackage.XSD_CONCRETE_COMPONENT__ROOT_CONTAINER:
1931 return getRootContainer();
1932 case XSDPackage.XSD_CONCRETE_COMPONENT__SCHEMA:
1933 return getSchema();
1934 case XSDPackage.XSD_CONCRETE_COMPONENT__DIAGNOSTICS:
1935 return getDiagnostics();
1936 }
1937 return super.eGet(featureID, resolve, coreType);
1938 }
1939
1940 /**
1941 * <!-- begin-user-doc -->
1942 * <!-- end-user-doc -->
1943 * @generated
1944 */
1945 @SuppressWarnings("unchecked")
1946 @Override
1947 public void eSet(int featureID, Object newValue)
1948 {
1949 switch (featureID)
1950 {
1951 case XSDPackage.XSD_CONCRETE_COMPONENT__ELEMENT:
1952 setElement((Element)newValue);
1953 return;
1954 case XSDPackage.XSD_CONCRETE_COMPONENT__DIAGNOSTICS:
1955 getDiagnostics().clear();
1956 getDiagnostics().addAll((Collection<? extends XSDDiagnostic>)newValue);
1957 return;
1958 }
1959 super.eSet(featureID, newValue);
1960 }
1961
1962 /**
1963 * <!-- begin-user-doc -->
1964 * <!-- end-user-doc -->
1965 * @generated
1966 */
1967 @Override
1968 public void eUnset(int featureID)
1969 {
1970 switch (featureID)
1971 {
1972 case XSDPackage.XSD_CONCRETE_COMPONENT__ELEMENT:
1973 setElement(ELEMENT_EDEFAULT);
1974 return;
1975 case XSDPackage.XSD_CONCRETE_COMPONENT__DIAGNOSTICS:
1976 getDiagnostics().clear();
1977 return;
1978 }
1979 super.eUnset(featureID);
1980 }
1981
1982 /**
1983 * <!-- begin-user-doc -->
1984 * <!-- end-user-doc -->
1985 * @generated
1986 */
1987 @Override
1988 public boolean eIsSet(int featureID)
1989 {
1990 switch (featureID)
1991 {
1992 case XSDPackage.XSD_CONCRETE_COMPONENT__ELEMENT:
1993 return ELEMENT_EDEFAULT == null ? element != null : !ELEMENT_EDEFAULT.equals(element);
1994 case XSDPackage.XSD_CONCRETE_COMPONENT__CONTAINER:
1995 return getContainer() != null;
1996 case XSDPackage.XSD_CONCRETE_COMPONENT__ROOT_CONTAINER:
1997 return getRootContainer() != null;
1998 case XSDPackage.XSD_CONCRETE_COMPONENT__SCHEMA:
1999 return getSchema() != null;
2000 case XSDPackage.XSD_CONCRETE_COMPONENT__DIAGNOSTICS:
2001 return diagnostics != null && !diagnostics.isEmpty();
2002 }
2003 return super.eIsSet(featureID);
2004 }
2005
2006 /**
2007 * <!-- begin-user-doc -->
2008 * <!-- end-user-doc -->
2009 * @generated
2010 */
2011 @Override
2012 public String toString()
2013 {
2014 if (eIsProxy()) return super.toString();
2015
2016 StringBuilder result = new StringBuilder(super.toString());
2017 result.append(" (element: ");
2018 result.append(element);
2019 result.append(')');
2020 return result.toString();
2021 }
2022
2023 public XSDConcreteComponent getBestConcreteComponent(List<Element> elementPath)
2024 {
2025 XSDConcreteComponent result = this;
2026 for (XSDConcreteComponentImpl childXSDConcreteComponent : getXSDConcreteComponentImpls())
2027 {
2028 if (elementPath.contains(childXSDConcreteComponent.getElement()))
2029 {
2030 result = childXSDConcreteComponent;
2031 XSDConcreteComponent betterXSDConcreteComponent = childXSDConcreteComponent.getBestConcreteComponent(elementPath);
2032 if (betterXSDConcreteComponent != null)
2033 {
2034 result = betterXSDConcreteComponent;
2035 }
2036
2037 if (!considerAllContainsForBestConcreteComponent())
2038 {
2039 break;
2040 }
2041 }
2042 }
2043
2044 return result;
2045 }
2046
2047 protected boolean considerAllContainsForBestConcreteComponent()
2048 {
2049 return false;
2050 }
2051
2052 public static <T> void setListContentAndOrder(EList<T> targetList, List<? extends T> prototypeList)
2053 {
2054 for (int index = 0, size = prototypeList.size(); index < size; ++index)
2055 {
2056 T prototypeObject = prototypeList.get(index);
2057 if (targetList.size() <= index)
2058 {
2059 targetList.add(prototypeObject);
2060 }
2061 else
2062 {
2063 Object targetObject = targetList.get(index);
2064 if (targetObject == null ? prototypeObject != null : !targetObject.equals(prototypeObject))
2065 {
2066 if (targetList.contains(prototypeObject))
2067 {
2068 targetList.move(index, prototypeObject);
2069 }
2070 else
2071 {
2072 targetList.add(index, prototypeObject);
2073 }
2074 }
2075 }
2076 }
2077 }
2078
2079 protected String getURIReferenceLabel()
2080 {
2081 return null;
2082 }
2083
2084 @Override
2085 public String eURIFragmentSegment(EStructuralFeature eStructuralFeature, EObject eObject)
2086 {
2087 StringBuffer result = new StringBuffer();
2088 XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent)eObject;
2089 String sort = xsdConcreteComponent.eClass().getName();
2090 int sortCount = 0;
2091 int labelCount = 0;
2092 String uriReferenceLabel = ((XSDConcreteComponentImpl)xsdConcreteComponent).getURIReferenceLabel();
2093 @SuppressWarnings("unchecked") EList<XSDConcreteComponentImpl> eContents = (EList<XSDConcreteComponentImpl>)(EList<?>)eContents();
2094 for (XSDConcreteComponentImpl sibling : eContents)
2095 {
2096 if (sibling == eObject)
2097 {
2098 break;
2099 }
2100 if (sibling.eClass().getName().equals(sort))
2101 {
2102 ++sortCount;
2103 if (uriReferenceLabel != null &&
2104 uriReferenceLabel.equals(sibling.getURIReferenceLabel()))
2105 {
2106 ++labelCount;
2107 }
2108 }
2109 }
2110
2111 if (uriReferenceLabel != null)
2112 {
2113 result.append(uriReferenceLabel);
2114 if (labelCount != 0)
2115 {
2116 result.append("=");
2117 result.append(labelCount);
2118 }
2119 result.append(";");
2120 }
2121 result.append(sort);
2122 if (sortCount != 0)
2123 {
2124 result.append("=");
2125 result.append(sortCount);
2126 }
2127
2128 return result.toString();
2129 }
2130
2131 @Override
2132 public EObject eObjectForURIFragmentSegment(String uriFragmentSegment)
2133 {
2134 EObject result = null;
2135 if (uriFragmentSegment.startsWith("@"))
2136 {
2137 result = super.eObjectForURIFragmentSegment(uriFragmentSegment);
2138 }
2139 else
2140 {
2141 StringTokenizer stringTokenizer = new StringTokenizer(uriFragmentSegment, ";=,", true);
2142
2143 String uriReferenceLabel = null;
2144 String sort = stringTokenizer.nextToken();
2145 if (Character.isDigit(sort.charAt(0)))
2146 {
2147 int diagnosticIndex = 0;
2148 try
2149 {
2150 diagnosticIndex = Integer.parseInt(sort);
2151 }
2152 catch (NumberFormatException exception)
2153 {
2154 // Ignore.
2155 }
2156 List<XSDDiagnostic> theDiagnostics = getDiagnostics();
2157 if (theDiagnostics.size() > diagnosticIndex)
2158 {
2159 result = theDiagnostics.get(diagnosticIndex);
2160 }
2161 }
2162 else
2163 {
2164 EReference eReference = null;
2165 int labelCount = 0;
2166 int sortCount = 0;
2167 String prefix = stringTokenizer.hasMoreTokens() ? stringTokenizer.nextToken() : "";
2168 if (prefix.equals(","))
2169 {
2170 String relationName = sort;
2171 eReference = (EReference)eClass().getEStructuralFeature(relationName);
2172 sort = stringTokenizer.nextToken();
2173 prefix = stringTokenizer.nextToken();
2174 }
2175
2176 if (prefix.equals("="))
2177 {
2178 String sortCountString = stringTokenizer.nextToken();
2179 try
2180 {
2181 sortCount = Integer.parseInt(sortCountString);
2182 }
2183 catch (NumberFormatException exception)
2184 {
2185 // Ignore.
2186 }
2187 prefix = stringTokenizer.hasMoreTokens() ? stringTokenizer.nextToken() : "";
2188 }
2189 if (prefix.equals(";"))
2190 {
2191 uriReferenceLabel = sort;
2192 labelCount = sortCount;
2193 sort = stringTokenizer.nextToken();
2194 sortCount = 0;
2195 if (stringTokenizer.hasMoreTokens())
2196 {
2197 prefix = stringTokenizer.nextToken();
2198 if (prefix.equals("="))
2199 {
2200 String sortCountString = stringTokenizer.nextToken();
2201 try
2202 {
2203 sortCount = Integer.parseInt(sortCountString);
2204 }
2205 catch (NumberFormatException exception)
2206 {
2207 // Ignore.
2208 }
2209 }
2210 }
2211 }
2212
2213 @SuppressWarnings("unchecked")
2214 Collection<XSDConcreteComponentImpl> collection =
2215 eReference == null ?
2216 (Collection<XSDConcreteComponentImpl>)(Collection<?>)eContents() :
2217 eReference.isMany() ?
2218 (Collection<XSDConcreteComponentImpl>)eGet(eReference) :
2219 Collections.singleton((XSDConcreteComponentImpl)eGet(eReference));
2220
2221 EObject candidate = null;
2222 for (XSDConcreteComponentImpl child : collection)
2223 {
2224 if (sortCount >= 0 && child.eClass().getName().equals(sort))
2225 {
2226 --sortCount;
2227 candidate = child;
2228 if (sortCount == -1 && uriReferenceLabel == null)
2229 {
2230 break;
2231 }
2232 }
2233 if (uriReferenceLabel != null &&
2234 uriReferenceLabel.equals(child.getURIReferenceLabel()) &&
2235 child.eClass().getName().equals(sort))
2236 {
2237 if (labelCount-- == 0)
2238 {
2239 candidate = child;
2240 break;
2241 }
2242 }
2243 }
2244
2245 result = candidate;
2246 }
2247 }
2248
2249 return result;
2250 }
2251
2252 public XSDTypeDefinition resolveTypeDefinitionURI(String uri)
2253 {
2254 int index = uri.lastIndexOf("#");
2255 if (index == -1)
2256 {
2257 return resolveTypeDefinition(null, uri);
2258 }
2259 else
2260 {
2261 return resolveTypeDefinition(uri.substring(0, index), uri.substring(index + 1));
2262 }
2263 }
2264
2265 public XSDTypeDefinition resolveTypeDefinition(String localName)
2266 {
2267 XSDSchema xsdSchema = getSchema();
2268 if (xsdSchema != null)
2269 {
2270 return xsdSchema.resolveTypeDefinition(xsdSchema.getTargetNamespace(), localName);
2271 }
2272 else
2273 {
2274 return createUnresolvedTypeDefinition(null, localName);
2275 }
2276 }
2277
2278 public XSDTypeDefinition resolveTypeDefinition(String namespace, String localName)
2279 {
2280 XSDSchema xsdSchema = getSchema();
2281 if (xsdSchema != null)
2282 {
2283 return xsdSchema.resolveTypeDefinition(namespace, localName);
2284 }
2285 else
2286 {
2287 return createUnresolvedTypeDefinition(namespace, localName);
2288 }
2289 }
2290
2291 protected XSDTypeDefinition createUnresolvedTypeDefinition(String namespace, String localName)
2292 {
2293 return createUnresolvedSimpleTypeDefinition(namespace, localName);
2294 }
2295
2296
2297
2298 public XSDSimpleTypeDefinition resolveSimpleTypeDefinitionURI(String uri)
2299 {
2300 int index = uri.lastIndexOf("#");
2301 if (index == -1)
2302 {
2303 return resolveSimpleTypeDefinition(null, uri);
2304 }
2305 else
2306 {
2307 return resolveSimpleTypeDefinition(uri.substring(0, index), uri.substring(index + 1));
2308 }
2309 }
2310
2311 public XSDSimpleTypeDefinition resolveSimpleTypeDefinition(String localName)
2312 {
2313 XSDSchema xsdSchema = getSchema();
2314 if (xsdSchema != null)
2315 {
2316 return xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getTargetNamespace(), localName);
2317 }
2318 else
2319 {
2320 return createUnresolvedSimpleTypeDefinition(null, localName);
2321 }
2322 }
2323
2324 public XSDSimpleTypeDefinition resolveSimpleTypeDefinition(String namespace, String localName)
2325 {
2326 XSDSchema xsdSchema = getSchema();
2327 if (xsdSchema != null)
2328 {
2329 return xsdSchema.resolveSimpleTypeDefinition(namespace, localName);
2330 }
2331 else
2332 {
2333 return createUnresolvedSimpleTypeDefinition(namespace, localName);
2334 }
2335 }
2336
2337 protected XSDSimpleTypeDefinition createUnresolvedSimpleTypeDefinition(String namespace, String localName)
2338 {
2339 XSDSimpleTypeDefinition xsdSimpleTypeDefinition = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
2340 if (localName != null)
2341 {
2342 xsdSimpleTypeDefinition.setName(localName);
2343 }
2344 if (namespace != null)
2345 {
2346 xsdSimpleTypeDefinition.setTargetNamespace(namespace);
2347 }
2348 xsdSimpleTypeDefinition.setVariety(XSDVariety.ATOMIC_LITERAL);
2349 return xsdSimpleTypeDefinition;
2350 }
2351
2352 public XSDComplexTypeDefinition resolveComplexTypeDefinitionURI(String uri)
2353 {
2354 int index = uri.lastIndexOf("#");
2355 if (index == -1)
2356 {
2357 return resolveComplexTypeDefinition(null, uri);
2358 }
2359 else
2360 {
2361 return resolveComplexTypeDefinition(uri.substring(0, index), uri.substring(index + 1));
2362 }
2363 }
2364
2365 public XSDComplexTypeDefinition resolveComplexTypeDefinition(String localName)
2366 {
2367 XSDSchema xsdSchema = getSchema();
2368 if (xsdSchema != null)
2369 {
2370 return xsdSchema.resolveComplexTypeDefinition(xsdSchema.getTargetNamespace(), localName);
2371 }
2372 else
2373 {
2374 return createUnresolvedComplexTypeDefinition(null, localName);
2375 }
2376 }
2377
2378 public XSDComplexTypeDefinition resolveComplexTypeDefinition(String namespace, String localName)
2379 {
2380 XSDSchema xsdSchema = getSchema();
2381 if (xsdSchema != null)
2382 {
2383 return xsdSchema.resolveComplexTypeDefinition(namespace, localName);
2384 }
2385 else
2386 {
2387 return createUnresolvedComplexTypeDefinition(namespace, localName);
2388 }
2389 }
2390
2391 protected XSDComplexTypeDefinition createUnresolvedComplexTypeDefinition(String namespace, String localName)
2392 {
2393 XSDComplexTypeDefinition xsdComplexTypeDefinition = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
2394 if (localName != null)
2395 {
2396 xsdComplexTypeDefinition.setName(localName);
2397 }
2398 if (namespace != null)
2399 {
2400 xsdComplexTypeDefinition.setTargetNamespace(namespace);
2401 }
2402 return xsdComplexTypeDefinition;
2403 }
2404
2405
2406
2407
2408 public XSDAttributeDeclaration resolveAttributeDeclarationURI(String uri)
2409 {
2410 int index = uri.lastIndexOf("#");
2411 if (index == -1)
2412 {
2413 return resolveAttributeDeclaration(null, uri);
2414 }
2415 else
2416 {
2417 return resolveAttributeDeclaration(uri.substring(0, index), uri.substring(index + 1));
2418 }
2419 }
2420
2421 public XSDAttributeDeclaration resolveAttributeDeclaration(String localName)
2422 {
2423 XSDSchema xsdSchema = getSchema();
2424 if (xsdSchema != null)
2425 {
2426 return xsdSchema.resolveAttributeDeclaration(xsdSchema.getTargetNamespace(), localName);
2427 }
2428 else
2429 {
2430 return createUnresolvedAttributeDeclaration(null, localName);
2431 }
2432 }
2433
2434 public XSDAttributeDeclaration resolveAttributeDeclaration(String namespace, String localName)
2435 {
2436 XSDSchema xsdSchema = getSchema();
2437 if (xsdSchema != null)
2438 {
2439 return xsdSchema.resolveAttributeDeclaration(namespace, localName);
2440 }
2441 else
2442 {
2443 return createUnresolvedAttributeDeclaration(namespace, localName);
2444 }
2445 }
2446
2447 protected XSDAttributeDeclaration createUnresolvedAttributeDeclaration(String namespace, String localName)
2448 {
2449 XSDAttributeDeclaration xsdAttributeDeclaration = XSDFactory.eINSTANCE.createXSDAttributeDeclaration();
2450 if (localName != null)
2451 {
2452 xsdAttributeDeclaration.setName(localName);
2453 }
2454 if (namespace != null)
2455 {
2456 xsdAttributeDeclaration.setTargetNamespace(namespace);
2457 }
2458 xsdAttributeDeclaration.setResolvedAttributeDeclaration(xsdAttributeDeclaration);
2459 return xsdAttributeDeclaration;
2460 }
2461
2462
2463
2464 public XSDElementDeclaration resolveElementDeclarationURI(String uri)
2465 {
2466 int index = uri.lastIndexOf("#");
2467 if (index == -1)
2468 {
2469 return resolveElementDeclaration(null, uri);
2470 }
2471 else
2472 {
2473 return resolveElementDeclaration(uri.substring(0, index), uri.substring(index + 1));
2474 }
2475 }
2476
2477 public XSDElementDeclaration resolveElementDeclaration(String localName)
2478 {
2479 XSDSchema xsdSchema = getSchema();
2480 if (xsdSchema != null)
2481 {
2482 return xsdSchema.resolveElementDeclaration(xsdSchema.getTargetNamespace(), localName);
2483 }
2484 else
2485 {
2486 return createUnresolvedElementDeclaration(null, localName);
2487 }
2488 }
2489
2490 public XSDElementDeclaration resolveElementDeclaration(String namespace, String localName)
2491 {
2492 XSDSchema xsdSchema = getSchema();
2493 if (xsdSchema != null)
2494 {
2495 return xsdSchema.resolveElementDeclaration(namespace, localName);
2496 }
2497 else
2498 {
2499 return createUnresolvedElementDeclaration(namespace, localName);
2500 }
2501 }
2502
2503 protected XSDElementDeclaration createUnresolvedElementDeclaration(String namespace, String localName)
2504 {
2505 XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration();
2506 if (localName != null)
2507 {
2508 xsdElementDeclaration.setName(localName);
2509 }
2510 if (namespace != null)
2511 {
2512 xsdElementDeclaration.setTargetNamespace(namespace);
2513 }
2514 xsdElementDeclaration.setResolvedElementDeclaration(xsdElementDeclaration);
2515 return xsdElementDeclaration;
2516 }
2517
2518
2519
2520
2521
2522 public XSDAttributeGroupDefinition resolveAttributeGroupDefinitionURI(String uri)
2523 {
2524 int index = uri.lastIndexOf("#");
2525 if (index == -1)
2526 {
2527 return resolveAttributeGroupDefinition(null, uri);
2528 }
2529 else
2530 {
2531 return resolveAttributeGroupDefinition(uri.substring(0, index), uri.substring(index + 1));
2532 }
2533 }
2534
2535 public XSDAttributeGroupDefinition resolveAttributeGroupDefinition(String localName)
2536 {
2537 XSDSchema xsdSchema = getSchema();
2538 if (xsdSchema != null)
2539 {
2540 return xsdSchema.resolveAttributeGroupDefinition(xsdSchema.getTargetNamespace(), localName);
2541 }
2542 else
2543 {
2544 return createUnresolvedAttributeGroupDefinition(null, localName);
2545 }
2546 }
2547
2548 public XSDAttributeGroupDefinition resolveAttributeGroupDefinition(String namespace, String localName)
2549 {
2550 XSDSchema xsdSchema = getSchema();
2551 if (xsdSchema != null)
2552 {
2553 return xsdSchema.resolveAttributeGroupDefinition(namespace, localName);
2554 }
2555 else
2556 {
2557 return createUnresolvedAttributeGroupDefinition(namespace, localName);
2558 }
2559 }
2560
2561 protected XSDAttributeGroupDefinition createUnresolvedAttributeGroupDefinition(String namespace, String localName)
2562 {
2563 XSDAttributeGroupDefinition xsdAttributeGroupDefinition = XSDFactory.eINSTANCE.createXSDAttributeGroupDefinition();
2564 if (localName != null)
2565 {
2566 xsdAttributeGroupDefinition.setName(localName);
2567 }
2568 if (namespace != null)
2569 {
2570 xsdAttributeGroupDefinition.setTargetNamespace(namespace);
2571 }
2572 xsdAttributeGroupDefinition.setResolvedAttributeGroupDefinition(xsdAttributeGroupDefinition);
2573 return xsdAttributeGroupDefinition;
2574 }
2575
2576
2577
2578 public XSDModelGroupDefinition resolveModelGroupDefinitionURI(String uri)
2579 {
2580 int index = uri.lastIndexOf("#");
2581 if (index == -1)
2582 {
2583 return resolveModelGroupDefinition(null, uri);
2584 }
2585 else
2586 {
2587 return resolveModelGroupDefinition(uri.substring(0, index), uri.substring(index + 1));
2588 }
2589 }
2590
2591 public XSDModelGroupDefinition resolveModelGroupDefinition(String localName)
2592 {
2593 XSDSchema xsdSchema = getSchema();
2594 if (xsdSchema != null)
2595 {
2596 return xsdSchema.resolveModelGroupDefinition(xsdSchema.getTargetNamespace(), localName);
2597 }
2598 else
2599 {
2600 return createUnresolvedModelGroupDefinition(null, localName);
2601 }
2602 }
2603
2604 public XSDModelGroupDefinition resolveModelGroupDefinition(String namespace, String localName)
2605 {
2606 XSDSchema xsdSchema = getSchema();
2607 if (xsdSchema != null)
2608 {
2609 return xsdSchema.resolveModelGroupDefinition(namespace, localName);
2610 }
2611 else
2612 {
2613 return createUnresolvedModelGroupDefinition(namespace, localName);
2614 }
2615 }
2616
2617 protected XSDModelGroupDefinition createUnresolvedModelGroupDefinition(String namespace, String localName)
2618 {
2619 XSDModelGroupDefinition xsdModelGroupDefinition = XSDFactory.eINSTANCE.createXSDModelGroupDefinition();
2620 if (localName != null)
2621 {
2622 xsdModelGroupDefinition.setName(localName);
2623 }
2624 if (namespace != null)
2625 {
2626 xsdModelGroupDefinition.setTargetNamespace(namespace);
2627 }
2628 xsdModelGroupDefinition.setResolvedModelGroupDefinition(xsdModelGroupDefinition);
2629 XSDModelGroup xsdModelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
2630 xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
2631 xsdModelGroupDefinition.setModelGroup(xsdModelGroup);
2632 return xsdModelGroupDefinition;
2633 }
2634
2635 public XSDIdentityConstraintDefinition resolveIdentityConstraintDefinitionURI(String uri)
2636 {
2637 int index = uri.lastIndexOf("#");
2638 if (index == -1)
2639 {
2640 return resolveIdentityConstraintDefinition(null, uri);
2641 }
2642 else
2643 {
2644 return resolveIdentityConstraintDefinition(uri.substring(0, index), uri.substring(index + 1));
2645 }
2646 }
2647
2648 public XSDIdentityConstraintDefinition resolveIdentityConstraintDefinition(String localName)
2649 {
2650 XSDSchema xsdSchema = getSchema();
2651 if (xsdSchema != null)
2652 {
2653 return xsdSchema.resolveIdentityConstraintDefinition(xsdSchema.getTargetNamespace(), localName);
2654 }
2655 else
2656 {
2657 return createUnresolvedIdentityConstraintDefinition(null, localName);
2658 }
2659 }
2660
2661 public XSDIdentityConstraintDefinition resolveIdentityConstraintDefinition(String namespace, String localName)
2662 {
2663 XSDSchema xsdSchema = getSchema();
2664 if (xsdSchema != null)
2665 {
2666 return xsdSchema.resolveIdentityConstraintDefinition(namespace, localName);
2667 }
2668 else
2669 {
2670 return createUnresolvedIdentityConstraintDefinition(namespace, localName);
2671 }
2672 }
2673
2674 protected XSDIdentityConstraintDefinition createUnresolvedIdentityConstraintDefinition(String namespace, String localName)
2675 {
2676 XSDIdentityConstraintDefinition xsdIdentityConstraintDefinition =
2677 XSDFactory.eINSTANCE.createXSDIdentityConstraintDefinition();
2678 xsdIdentityConstraintDefinition.setIdentityConstraintCategory(XSDIdentityConstraintCategory.KEY_LITERAL);
2679 if (localName != null)
2680 {
2681 xsdIdentityConstraintDefinition.setName(localName);
2682 }
2683 if (namespace != null)
2684 {
2685 xsdIdentityConstraintDefinition.setTargetNamespace(namespace);
2686 }
2687 return xsdIdentityConstraintDefinition;
2688 }
2689
2690 public XSDNotationDeclaration resolveNotationDeclarationURI(String uri)
2691 {
2692 int index = uri.lastIndexOf("#");
2693 if (index == -1)
2694 {
2695 return resolveNotationDeclaration(null, uri);
2696 }
2697 else
2698 {
2699 return resolveNotationDeclaration(uri.substring(0, index), uri.substring(index + 1));
2700 }
2701 }
2702
2703 public XSDNotationDeclaration resolveNotationDeclaration(String localName)
2704 {
2705 XSDSchema xsdSchema = getSchema();
2706 if (xsdSchema != null)
2707 {
2708 return xsdSchema.resolveNotationDeclaration(xsdSchema.getTargetNamespace(), localName);
2709 }
2710 else
2711 {
2712 return createUnresolvedNotationDeclaration(null, localName);
2713 }
2714 }
2715
2716 public XSDNotationDeclaration resolveNotationDeclaration(String namespace, String localName)
2717 {
2718 XSDSchema xsdSchema = getSchema();
2719 if (xsdSchema != null)
2720 {
2721 return xsdSchema.resolveNotationDeclaration(namespace, localName);
2722 }
2723 else
2724 {
2725 return createUnresolvedNotationDeclaration(namespace, localName);
2726 }
2727 }
2728
2729 protected XSDNotationDeclaration createUnresolvedNotationDeclaration(String namespace, String localName)
2730 {
2731 XSDNotationDeclaration xsdNotationDeclaration =
2732 XSDFactory.eINSTANCE.createXSDNotationDeclaration();
2733 if (localName != null)
2734 {
2735 xsdNotationDeclaration.setName(localName);
2736 }
2737 if (namespace != null)
2738 {
2739 xsdNotationDeclaration.setTargetNamespace(namespace);
2740 }
2741 return xsdNotationDeclaration;
2742 }
2743
2744 public Collection<XSDConcreteComponent> getComponentsWithApplicationInformation(String sourceURI)
2745 {
2746 Collection<XSDConcreteComponent> result = new HashSet<XSDConcreteComponent>();
2747 getComponentsWithInformation(result, XSDConstants.APPINFO_ELEMENT, sourceURI);
2748 return result;
2749 }
2750
2751 public Collection<XSDConcreteComponent> getComponentsWithUserInformation(String sourceURI)
2752 {
2753 Collection<XSDConcreteComponent> result = new HashSet<XSDConcreteComponent>();
2754 getComponentsWithInformation(result, XSDConstants.DOCUMENTATION_ELEMENT, sourceURI);
2755 return result;
2756 }
2757
2758 protected void getComponentsWithInformation(Collection<XSDConcreteComponent> result, int nodeType, String sourceURI)
2759 {
2760 for (XSDConcreteComponentImpl xsdConcreteComponent : getXSDConcreteComponentImpls())
2761 {
2762 xsdConcreteComponent.getComponentsWithInformation(result, nodeType, sourceURI);
2763 }
2764 }
2765
2766 /**
2767 * <!-- begin-user-doc -->
2768 * <!-- end-user-doc -->
2769 * @generated
2770 */
2771 @Override
2772 public Element getElement()
2773 {
2774 return element;
2775 }
2776
2777 /**
2778 * <!-- begin-user-doc -->
2779 * <!-- end-user-doc -->
2780 * @generated
2781 */
2782 public void setElementGen(Element newElement)
2783 {
2784 Element oldElement = element;
2785 element = newElement;
2786 if (eNotificationRequired())
2787 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_CONCRETE_COMPONENT__ELEMENT, oldElement, element));
2788 }
2789
2790 /*
2791 public void unsetElement()
2792 {
2793 isReconciling = true;
2794 unsetElementGen();
2795 for (Iterator contents = getXSDContents().iterator(); contents.hasNext(); )
2796 {
2797 XSDConcreteComponentImpl content = (XSDConcreteComponentImpl)contents.next();
2798 content.unsetElement();
2799 }
2800 isReconciling = false;
2801 }
2802 */
2803
2804 public void setElement(Element element)
2805 {
2806 if (element == null)
2807 {
2808 isReconciling = true;
2809 setElementGen(null);
2810 for (XSDConcreteComponentImpl content : getXSDConcreteComponentImpls())
2811 {
2812 content.setElement(null);
2813 }
2814 isReconciling = false;
2815 }
2816 else
2817 {
2818 setElementGen(element);
2819 }
2820 }
2821
2822 /**
2823 */
2824 public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM)
2825 {
2826 throw new RuntimeException("Unimplemented: XSDConcreteComponent.cloneConcreteComponent(boolean deep, boolean shareDOM)");
2827 }
2828
2829 protected static <T extends XSDConcreteComponent> List<T> cloneConcreteComponents(List<T> xsdConcreteComponents, boolean deep, boolean shareDOM)
2830 {
2831 List<T> result = new ArrayList<T>(xsdConcreteComponents.size());
2832 for (XSDConcreteComponent xsdConcreteComponent : xsdConcreteComponents)
2833 {
2834 try
2835 {
2836 @SuppressWarnings("unchecked")
2837 T clonedConcreteComponent = (T)xsdConcreteComponent.cloneConcreteComponent(deep, shareDOM);
2838 result.add(clonedConcreteComponent);
2839 }
2840 catch (Exception exception)
2841 {
2842 exception.printStackTrace();
2843 }
2844 }
2845 return result;
2846 }
2847
2848 @Override
2849 public boolean eNotificationRequired()
2850 {
2851 return true;
2852 }
2853
2854 protected boolean convertToBoolean(String value)
2855 {
2856 value = XMLTypeUtil.normalize(value, true);
2857 return "true".equals(value) || "1".equals(value);
2858 }
2859 }