| 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.EClass; |
| 22 |
import org.eclipse.emf.ecore.InternalEObject; |
| 23 |
import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 24 |
import org.eclipse.xsd.XSDAnnotation; |
| 25 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 26 |
import org.eclipse.xsd.XSDDiagnosticSeverity; |
| 27 |
import org.eclipse.xsd.XSDFactory; |
| 28 |
import org.eclipse.xsd.XSDInclude; |
| 29 |
import org.eclipse.xsd.XSDPackage; |
| 30 |
import org.eclipse.xsd.XSDSchema; |
| 31 |
import org.eclipse.xsd.util.XSDConstants; |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* <!-- begin-user-doc --> |
| 36 |
* An implementation of the model object '<em><b>Include</b></em>'. |
| 37 |
* <!-- end-user-doc --> |
| 38 |
* <p> |
| 39 |
* The following features are implemented: |
| 40 |
* </p> |
| 41 |
* <ul> |
| 42 |
* <li>{@link org.eclipse.xsd.impl.XSDIncludeImpl#getAnnotation <em>Annotation</em>}</li> |
| 43 |
* </ul> |
| 44 |
* |
| 45 |
* @generated |
| 46 |
*/ |
| 47 |
public class XSDIncludeImpl |
| 48 |
extends XSDSchemaCompositorImpl |
| 49 |
implements XSDInclude |
| 50 |
{ |
| 51 |
/** |
| 52 |
* The cached value of the '{@link #getAnnotation() <em>Annotation</em>}' containment reference. |
| 53 |
* <!-- begin-user-doc --> |
| 54 |
* <!-- end-user-doc --> |
| 55 |
* @see #getAnnotation() |
| 56 |
* @generated |
| 57 |
* @ordered |
| 58 |
*/ |
| 59 |
protected XSDAnnotation annotation; |
| 60 |
|
| 61 |
public static XSDInclude createInclude(Node node) |
| 62 |
{ |
| 63 |
if (XSDConstants.nodeType(node) == XSDConstants.INCLUDE_ELEMENT) |
| 64 |
{ |
| 65 |
XSDInclude xsdInclude = XSDFactory.eINSTANCE.createXSDInclude(); |
| 66 |
xsdInclude.setElement((Element)node); |
| 67 |
return xsdInclude; |
| 68 |
} |
| 69 |
|
| 70 |
return null; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* <!-- begin-user-doc --> |
| 75 |
* <!-- end-user-doc --> |
| 76 |
* @generated |
| 77 |
*/ |
| 78 |
protected XSDIncludeImpl() |
| 79 |
{ |
| 80 |
super(); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* <!-- begin-user-doc --> |
| 85 |
* <!-- end-user-doc --> |
| 86 |
* @generated |
| 87 |
*/ |
| 88 |
@Override |
| 89 |
protected EClass eStaticClass() |
| 90 |
{ |
| 91 |
return XSDPackage.Literals.XSD_INCLUDE; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* <!-- begin-user-doc --> |
| 96 |
* <!-- end-user-doc --> |
| 97 |
* @generated |
| 98 |
*/ |
| 99 |
@Override |
| 100 |
public XSDAnnotation getAnnotation() |
| 101 |
{ |
| 102 |
return annotation; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* <!-- begin-user-doc --> |
| 107 |
* <!-- end-user-doc --> |
| 108 |
* @generated |
| 109 |
*/ |
| 110 |
@Override |
| 111 |
public void setAnnotation(XSDAnnotation newAnnotation) |
| 112 |
{ |
| 113 |
if (newAnnotation != annotation) |
| 114 |
{ |
| 115 |
NotificationChain msgs = null; |
| 116 |
if (annotation != null) |
| 117 |
msgs = ((InternalEObject)annotation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_INCLUDE__ANNOTATION, null, msgs); |
| 118 |
if (newAnnotation != null) |
| 119 |
msgs = ((InternalEObject)newAnnotation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_INCLUDE__ANNOTATION, null, msgs); |
| 120 |
msgs = basicSetAnnotation(newAnnotation, msgs); |
| 121 |
if (msgs != null) msgs.dispatch(); |
| 122 |
} |
| 123 |
else if (eNotificationRequired()) |
| 124 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_INCLUDE__ANNOTATION, newAnnotation, newAnnotation)); |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* <!-- begin-user-doc --> |
| 129 |
* <!-- end-user-doc --> |
| 130 |
* @generated |
| 131 |
*/ |
| 132 |
@Override |
| 133 |
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) |
| 134 |
{ |
| 135 |
switch (featureID) |
| 136 |
{ |
| 137 |
case XSDPackage.XSD_INCLUDE__ANNOTATION: |
| 138 |
return basicSetAnnotation(null, msgs); |
| 139 |
} |
| 140 |
return super.eInverseRemove(otherEnd, featureID, msgs); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* <!-- begin-user-doc --> |
| 145 |
* <!-- end-user-doc --> |
| 146 |
* @generated |
| 147 |
*/ |
| 148 |
public NotificationChain basicSetAnnotation(XSDAnnotation newAnnotation, NotificationChain msgs) |
| 149 |
{ |
| 150 |
XSDAnnotation oldAnnotation = annotation; |
| 151 |
annotation = newAnnotation; |
| 152 |
if (eNotificationRequired()) |
| 153 |
{ |
| 154 |
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_INCLUDE__ANNOTATION, oldAnnotation, newAnnotation); |
| 155 |
if (msgs == null) msgs = notification; else msgs.add(notification); |
| 156 |
} |
| 157 |
return msgs; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* <!-- begin-user-doc --> |
| 162 |
* <!-- end-user-doc --> |
| 163 |
* @generated |
| 164 |
*/ |
| 165 |
@Override |
| 166 |
public Object eGet(int featureID, boolean resolve, boolean coreType) |
| 167 |
{ |
| 168 |
switch (featureID) |
| 169 |
{ |
| 170 |
case XSDPackage.XSD_INCLUDE__ANNOTATION: |
| 171 |
return getAnnotation(); |
| 172 |
} |
| 173 |
return super.eGet(featureID, resolve, coreType); |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* <!-- begin-user-doc --> |
| 178 |
* <!-- end-user-doc --> |
| 179 |
* @generated |
| 180 |
*/ |
| 181 |
@Override |
| 182 |
public void eSet(int featureID, Object newValue) |
| 183 |
{ |
| 184 |
switch (featureID) |
| 185 |
{ |
| 186 |
case XSDPackage.XSD_INCLUDE__ANNOTATION: |
| 187 |
setAnnotation((XSDAnnotation)newValue); |
| 188 |
return; |
| 189 |
} |
| 190 |
super.eSet(featureID, newValue); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* <!-- begin-user-doc --> |
| 195 |
* <!-- end-user-doc --> |
| 196 |
* @generated |
| 197 |
*/ |
| 198 |
@Override |
| 199 |
public void eUnset(int featureID) |
| 200 |
{ |
| 201 |
switch (featureID) |
| 202 |
{ |
| 203 |
case XSDPackage.XSD_INCLUDE__ANNOTATION: |
| 204 |
setAnnotation((XSDAnnotation)null); |
| 205 |
return; |
| 206 |
} |
| 207 |
super.eUnset(featureID); |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* <!-- begin-user-doc --> |
| 212 |
* <!-- end-user-doc --> |
| 213 |
* @generated |
| 214 |
*/ |
| 215 |
@Override |
| 216 |
public boolean eIsSet(int featureID) |
| 217 |
{ |
| 218 |
switch (featureID) |
| 219 |
{ |
| 220 |
case XSDPackage.XSD_INCLUDE__ANNOTATION: |
| 221 |
return annotation != null; |
| 222 |
} |
| 223 |
return super.eIsSet(featureID); |
| 224 |
} |
| 225 |
|
| 226 |
@Override |
| 227 |
public Element createElement() |
| 228 |
{ |
| 229 |
Element newElement = createElement(XSDConstants.INCLUDE_ELEMENT); |
| 230 |
setElement(newElement); |
| 231 |
return newElement; |
| 232 |
} |
| 233 |
|
| 234 |
@Override |
| 235 |
protected void patch() |
| 236 |
{ |
| 237 |
if (getSchemaLocation() != null && getSchemaLocation().length() > 0) |
| 238 |
{ |
| 239 |
resolve("", getSchemaLocation()); |
| 240 |
} |
| 241 |
super.patch(); |
| 242 |
} |
| 243 |
|
| 244 |
@Override |
| 245 |
protected void handleResolvedSchema(XSDSchema xsdSchema) |
| 246 |
{ |
| 247 |
if (xsdSchema == null) |
| 248 |
{ |
| 249 |
setResolvedSchema(null); |
| 250 |
setIncorporatedSchema(null); |
| 251 |
} |
| 252 |
else |
| 253 |
{ |
| 254 |
((XSDSchemaImpl)xsdSchema).included(this); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
@Override |
| 259 |
protected void handleUnreconciledElement(Element child, List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents) |
| 260 |
{ |
| 261 |
XSDAnnotation xsdAnnotation = XSDAnnotationImpl.createAnnotation(child); |
| 262 |
if (xsdAnnotation != null) |
| 263 |
{ |
| 264 |
newContents.add(xsdAnnotation); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
@Override |
| 269 |
protected void handleReconciliation(List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents) |
| 270 |
{ |
| 271 |
handleAnnotationReconciliation(XSDPackage.Literals.XSD_INCLUDE__ANNOTATION, newContents, remainingContents); |
| 272 |
} |
| 273 |
|
| 274 |
@Override |
| 275 |
public void validate() |
| 276 |
{ |
| 277 |
super.validate(); |
| 278 |
|
| 279 |
Element theElement = getElement(); |
| 280 |
if (theElement != null) |
| 281 |
{ |
| 282 |
checkAttributes |
| 283 |
(XSDConstants.PART1, |
| 284 |
"element-include", |
| 285 |
theElement, |
| 286 |
new String [] |
| 287 |
{ |
| 288 |
XSDConstants.ID_ATTRIBUTE, |
| 289 |
XSDConstants.SCHEMALOCATION_ATTRIBUTE, |
| 290 |
}); |
| 291 |
|
| 292 |
checkComplexContent("annotated", XSDConstants.PART1, "element-include", theElement); |
| 293 |
|
| 294 |
checkBuiltInTypeConstraint |
| 295 |
("ID", |
| 296 |
null, |
| 297 |
XSDConstants.PART1, |
| 298 |
"element-include", |
| 299 |
theElement, |
| 300 |
XSDConstants.ID_ATTRIBUTE, |
| 301 |
false); |
| 302 |
} |
| 303 |
|
| 304 |
checkBuiltInTypeConstraint |
| 305 |
("anyURI", |
| 306 |
getSchemaLocation(), |
| 307 |
XSDConstants.PART1, |
| 308 |
"element-include", |
| 309 |
theElement, |
| 310 |
XSDConstants.SCHEMALOCATION_ATTRIBUTE, |
| 311 |
true); |
| 312 |
|
| 313 |
XSDSchema theResolvedSchema = getResolvedSchema(); |
| 314 |
if (theResolvedSchema == null) |
| 315 |
{ |
| 316 |
createDiagnostic |
| 317 |
(XSDDiagnosticSeverity.WARNING_LITERAL, |
| 318 |
"src-include.0", |
| 319 |
getSchemaLocation() == null ? "" : getSchemaLocation()); |
| 320 |
} |
| 321 |
else |
| 322 |
{ |
| 323 |
if (theResolvedSchema.eResource() == null || |
| 324 |
theResolvedSchema.getElement() == null || |
| 325 |
XSDConstants.nodeType(theResolvedSchema.getElement()) != XSDConstants.SCHEMA_ELEMENT) |
| 326 |
{ |
| 327 |
createDiagnostic |
| 328 |
(XSDDiagnosticSeverity.ERROR_LITERAL, |
| 329 |
"src-include.1", |
| 330 |
getSchemaLocation() == null ? "" : getSchemaLocation()); |
| 331 |
} |
| 332 |
else |
| 333 |
{ |
| 334 |
XSDSchema theSchema = getSchema(); |
| 335 |
if (theSchema.getTargetNamespace() == null ? |
| 336 |
theResolvedSchema.getTargetNamespace() != null : |
| 337 |
!theSchema.getTargetNamespace().equals(theResolvedSchema.getTargetNamespace()) && |
| 338 |
theResolvedSchema.getTargetNamespace() != null) |
| 339 |
{ |
| 340 |
createDiagnostic |
| 341 |
(XSDDiagnosticSeverity.ERROR_LITERAL, |
| 342 |
"src-include.2", |
| 343 |
theResolvedSchema.getTargetNamespace() == null ? "" : theResolvedSchema.getTargetNamespace(), |
| 344 |
theSchema.getTargetNamespace() == null ? "" : theSchema.getTargetNamespace()); |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
@Override |
| 351 |
public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM) |
| 352 |
{ |
| 353 |
XSDIncludeImpl clonedInclude = |
| 354 |
(XSDIncludeImpl)getXSDFactory().createXSDInclude(); |
| 355 |
clonedInclude.isReconciling = true; |
| 356 |
|
| 357 |
clonedInclude.setSchemaLocation(getSchemaLocation()); |
| 358 |
|
| 359 |
if (deep) |
| 360 |
{ |
| 361 |
if (getAnnotation() != null) |
| 362 |
{ |
| 363 |
clonedInclude.setAnnotation((XSDAnnotation)getAnnotation().cloneConcreteComponent(deep, shareDOM)); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
if (shareDOM && getElement() != null) |
| 368 |
{ |
| 369 |
clonedInclude.setElement(getElement()); |
| 370 |
} |
| 371 |
|
| 372 |
clonedInclude.isReconciling = shareDOM; |
| 373 |
return clonedInclude; |
| 374 |
} |
| 375 |
} |