| 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.ArrayList; |
| 15 |
import java.util.Collection; |
| 16 |
import java.util.HashSet; |
| 17 |
import java.util.List; |
| 18 |
import java.util.Set; |
| 19 |
|
| 20 |
import org.w3c.dom.Attr; |
| 21 |
import org.w3c.dom.Element; |
| 22 |
import org.w3c.dom.NamedNodeMap; |
| 23 |
import org.w3c.dom.Node; |
| 24 |
|
| 25 |
import org.eclipse.emf.common.util.BasicEList; |
| 26 |
import org.eclipse.emf.common.util.EList; |
| 27 |
import org.eclipse.emf.ecore.EClass; |
| 28 |
import org.eclipse.emf.ecore.util.EDataTypeUniqueEList; |
| 29 |
|
| 30 |
import org.eclipse.xsd.XSDAnnotation; |
| 31 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 32 |
import org.eclipse.xsd.XSDFactory; |
| 33 |
import org.eclipse.xsd.XSDPackage; |
| 34 |
import org.eclipse.xsd.util.XSDConstants; |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* <!-- begin-user-doc --> |
| 39 |
* An implementation of the model object '<em><b>Annotation</b></em>'. |
| 40 |
* <!-- end-user-doc --> |
| 41 |
* <p> |
| 42 |
* The following features are implemented: |
| 43 |
* </p> |
| 44 |
* <ul> |
| 45 |
* <li>{@link org.eclipse.xsd.impl.XSDAnnotationImpl#getApplicationInformation <em>Application Information</em>}</li> |
| 46 |
* <li>{@link org.eclipse.xsd.impl.XSDAnnotationImpl#getUserInformation <em>User Information</em>}</li> |
| 47 |
* <li>{@link org.eclipse.xsd.impl.XSDAnnotationImpl#getAttributes <em>Attributes</em>}</li> |
| 48 |
* </ul> |
| 49 |
* |
| 50 |
* @generated |
| 51 |
*/ |
| 52 |
public class XSDAnnotationImpl |
| 53 |
extends XSDComponentImpl |
| 54 |
implements XSDAnnotation |
| 55 |
{ |
| 56 |
/** |
| 57 |
* The cached value of the '{@link #getApplicationInformation() <em>Application Information</em>}' attribute list. |
| 58 |
* <!-- begin-user-doc --> |
| 59 |
* <!-- end-user-doc --> |
| 60 |
* @see #getApplicationInformation() |
| 61 |
* @generated |
| 62 |
* @ordered |
| 63 |
*/ |
| 64 |
protected EList<Element> applicationInformation; |
| 65 |
|
| 66 |
/** |
| 67 |
* The cached value of the '{@link #getUserInformation() <em>User Information</em>}' attribute list. |
| 68 |
* <!-- begin-user-doc --> |
| 69 |
* <!-- end-user-doc --> |
| 70 |
* @see #getUserInformation() |
| 71 |
* @generated |
| 72 |
* @ordered |
| 73 |
*/ |
| 74 |
protected EList<Element> userInformation; |
| 75 |
|
| 76 |
/** |
| 77 |
* The cached value of the '{@link #getAttributes() <em>Attributes</em>}' attribute list. |
| 78 |
* <!-- begin-user-doc --> |
| 79 |
* <!-- end-user-doc --> |
| 80 |
* @see #getAttributes() |
| 81 |
* @generated |
| 82 |
* @ordered |
| 83 |
*/ |
| 84 |
protected EList<Attr> attributes; |
| 85 |
|
| 86 |
public static XSDAnnotation createAnnotation(Node node) |
| 87 |
{ |
| 88 |
if (XSDConstants.nodeType(node) == XSDConstants.ANNOTATION_ELEMENT) |
| 89 |
{ |
| 90 |
XSDAnnotation xsdAnnotation = XSDFactory.eINSTANCE.createXSDAnnotation(); |
| 91 |
xsdAnnotation.setElement((Element)node); |
| 92 |
return xsdAnnotation; |
| 93 |
} |
| 94 |
|
| 95 |
return null; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* <!-- begin-user-doc --> |
| 100 |
* <!-- end-user-doc --> |
| 101 |
* @generated |
| 102 |
*/ |
| 103 |
protected XSDAnnotationImpl() |
| 104 |
{ |
| 105 |
super(); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* <!-- begin-user-doc --> |
| 110 |
* <!-- end-user-doc --> |
| 111 |
* @generated |
| 112 |
*/ |
| 113 |
@Override |
| 114 |
protected EClass eStaticClass() |
| 115 |
{ |
| 116 |
return XSDPackage.Literals.XSD_ANNOTATION; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* <!-- begin-user-doc --> |
| 121 |
* <!-- end-user-doc --> |
| 122 |
* @generated |
| 123 |
*/ |
| 124 |
@Override |
| 125 |
public EList<Element> getApplicationInformation() |
| 126 |
{ |
| 127 |
if (applicationInformation == null) |
| 128 |
{ |
| 129 |
applicationInformation = new EDataTypeUniqueEList<Element>(Element.class, this, XSDPackage.XSD_ANNOTATION__APPLICATION_INFORMATION); |
| 130 |
} |
| 131 |
return applicationInformation; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* <!-- begin-user-doc --> |
| 136 |
* <!-- end-user-doc --> |
| 137 |
* @generated |
| 138 |
*/ |
| 139 |
@Override |
| 140 |
public EList<Element> getUserInformation() |
| 141 |
{ |
| 142 |
if (userInformation == null) |
| 143 |
{ |
| 144 |
userInformation = new EDataTypeUniqueEList<Element>(Element.class, this, XSDPackage.XSD_ANNOTATION__USER_INFORMATION); |
| 145 |
} |
| 146 |
return userInformation; |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* <!-- begin-user-doc --> |
| 151 |
* <!-- end-user-doc --> |
| 152 |
* @generated |
| 153 |
*/ |
| 154 |
@Override |
| 155 |
public EList<Attr> getAttributes() |
| 156 |
{ |
| 157 |
if (attributes == null) |
| 158 |
{ |
| 159 |
attributes = new EDataTypeUniqueEList<Attr>(Attr.class, this, XSDPackage.XSD_ANNOTATION__ATTRIBUTES); |
| 160 |
} |
| 161 |
return attributes; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* <!-- begin-user-doc --> |
| 166 |
* <!-- end-user-doc --> |
| 167 |
* @generated |
| 168 |
*/ |
| 169 |
@Override |
| 170 |
public Object eGet(int featureID, boolean resolve, boolean coreType) |
| 171 |
{ |
| 172 |
switch (featureID) |
| 173 |
{ |
| 174 |
case XSDPackage.XSD_ANNOTATION__APPLICATION_INFORMATION: |
| 175 |
return getApplicationInformation(); |
| 176 |
case XSDPackage.XSD_ANNOTATION__USER_INFORMATION: |
| 177 |
return getUserInformation(); |
| 178 |
case XSDPackage.XSD_ANNOTATION__ATTRIBUTES: |
| 179 |
return getAttributes(); |
| 180 |
} |
| 181 |
return super.eGet(featureID, resolve, coreType); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* <!-- begin-user-doc --> |
| 186 |
* <!-- end-user-doc --> |
| 187 |
* @generated |
| 188 |
*/ |
| 189 |
@SuppressWarnings("unchecked") |
| 190 |
@Override |
| 191 |
public void eSet(int featureID, Object newValue) |
| 192 |
{ |
| 193 |
switch (featureID) |
| 194 |
{ |
| 195 |
case XSDPackage.XSD_ANNOTATION__APPLICATION_INFORMATION: |
| 196 |
getApplicationInformation().clear(); |
| 197 |
getApplicationInformation().addAll((Collection<? extends Element>)newValue); |
| 198 |
return; |
| 199 |
case XSDPackage.XSD_ANNOTATION__USER_INFORMATION: |
| 200 |
getUserInformation().clear(); |
| 201 |
getUserInformation().addAll((Collection<? extends Element>)newValue); |
| 202 |
return; |
| 203 |
case XSDPackage.XSD_ANNOTATION__ATTRIBUTES: |
| 204 |
getAttributes().clear(); |
| 205 |
getAttributes().addAll((Collection<? extends Attr>)newValue); |
| 206 |
return; |
| 207 |
} |
| 208 |
super.eSet(featureID, newValue); |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* <!-- begin-user-doc --> |
| 213 |
* <!-- end-user-doc --> |
| 214 |
* @generated |
| 215 |
*/ |
| 216 |
@Override |
| 217 |
public void eUnset(int featureID) |
| 218 |
{ |
| 219 |
switch (featureID) |
| 220 |
{ |
| 221 |
case XSDPackage.XSD_ANNOTATION__APPLICATION_INFORMATION: |
| 222 |
getApplicationInformation().clear(); |
| 223 |
return; |
| 224 |
case XSDPackage.XSD_ANNOTATION__USER_INFORMATION: |
| 225 |
getUserInformation().clear(); |
| 226 |
return; |
| 227 |
case XSDPackage.XSD_ANNOTATION__ATTRIBUTES: |
| 228 |
getAttributes().clear(); |
| 229 |
return; |
| 230 |
} |
| 231 |
super.eUnset(featureID); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* <!-- begin-user-doc --> |
| 236 |
* <!-- end-user-doc --> |
| 237 |
* @generated |
| 238 |
*/ |
| 239 |
@Override |
| 240 |
public boolean eIsSet(int featureID) |
| 241 |
{ |
| 242 |
switch (featureID) |
| 243 |
{ |
| 244 |
case XSDPackage.XSD_ANNOTATION__APPLICATION_INFORMATION: |
| 245 |
return applicationInformation != null && !applicationInformation.isEmpty(); |
| 246 |
case XSDPackage.XSD_ANNOTATION__USER_INFORMATION: |
| 247 |
return userInformation != null && !userInformation.isEmpty(); |
| 248 |
case XSDPackage.XSD_ANNOTATION__ATTRIBUTES: |
| 249 |
return attributes != null && !attributes.isEmpty(); |
| 250 |
} |
| 251 |
return super.eIsSet(featureID); |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* <!-- begin-user-doc --> |
| 256 |
* <!-- end-user-doc --> |
| 257 |
* @generated |
| 258 |
*/ |
| 259 |
@Override |
| 260 |
public String toString() |
| 261 |
{ |
| 262 |
if (eIsProxy()) return super.toString(); |
| 263 |
|
| 264 |
StringBuilder result = new StringBuilder(super.toString()); |
| 265 |
result.append(" (applicationInformation: "); |
| 266 |
result.append(applicationInformation); |
| 267 |
result.append(", userInformation: "); |
| 268 |
result.append(userInformation); |
| 269 |
result.append(", attributes: "); |
| 270 |
result.append(attributes); |
| 271 |
result.append(')'); |
| 272 |
return result.toString(); |
| 273 |
} |
| 274 |
|
| 275 |
@Override |
| 276 |
public Element createElement() |
| 277 |
{ |
| 278 |
Element newElement = createElement(XSDConstants.ANNOTATION_ELEMENT); |
| 279 |
setElement(newElement); |
| 280 |
return newElement; |
| 281 |
} |
| 282 |
|
| 283 |
/* |
| 284 |
protected void patch() |
| 285 |
{ |
| 286 |
super.patch(); |
| 287 |
} |
| 288 |
*/ |
| 289 |
|
| 290 |
@Override |
| 291 |
public void validate() |
| 292 |
{ |
| 293 |
super.validate(); |
| 294 |
|
| 295 |
Element theElement = getElement(); |
| 296 |
if (theElement != null) |
| 297 |
{ |
| 298 |
checkElementComplexContent("annotation", XSDConstants.PART1, "element-annotation", theElement); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
@Override |
| 303 |
protected void reconcileAttributes(Element changedElement) |
| 304 |
{ |
| 305 |
super.reconcileAttributes(changedElement); |
| 306 |
|
| 307 |
Element theElement = getElement(); |
| 308 |
if (changedElement == theElement || changedElement.getParentNode() == theElement) |
| 309 |
{ |
| 310 |
XSDConcreteComponent container = getContainer(); |
| 311 |
List<Attr> newAttributes = new ArrayList<Attr>(); |
| 312 |
for (Node theNode = theElement; theNode != null; theNode = theNode.getParentNode()) |
| 313 |
{ |
| 314 |
NamedNodeMap attributes = theNode.getAttributes(); |
| 315 |
for (int i = 0, size = attributes.getLength(); i < size; ++i) |
| 316 |
{ |
| 317 |
Attr attr = (Attr)attributes.item(i); |
| 318 |
String attrName = attr.getNodeName(); |
| 319 |
int index = attrName.lastIndexOf(":"); |
| 320 |
if (index != -1) |
| 321 |
{ |
| 322 |
newAttributes.add(attr); |
| 323 |
} |
| 324 |
} |
| 325 |
if (container == null || container.getElement() == theNode) |
| 326 |
{ |
| 327 |
break; |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
EList<Attr> theAttributes = getAttributes(); |
| 332 |
List<Attr> remainingAttributes = new ArrayList<Attr>(theAttributes); |
| 333 |
remainingAttributes.removeAll(newAttributes); |
| 334 |
if (!remainingAttributes.isEmpty()) |
| 335 |
{ |
| 336 |
theAttributes.removeAll(remainingAttributes); |
| 337 |
} |
| 338 |
setListContentAndOrder(theAttributes, newAttributes); |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
@Override |
| 343 |
protected void reconcileContents(Element changedElement) |
| 344 |
{ |
| 345 |
Element theElement = getElement(); |
| 346 |
if (changedElement == theElement || changedElement.getParentNode() == theElement) |
| 347 |
{ |
| 348 |
List<Element> newApplicationInformation = new ArrayList<Element>(); |
| 349 |
List<Element> newUserInformation = new ArrayList<Element>(); |
| 350 |
for (Node child = theElement.getFirstChild(); child != null; child = child.getNextSibling()) |
| 351 |
{ |
| 352 |
switch (XSDConstants.nodeType(child)) |
| 353 |
{ |
| 354 |
case XSDConstants.APPINFO_ELEMENT: |
| 355 |
{ |
| 356 |
newApplicationInformation.add((Element)child); |
| 357 |
break; |
| 358 |
} |
| 359 |
case XSDConstants.DOCUMENTATION_ELEMENT: |
| 360 |
{ |
| 361 |
newUserInformation.add((Element)child); |
| 362 |
break; |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
EList<Element> theApplicationInformation = getApplicationInformation(); |
| 368 |
List<Element> remainingApplicationInformation = new ArrayList<Element>(theApplicationInformation); |
| 369 |
remainingApplicationInformation.removeAll(newApplicationInformation); |
| 370 |
if (!remainingApplicationInformation.isEmpty()) |
| 371 |
{ |
| 372 |
theApplicationInformation.removeAll(remainingApplicationInformation); |
| 373 |
} |
| 374 |
setListContentAndOrder(theApplicationInformation, newApplicationInformation); |
| 375 |
|
| 376 |
EList<Element> theUserInformation = getUserInformation(); |
| 377 |
List<Element> remainingUserInformation = new ArrayList<Element>(theUserInformation); |
| 378 |
remainingUserInformation.removeAll(newUserInformation); |
| 379 |
if (!remainingUserInformation.isEmpty()) |
| 380 |
{ |
| 381 |
remainingUserInformation.removeAll(newUserInformation); |
| 382 |
} |
| 383 |
theUserInformation.removeAll(remainingUserInformation); |
| 384 |
setListContentAndOrder(theUserInformation, newUserInformation); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
public Element createApplicationInformation(String sourceURI) |
| 389 |
{ |
| 390 |
if (getElement() == null) |
| 391 |
{ |
| 392 |
updateElement(); |
| 393 |
} |
| 394 |
|
| 395 |
Element result = createElement(XSDConstants.APPINFO_ELEMENT); |
| 396 |
if (sourceURI != null && result != null) |
| 397 |
{ |
| 398 |
result.setAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE, sourceURI); |
| 399 |
} |
| 400 |
return result; |
| 401 |
} |
| 402 |
|
| 403 |
public Element createUserInformation(String sourceURI) |
| 404 |
{ |
| 405 |
if (getElement() == null) |
| 406 |
{ |
| 407 |
updateElement(); |
| 408 |
} |
| 409 |
|
| 410 |
Element result = createElement(XSDConstants.DOCUMENTATION_ELEMENT); |
| 411 |
if (sourceURI != null && result != null) |
| 412 |
{ |
| 413 |
result.setAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE, sourceURI); |
| 414 |
} |
| 415 |
return result; |
| 416 |
} |
| 417 |
|
| 418 |
public EList<Element> getApplicationInformation(String sourceURI) |
| 419 |
{ |
| 420 |
EList<Element> result = new BasicEList<Element>(); |
| 421 |
for (Element appinfo : getApplicationInformation()) |
| 422 |
{ |
| 423 |
if (sourceURI == null ? |
| 424 |
!appinfo.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : |
| 425 |
appinfo.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE).equals(sourceURI)) |
| 426 |
{ |
| 427 |
result.add(appinfo); |
| 428 |
} |
| 429 |
} |
| 430 |
return result; |
| 431 |
} |
| 432 |
|
| 433 |
public EList<Element> getUserInformation(String sourceURI) |
| 434 |
{ |
| 435 |
EList<Element> result = new BasicEList<Element>(); |
| 436 |
for (Element documentation : getUserInformation()) |
| 437 |
{ |
| 438 |
if (sourceURI == null ? |
| 439 |
!documentation.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : |
| 440 |
documentation.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE).equals(sourceURI)) |
| 441 |
{ |
| 442 |
result.add(documentation); |
| 443 |
} |
| 444 |
} |
| 445 |
return result; |
| 446 |
} |
| 447 |
|
| 448 |
public Set<String> getApplicationInformationSources() |
| 449 |
{ |
| 450 |
Set<String> result = new HashSet<String>(); |
| 451 |
for (Element appinfo : getApplicationInformation()) |
| 452 |
{ |
| 453 |
result.add |
| 454 |
(appinfo.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) ? appinfo.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : null); |
| 455 |
} |
| 456 |
return result; |
| 457 |
} |
| 458 |
|
| 459 |
public Set<String> getUserInformationSources() |
| 460 |
{ |
| 461 |
Set<String> result = new HashSet<String>(); |
| 462 |
for (Element documentation : getUserInformation()) |
| 463 |
{ |
| 464 |
result.add |
| 465 |
(documentation.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) ? |
| 466 |
documentation.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : null); |
| 467 |
} |
| 468 |
return result; |
| 469 |
} |
| 470 |
|
| 471 |
@Override |
| 472 |
protected void getComponentsWithInformation(Collection<XSDConcreteComponent> result, int nodeType, String sourceURI) |
| 473 |
{ |
| 474 |
for (Element childElement : nodeType == XSDConstants.APPINFO_ELEMENT ? getApplicationInformation() : getUserInformation()) |
| 475 |
{ |
| 476 |
if (sourceURI == null ? |
| 477 |
!childElement.hasAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE) : |
| 478 |
childElement.getAttributeNS(null, XSDConstants.SOURCE_ATTRIBUTE).equals(sourceURI)) |
| 479 |
{ |
| 480 |
result.add(getContainer()); |
| 481 |
break; |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
@Override |
| 487 |
public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM) |
| 488 |
{ |
| 489 |
XSDAnnotationImpl clonedAnnotation = (XSDAnnotationImpl)getXSDFactory().createXSDAnnotation(); |
| 490 |
clonedAnnotation.isReconciling = true; |
| 491 |
|
| 492 |
if (shareDOM) |
| 493 |
{ |
| 494 |
Element element = getElement(); |
| 495 |
if (element != null) |
| 496 |
{ |
| 497 |
clonedAnnotation.setElement(element); |
| 498 |
} |
| 499 |
|
| 500 |
clonedAnnotation.getApplicationInformation().addAll(getApplicationInformation()); |
| 501 |
clonedAnnotation.getUserInformation().addAll(getUserInformation()); |
| 502 |
clonedAnnotation.getAttributes().addAll(getAttributes()); |
| 503 |
} |
| 504 |
|
| 505 |
clonedAnnotation.isReconciling = shareDOM; |
| 506 |
return clonedAnnotation; |
| 507 |
} |
| 508 |
} |