Debian Codegraph @

plugins/org.eclipse.xsd/src/org/eclipse/xsd/impl/XSDImportImpl.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.InternalEObject;
24 import org.eclipse.emf.ecore.impl.ENotificationImpl;
25 import org.eclipse.xsd.XSDAnnotation;
26 import org.eclipse.xsd.XSDComplexTypeDefinition;
27 import org.eclipse.xsd.XSDConcreteComponent;
28 import org.eclipse.xsd.XSDDiagnosticSeverity;
29 import org.eclipse.xsd.XSDFactory;
30 import org.eclipse.xsd.XSDImport;
31 import org.eclipse.xsd.XSDPackage;
32 import org.eclipse.xsd.XSDSchema;
33 import org.eclipse.xsd.util.XSDConstants;
34
35
36 /**
37 * <!-- begin-user-doc -->
38 * An implementation of the model object '<em><b>Import</b></em>'.
39 * <!-- end-user-doc -->
40 * <p>
41 * The following features are implemented:
42 * </p>
43 * <ul>
44 * <li>{@link org.eclipse.xsd.impl.XSDImportImpl#getNamespace <em>Namespace</em>}</li>
45 * <li>{@link org.eclipse.xsd.impl.XSDImportImpl#getAnnotation <em>Annotation</em>}</li>
46 * </ul>
47 *
48 * @generated
49 */
50 public class XSDImportImpl
51 extends XSDSchemaDirectiveImpl
52 implements XSDImport
53 {
54 /**
55 * The default value of the '{@link #getNamespace() <em>Namespace</em>}' attribute.
56 * <!-- begin-user-doc -->
57 * <!-- end-user-doc -->
58 * @see #getNamespace()
59 * @generated
60 * @ordered
61 */
62 protected static final String NAMESPACE_EDEFAULT = null;
63
64 /**
65 * The cached value of the '{@link #getNamespace() <em>Namespace</em>}' attribute.
66 * <!-- begin-user-doc -->
67 * <!-- end-user-doc -->
68 * @see #getNamespace()
69 * @generated
70 * @ordered
71 */
72 protected String namespace = NAMESPACE_EDEFAULT;
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 public static XSDImport createImport(Node node)
85 {
86 if (XSDConstants.nodeType(node) == XSDConstants.IMPORT_ELEMENT)
87 {
88 XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
89 xsdImport.setElement((Element)node);
90 return xsdImport;
91 }
92
93 return null;
94 }
95
96 // protected XSDSchema importedSchema;
97
98 @Override
99 public Element createElement()
100 {
101 Element newElement = createElement(XSDConstants.IMPORT_ELEMENT);
102 setElement(newElement);
103 return newElement;
104 }
105
106 /**
107 * <!-- begin-user-doc -->
108 * <!-- end-user-doc -->
109 * @generated
110 */
111 protected XSDImportImpl()
112 {
113 super();
114 }
115
116 /**
117 * <!-- begin-user-doc -->
118 * <!-- end-user-doc -->
119 * @generated
120 */
121 @Override
122 protected EClass eStaticClass()
123 {
124 return XSDPackage.Literals.XSD_IMPORT;
125 }
126
127 /**
128 * <!-- begin-user-doc -->
129 * <!-- end-user-doc -->
130 * @generated
131 */
132 @Override
133 public String getNamespace()
134 {
135 return namespace;
136 }
137
138 /**
139 * <!-- begin-user-doc -->
140 * <!-- end-user-doc -->
141 * @generated
142 */
143 @Override
144 public void setNamespace(String newNamespace)
145 {
146 String oldNamespace = namespace;
147 namespace = newNamespace;
148 if (eNotificationRequired())
149 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_IMPORT__NAMESPACE, oldNamespace, namespace));
150 }
151
152 /**
153 * <!-- begin-user-doc -->
154 * <!-- end-user-doc -->
155 * @generated
156 */
157 @Override
158 public XSDAnnotation getAnnotation()
159 {
160 return annotation;
161 }
162
163 /**
164 * <!-- begin-user-doc -->
165 * <!-- end-user-doc -->
166 * @generated
167 */
168 @Override
169 public void setAnnotation(XSDAnnotation newAnnotation)
170 {
171 if (newAnnotation != annotation)
172 {
173 NotificationChain msgs = null;
174 if (annotation != null)
175 msgs = ((InternalEObject)annotation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_IMPORT__ANNOTATION, null, msgs);
176 if (newAnnotation != null)
177 msgs = ((InternalEObject)newAnnotation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_IMPORT__ANNOTATION, null, msgs);
178 msgs = basicSetAnnotation(newAnnotation, msgs);
179 if (msgs != null) msgs.dispatch();
180 }
181 else if (eNotificationRequired())
182 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_IMPORT__ANNOTATION, newAnnotation, newAnnotation));
183 }
184
185 /**
186 * <!-- begin-user-doc -->
187 * <!-- end-user-doc -->
188 * @generated
189 */
190 @Override
191 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
192 {
193 switch (featureID)
194 {
195 case XSDPackage.XSD_IMPORT__ANNOTATION:
196 return basicSetAnnotation(null, msgs);
197 }
198 return super.eInverseRemove(otherEnd, featureID, msgs);
199 }
200
201 /**
202 * <!-- begin-user-doc -->
203 * <!-- end-user-doc -->
204 * @generated
205 */
206 public NotificationChain basicSetAnnotation(XSDAnnotation newAnnotation, NotificationChain msgs)
207 {
208 XSDAnnotation oldAnnotation = annotation;
209 annotation = newAnnotation;
210 if (eNotificationRequired())
211 {
212 ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_IMPORT__ANNOTATION, oldAnnotation, newAnnotation);
213 if (msgs == null) msgs = notification; else msgs.add(notification);
214 }
215 return msgs;
216 }
217
218 /**
219 * <!-- begin-user-doc -->
220 * <!-- end-user-doc -->
221 * @generated
222 */
223 @Override
224 public Object eGet(int featureID, boolean resolve, boolean coreType)
225 {
226 switch (featureID)
227 {
228 case XSDPackage.XSD_IMPORT__NAMESPACE:
229 return getNamespace();
230 case XSDPackage.XSD_IMPORT__ANNOTATION:
231 return getAnnotation();
232 }
233 return super.eGet(featureID, resolve, coreType);
234 }
235
236 /**
237 * <!-- begin-user-doc -->
238 * <!-- end-user-doc -->
239 * @generated
240 */
241 @Override
242 public void eSet(int featureID, Object newValue)
243 {
244 switch (featureID)
245 {
246 case XSDPackage.XSD_IMPORT__NAMESPACE:
247 setNamespace((String)newValue);
248 return;
249 case XSDPackage.XSD_IMPORT__ANNOTATION:
250 setAnnotation((XSDAnnotation)newValue);
251 return;
252 }
253 super.eSet(featureID, newValue);
254 }
255
256 /**
257 * <!-- begin-user-doc -->
258 * <!-- end-user-doc -->
259 * @generated
260 */
261 @Override
262 public void eUnset(int featureID)
263 {
264 switch (featureID)
265 {
266 case XSDPackage.XSD_IMPORT__NAMESPACE:
267 setNamespace(NAMESPACE_EDEFAULT);
268 return;
269 case XSDPackage.XSD_IMPORT__ANNOTATION:
270 setAnnotation((XSDAnnotation)null);
271 return;
272 }
273 super.eUnset(featureID);
274 }
275
276 /**
277 * <!-- begin-user-doc -->
278 * <!-- end-user-doc -->
279 * @generated
280 */
281 @Override
282 public boolean eIsSet(int featureID)
283 {
284 switch (featureID)
285 {
286 case XSDPackage.XSD_IMPORT__NAMESPACE:
287 return NAMESPACE_EDEFAULT == null ? namespace != null : !NAMESPACE_EDEFAULT.equals(namespace);
288 case XSDPackage.XSD_IMPORT__ANNOTATION:
289 return annotation != null;
290 }
291 return super.eIsSet(featureID);
292 }
293
294 /**
295 * <!-- begin-user-doc -->
296 * <!-- end-user-doc -->
297 * @generated
298 */
299 @Override
300 public String toString()
301 {
302 if (eIsProxy()) return super.toString();
303
304 StringBuilder result = new StringBuilder(super.toString());
305 result.append(" (namespace: ");
306 result.append(namespace);
307 result.append(')');
308 return result.toString();
309 }
310
311 @Override
312 public void validate()
313 {
314 super.validate();
315
316 Element theElement = getElement();
317 if (theElement != null)
318 {
319 checkAttributes
320 (XSDConstants.PART1,
321 "element-import",
322 theElement,
323 new String []
324 {
325 XSDConstants.ID_ATTRIBUTE,
326 XSDConstants.NAMESPACE_ATTRIBUTE,
327 XSDConstants.SCHEMALOCATION_ATTRIBUTE,
328 });
329
330 XSDComplexTypeDefinition xsdComplexTypeDefinition =
331 (XSDComplexTypeDefinition)getSchema().getSchemaForSchema().resolveElementDeclaration("import").getTypeDefinition();
332
333 checkComplexContent(xsdComplexTypeDefinition, XSDConstants.PART1, "element-import", theElement);
334
335 checkBuiltInTypeConstraint
336 ("ID",
337 null,
338 XSDConstants.PART1,
339 "element-import",
340 theElement,
341 XSDConstants.ID_ATTRIBUTE,
342 false);
343 }
344
345 checkBuiltInTypeConstraint
346 ("anyURI",
347 getNamespace(),
348 XSDConstants.PART1,
349 "element-import",
350 theElement,
351 XSDConstants.NAMESPACE_ATTRIBUTE,
352 false);
353
354 checkBuiltInTypeConstraint
355 ("anyURI",
356 getSchemaLocation(),
357 XSDConstants.PART1,
358 "element-import",
359 theElement,
360 XSDConstants.SCHEMALOCATION_ATTRIBUTE,
361 false);
362
363
364 XSDSchema xsdSchema = getSchema();
365 if (getNamespace() == null ? xsdSchema.getTargetNamespace() == null : getNamespace().equals(xsdSchema.getTargetNamespace()))
366 {
367 createDiagnostic
368 (XSDDiagnosticSeverity.ERROR_LITERAL,
369 "src-import.1",
370 getNamespace() == null ? "" : getNamespace());
371 }
372
373 XSDSchema theResolvedSchema = getResolvedSchema();
374 if (theResolvedSchema == null)
375 {
376 createDiagnostic
377 (XSDDiagnosticSeverity.WARNING_LITERAL,
378 resolved ? "src-import.0" : "src-import.0.2",
379 getSchemaLocation() == null ? "" : getSchemaLocation());
380 }
381 else
382 {
383 if (theResolvedSchema.eResource() == null ||
384 theResolvedSchema.getElement() == null ||
385 XSDConstants.nodeType(theResolvedSchema.getElement()) != XSDConstants.SCHEMA_ELEMENT)
386 {
387 createDiagnostic
388 (XSDDiagnosticSeverity.ERROR_LITERAL,
389 "src-import.2",
390 getSchemaLocation() == null ? "" : getSchemaLocation());
391 }
392 else
393 {
394 if (getNamespace() == null ?
395 theResolvedSchema.getTargetNamespace() != null :
396 !getNamespace().equals(theResolvedSchema.getTargetNamespace()))
397 {
398 createDiagnostic
399 (XSDDiagnosticSeverity.ERROR_LITERAL,
400 "src-import.3",
401 theResolvedSchema.getTargetNamespace() == null ? "" : theResolvedSchema.getTargetNamespace(),
402 getNamespace() == null ? "" : getNamespace());
403 }
404 }
405 }
406
407 if (getNamespace() != null &&
408 !getSchema().getQNamePrefixToNamespaceMap().containsValue(getNamespace()) &&
409 !XSDConstants.isXMLNamespace(getNamespace()))
410 {
411 createDiagnostic
412 (XSDDiagnosticSeverity.WARNING_LITERAL,
413 "src-import.0.1",
414 getNamespace() == null ? "" : getNamespace());
415 }
416 }
417
418 public XSDSchema importSchema()
419 {
420 resolve(getNamespace(), getSchemaLocation());
421
422 return getResolvedSchema();
423 }
424
425 @Override
426 protected void handleResolvedSchema(XSDSchema xsdSchema)
427 {
428 if (xsdSchema == null)
429 {
430 setResolvedSchema(null);
431 }
432 else
433 {
434 ((XSDSchemaImpl)xsdSchema).imported(this);
435 }
436 }
437
438 @Override
439 protected void handleUnreconciledElement(Element child, List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
440 {
441 XSDAnnotation xsdAnnotation = XSDAnnotationImpl.createAnnotation(child);
442 if (xsdAnnotation != null)
443 {
444 newContents.add(xsdAnnotation);
445 }
446 }
447
448 @Override
449 protected void handleReconciliation(List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
450 {
451 handleAnnotationReconciliation(XSDPackage.Literals.XSD_IMPORT__ANNOTATION, newContents, remainingContents);
452 }
453
454 @Override
455 protected void reconcileAttributes(Element changedElement)
456 {
457 super.reconcileAttributes(changedElement);
458
459 String newNamespace = null;
460 if (changedElement.hasAttributeNS(null, XSDConstants.NAMESPACE_ATTRIBUTE))
461 {
462 newNamespace = changedElement.getAttributeNS(null, XSDConstants.NAMESPACE_ATTRIBUTE);
463 }
464
465 if (newNamespace == null ? getNamespace() != null : !newNamespace.equals(getNamespace()))
466 {
467 setNamespace(newNamespace);
468 }
469 }
470
471 @Override
472 protected void changeAttribute(EAttribute eAttribute)
473 {
474 if (isReconciling)
475 {
476 return;
477 }
478
479 super.changeAttribute(eAttribute);
480 if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_IMPORT__NAMESPACE)
481 {
482 Element theElement = getElement();
483 if (theElement != null)
484 {
485 niceSetAttribute(theElement, XSDConstants.NAMESPACE_ATTRIBUTE, getNamespace());
486 }
487 if (eAttribute != null && getResolvedSchema() != null && getSchema().isIncrementalUpdate())
488 {
489 getSchema().reset();
490 }
491 }
492 }
493
494 @Override
495 public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM)
496 {
497 XSDImportImpl clonedImport =
498 (XSDImportImpl)getXSDFactory().createXSDImport();
499 clonedImport.isReconciling = true;
500
501 clonedImport.setNamespace(getNamespace());
502 clonedImport.setSchemaLocation(getSchemaLocation());
503
504 if (deep)
505 {
506 if (getAnnotation() != null)
507 {
508 clonedImport.setAnnotation((XSDAnnotation)getAnnotation().cloneConcreteComponent(deep, shareDOM));
509 }
510 }
511
512 if (shareDOM && getElement() != null)
513 {
514 clonedImport.setElement(getElement());
515 }
516
517 clonedImport.isReconciling = shareDOM;
518 return clonedImport;
519 }
520 }