| 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.io.PrintStream; |
| 15 |
import java.util.ArrayList; |
| 16 |
import java.util.Collection; |
| 17 |
import java.util.Collections; |
| 18 |
import java.util.HashMap; |
| 19 |
import java.util.HashSet; |
| 20 |
import java.util.Iterator; |
| 21 |
import java.util.List; |
| 22 |
import java.util.Map; |
| 23 |
import java.util.Set; |
| 24 |
|
| 25 |
import org.eclipse.emf.common.notify.Notification; |
| 26 |
import org.eclipse.emf.common.notify.NotificationChain; |
| 27 |
import org.eclipse.emf.common.util.BasicEList; |
| 28 |
import org.eclipse.emf.common.util.UniqueEList; |
| 29 |
import org.eclipse.emf.ecore.EAttribute; |
| 30 |
import org.eclipse.emf.ecore.EClass; |
| 31 |
import org.eclipse.emf.ecore.EReference; |
| 32 |
import org.eclipse.emf.ecore.InternalEObject; |
| 33 |
import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 34 |
import org.eclipse.xsd.XSDComponent; |
| 35 |
import org.eclipse.xsd.XSDCompositor; |
| 36 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 37 |
import org.eclipse.xsd.XSDConstraint; |
| 38 |
import org.eclipse.xsd.XSDDiagnostic; |
| 39 |
import org.eclipse.xsd.XSDDiagnosticSeverity; |
| 40 |
import org.eclipse.xsd.XSDElementDeclaration; |
| 41 |
import org.eclipse.xsd.XSDFactory; |
| 42 |
import org.eclipse.xsd.XSDModelGroup; |
| 43 |
import org.eclipse.xsd.XSDModelGroupDefinition; |
| 44 |
import org.eclipse.xsd.XSDPackage; |
| 45 |
import org.eclipse.xsd.XSDParticle; |
| 46 |
import org.eclipse.xsd.XSDParticleContent; |
| 47 |
import org.eclipse.xsd.XSDPlugin; |
| 48 |
import org.eclipse.xsd.XSDSimpleTypeDefinition; |
| 49 |
import org.eclipse.xsd.XSDTerm; |
| 50 |
import org.eclipse.xsd.XSDTypeDefinition; |
| 51 |
import org.eclipse.xsd.XSDWildcard; |
| 52 |
import org.eclipse.xsd.util.XSDConstants; |
| 53 |
import org.eclipse.xsd.util.XSDSwitch; |
| 54 |
import org.w3c.dom.Element; |
| 55 |
import org.w3c.dom.Node; |
| 56 |
|
| 57 |
|
| 58 |
/** |
| 59 |
* <!-- begin-user-doc --> |
| 60 |
* An implementation of the model object '<em><b>Particle</b></em>'. |
| 61 |
* <!-- end-user-doc --> |
| 62 |
* <p> |
| 63 |
* The following features are implemented: |
| 64 |
* </p> |
| 65 |
* <ul> |
| 66 |
* <li>{@link org.eclipse.xsd.impl.XSDParticleImpl#getMinOccurs <em>Min Occurs</em>}</li> |
| 67 |
* <li>{@link org.eclipse.xsd.impl.XSDParticleImpl#getMaxOccurs <em>Max Occurs</em>}</li> |
| 68 |
* <li>{@link org.eclipse.xsd.impl.XSDParticleImpl#getContent <em>Content</em>}</li> |
| 69 |
* <li>{@link org.eclipse.xsd.impl.XSDParticleImpl#getTerm <em>Term</em>}</li> |
| 70 |
* </ul> |
| 71 |
* |
| 72 |
* @generated |
| 73 |
*/ |
| 74 |
public class XSDParticleImpl |
| 75 |
extends XSDComplexTypeContentImpl |
| 76 |
implements XSDParticle |
| 77 |
{ |
| 78 |
protected static final int MAXIMUM_STATES = 10000; |
| 79 |
|
| 80 |
/** |
| 81 |
* The default value of the '{@link #getMinOccurs() <em>Min Occurs</em>}' attribute. |
| 82 |
* <!-- begin-user-doc --> |
| 83 |
* <!-- end-user-doc --> |
| 84 |
* @see #getMinOccurs() |
| 85 |
* @generated |
| 86 |
* @ordered |
| 87 |
*/ |
| 88 |
protected static final int MIN_OCCURS_EDEFAULT = 1; |
| 89 |
|
| 90 |
/** |
| 91 |
* The cached value of the '{@link #getMinOccurs() <em>Min Occurs</em>}' attribute. |
| 92 |
* <!-- begin-user-doc --> |
| 93 |
* <!-- end-user-doc --> |
| 94 |
* @see #getMinOccurs() |
| 95 |
* @generated |
| 96 |
* @ordered |
| 97 |
*/ |
| 98 |
protected int minOccurs = MIN_OCCURS_EDEFAULT; |
| 99 |
|
| 100 |
/** |
| 101 |
* The flag representing whether the Min Occurs attribute has been set. |
| 102 |
* <!-- begin-user-doc --> |
| 103 |
* <!-- end-user-doc --> |
| 104 |
* @generated |
| 105 |
* @ordered |
| 106 |
*/ |
| 107 |
protected static final int MIN_OCCURS_ESETFLAG = 1 << 8; |
| 108 |
|
| 109 |
/** |
| 110 |
* The default value of the '{@link #getMaxOccurs() <em>Max Occurs</em>}' attribute. |
| 111 |
* <!-- begin-user-doc --> |
| 112 |
* <!-- end-user-doc --> |
| 113 |
* @see #getMaxOccurs() |
| 114 |
* @generated |
| 115 |
* @ordered |
| 116 |
*/ |
| 117 |
protected static final int MAX_OCCURS_EDEFAULT = 1; |
| 118 |
|
| 119 |
/** |
| 120 |
* The cached value of the '{@link #getMaxOccurs() <em>Max Occurs</em>}' attribute. |
| 121 |
* <!-- begin-user-doc --> |
| 122 |
* <!-- end-user-doc --> |
| 123 |
* @see #getMaxOccurs() |
| 124 |
* @generated |
| 125 |
* @ordered |
| 126 |
*/ |
| 127 |
protected int maxOccurs = MAX_OCCURS_EDEFAULT; |
| 128 |
|
| 129 |
/** |
| 130 |
* The flag representing whether the Max Occurs attribute has been set. |
| 131 |
* <!-- begin-user-doc --> |
| 132 |
* <!-- end-user-doc --> |
| 133 |
* @generated |
| 134 |
* @ordered |
| 135 |
*/ |
| 136 |
protected static final int MAX_OCCURS_ESETFLAG = 1 << 9; |
| 137 |
|
| 138 |
/** |
| 139 |
* The cached value of the '{@link #getContent() <em>Content</em>}' containment reference. |
| 140 |
* <!-- begin-user-doc --> |
| 141 |
* <!-- end-user-doc --> |
| 142 |
* @see #getContent() |
| 143 |
* @generated |
| 144 |
* @ordered |
| 145 |
*/ |
| 146 |
protected XSDParticleContent content; |
| 147 |
|
| 148 |
/** |
| 149 |
* The cached value of the '{@link #getTerm() <em>Term</em>}' reference. |
| 150 |
* <!-- begin-user-doc --> |
| 151 |
* <!-- end-user-doc --> |
| 152 |
* @see #getTerm() |
| 153 |
* @generated |
| 154 |
* @ordered |
| 155 |
*/ |
| 156 |
protected XSDTerm term; |
| 157 |
|
| 158 |
public static XSDParticle createParticle(Node node) |
| 159 |
{ |
| 160 |
XSDParticleContent xsdParticleContent = XSDParticleContentImpl.createParticleContent(node); |
| 161 |
if (xsdParticleContent != null) |
| 162 |
{ |
| 163 |
XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle(); |
| 164 |
xsdParticle.setElement((Element)node); |
| 165 |
xsdParticle.setContent(xsdParticleContent); |
| 166 |
return xsdParticle; |
| 167 |
} |
| 168 |
|
| 169 |
return null; |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* <!-- begin-user-doc --> |
| 174 |
* <!-- end-user-doc --> |
| 175 |
* @generated |
| 176 |
*/ |
| 177 |
protected XSDParticleImpl() |
| 178 |
{ |
| 179 |
super(); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* <!-- begin-user-doc --> |
| 184 |
* <!-- end-user-doc --> |
| 185 |
* @generated |
| 186 |
*/ |
| 187 |
@Override |
| 188 |
protected EClass eStaticClass() |
| 189 |
{ |
| 190 |
return XSDPackage.Literals.XSD_PARTICLE; |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* <!-- begin-user-doc --> |
| 195 |
* <!-- end-user-doc --> |
| 196 |
* @generated |
| 197 |
*/ |
| 198 |
@Override |
| 199 |
public int getMinOccurs() |
| 200 |
{ |
| 201 |
return minOccurs; |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* <!-- begin-user-doc --> |
| 206 |
* <!-- end-user-doc --> |
| 207 |
* @generated |
| 208 |
*/ |
| 209 |
@Override |
| 210 |
public void setMinOccurs(int newMinOccurs) |
| 211 |
{ |
| 212 |
int oldMinOccurs = minOccurs; |
| 213 |
minOccurs = newMinOccurs; |
| 214 |
boolean oldMinOccursESet = (eFlags & MIN_OCCURS_ESETFLAG) != 0; |
| 215 |
eFlags |= MIN_OCCURS_ESETFLAG; |
| 216 |
if (eNotificationRequired()) |
| 217 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_PARTICLE__MIN_OCCURS, oldMinOccurs, minOccurs, !oldMinOccursESet)); |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* <!-- begin-user-doc --> |
| 222 |
* <!-- end-user-doc --> |
| 223 |
* @generated |
| 224 |
*/ |
| 225 |
@Override |
| 226 |
public void unsetMinOccurs() |
| 227 |
{ |
| 228 |
int oldMinOccurs = minOccurs; |
| 229 |
boolean oldMinOccursESet = (eFlags & MIN_OCCURS_ESETFLAG) != 0; |
| 230 |
minOccurs = MIN_OCCURS_EDEFAULT; |
| 231 |
eFlags &= ~MIN_OCCURS_ESETFLAG; |
| 232 |
if (eNotificationRequired()) |
| 233 |
eNotify(new ENotificationImpl(this, Notification.UNSET, XSDPackage.XSD_PARTICLE__MIN_OCCURS, oldMinOccurs, MIN_OCCURS_EDEFAULT, oldMinOccursESet)); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* <!-- begin-user-doc --> |
| 238 |
* <!-- end-user-doc --> |
| 239 |
* @generated |
| 240 |
*/ |
| 241 |
@Override |
| 242 |
public boolean isSetMinOccurs() |
| 243 |
{ |
| 244 |
return (eFlags & MIN_OCCURS_ESETFLAG) != 0; |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* <!-- begin-user-doc --> |
| 249 |
* <!-- end-user-doc --> |
| 250 |
* @generated |
| 251 |
*/ |
| 252 |
@Override |
| 253 |
public int getMaxOccurs() |
| 254 |
{ |
| 255 |
return maxOccurs; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* <!-- begin-user-doc --> |
| 260 |
* <!-- end-user-doc --> |
| 261 |
* @generated |
| 262 |
*/ |
| 263 |
@Override |
| 264 |
public void setMaxOccurs(int newMaxOccurs) |
| 265 |
{ |
| 266 |
int oldMaxOccurs = maxOccurs; |
| 267 |
maxOccurs = newMaxOccurs; |
| 268 |
boolean oldMaxOccursESet = (eFlags & MAX_OCCURS_ESETFLAG) != 0; |
| 269 |
eFlags |= MAX_OCCURS_ESETFLAG; |
| 270 |
if (eNotificationRequired()) |
| 271 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_PARTICLE__MAX_OCCURS, oldMaxOccurs, maxOccurs, !oldMaxOccursESet)); |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* <!-- begin-user-doc --> |
| 276 |
* <!-- end-user-doc --> |
| 277 |
* @generated |
| 278 |
*/ |
| 279 |
@Override |
| 280 |
public void unsetMaxOccurs() |
| 281 |
{ |
| 282 |
int oldMaxOccurs = maxOccurs; |
| 283 |
boolean oldMaxOccursESet = (eFlags & MAX_OCCURS_ESETFLAG) != 0; |
| 284 |
maxOccurs = MAX_OCCURS_EDEFAULT; |
| 285 |
eFlags &= ~MAX_OCCURS_ESETFLAG; |
| 286 |
if (eNotificationRequired()) |
| 287 |
eNotify(new ENotificationImpl(this, Notification.UNSET, XSDPackage.XSD_PARTICLE__MAX_OCCURS, oldMaxOccurs, MAX_OCCURS_EDEFAULT, oldMaxOccursESet)); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* <!-- begin-user-doc --> |
| 292 |
* <!-- end-user-doc --> |
| 293 |
* @generated |
| 294 |
*/ |
| 295 |
@Override |
| 296 |
public boolean isSetMaxOccurs() |
| 297 |
{ |
| 298 |
return (eFlags & MAX_OCCURS_ESETFLAG) != 0; |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* <!-- begin-user-doc --> |
| 303 |
* <!-- end-user-doc --> |
| 304 |
* @generated |
| 305 |
*/ |
| 306 |
@Override |
| 307 |
public XSDParticleContent getContent() |
| 308 |
{ |
| 309 |
return content; |
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* <!-- begin-user-doc --> |
| 314 |
* <!-- end-user-doc --> |
| 315 |
* @generated |
| 316 |
*/ |
| 317 |
@Override |
| 318 |
public void setContent(XSDParticleContent newContent) |
| 319 |
{ |
| 320 |
if (newContent != content) |
| 321 |
{ |
| 322 |
NotificationChain msgs = null; |
| 323 |
if (content != null) |
| 324 |
msgs = ((InternalEObject)content).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_PARTICLE__CONTENT, null, msgs); |
| 325 |
if (newContent != null) |
| 326 |
msgs = ((InternalEObject)newContent).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_PARTICLE__CONTENT, null, msgs); |
| 327 |
msgs = basicSetContent(newContent, msgs); |
| 328 |
if (msgs != null) msgs.dispatch(); |
| 329 |
} |
| 330 |
else if (eNotificationRequired()) |
| 331 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_PARTICLE__CONTENT, newContent, newContent)); |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* <!-- begin-user-doc --> |
| 336 |
* <!-- end-user-doc --> |
| 337 |
* @generated |
| 338 |
*/ |
| 339 |
public NotificationChain basicSetContent(XSDParticleContent newContent, NotificationChain msgs) |
| 340 |
{ |
| 341 |
XSDParticleContent oldContent = content; |
| 342 |
content = newContent; |
| 343 |
if (eNotificationRequired()) |
| 344 |
{ |
| 345 |
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_PARTICLE__CONTENT, oldContent, newContent); |
| 346 |
if (msgs == null) msgs = notification; else msgs.add(notification); |
| 347 |
} |
| 348 |
return msgs; |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* <!-- begin-user-doc --> |
| 353 |
* <!-- end-user-doc --> |
| 354 |
* @generated |
| 355 |
*/ |
| 356 |
@Override |
| 357 |
public XSDTerm getTerm() |
| 358 |
{ |
| 359 |
return term; |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* <!-- begin-user-doc --> |
| 364 |
* <!-- end-user-doc --> |
| 365 |
* @generated |
| 366 |
*/ |
| 367 |
@Override |
| 368 |
public void setTerm(XSDTerm newTerm) |
| 369 |
{ |
| 370 |
XSDTerm oldTerm = term; |
| 371 |
term = newTerm; |
| 372 |
if (eNotificationRequired()) |
| 373 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_PARTICLE__TERM, oldTerm, term)); |
| 374 |
} |
| 375 |
|
| 376 |
/** |
| 377 |
* <!-- begin-user-doc --> |
| 378 |
* <!-- end-user-doc --> |
| 379 |
* @generated |
| 380 |
*/ |
| 381 |
@Override |
| 382 |
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) |
| 383 |
{ |
| 384 |
switch (featureID) |
| 385 |
{ |
| 386 |
case XSDPackage.XSD_PARTICLE__CONTENT: |
| 387 |
return basicSetContent(null, msgs); |
| 388 |
} |
| 389 |
return super.eInverseRemove(otherEnd, featureID, msgs); |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* <!-- begin-user-doc --> |
| 394 |
* <!-- end-user-doc --> |
| 395 |
* @generated |
| 396 |
*/ |
| 397 |
@Override |
| 398 |
public Object eGet(int featureID, boolean resolve, boolean coreType) |
| 399 |
{ |
| 400 |
switch (featureID) |
| 401 |
{ |
| 402 |
case XSDPackage.XSD_PARTICLE__MIN_OCCURS: |
| 403 |
return getMinOccurs(); |
| 404 |
case XSDPackage.XSD_PARTICLE__MAX_OCCURS: |
| 405 |
return getMaxOccurs(); |
| 406 |
case XSDPackage.XSD_PARTICLE__CONTENT: |
| 407 |
return getContent(); |
| 408 |
case XSDPackage.XSD_PARTICLE__TERM: |
| 409 |
return getTerm(); |
| 410 |
} |
| 411 |
return super.eGet(featureID, resolve, coreType); |
| 412 |
} |
| 413 |
|
| 414 |
/** |
| 415 |
* <!-- begin-user-doc --> |
| 416 |
* <!-- end-user-doc --> |
| 417 |
* @generated |
| 418 |
*/ |
| 419 |
@Override |
| 420 |
public void eSet(int featureID, Object newValue) |
| 421 |
{ |
| 422 |
switch (featureID) |
| 423 |
{ |
| 424 |
case XSDPackage.XSD_PARTICLE__MIN_OCCURS: |
| 425 |
setMinOccurs((Integer)newValue); |
| 426 |
return; |
| 427 |
case XSDPackage.XSD_PARTICLE__MAX_OCCURS: |
| 428 |
setMaxOccurs((Integer)newValue); |
| 429 |
return; |
| 430 |
case XSDPackage.XSD_PARTICLE__CONTENT: |
| 431 |
setContent((XSDParticleContent)newValue); |
| 432 |
return; |
| 433 |
case XSDPackage.XSD_PARTICLE__TERM: |
| 434 |
setTerm((XSDTerm)newValue); |
| 435 |
return; |
| 436 |
} |
| 437 |
super.eSet(featureID, newValue); |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* <!-- begin-user-doc --> |
| 442 |
* <!-- end-user-doc --> |
| 443 |
* @generated |
| 444 |
*/ |
| 445 |
@Override |
| 446 |
public void eUnset(int featureID) |
| 447 |
{ |
| 448 |
switch (featureID) |
| 449 |
{ |
| 450 |
case XSDPackage.XSD_PARTICLE__MIN_OCCURS: |
| 451 |
unsetMinOccurs(); |
| 452 |
return; |
| 453 |
case XSDPackage.XSD_PARTICLE__MAX_OCCURS: |
| 454 |
unsetMaxOccurs(); |
| 455 |
return; |
| 456 |
case XSDPackage.XSD_PARTICLE__CONTENT: |
| 457 |
setContent((XSDParticleContent)null); |
| 458 |
return; |
| 459 |
case XSDPackage.XSD_PARTICLE__TERM: |
| 460 |
setTerm((XSDTerm)null); |
| 461 |
return; |
| 462 |
} |
| 463 |
super.eUnset(featureID); |
| 464 |
} |
| 465 |
|
| 466 |
/** |
| 467 |
* <!-- begin-user-doc --> |
| 468 |
* <!-- end-user-doc --> |
| 469 |
* @generated |
| 470 |
*/ |
| 471 |
@Override |
| 472 |
public boolean eIsSet(int featureID) |
| 473 |
{ |
| 474 |
switch (featureID) |
| 475 |
{ |
| 476 |
case XSDPackage.XSD_PARTICLE__MIN_OCCURS: |
| 477 |
return isSetMinOccurs(); |
| 478 |
case XSDPackage.XSD_PARTICLE__MAX_OCCURS: |
| 479 |
return isSetMaxOccurs(); |
| 480 |
case XSDPackage.XSD_PARTICLE__CONTENT: |
| 481 |
return content != null; |
| 482 |
case XSDPackage.XSD_PARTICLE__TERM: |
| 483 |
return term != null; |
| 484 |
} |
| 485 |
return super.eIsSet(featureID); |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* <!-- begin-user-doc --> |
| 490 |
* <!-- end-user-doc --> |
| 491 |
* @generated |
| 492 |
*/ |
| 493 |
@Override |
| 494 |
public String toString() |
| 495 |
{ |
| 496 |
if (eIsProxy()) return super.toString(); |
| 497 |
|
| 498 |
StringBuilder result = new StringBuilder(super.toString()); |
| 499 |
result.append(" (minOccurs: "); |
| 500 |
if ((eFlags & MIN_OCCURS_ESETFLAG) != 0) result.append(minOccurs); else result.append("<unset>"); |
| 501 |
result.append(", maxOccurs: "); |
| 502 |
if ((eFlags & MAX_OCCURS_ESETFLAG) != 0) result.append(maxOccurs); else result.append("<unset>"); |
| 503 |
result.append(')'); |
| 504 |
return result.toString(); |
| 505 |
} |
| 506 |
|
| 507 |
@Override |
| 508 |
public Element createElement() |
| 509 |
{ |
| 510 |
Element newElement = null; |
| 511 |
XSDParticleContent theContent = getContent(); |
| 512 |
if (theContent != null) |
| 513 |
{ |
| 514 |
newElement = ((XSDConcreteComponentImpl)theContent).createElement(); |
| 515 |
setElement(newElement); |
| 516 |
} |
| 517 |
return newElement; |
| 518 |
} |
| 519 |
|
| 520 |
@Override |
| 521 |
protected void patch() |
| 522 |
{ |
| 523 |
super.patch(); |
| 524 |
patchHelper(); |
| 525 |
} |
| 526 |
|
| 527 |
protected void patchHelper() |
| 528 |
{ |
| 529 |
XSDParticleContent theContent = getContent(); |
| 530 |
XSDTerm newTerm = null; |
| 531 |
if (theContent instanceof XSDModelGroupDefinition) |
| 532 |
{ |
| 533 |
XSDModelGroupDefinition xsdModelGroupDefinition = (XSDModelGroupDefinition)theContent; |
| 534 |
newTerm = xsdModelGroupDefinition.getResolvedModelGroupDefinition().getModelGroup(); |
| 535 |
} |
| 536 |
else if (theContent instanceof XSDElementDeclaration) |
| 537 |
{ |
| 538 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)theContent; |
| 539 |
newTerm = xsdElementDeclaration.getResolvedElementDeclaration(); |
| 540 |
} |
| 541 |
else |
| 542 |
{ |
| 543 |
newTerm = (XSDTerm)theContent; |
| 544 |
} |
| 545 |
|
| 546 |
if (getTerm() != newTerm) |
| 547 |
{ |
| 548 |
setTerm(newTerm); |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
@Override |
| 553 |
public boolean analyze() |
| 554 |
{ |
| 555 |
xsdNFA = null; |
| 556 |
return super.analyze(); |
| 557 |
} |
| 558 |
|
| 559 |
@Override |
| 560 |
public void validate() |
| 561 |
{ |
| 562 |
super.validate(); |
| 563 |
|
| 564 |
if (getMaxOccurs() != -1) |
| 565 |
{ |
| 566 |
if (getMinOccurs() > getMaxOccurs()) |
| 567 |
{ |
| 568 |
createDiagnostic(XSDDiagnosticSeverity.ERROR_LITERAL, "coss-particle.2.1"); |
| 569 |
} |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
@Override |
| 574 |
protected Collection<Element> getContentNodes(Element changedElement) |
| 575 |
{ |
| 576 |
return Collections.singleton(getElement()); |
| 577 |
} |
| 578 |
|
| 579 |
@Override |
| 580 |
protected void reconcileAttributes(Element changedElement) |
| 581 |
{ |
| 582 |
super.reconcileAttributes(changedElement); |
| 583 |
|
| 584 |
if (changedElement == getElement()) |
| 585 |
{ |
| 586 |
if (changedElement.hasAttributeNS(null, XSDConstants.MINOCCURS_ATTRIBUTE)) |
| 587 |
{ |
| 588 |
String newMinOccurs = changedElement.getAttributeNS(null, XSDConstants.MINOCCURS_ATTRIBUTE); |
| 589 |
try |
| 590 |
{ |
| 591 |
int newMinOccursValue = Integer.parseInt(newMinOccurs); |
| 592 |
if (!isSetMinOccurs() || newMinOccursValue != getMinOccurs()) |
| 593 |
{ |
| 594 |
setMinOccurs(newMinOccursValue); |
| 595 |
} |
| 596 |
} |
| 597 |
catch (NumberFormatException exception) |
| 598 |
{ |
| 599 |
// Ignore |
| 600 |
} |
| 601 |
} |
| 602 |
else if (isSetMinOccurs()) |
| 603 |
{ |
| 604 |
unsetMinOccurs(); |
| 605 |
} |
| 606 |
|
| 607 |
if (changedElement.hasAttributeNS(null, XSDConstants.MAXOCCURS_ATTRIBUTE)) |
| 608 |
{ |
| 609 |
String newMaxOccurs = changedElement.getAttributeNS(null, XSDConstants.MAXOCCURS_ATTRIBUTE); |
| 610 |
try |
| 611 |
{ |
| 612 |
int newMaxOccursValue = "unbounded".equals(newMaxOccurs) ? -1 : Integer.parseInt(newMaxOccurs); |
| 613 |
if (!isSetMaxOccurs() || newMaxOccursValue != getMaxOccurs()) |
| 614 |
{ |
| 615 |
setMaxOccurs(newMaxOccursValue); |
| 616 |
} |
| 617 |
} |
| 618 |
catch (NumberFormatException exception) |
| 619 |
{ |
| 620 |
// Ignore |
| 621 |
} |
| 622 |
} |
| 623 |
else if (isSetMaxOccurs()) |
| 624 |
{ |
| 625 |
unsetMaxOccurs(); |
| 626 |
} |
| 627 |
|
| 628 |
XSDParticleContent theContent = getContent(); |
| 629 |
if (theContent != null) |
| 630 |
{ |
| 631 |
theContent.elementAttributesChanged(changedElement); |
| 632 |
} |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
@Override |
| 637 |
protected void reconcileContents(Element changedElement) |
| 638 |
{ |
| 639 |
super.reconcileContents(changedElement); |
| 640 |
XSDParticleContent theContent = getContent(); |
| 641 |
if (theContent != null) |
| 642 |
{ |
| 643 |
theContent.elementContentsChanged(changedElement); |
| 644 |
|
| 645 |
XSDTerm newTerm = |
| 646 |
(XSDTerm) |
| 647 |
new XSDSwitch<Object>() |
| 648 |
{ |
| 649 |
@Override |
| 650 |
public Object caseXSDElementDeclaration(XSDElementDeclaration xsdElementDeclaration) |
| 651 |
{ |
| 652 |
return xsdElementDeclaration.getResolvedElementDeclaration(); |
| 653 |
} |
| 654 |
@Override |
| 655 |
public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition xsdModelGroupDefinition) |
| 656 |
{ |
| 657 |
return xsdModelGroupDefinition.getResolvedModelGroupDefinition().getModelGroup(); |
| 658 |
} |
| 659 |
@Override |
| 660 |
public Object caseXSDWildcard(XSDWildcard xsdWildcard) |
| 661 |
{ |
| 662 |
return xsdWildcard; |
| 663 |
} |
| 664 |
@Override |
| 665 |
public Object caseXSDModelGroup(XSDModelGroup xsdModelGroup) |
| 666 |
{ |
| 667 |
return xsdModelGroup; |
| 668 |
} |
| 669 |
}.doSwitch(theContent); |
| 670 |
|
| 671 |
if (newTerm != getTerm()) |
| 672 |
{ |
| 673 |
setTerm(newTerm); |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
@Override |
| 679 |
protected void changeAttribute(EAttribute eAttribute) |
| 680 |
{ |
| 681 |
if (isReconciling) |
| 682 |
{ |
| 683 |
return; |
| 684 |
} |
| 685 |
|
| 686 |
super.changeAttribute(eAttribute); |
| 687 |
Element theElement = getElement(); |
| 688 |
if (theElement != null) |
| 689 |
{ |
| 690 |
if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_PARTICLE__MIN_OCCURS) |
| 691 |
{ |
| 692 |
niceSetAttribute |
| 693 |
(theElement, |
| 694 |
XSDConstants.MINOCCURS_ATTRIBUTE, |
| 695 |
isSetMinOccurs() ? Integer.toString(getMinOccurs()) : null); |
| 696 |
} |
| 697 |
if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_PARTICLE__MAX_OCCURS) |
| 698 |
{ |
| 699 |
niceSetAttribute |
| 700 |
(theElement, |
| 701 |
XSDConstants.MAXOCCURS_ATTRIBUTE, |
| 702 |
isSetMaxOccurs() ? getMaxOccurs() == -1 ? "unbounded" : Integer.toString(getMaxOccurs()) : null); |
| 703 |
} |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
@Override |
| 708 |
protected void adoptContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent) |
| 709 |
{ |
| 710 |
super.adoptContent(eReference, xsdConcreteComponent); |
| 711 |
if (eReference == XSDPackage.Literals.XSD_PARTICLE__CONTENT) |
| 712 |
{ |
| 713 |
patchHelper(); |
| 714 |
traverseToRootForPatching(); |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
@Override |
| 719 |
protected void orphanContent(EReference eReference, XSDConcreteComponent xsdConcreteComponent) |
| 720 |
{ |
| 721 |
super.orphanContent(eReference, xsdConcreteComponent); |
| 722 |
if (eReference == XSDPackage.Literals.XSD_PARTICLE__CONTENT) |
| 723 |
{ |
| 724 |
patchHelper(); |
| 725 |
traverseToRootForPatching(); |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
public static class XSDNFA implements XSDParticle.DFA |
| 730 |
{ |
| 731 |
private static final class StateList extends BasicEList<State> |
| 732 |
{ |
| 733 |
private static final long serialVersionUID = 1L; |
| 734 |
|
| 735 |
public StateList() |
| 736 |
{ |
| 737 |
super(); |
| 738 |
} |
| 739 |
|
| 740 |
public StateList(Collection<State> states) |
| 741 |
{ |
| 742 |
super(states); |
| 743 |
} |
| 744 |
|
| 745 |
@Override |
| 746 |
protected Object [] newData(int capacity) |
| 747 |
{ |
| 748 |
return new StateImpl [capacity]; |
| 749 |
} |
| 750 |
|
| 751 |
@Override |
| 752 |
protected final boolean useEquals() |
| 753 |
{ |
| 754 |
return false; |
| 755 |
} |
| 756 |
|
| 757 |
@Override |
| 758 |
public boolean contains(Object object) |
| 759 |
{ |
| 760 |
for (int i = 0; i < size; ++i) |
| 761 |
{ |
| 762 |
if (data[i] == object) |
| 763 |
{ |
| 764 |
return true; |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
return false; |
| 769 |
} |
| 770 |
|
| 771 |
@Override |
| 772 |
public void clear() |
| 773 |
{ |
| 774 |
Object [] oldData = data; |
| 775 |
super.clear(); |
| 776 |
data = oldData; |
| 777 |
} |
| 778 |
|
| 779 |
@SuppressWarnings("unchecked") |
| 780 |
@Override |
| 781 |
public <T> T[] toArray(T[] array) |
| 782 |
{ |
| 783 |
if (array == EMPTY_STATE_ARRAY) |
| 784 |
{ |
| 785 |
return (T[])data; |
| 786 |
} |
| 787 |
else |
| 788 |
{ |
| 789 |
return super.toArray(array); |
| 790 |
} |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
private static final class TransitionList extends UniqueEList<Transition> |
| 795 |
{ |
| 796 |
private static final long serialVersionUID = 1L; |
| 797 |
|
| 798 |
Set<XSDParticle.DFA.Transition> set = new HashSet<XSDParticle.DFA.Transition>(); |
| 799 |
|
| 800 |
@Override |
| 801 |
protected Object[] newData(int capacity) |
| 802 |
{ |
| 803 |
return new TransitionImpl [capacity]; |
| 804 |
} |
| 805 |
|
| 806 |
@Override |
| 807 |
public boolean addAll(Collection<? extends Transition> collection) |
| 808 |
{ |
| 809 |
boolean result = false; |
| 810 |
Transition [] transitions = collection.toArray(EMPTY_TRANSITION_ARRAY); |
| 811 |
int collectionSize = collection.size(); |
| 812 |
grow(size + collectionSize); |
| 813 |
for (int i = 0; i < collectionSize; ++i) |
| 814 |
{ |
| 815 |
Transition transition = transitions[i]; |
| 816 |
if (set.add(transition)) |
| 817 |
{ |
| 818 |
data[size++] = transition; |
| 819 |
result = true; |
| 820 |
} |
| 821 |
} |
| 822 |
return result; |
| 823 |
} |
| 824 |
|
| 825 |
@Override |
| 826 |
protected void didAdd(int index, Transition newObject) |
| 827 |
{ |
| 828 |
set.add(newObject); |
| 829 |
} |
| 830 |
|
| 831 |
@Override |
| 832 |
protected void didRemove(int index, Transition oldObject) |
| 833 |
{ |
| 834 |
set.remove(oldObject); |
| 835 |
} |
| 836 |
|
| 837 |
@Override |
| 838 |
protected void didClear(int size, Object[] oldObjects) |
| 839 |
{ |
| 840 |
set.clear(); |
| 841 |
} |
| 842 |
|
| 843 |
@Override |
| 844 |
public boolean contains(Object object) |
| 845 |
{ |
| 846 |
return set.contains(object); |
| 847 |
} |
| 848 |
|
| 849 |
@Override |
| 850 |
public void clear() |
| 851 |
{ |
| 852 |
Object [] oldData = data; |
| 853 |
super.clear(); |
| 854 |
data = oldData; |
| 855 |
} |
| 856 |
|
| 857 |
@SuppressWarnings("unchecked") |
| 858 |
@Override |
| 859 |
public <T> T[] toArray(T[] array) |
| 860 |
{ |
| 861 |
if (array == EMPTY_TRANSITION_ARRAY) |
| 862 |
{ |
| 863 |
return (T[])data; |
| 864 |
} |
| 865 |
else |
| 866 |
{ |
| 867 |
return super.toArray(array); |
| 868 |
} |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
public static class StateImpl implements XSDParticle.DFA.State |
| 873 |
{ |
| 874 |
protected UniqueEList<XSDParticle.DFA.Transition> transitions; |
| 875 |
protected boolean isAccepting; |
| 876 |
|
| 877 |
public StateImpl() |
| 878 |
{ |
| 879 |
transitions = new TransitionList(); |
| 880 |
} |
| 881 |
|
| 882 |
public List<XSDParticle.DFA.Transition> getTransitions() |
| 883 |
{ |
| 884 |
return transitions; |
| 885 |
} |
| 886 |
|
| 887 |
public boolean isAccepting() |
| 888 |
{ |
| 889 |
return isAccepting; |
| 890 |
} |
| 891 |
|
| 892 |
public void setAccepting(boolean isAccepting) |
| 893 |
{ |
| 894 |
this.isAccepting = isAccepting; |
| 895 |
} |
| 896 |
|
| 897 |
protected TransitionImpl createdTransition; |
| 898 |
|
| 899 |
public XSDParticle.DFA.Transition createTransition(XSDParticle xsdParticle, XSDParticle.DFA.State state) |
| 900 |
{ |
| 901 |
if (createdTransition == null) |
| 902 |
{ |
| 903 |
createdTransition = new TransitionImpl(xsdParticle, state); |
| 904 |
} |
| 905 |
else |
| 906 |
{ |
| 907 |
createdTransition.setParticle(xsdParticle); |
| 908 |
createdTransition.setState(state); |
| 909 |
} |
| 910 |
|
| 911 |
if (transitions.add(createdTransition)) |
| 912 |
{ |
| 913 |
XSDParticle.DFA.Transition result = createdTransition; |
| 914 |
createdTransition = null; |
| 915 |
return result; |
| 916 |
} |
| 917 |
else |
| 918 |
{ |
| 919 |
return null; |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
public XSDParticle.DFA.Transition accept(String namespaceURI, String localName) |
| 924 |
{ |
| 925 |
for (Transition transition : getTransitions()) |
| 926 |
{ |
| 927 |
XSDParticle xsdParticle = transition.getParticle(); |
| 928 |
XSDTerm xsdTerm = xsdParticle.getTerm(); |
| 929 |
if (xsdTerm instanceof XSDElementDeclaration) |
| 930 |
{ |
| 931 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; |
| 932 |
if ((namespaceURI == null ? |
| 933 |
xsdElementDeclaration.getTargetNamespace() == null : |
| 934 |
namespaceURI.equals(xsdElementDeclaration.getTargetNamespace())) && |
| 935 |
localName.equals(xsdElementDeclaration.getName())) |
| 936 |
{ |
| 937 |
return transition; |
| 938 |
} |
| 939 |
} |
| 940 |
else if (xsdTerm instanceof XSDWildcard) |
| 941 |
{ |
| 942 |
XSDWildcard xsdWildcard = (XSDWildcard)xsdTerm; |
| 943 |
if (xsdWildcard.allows(namespaceURI)) |
| 944 |
{ |
| 945 |
return transition; |
| 946 |
} |
| 947 |
} |
| 948 |
} |
| 949 |
|
| 950 |
return null; |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
public static class TransitionImpl implements XSDParticle.DFA.Transition |
| 955 |
{ |
| 956 |
protected XSDParticle xsdParticle; |
| 957 |
protected XSDParticle.DFA.State state; |
| 958 |
protected int hashCode; |
| 959 |
|
| 960 |
public TransitionImpl(XSDParticle xsdParticle, XSDParticle.DFA.State state) |
| 961 |
{ |
| 962 |
this.xsdParticle = xsdParticle; |
| 963 |
this.state = state; |
| 964 |
hashCode = -1; |
| 965 |
} |
| 966 |
|
| 967 |
public final XSDParticle.DFA.State getState() |
| 968 |
{ |
| 969 |
return state; |
| 970 |
} |
| 971 |
|
| 972 |
public void setState(XSDParticle.DFA.State state) |
| 973 |
{ |
| 974 |
this.state = state; |
| 975 |
hashCode = -1; |
| 976 |
} |
| 977 |
|
| 978 |
public final XSDParticle getParticle() |
| 979 |
{ |
| 980 |
return xsdParticle; |
| 981 |
} |
| 982 |
|
| 983 |
public void setParticle(XSDParticle xsdParticle) |
| 984 |
{ |
| 985 |
this.xsdParticle = xsdParticle; |
| 986 |
hashCode = -1; |
| 987 |
} |
| 988 |
|
| 989 |
@Override |
| 990 |
public int hashCode() |
| 991 |
{ |
| 992 |
if (hashCode == -1) |
| 993 |
{ |
| 994 |
hashCode = (xsdParticle == null ? 0 : xsdParticle.hashCode()) ^ (state == null ? 0 : state.hashCode()); |
| 995 |
} |
| 996 |
return hashCode; |
| 997 |
} |
| 998 |
|
| 999 |
@Override |
| 1000 |
public boolean equals(Object that) |
| 1001 |
{ |
| 1002 |
if (that instanceof TransitionImpl) |
| 1003 |
{ |
| 1004 |
TransitionImpl otherTransition = (TransitionImpl)that; |
| 1005 |
return |
| 1006 |
xsdParticle == otherTransition.xsdParticle && |
| 1007 |
state == otherTransition.state; |
| 1008 |
} |
| 1009 |
else |
| 1010 |
{ |
| 1011 |
return false; |
| 1012 |
} |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
private static final StateImpl[] EMPTY_STATE_ARRAY = new StateImpl [0]; |
| 1017 |
private static final TransitionImpl[] EMPTY_TRANSITION_ARRAY = new TransitionImpl [0]; |
| 1018 |
|
| 1019 |
protected List<State> states = new StateList(); |
| 1020 |
|
| 1021 |
protected StateImpl initialState; |
| 1022 |
protected StateImpl finalState; |
| 1023 |
protected XSDParticle xsdParticle; |
| 1024 |
protected StateImpl currentState; |
| 1025 |
protected Set<XSDModelGroup> visitedModelGroups; |
| 1026 |
protected Collection<XSDDiagnostic> diagnostics; |
| 1027 |
protected boolean isApproximate; |
| 1028 |
|
| 1029 |
protected XSDNFA(boolean isApproximate) |
| 1030 |
{ |
| 1031 |
this.isApproximate = isApproximate; |
| 1032 |
currentState = initialState = createState(null); |
| 1033 |
finalState = createState(null); |
| 1034 |
} |
| 1035 |
|
| 1036 |
protected XSDNFA(Set<XSDModelGroup> visitedModelGroups, XSDParticle xsdParticle, XSDTerm xsdTerm, boolean isApproximate) |
| 1037 |
{ |
| 1038 |
this.isApproximate = isApproximate; |
| 1039 |
this.visitedModelGroups = visitedModelGroups; |
| 1040 |
this.xsdParticle = xsdParticle; |
| 1041 |
currentState = initialState = createState(null); |
| 1042 |
finalState = createState(xsdTerm); |
| 1043 |
if (!visitedModelGroups.contains(xsdTerm)) |
| 1044 |
{ |
| 1045 |
initialize(xsdTerm); |
| 1046 |
} |
| 1047 |
} |
| 1048 |
|
| 1049 |
public XSDNFA(Set<XSDModelGroup> visitedModelGroups, XSDParticle xsdParticle, boolean isApproximate) |
| 1050 |
{ |
| 1051 |
this.isApproximate = isApproximate; |
| 1052 |
this.visitedModelGroups = visitedModelGroups; |
| 1053 |
this.xsdParticle = xsdParticle; |
| 1054 |
currentState = initialState = createState(null); |
| 1055 |
finalState = createState(xsdParticle); |
| 1056 |
initialize(xsdParticle); |
| 1057 |
} |
| 1058 |
|
| 1059 |
public XSDNFA(XSDParticle xsdParticle, boolean isApproximate) |
| 1060 |
{ |
| 1061 |
this.isApproximate = isApproximate; |
| 1062 |
this.visitedModelGroups = new HashSet<XSDModelGroup>(); |
| 1063 |
this.xsdParticle = xsdParticle; |
| 1064 |
currentState = initialState = createState(null); |
| 1065 |
finalState = createState(xsdParticle); |
| 1066 |
initialize(xsdParticle); |
| 1067 |
} |
| 1068 |
|
| 1069 |
protected void checkBadTransitions() |
| 1070 |
{ |
| 1071 |
for (State state : getStates()) |
| 1072 |
{ |
| 1073 |
for (Transition transition : state.getTransitions()) |
| 1074 |
{ |
| 1075 |
if (!getStates().contains(transition.getState())) |
| 1076 |
{ |
| 1077 |
Thread.dumpStack(); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
protected XSDNFA(XSDNFA original, boolean isApproximate) |
| 1084 |
{ |
| 1085 |
this.isApproximate = isApproximate; |
| 1086 |
xsdParticle = original.getParticle(); |
| 1087 |
|
| 1088 |
Map<State, State> stateCloneMap = new HashMap<State, State>(); |
| 1089 |
List<State> originalStates = original.getStates(); |
| 1090 |
for (int i = 0, size = originalStates.size(); i < size; ++i) |
| 1091 |
{ |
| 1092 |
State originalState = originalStates.get(i); |
| 1093 |
StateImpl clonedState = createState(null); |
| 1094 |
stateCloneMap.put(originalState, clonedState); |
| 1095 |
clonedState.setAccepting(originalState.isAccepting()); |
| 1096 |
} |
| 1097 |
|
| 1098 |
currentState = initialState = (StateImpl)stateCloneMap.get(original.getInitialState()); |
| 1099 |
finalState = (StateImpl)stateCloneMap.get(original.getFinalState()); |
| 1100 |
|
| 1101 |
for (int i = 0, size = originalStates.size(); i < size; ++i) |
| 1102 |
{ |
| 1103 |
State originalState = originalStates.get(i); |
| 1104 |
List<Transition> originalTransitions = originalState.getTransitions(); |
| 1105 |
for (int j = 0, transitionSize = originalTransitions.size(); j < transitionSize; ++j) |
| 1106 |
{ |
| 1107 |
Transition originalTransition = originalTransitions.get(j); |
| 1108 |
((StateImpl)stateCloneMap.get(originalState)).createTransition |
| 1109 |
(originalTransition.getParticle(), stateCloneMap.get(originalTransition.getState())); |
| 1110 |
} |
| 1111 |
} |
| 1112 |
} |
| 1113 |
|
| 1114 |
protected StateImpl createState(XSDComponent associatedComponent) |
| 1115 |
{ |
| 1116 |
StateImpl result = new StateImpl(); |
| 1117 |
states.add(result); |
| 1118 |
return result; |
| 1119 |
} |
| 1120 |
|
| 1121 |
protected void initialize(XSDComponent xsdComponent) |
| 1122 |
{ |
| 1123 |
if (xsdComponent instanceof XSDElementDeclaration) |
| 1124 |
{ |
| 1125 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdComponent; |
| 1126 |
for (XSDElementDeclaration substititonGroupMember : xsdElementDeclaration.getSubstitutionGroup()) |
| 1127 |
{ |
| 1128 |
if (substititonGroupMember == xsdElementDeclaration) |
| 1129 |
{ |
| 1130 |
initialState.createTransition(xsdParticle, finalState); |
| 1131 |
} |
| 1132 |
else |
| 1133 |
{ |
| 1134 |
XSDParticle substititonGroupMemberParticle = ((XSDParticleImpl)xsdParticle).getXSDFactory().createXSDParticle(); |
| 1135 |
substititonGroupMemberParticle.setTerm(substititonGroupMember); |
| 1136 |
initialState.createTransition(substititonGroupMemberParticle, finalState); |
| 1137 |
} |
| 1138 |
} |
| 1139 |
} |
| 1140 |
else if (xsdComponent instanceof XSDWildcard) |
| 1141 |
{ |
| 1142 |
initialState.createTransition(xsdParticle, finalState); |
| 1143 |
} |
| 1144 |
else if (xsdComponent instanceof XSDModelGroup) |
| 1145 |
{ |
| 1146 |
XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdComponent; |
| 1147 |
visitedModelGroups.add(xsdModelGroup); |
| 1148 |
switch (xsdModelGroup.getCompositor().getValue()) |
| 1149 |
{ |
| 1150 |
case XSDCompositor.SEQUENCE: |
| 1151 |
{ |
| 1152 |
StateImpl previousState = initialState; |
| 1153 |
for (XSDParticle xsdParticle : xsdModelGroup.getParticles()) |
| 1154 |
{ |
| 1155 |
XSDNFA particleNFA = new XSDNFA(visitedModelGroups, xsdParticle, isApproximate); |
| 1156 |
propagateStates(particleNFA); |
| 1157 |
previousState.createTransition(null, particleNFA.getInitialState()); |
| 1158 |
previousState = (StateImpl)particleNFA.getFinalState(); |
| 1159 |
if (getStates().size() > MAXIMUM_STATES) |
| 1160 |
{ |
| 1161 |
break; |
| 1162 |
} |
| 1163 |
} |
| 1164 |
previousState.createTransition(null, finalState); |
| 1165 |
break; |
| 1166 |
} |
| 1167 |
case XSDCompositor.CHOICE: |
| 1168 |
{ |
| 1169 |
for (XSDParticle xsdParticle : xsdModelGroup.getParticles()) |
| 1170 |
{ |
| 1171 |
XSDNFA particleNFA = new XSDNFA(visitedModelGroups, xsdParticle, isApproximate); |
| 1172 |
propagateStates(particleNFA); |
| 1173 |
initialState.createTransition(null, particleNFA.getInitialState()); |
| 1174 |
((StateImpl)particleNFA.getFinalState()).createTransition(null, finalState); |
| 1175 |
if (getStates().size() > MAXIMUM_STATES) |
| 1176 |
{ |
| 1177 |
break; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
break; |
| 1181 |
} |
| 1182 |
case XSDCompositor.ALL: |
| 1183 |
default: |
| 1184 |
{ |
| 1185 |
if (visitedModelGroups.size() > 1) |
| 1186 |
{ |
| 1187 |
if (diagnostics == null) |
| 1188 |
{ |
| 1189 |
diagnostics = new ArrayList<XSDDiagnostic>(); |
| 1190 |
} |
| 1191 |
|
| 1192 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1193 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1194 |
xsdDiagnostic.setMessage |
| 1195 |
(XSDPlugin.INSTANCE.getString |
| 1196 |
("_UI_XSDError_message", |
| 1197 |
new Object [] |
| 1198 |
{ |
| 1199 |
populateDiagnostic(xsdDiagnostic, "cos-all-limited.1", null) |
| 1200 |
})); |
| 1201 |
|
| 1202 |
diagnostics.add(xsdDiagnostic); |
| 1203 |
} |
| 1204 |
|
| 1205 |
if (xsdModelGroup.getParticles().size() == 0) |
| 1206 |
{ |
| 1207 |
initialState.createTransition(null, finalState); |
| 1208 |
} |
| 1209 |
else |
| 1210 |
{ |
| 1211 |
List<XSDNFA> particleNFAs = new ArrayList<XSDNFA>(xsdModelGroup.getParticles().size()); |
| 1212 |
for (XSDParticle xsdParticle : xsdModelGroup.getParticles()) |
| 1213 |
{ |
| 1214 |
XSDNFA newParticleNFA = new XSDNFA(visitedModelGroups, xsdParticle, isApproximate); |
| 1215 |
particleNFAs.add(newParticleNFA); |
| 1216 |
if (getStates().size() > MAXIMUM_STATES) |
| 1217 |
{ |
| 1218 |
break; |
| 1219 |
} |
| 1220 |
} |
| 1221 |
|
| 1222 |
if (xsdModelGroup.getParticles().size() > 4) |
| 1223 |
{ |
| 1224 |
// diagnostics = new ArrayList(); |
| 1225 |
// XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1226 |
// xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1227 |
// xsdDiagnostic.setMessage |
| 1228 |
// (XSDPlugin.INSTANCE.getString |
| 1229 |
// ("_UI_XSDError_message", |
| 1230 |
// new Object [] |
| 1231 |
// { |
| 1232 |
// XSDPlugin.INSTANCE.getString |
| 1233 |
// ("coss-particle.0.2", new Object [] { xsdModelGroup.getParticles().size() }) |
| 1234 |
// })); |
| 1235 |
// diagnostics.add(xsdDiagnostic); |
| 1236 |
|
| 1237 |
isApproximate = true; |
| 1238 |
|
| 1239 |
// Treat it like a repeating choice. |
| 1240 |
// |
| 1241 |
for (XSDParticle xsdParticle : xsdModelGroup.getParticles()) |
| 1242 |
{ |
| 1243 |
XSDNFA particleNFA = new XSDNFA(visitedModelGroups, xsdParticle, isApproximate); |
| 1244 |
propagateStates(particleNFA); |
| 1245 |
initialState.createTransition(null, particleNFA.getInitialState()); |
| 1246 |
((StateImpl)particleNFA.getFinalState()).createTransition(null, finalState); |
| 1247 |
((StateImpl)particleNFA.getFinalState()).createTransition(null, initialState); |
| 1248 |
if (getStates().size() > MAXIMUM_STATES) |
| 1249 |
{ |
| 1250 |
break; |
| 1251 |
} |
| 1252 |
} |
| 1253 |
} |
| 1254 |
else |
| 1255 |
{ |
| 1256 |
XSDNFA xsdNFA = createPermutations(xsdModelGroup.getParticles(), particleNFAs, new HashMap<List<XSDParticle>, XSDNFA>()); |
| 1257 |
|
| 1258 |
propagateStates(xsdNFA); |
| 1259 |
|
| 1260 |
initialState.createTransition(null, xsdNFA.getInitialState()); |
| 1261 |
((StateImpl)xsdNFA.getFinalState()).createTransition(null, finalState); |
| 1262 |
} |
| 1263 |
} |
| 1264 |
break; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
visitedModelGroups.remove(xsdModelGroup); |
| 1268 |
} |
| 1269 |
else if (xsdComponent instanceof XSDParticle) |
| 1270 |
{ |
| 1271 |
XSDParticle xsdParticle = (XSDParticle)xsdComponent; |
| 1272 |
int minOccurs = xsdParticle.getMinOccurs(); |
| 1273 |
int maxOccurs = xsdParticle.getMaxOccurs(); |
| 1274 |
int count = maxOccurs == -1 || isApproximate ? minOccurs : maxOccurs; |
| 1275 |
if (minOccurs <= count) |
| 1276 |
{ |
| 1277 |
List<XSDNFA> termNFAs = new ArrayList<XSDNFA>(count); |
| 1278 |
XSDNFA firstTermNFA = new XSDNFA(visitedModelGroups, xsdParticle, xsdParticle.getTerm(), isApproximate); |
| 1279 |
propagateStates(firstTermNFA); |
| 1280 |
termNFAs.add(firstTermNFA); |
| 1281 |
for (int i = 2; i <= count; ++i) |
| 1282 |
{ |
| 1283 |
XSDNFA clonedTermNFA = new XSDNFA(firstTermNFA, isApproximate); |
| 1284 |
propagateStates(clonedTermNFA); |
| 1285 |
termNFAs.add(clonedTermNFA); |
| 1286 |
if (getStates().size() > MAXIMUM_STATES) |
| 1287 |
{ |
| 1288 |
break; |
| 1289 |
} |
| 1290 |
} |
| 1291 |
|
| 1292 |
//XSDNFA previousTermNFA = firstTermNFA; |
| 1293 |
StateImpl previousState = initialState; |
| 1294 |
int i; |
| 1295 |
if (minOccurs == 0) |
| 1296 |
{ |
| 1297 |
initialState.createTransition(null, firstTermNFA.getInitialState()); |
| 1298 |
initialState.createTransition(null, firstTermNFA.getFinalState()); |
| 1299 |
previousState = (StateImpl)firstTermNFA.getFinalState(); |
| 1300 |
i = 2; |
| 1301 |
} |
| 1302 |
else |
| 1303 |
{ |
| 1304 |
for (i = 1; i <= minOccurs; ++i) |
| 1305 |
{ |
| 1306 |
XSDNFA termNFA = termNFAs.get(i - 1); |
| 1307 |
previousState.createTransition(null, termNFA.getInitialState()); |
| 1308 |
previousState = (StateImpl)termNFA.getFinalState(); |
| 1309 |
if (getStates().size() > MAXIMUM_STATES) |
| 1310 |
{ |
| 1311 |
break; |
| 1312 |
} |
| 1313 |
} |
| 1314 |
} |
| 1315 |
|
| 1316 |
if (maxOccurs == -1 || isApproximate) |
| 1317 |
{ |
| 1318 |
previousState.createTransition(null, firstTermNFA.getInitialState()); |
| 1319 |
} |
| 1320 |
else |
| 1321 |
{ |
| 1322 |
for ( ; i <= maxOccurs; ++i) |
| 1323 |
{ |
| 1324 |
XSDNFA termNFA = termNFAs.get(i - 1); |
| 1325 |
previousState.createTransition(null, termNFA.getInitialState()); |
| 1326 |
((StateImpl)termNFA.getInitialState()).createTransition(null, finalState); |
| 1327 |
previousState = (StateImpl)termNFA.getFinalState(); |
| 1328 |
if (getStates().size() > MAXIMUM_STATES) |
| 1329 |
{ |
| 1330 |
break; |
| 1331 |
} |
| 1332 |
} |
| 1333 |
} |
| 1334 |
previousState.createTransition(null, finalState); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
} |
| 1338 |
|
| 1339 |
protected XSDNFA createPermutations(List<XSDParticle> particles, List<XSDNFA> particleNFAs, Map<List<XSDParticle>, XSDNFA> particlesToNFAMap) |
| 1340 |
{ |
| 1341 |
XSDNFA result = particlesToNFAMap.get(particles); |
| 1342 |
if (result == null) |
| 1343 |
{ |
| 1344 |
int size = particleNFAs.size(); |
| 1345 |
if (size == 1) |
| 1346 |
{ |
| 1347 |
result = new XSDNFA(particleNFAs.get(0), isApproximate); |
| 1348 |
particlesToNFAMap.put(particles, result); |
| 1349 |
} |
| 1350 |
else |
| 1351 |
{ |
| 1352 |
result = new XSDNFA(isApproximate); |
| 1353 |
List<XSDNFA> otherParticleNFAs = new ArrayList<XSDNFA>(size - 1); |
| 1354 |
List<XSDParticle> otherParticles = new ArrayList<XSDParticle>(size - 1); |
| 1355 |
for (int i = 0; i < size; ++i) |
| 1356 |
{ |
| 1357 |
XSDNFA particleNFA = particleNFAs.get(i); |
| 1358 |
XSDParticle particle = particles.get(i); |
| 1359 |
otherParticleNFAs.clear(); |
| 1360 |
otherParticles.clear(); |
| 1361 |
for (int j = 0; j < size; ++j) |
| 1362 |
{ |
| 1363 |
XSDParticle otherParticle = particles.get(j); |
| 1364 |
if (particle != otherParticle) |
| 1365 |
{ |
| 1366 |
XSDNFA otherParticleNFA = particleNFAs.get(j); |
| 1367 |
otherParticleNFAs.add(otherParticleNFA); |
| 1368 |
otherParticles.add(otherParticle); |
| 1369 |
} |
| 1370 |
} |
| 1371 |
|
| 1372 |
XSDNFA clonedParticleNFA = new XSDNFA(particleNFA, isApproximate); |
| 1373 |
result.propagateStates(clonedParticleNFA); |
| 1374 |
((StateImpl)result.getInitialState()).createTransition(null, clonedParticleNFA.getInitialState()); |
| 1375 |
|
| 1376 |
XSDNFA combinationXSDNFA = createPermutations |
| 1377 |
(otherParticles, |
| 1378 |
otherParticleNFAs, |
| 1379 |
particlesToNFAMap); |
| 1380 |
result.propagateStates(combinationXSDNFA); |
| 1381 |
|
| 1382 |
((StateImpl)clonedParticleNFA.getFinalState()).createTransition(null, combinationXSDNFA.getInitialState()); |
| 1383 |
((StateImpl)combinationXSDNFA.getFinalState()).createTransition(null, result.getFinalState()); |
| 1384 |
} |
| 1385 |
|
| 1386 |
if (result.getStates().size() > 50) |
| 1387 |
{ |
| 1388 |
result.epsilonClosure(); |
| 1389 |
result.minimize(); |
| 1390 |
result.determinize(); |
| 1391 |
result.minimize(); |
| 1392 |
result.createFinalState(); |
| 1393 |
} |
| 1394 |
} |
| 1395 |
particlesToNFAMap.put(particles, result); |
| 1396 |
} |
| 1397 |
|
| 1398 |
return result; |
| 1399 |
} |
| 1400 |
|
| 1401 |
public boolean isApproximate() |
| 1402 |
{ |
| 1403 |
return isApproximate; |
| 1404 |
} |
| 1405 |
|
| 1406 |
public List<State> getStates() |
| 1407 |
{ |
| 1408 |
return states; |
| 1409 |
} |
| 1410 |
|
| 1411 |
public XSDParticle.DFA.State getInitialState() |
| 1412 |
{ |
| 1413 |
return initialState; |
| 1414 |
} |
| 1415 |
|
| 1416 |
public XSDParticle.DFA.State getFinalState() |
| 1417 |
{ |
| 1418 |
return finalState; |
| 1419 |
} |
| 1420 |
|
| 1421 |
public XSDParticle getParticle() |
| 1422 |
{ |
| 1423 |
return xsdParticle; |
| 1424 |
} |
| 1425 |
|
| 1426 |
public static String getComponentLabel(Collection<XSDComponent> xsdComponents) |
| 1427 |
{ |
| 1428 |
StringBuffer result = new StringBuffer(); |
| 1429 |
result.append("{"); |
| 1430 |
for (Iterator<XSDComponent> i = xsdComponents.iterator(); i.hasNext(); ) |
| 1431 |
{ |
| 1432 |
XSDComponent xsdComponent = i.next(); |
| 1433 |
result.append(getComponentLabel(xsdComponent)); |
| 1434 |
if (i.hasNext()) |
| 1435 |
{ |
| 1436 |
result.append(" "); |
| 1437 |
} |
| 1438 |
} |
| 1439 |
result.append("}"); |
| 1440 |
return result.toString(); |
| 1441 |
} |
| 1442 |
|
| 1443 |
public static String getComponentLabel(XSDComponent xsdComponent) |
| 1444 |
{ |
| 1445 |
if (xsdComponent == null) |
| 1446 |
{ |
| 1447 |
return "-"; |
| 1448 |
} |
| 1449 |
else if (xsdComponent instanceof XSDElementDeclaration) |
| 1450 |
{ |
| 1451 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdComponent; |
| 1452 |
return xsdElementDeclaration.getName(); |
| 1453 |
} |
| 1454 |
else if (xsdComponent instanceof XSDWildcard) |
| 1455 |
{ |
| 1456 |
XSDWildcard xsdWildcard = (XSDWildcard)xsdComponent; |
| 1457 |
return xsdWildcard.getStringNamespaceConstraint(); |
| 1458 |
} |
| 1459 |
else if (xsdComponent instanceof XSDModelGroup) |
| 1460 |
{ |
| 1461 |
XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdComponent; |
| 1462 |
switch (xsdModelGroup.getCompositor().getValue()) |
| 1463 |
{ |
| 1464 |
case XSDCompositor.SEQUENCE: |
| 1465 |
{ |
| 1466 |
return "<sequence/>"; |
| 1467 |
} |
| 1468 |
case XSDCompositor.CHOICE: |
| 1469 |
{ |
| 1470 |
return "<choice/>"; |
| 1471 |
} |
| 1472 |
case XSDCompositor.ALL: |
| 1473 |
default: |
| 1474 |
{ |
| 1475 |
return "<all/>"; |
| 1476 |
} |
| 1477 |
} |
| 1478 |
} |
| 1479 |
else if (xsdComponent instanceof XSDParticle) |
| 1480 |
{ |
| 1481 |
XSDParticle xsdParticle = (XSDParticle)xsdComponent; |
| 1482 |
return getComponentLabel(xsdParticle.getTerm()) + "[" + xsdParticle.getMinOccurs() + "," + xsdParticle.getMaxOccurs() + "]"; |
| 1483 |
} |
| 1484 |
else |
| 1485 |
{ |
| 1486 |
return xsdComponent.toString(); |
| 1487 |
} |
| 1488 |
} |
| 1489 |
|
| 1490 |
public void dump(PrintStream out) |
| 1491 |
{ |
| 1492 |
List<State> stateList = new StateList(getStates()); |
| 1493 |
stateList.remove(initialState); |
| 1494 |
stateList.add(0, initialState); |
| 1495 |
if (finalState != null) |
| 1496 |
{ |
| 1497 |
stateList.remove(finalState); |
| 1498 |
stateList.add(finalState); |
| 1499 |
} |
| 1500 |
|
| 1501 |
out.println |
| 1502 |
("Component: " + getComponentLabel(xsdParticle) + |
| 1503 |
" [" + stateList.indexOf(initialState) + ", " + |
| 1504 |
stateList.indexOf(finalState) + "]"); |
| 1505 |
for (State state : stateList) |
| 1506 |
{ |
| 1507 |
out.println |
| 1508 |
(" State: " + stateList.indexOf(state) + (state.isAccepting() ? " *" : "")); |
| 1509 |
|
| 1510 |
for (Transition transition : state.getTransitions()) |
| 1511 |
{ |
| 1512 |
out.println |
| 1513 |
(" --> : " + getComponentLabel(transition.getParticle()) + " -> " + stateList.indexOf(transition.getState())); |
| 1514 |
} |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
public void epsilonClosure() |
| 1519 |
{ |
| 1520 |
finalState.setAccepting(true); |
| 1521 |
boolean closed; |
| 1522 |
|
| 1523 |
StateImpl[] statesArray = states.toArray(EMPTY_STATE_ARRAY); |
| 1524 |
int statesSize = states.size(); |
| 1525 |
Set<Transition> nullTransitions = new HashSet<Transition>(); |
| 1526 |
do |
| 1527 |
{ |
| 1528 |
closed = true; |
| 1529 |
for (int i = 0; i < statesSize; ++i) |
| 1530 |
{ |
| 1531 |
StateImpl state = statesArray[i]; |
| 1532 |
List<Transition> stateTransitions = state.getTransitions(); |
| 1533 |
TransitionImpl [] stateTransitionsArray = stateTransitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1534 |
for (int j = 0; j < stateTransitions.size(); ++j) |
| 1535 |
{ |
| 1536 |
TransitionImpl transition = stateTransitionsArray[j]; |
| 1537 |
if (transition.getParticle() == null) |
| 1538 |
{ |
| 1539 |
stateTransitions.remove(j); |
| 1540 |
--j; |
| 1541 |
closed = false; |
| 1542 |
State otherState = transition.getState(); |
| 1543 |
if (state != otherState && nullTransitions.add(transition)) |
| 1544 |
{ |
| 1545 |
if (otherState.isAccepting()) |
| 1546 |
{ |
| 1547 |
state.setAccepting(true); |
| 1548 |
} |
| 1549 |
stateTransitions.addAll(otherState.getTransitions()); |
| 1550 |
} |
| 1551 |
stateTransitionsArray = stateTransitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1552 |
} |
| 1553 |
} |
| 1554 |
nullTransitions.clear(); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
while (!closed); |
| 1558 |
} |
| 1559 |
|
| 1560 |
public void createFinalState() |
| 1561 |
{ |
| 1562 |
finalState = createState(null); |
| 1563 |
for (int i = 0, iSize = states.size(); i < iSize; ++i) |
| 1564 |
{ |
| 1565 |
StateImpl state = (StateImpl)states.get(i); |
| 1566 |
if (state.isAccepting()) |
| 1567 |
{ |
| 1568 |
state.setAccepting(false); |
| 1569 |
state.createTransition(null, finalState); |
| 1570 |
} |
| 1571 |
} |
| 1572 |
} |
| 1573 |
|
| 1574 |
protected TransitionImpl testTransition = new TransitionImpl(null, null); |
| 1575 |
|
| 1576 |
public boolean isEquivalent(XSDParticle.DFA.State s1, XSDParticle.DFA.State s2) |
| 1577 |
{ |
| 1578 |
if (s1.isAccepting() != s2.isAccepting() || s1.getTransitions().size() != s2.getTransitions().size()) |
| 1579 |
{ |
| 1580 |
return false; |
| 1581 |
} |
| 1582 |
else |
| 1583 |
{ |
| 1584 |
List<Transition> stateTransitions = s1.getTransitions(); |
| 1585 |
TransitionImpl[] stateTransitionsArray = stateTransitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1586 |
for (int i = 0, iSize = stateTransitions.size(); i < iSize; ++i) |
| 1587 |
{ |
| 1588 |
TransitionImpl transition = stateTransitionsArray[i]; |
| 1589 |
testTransition.setParticle(transition.getParticle()); |
| 1590 |
testTransition.setState(transition.getState()); |
| 1591 |
|
| 1592 |
if (!s2.getTransitions().contains(testTransition)) |
| 1593 |
{ |
| 1594 |
return false; |
| 1595 |
} |
| 1596 |
} |
| 1597 |
|
| 1598 |
return true; |
| 1599 |
} |
| 1600 |
} |
| 1601 |
|
| 1602 |
public void minimize() |
| 1603 |
{ |
| 1604 |
int size = states.size(); |
| 1605 |
StateImpl [] theStates = states.toArray(new StateImpl[size]); |
| 1606 |
StateList equivalentStates = new StateList(); |
| 1607 |
equivalentStates.grow(size); |
| 1608 |
boolean minimal; |
| 1609 |
do |
| 1610 |
{ |
| 1611 |
minimal = true; |
| 1612 |
for (int i = 0; i < theStates.length; ++i) |
| 1613 |
{ |
| 1614 |
StateImpl state = theStates[i]; |
| 1615 |
if (state != null) |
| 1616 |
{ |
| 1617 |
for (int j = i + 1; j < theStates.length; ++j) |
| 1618 |
{ |
| 1619 |
State otherState = theStates[j]; |
| 1620 |
if (otherState != null && isEquivalent(state, otherState)) |
| 1621 |
{ |
| 1622 |
equivalentStates.add(otherState); |
| 1623 |
theStates[j] = null; |
| 1624 |
} |
| 1625 |
} |
| 1626 |
if (!equivalentStates.isEmpty()) |
| 1627 |
{ |
| 1628 |
for (int j = 0; j < theStates.length; ++j) |
| 1629 |
{ |
| 1630 |
State otherState = theStates[j]; |
| 1631 |
if (otherState != null) |
| 1632 |
{ |
| 1633 |
List<Transition> theTransitions = otherState.getTransitions(); |
| 1634 |
TransitionImpl[] theTransitionsArray = theTransitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1635 |
if (equivalentStates.contains(otherState)) |
| 1636 |
{ |
| 1637 |
for (int k = 0, kSize = theTransitions.size(); k < kSize; ++k) |
| 1638 |
{ |
| 1639 |
TransitionImpl transition = theTransitionsArray[k]; |
| 1640 |
State outgoingState = transition.getState(); |
| 1641 |
if (equivalentStates.contains(outgoingState)) |
| 1642 |
{ |
| 1643 |
state.createTransition(transition.getParticle(), state); |
| 1644 |
} |
| 1645 |
else |
| 1646 |
{ |
| 1647 |
state.createTransition(transition.getParticle(), outgoingState); |
| 1648 |
} |
| 1649 |
} |
| 1650 |
} |
| 1651 |
else |
| 1652 |
{ |
| 1653 |
for (int k = theTransitions.size(); --k >= 0; ) |
| 1654 |
{ |
| 1655 |
TransitionImpl transition = theTransitionsArray[k]; |
| 1656 |
State outgoingState = transition.getState(); |
| 1657 |
if (equivalentStates.contains(outgoingState)) |
| 1658 |
{ |
| 1659 |
theTransitions.remove(k); |
| 1660 |
theTransitions.add(new TransitionImpl(transition.getParticle(), state)); |
| 1661 |
} |
| 1662 |
} |
| 1663 |
} |
| 1664 |
} |
| 1665 |
} |
| 1666 |
|
| 1667 |
states.removeAll(equivalentStates); |
| 1668 |
equivalentStates.clear(); |
| 1669 |
minimal = false; |
| 1670 |
} |
| 1671 |
} |
| 1672 |
} |
| 1673 |
} |
| 1674 |
while (!minimal); |
| 1675 |
} |
| 1676 |
|
| 1677 |
protected XSDElementDeclaration [] xsdElementDeclarations; |
| 1678 |
|
| 1679 |
public int checksum() |
| 1680 |
{ |
| 1681 |
int result = 0; |
| 1682 |
if (xsdElementDeclarations != null) |
| 1683 |
{ |
| 1684 |
for (int i = 0, length = xsdElementDeclarations.length; i < length; ++i) |
| 1685 |
{ |
| 1686 |
result += xsdElementDeclarations[i].getSubstitutionGroup().hashCode(); |
| 1687 |
} |
| 1688 |
} |
| 1689 |
else |
| 1690 |
{ |
| 1691 |
List<XSDElementDeclaration> elements = new UniqueEList.FastCompare<XSDElementDeclaration>(); |
| 1692 |
StateImpl[] statesArray = states.toArray(EMPTY_STATE_ARRAY); |
| 1693 |
for (int i = 0, iSize = states.size(); i < iSize; ++i) |
| 1694 |
{ |
| 1695 |
StateImpl state = statesArray[i]; |
| 1696 |
List<Transition> theTransitions = state.getTransitions(); |
| 1697 |
TransitionImpl[] transitionsArray = theTransitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1698 |
for (int j = 0, jSize = theTransitions.size(); j < jSize; ++j) |
| 1699 |
{ |
| 1700 |
TransitionImpl transition = transitionsArray[j]; |
| 1701 |
XSDTerm xsdTerm = transition.getParticle().getTerm(); |
| 1702 |
if (xsdTerm instanceof XSDElementDeclaration) |
| 1703 |
{ |
| 1704 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; |
| 1705 |
if (elements.add(xsdElementDeclaration)) |
| 1706 |
{ |
| 1707 |
result += xsdElementDeclaration.getSubstitutionGroup().hashCode(); |
| 1708 |
} |
| 1709 |
} |
| 1710 |
} |
| 1711 |
} |
| 1712 |
xsdElementDeclarations = new XSDElementDeclaration[elements.size()]; |
| 1713 |
elements.toArray(xsdElementDeclarations); |
| 1714 |
} |
| 1715 |
return result; |
| 1716 |
} |
| 1717 |
|
| 1718 |
public void determinize() |
| 1719 |
{ |
| 1720 |
Set<Set<State>> stateSubsets = new HashSet<Set<State>>(); |
| 1721 |
State originalInitialState = initialState; |
| 1722 |
Set<State> initialStateSubset = Collections.<State>singleton(initialState); |
| 1723 |
stateSubsets.add(initialStateSubset); |
| 1724 |
|
| 1725 |
states.clear(); |
| 1726 |
currentState = initialState = createState(null); |
| 1727 |
initialState.setAccepting(originalInitialState.isAccepting()); |
| 1728 |
finalState = null; |
| 1729 |
xsdParticle = null; |
| 1730 |
|
| 1731 |
Map<Set<State>, State> stateSubsetToStateMap = new HashMap<Set<State>, State>(); |
| 1732 |
stateSubsetToStateMap.put(initialStateSubset, initialState); |
| 1733 |
List<Transition> transitions = new TransitionList(); |
| 1734 |
do |
| 1735 |
{ |
| 1736 |
Iterator<Set<State>> s = stateSubsets.iterator(); |
| 1737 |
Set<State> stateSubset = s.next(); |
| 1738 |
s.remove(); |
| 1739 |
|
| 1740 |
StateImpl newState = (StateImpl)stateSubsetToStateMap.get(stateSubset); |
| 1741 |
|
| 1742 |
transitions.clear(); |
| 1743 |
for (State originalState : stateSubset) |
| 1744 |
{ |
| 1745 |
transitions.addAll(originalState.getTransitions()); |
| 1746 |
} |
| 1747 |
|
| 1748 |
TransitionImpl [] transitionsArray = transitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1749 |
int count = transitions.size(); |
| 1750 |
while (count > 0) |
| 1751 |
{ |
| 1752 |
TransitionImpl originalTransition = transitionsArray[0]; |
| 1753 |
int moveIndex = 0; |
| 1754 |
int index = 1; |
| 1755 |
XSDParticle particle = originalTransition.getParticle(); |
| 1756 |
State orginalTransitionState = originalTransition.getState(); |
| 1757 |
Set<State> newStateSubset = new HashSet<State>(); |
| 1758 |
newStateSubset.add(orginalTransitionState); |
| 1759 |
boolean isAccepting = orginalTransitionState.isAccepting(); |
| 1760 |
while (index < count) |
| 1761 |
{ |
| 1762 |
TransitionImpl otherOriginalTransition = transitionsArray[index++]; |
| 1763 |
if (otherOriginalTransition.getParticle() == particle) |
| 1764 |
{ |
| 1765 |
State otherOriginalTransitionState = otherOriginalTransition.getState(); |
| 1766 |
newStateSubset.add(otherOriginalTransitionState); |
| 1767 |
if (otherOriginalTransitionState.isAccepting()) |
| 1768 |
{ |
| 1769 |
isAccepting = true; |
| 1770 |
} |
| 1771 |
} |
| 1772 |
else |
| 1773 |
{ |
| 1774 |
// Shift it forward to the next unused slot for subsequent processing. |
| 1775 |
// |
| 1776 |
transitionsArray[moveIndex++] = otherOriginalTransition; |
| 1777 |
} |
| 1778 |
} |
| 1779 |
count = moveIndex; |
| 1780 |
StateImpl newNextState = (StateImpl)stateSubsetToStateMap.get(newStateSubset); |
| 1781 |
if (newNextState == null) |
| 1782 |
{ |
| 1783 |
newNextState = createState(null); |
| 1784 |
if (isAccepting) |
| 1785 |
{ |
| 1786 |
newNextState.setAccepting(true); |
| 1787 |
} |
| 1788 |
stateSubsetToStateMap.put(newStateSubset, newNextState); |
| 1789 |
stateSubsets.add(newStateSubset); |
| 1790 |
} |
| 1791 |
else |
| 1792 |
{ |
| 1793 |
if (newNextState.isAccepting() != isAccepting) |
| 1794 |
{ |
| 1795 |
Thread.dumpStack(); |
| 1796 |
} |
| 1797 |
} |
| 1798 |
|
| 1799 |
newState.createTransition(particle, newNextState); |
| 1800 |
} |
| 1801 |
} |
| 1802 |
while (!stateSubsets.isEmpty()); |
| 1803 |
} |
| 1804 |
|
| 1805 |
public XSDDiagnostic checkOverlap(XSDTerm xsdComponent1, XSDTerm xsdComponent2) |
| 1806 |
{ |
| 1807 |
if (xsdComponent1 instanceof XSDElementDeclaration) |
| 1808 |
{ |
| 1809 |
XSDElementDeclaration xsdElementDeclaration1 = (XSDElementDeclaration)xsdComponent1; |
| 1810 |
return checkOverlap(xsdElementDeclaration1, xsdComponent2); |
| 1811 |
} |
| 1812 |
else if (xsdComponent1 instanceof XSDWildcard) |
| 1813 |
{ |
| 1814 |
XSDWildcard xsdWildcard1 = (XSDWildcard)xsdComponent1; |
| 1815 |
return checkOverlap(xsdWildcard1, xsdComponent2); |
| 1816 |
} |
| 1817 |
else |
| 1818 |
{ |
| 1819 |
return null; |
| 1820 |
} |
| 1821 |
} |
| 1822 |
|
| 1823 |
protected XSDDiagnostic checkOverlap(XSDElementDeclaration xsdElementDeclaration1, XSDTerm xsdComponent2) |
| 1824 |
{ |
| 1825 |
if (xsdComponent2 instanceof XSDElementDeclaration) |
| 1826 |
{ |
| 1827 |
XSDElementDeclaration xsdElementDeclaration2 = (XSDElementDeclaration)xsdComponent2; |
| 1828 |
if (xsdElementDeclaration1.hasSameNameAndTargetNamespace(xsdElementDeclaration2)) |
| 1829 |
{ |
| 1830 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1831 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1832 |
xsdDiagnostic.setMessage |
| 1833 |
(XSDPlugin.INSTANCE.getString |
| 1834 |
("_UI_XSDError_message", |
| 1835 |
new Object [] |
| 1836 |
{ |
| 1837 |
populateDiagnostic |
| 1838 |
(xsdDiagnostic, "key-overlap.1", new Object [] { xsdElementDeclaration1.getURI() }) |
| 1839 |
})); |
| 1840 |
return xsdDiagnostic; |
| 1841 |
} |
| 1842 |
} |
| 1843 |
else if (xsdComponent2 instanceof XSDWildcard) |
| 1844 |
{ |
| 1845 |
XSDWildcard xsdWildcard2 = (XSDWildcard)xsdComponent2; |
| 1846 |
if (xsdWildcard2.allows(xsdElementDeclaration1.getTargetNamespace())) |
| 1847 |
{ |
| 1848 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1849 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1850 |
xsdDiagnostic.setMessage |
| 1851 |
(XSDPlugin.INSTANCE.getString |
| 1852 |
("_UI_XSDError_message", |
| 1853 |
new Object [] |
| 1854 |
{ |
| 1855 |
populateDiagnostic(xsdDiagnostic, "key-overlap.2", new Object [] { xsdElementDeclaration1.getURI() }) |
| 1856 |
})); |
| 1857 |
return xsdDiagnostic; |
| 1858 |
} |
| 1859 |
} |
| 1860 |
return null; |
| 1861 |
} |
| 1862 |
|
| 1863 |
protected XSDDiagnostic checkOverlap(XSDWildcard xsdWildcard1, XSDTerm xsdComponent2) |
| 1864 |
{ |
| 1865 |
if (xsdComponent2 instanceof XSDElementDeclaration) |
| 1866 |
{ |
| 1867 |
XSDElementDeclaration xsdElementDeclaration2 = (XSDElementDeclaration)xsdComponent2; |
| 1868 |
if (xsdWildcard1.allows(xsdElementDeclaration2.getTargetNamespace())) |
| 1869 |
{ |
| 1870 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1871 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1872 |
xsdDiagnostic.setMessage |
| 1873 |
(XSDPlugin.INSTANCE.getString |
| 1874 |
("_UI_XSDError_message", |
| 1875 |
new Object [] |
| 1876 |
{ |
| 1877 |
populateDiagnostic(xsdDiagnostic, "key-overlap.2", new Object [] { xsdElementDeclaration2.getURI() }) |
| 1878 |
})); |
| 1879 |
return xsdDiagnostic; |
| 1880 |
} |
| 1881 |
} |
| 1882 |
else if (xsdComponent2 instanceof XSDWildcard) |
| 1883 |
{ |
| 1884 |
XSDWildcard xsdWildcard2 = (XSDWildcard)xsdComponent2; |
| 1885 |
XSDWildcard intersection = xsdWildcard1.attributeWildcardIntersection(xsdWildcard2); |
| 1886 |
if (intersection != null && !intersection.getNamespaceConstraint().isEmpty()) |
| 1887 |
{ |
| 1888 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1889 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1890 |
xsdDiagnostic.setMessage |
| 1891 |
(XSDPlugin.INSTANCE.getString |
| 1892 |
("_UI_XSDError_message", |
| 1893 |
new Object [] |
| 1894 |
{ |
| 1895 |
populateDiagnostic(xsdDiagnostic, "key-overlap.3", new Object [] { intersection.getNamespaceConstraint().get(0) }) |
| 1896 |
})); |
| 1897 |
return xsdDiagnostic; |
| 1898 |
} |
| 1899 |
} |
| 1900 |
return null; |
| 1901 |
} |
| 1902 |
|
| 1903 |
public void propagateStates(XSDNFA xsdNFA) |
| 1904 |
{ |
| 1905 |
states.addAll(xsdNFA.getStates()); |
| 1906 |
if (xsdNFA.diagnostics != null) |
| 1907 |
{ |
| 1908 |
if (diagnostics == null) |
| 1909 |
{ |
| 1910 |
diagnostics = new ArrayList<XSDDiagnostic>(); |
| 1911 |
} |
| 1912 |
diagnostics.addAll(xsdNFA.diagnostics); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
|
| 1916 |
public Collection<XSDDiagnostic> getDiagnostics() |
| 1917 |
{ |
| 1918 |
if (diagnostics == null) |
| 1919 |
{ |
| 1920 |
diagnostics = new ArrayList<XSDDiagnostic>(); |
| 1921 |
Map<String, XSDTypeDefinition> elementURIToTypeMap = new HashMap<String, XSDTypeDefinition>(); |
| 1922 |
int iSize = states.size(); |
| 1923 |
if (iSize > MAXIMUM_STATES) |
| 1924 |
{ |
| 1925 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1926 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.WARNING_LITERAL); |
| 1927 |
xsdDiagnostic.setMessage |
| 1928 |
(XSDPlugin.INSTANCE.getString |
| 1929 |
("_UI_XSDError_message", |
| 1930 |
new Object [] |
| 1931 |
{ |
| 1932 |
populateDiagnostic(xsdDiagnostic, "coss-particle.0.1", new Object [] { getStates().size() }) |
| 1933 |
})); |
| 1934 |
diagnostics.add(xsdDiagnostic); |
| 1935 |
} |
| 1936 |
else |
| 1937 |
{ |
| 1938 |
StateImpl [] statesArray = states.toArray(EMPTY_STATE_ARRAY); |
| 1939 |
Map<String, XSDElementDeclaration> uriToElementMap = new HashMap<String, XSDElementDeclaration>(); |
| 1940 |
for (int i = 0; i < iSize; ++i) |
| 1941 |
{ |
| 1942 |
StateImpl state = statesArray[i]; |
| 1943 |
List<Transition> transitions = state.getTransitions(); |
| 1944 |
TransitionImpl[] transitionsArray = transitions.toArray(EMPTY_TRANSITION_ARRAY); |
| 1945 |
int jSize = transitions.size(); |
| 1946 |
uriToElementMap.clear(); |
| 1947 |
for (int j = 0; j < jSize; ++j) |
| 1948 |
{ |
| 1949 |
TransitionImpl transition = transitionsArray[j]; |
| 1950 |
XSDTerm xsdTerm = transition.getParticle().getTerm(); |
| 1951 |
if (xsdTerm instanceof XSDElementDeclaration) |
| 1952 |
{ |
| 1953 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; |
| 1954 |
XSDTypeDefinition xsdTypeDefinition = xsdElementDeclaration.getTypeDefinition(); |
| 1955 |
Object otherXSDTypeDefinition = elementURIToTypeMap.put(xsdElementDeclaration.getURI(), xsdTypeDefinition); |
| 1956 |
if (otherXSDTypeDefinition != null && otherXSDTypeDefinition != xsdTypeDefinition) |
| 1957 |
{ |
| 1958 |
XSDDiagnostic xsdDiagnostic = XSDFactory.eINSTANCE.createXSDDiagnostic(); |
| 1959 |
xsdDiagnostic.setSeverity(XSDDiagnosticSeverity.ERROR_LITERAL); |
| 1960 |
xsdDiagnostic.setMessage |
| 1961 |
(XSDPlugin.INSTANCE.getString |
| 1962 |
("_UI_XSDError_message", |
| 1963 |
new Object [] |
| 1964 |
{ |
| 1965 |
populateDiagnostic |
| 1966 |
(xsdDiagnostic, |
| 1967 |
"cos-element-consistent", |
| 1968 |
new Object [] |
| 1969 |
{ |
| 1970 |
xsdElementDeclaration.getURI(), |
| 1971 |
xsdTypeDefinition.getURI(), |
| 1972 |
((XSDTypeDefinition)otherXSDTypeDefinition).getURI() |
| 1973 |
}) |
| 1974 |
})); |
| 1975 |
diagnostics.add(xsdDiagnostic); |
| 1976 |
} |
| 1977 |
|
| 1978 |
if (jSize > 1) |
| 1979 |
{ |
| 1980 |
XSDElementDeclaration otherXSDElementDeclaration = uriToElementMap.put(xsdElementDeclaration.getURI(), xsdElementDeclaration); |
| 1981 |
if (otherXSDElementDeclaration != null) |
| 1982 |
{ |
| 1983 |
XSDDiagnostic xsdDiagnostic = checkOverlap(xsdElementDeclaration, otherXSDElementDeclaration); |
| 1984 |
if (xsdDiagnostic != null) |
| 1985 |
{ |
| 1986 |
diagnostics.add(xsdDiagnostic); |
| 1987 |
} |
| 1988 |
} |
| 1989 |
} |
| 1990 |
} |
| 1991 |
} |
| 1992 |
// Only if there are wildcards do the check for overlapping wildcards. |
| 1993 |
// |
| 1994 |
if (jSize > 1 && uriToElementMap.size() <= jSize) |
| 1995 |
{ |
| 1996 |
for (int j = 0; j < jSize; ++j) |
| 1997 |
{ |
| 1998 |
TransitionImpl transition = transitionsArray[j]; |
| 1999 |
XSDTerm xsdTerm = transition.getParticle().getTerm(); |
| 2000 |
if (xsdTerm instanceof XSDWildcard) |
| 2001 |
{ |
| 2002 |
XSDWildcard xsdWildcard = (XSDWildcard)xsdTerm; |
| 2003 |
for (int k = j + 1; k < jSize; ++k) |
| 2004 |
{ |
| 2005 |
TransitionImpl otherTransition = transitionsArray[k]; |
| 2006 |
XSDDiagnostic xsdDiagnostic = checkOverlap(xsdWildcard, otherTransition.getParticle().getTerm()); |
| 2007 |
if (xsdDiagnostic != null) |
| 2008 |
{ |
| 2009 |
diagnostics.add(xsdDiagnostic); |
| 2010 |
} |
| 2011 |
} |
| 2012 |
} |
| 2013 |
} |
| 2014 |
} |
| 2015 |
} |
| 2016 |
} |
| 2017 |
} |
| 2018 |
|
| 2019 |
return diagnostics; |
| 2020 |
} |
| 2021 |
|
| 2022 |
public XSDParticle.DFA.State getCurrentState() |
| 2023 |
{ |
| 2024 |
return currentState; |
| 2025 |
} |
| 2026 |
|
| 2027 |
public void reset() |
| 2028 |
{ |
| 2029 |
currentState = initialState; |
| 2030 |
} |
| 2031 |
|
| 2032 |
public XSDParticle.DFA cloneDFA() |
| 2033 |
{ |
| 2034 |
return new XSDNFA(this, isApproximate); |
| 2035 |
} |
| 2036 |
} |
| 2037 |
|
| 2038 |
public static final boolean debug = false; |
| 2039 |
|
| 2040 |
protected XSDNFA xsdNFA; |
| 2041 |
protected int xsdNFACheckSum; |
| 2042 |
|
| 2043 |
public XSDParticle.DFA getDFA() |
| 2044 |
{ |
| 2045 |
if (xsdNFA == null || (!getSchema().getSchemaForSchemaNamespace().equals(getSchema().getTargetNamespace()) && xsdNFACheckSum != xsdNFA.checksum())) |
| 2046 |
{ |
| 2047 |
XSDNFA localNFA = new XSDNFA(this, false); |
| 2048 |
if (localNFA.getStates().size() > MAXIMUM_STATES) |
| 2049 |
{ |
| 2050 |
localNFA = new XSDNFA(this, true); |
| 2051 |
} |
| 2052 |
if (localNFA.getStates().size() < MAXIMUM_STATES) |
| 2053 |
{ |
| 2054 |
if (debug) |
| 2055 |
{ |
| 2056 |
System.out.println("-- NFA initial --"); |
| 2057 |
localNFA.dump(System.out); |
| 2058 |
System.out.println("-- NFA no-epsilon --"); |
| 2059 |
} |
| 2060 |
localNFA.epsilonClosure(); |
| 2061 |
if (debug) |
| 2062 |
{ |
| 2063 |
localNFA.dump(System.out); |
| 2064 |
System.out.println("-- NFA minimal --"); |
| 2065 |
} |
| 2066 |
localNFA.minimize(); |
| 2067 |
if (debug) |
| 2068 |
{ |
| 2069 |
localNFA.dump(System.out); |
| 2070 |
System.out.println("-- DFA --"); |
| 2071 |
} |
| 2072 |
localNFA.determinize(); |
| 2073 |
if (debug) |
| 2074 |
{ |
| 2075 |
localNFA.dump(System.out); |
| 2076 |
System.out.println("-- DFA minimal--"); |
| 2077 |
} |
| 2078 |
localNFA.minimize(); |
| 2079 |
if (debug) |
| 2080 |
{ |
| 2081 |
localNFA.dump(System.out); |
| 2082 |
} |
| 2083 |
} |
| 2084 |
else |
| 2085 |
{ |
| 2086 |
// Clean up bad transitions. |
| 2087 |
// |
| 2088 |
for (DFA.State state : localNFA.getStates()) |
| 2089 |
{ |
| 2090 |
for (Iterator<DFA.Transition> j = state.getTransitions().iterator(); j.hasNext(); ) |
| 2091 |
{ |
| 2092 |
DFA.Transition transition = j.next(); |
| 2093 |
if (transition.getParticle() == null) |
| 2094 |
{ |
| 2095 |
j.remove(); |
| 2096 |
} |
| 2097 |
} |
| 2098 |
} |
| 2099 |
} |
| 2100 |
xsdNFA = localNFA; |
| 2101 |
} |
| 2102 |
return xsdNFA; |
| 2103 |
} |
| 2104 |
|
| 2105 |
public boolean isEmptiable() |
| 2106 |
{ |
| 2107 |
return getDFA().getInitialState().isAccepting(); |
| 2108 |
} |
| 2109 |
|
| 2110 |
public boolean isSubset(XSDParticle otherParticle) |
| 2111 |
{ |
| 2112 |
return isSubset(otherParticle, false); |
| 2113 |
} |
| 2114 |
|
| 2115 |
public boolean isSubset(XSDParticle otherParticle, boolean diagnose) |
| 2116 |
{ |
| 2117 |
XSDNFA subset = (XSDNFA)getDFA(); |
| 2118 |
XSDNFA superSet = (XSDNFA)otherParticle.getDFA(); |
| 2119 |
|
| 2120 |
if (!subset.getDiagnostics().isEmpty() || !superSet.getDiagnostics().isEmpty()) |
| 2121 |
{ |
| 2122 |
return true; |
| 2123 |
} |
| 2124 |
|
| 2125 |
final Set<List<DFA.State>> states = new HashSet<List<DFA.State>>(); |
| 2126 |
Map<DFA.State, Object> map = |
| 2127 |
new HashMap<DFA.State, Object>() |
| 2128 |
{ |
| 2129 |
private static final long serialVersionUID = 1L; |
| 2130 |
|
| 2131 |
@Override |
| 2132 |
public Object put(DFA.State key, Object value) |
| 2133 |
{ |
| 2134 |
DFA.State s1 = key; |
| 2135 |
DFA.State s2 = (DFA.State)value; |
| 2136 |
if (s1.isAccepting() && !s2.isAccepting()) |
| 2137 |
{ |
| 2138 |
return null; |
| 2139 |
} |
| 2140 |
|
| 2141 |
@SuppressWarnings("unchecked") Set<DFA.State> set = (Set<DFA.State>)super.get(key); |
| 2142 |
if (set == null) |
| 2143 |
{ |
| 2144 |
set = new HashSet<DFA.State>(); |
| 2145 |
super.put(key, set); |
| 2146 |
} |
| 2147 |
if (set.add(s2)) |
| 2148 |
{ |
| 2149 |
List<DFA.State> pair = new ArrayList<DFA.State>(2); |
| 2150 |
pair.add(s1); |
| 2151 |
pair.add(s2); |
| 2152 |
states.add(pair); |
| 2153 |
} |
| 2154 |
return set; |
| 2155 |
} |
| 2156 |
}; |
| 2157 |
|
| 2158 |
boolean result = false; |
| 2159 |
if (map.put(subset.getInitialState(), superSet.getInitialState()) != null) |
| 2160 |
{ |
| 2161 |
Map<XSDElementDeclaration, XSDElementDeclaration> elementMap = new HashMap<XSDElementDeclaration, XSDElementDeclaration>(); |
| 2162 |
|
| 2163 |
result = true; |
| 2164 |
LOOP: while (!states.isEmpty()) |
| 2165 |
{ |
| 2166 |
Iterator<List<DFA.State>> iterator = states.iterator(); |
| 2167 |
List<DFA.State> pair = iterator.next(); |
| 2168 |
iterator.remove(); |
| 2169 |
|
| 2170 |
DFA.State substate = pair.get(0); |
| 2171 |
DFA.State superState = pair.get(1); |
| 2172 |
for (DFA.Transition subtransition : substate.getTransitions()) |
| 2173 |
{ |
| 2174 |
XSDTerm subXSDTerm = subtransition.getParticle().getTerm(); |
| 2175 |
boolean transitionResult = false; |
| 2176 |
if (subXSDTerm instanceof XSDElementDeclaration) |
| 2177 |
{ |
| 2178 |
XSDElementDeclaration subXSDElementDeclaration = (XSDElementDeclaration)subXSDTerm; |
| 2179 |
for (DFA.Transition superTransition : superState.getTransitions()) |
| 2180 |
{ |
| 2181 |
XSDTerm superXSDTerm = superTransition.getParticle().getTerm(); |
| 2182 |
if (superXSDTerm instanceof XSDElementDeclaration) |
| 2183 |
{ |
| 2184 |
XSDElementDeclaration superXSDElementDeclaration = (XSDElementDeclaration)superXSDTerm; |
| 2185 |
if (superXSDElementDeclaration.hasSameNameAndTargetNamespace(subXSDElementDeclaration)) |
| 2186 |
{ |
| 2187 |
if (map.put(subtransition.getState(), superTransition.getState()) != null) |
| 2188 |
{ |
| 2189 |
elementMap.put(subXSDElementDeclaration, superXSDElementDeclaration); |
| 2190 |
transitionResult = true; |
| 2191 |
break; |
| 2192 |
} |
| 2193 |
else |
| 2194 |
{ |
| 2195 |
result = false; |
| 2196 |
break LOOP; |
| 2197 |
} |
| 2198 |
} |
| 2199 |
} |
| 2200 |
else |
| 2201 |
{ |
| 2202 |
XSDWildcard superXSDWildcard = (XSDWildcard)superXSDTerm; |
| 2203 |
if (superXSDWildcard.allows(subXSDElementDeclaration.getTargetNamespace())) |
| 2204 |
{ |
| 2205 |
if (map.put(subtransition.getState(), superTransition.getState()) != null) |
| 2206 |
{ |
| 2207 |
transitionResult = true; |
| 2208 |
break; |
| 2209 |
} |
| 2210 |
else |
| 2211 |
{ |
| 2212 |
result = false; |
| 2213 |
break LOOP; |
| 2214 |
} |
| 2215 |
} |
| 2216 |
} |
| 2217 |
} |
| 2218 |
} |
| 2219 |
else |
| 2220 |
{ |
| 2221 |
XSDWildcard subXSDWildcard = (XSDWildcard)subXSDTerm; |
| 2222 |
for (DFA.Transition superTransition : superState.getTransitions()) |
| 2223 |
{ |
| 2224 |
XSDTerm superXSDTerm = superTransition.getParticle().getTerm(); |
| 2225 |
if (superXSDTerm instanceof XSDWildcard) |
| 2226 |
{ |
| 2227 |
XSDWildcard superXSDWildcard = (XSDWildcard)superXSDTerm; |
| 2228 |
if (subXSDWildcard.isWildcardSubset(superXSDWildcard)) |
| 2229 |
{ |
| 2230 |
if (map.put(subtransition.getState(), superTransition.getState()) != null) |
| 2231 |
{ |
| 2232 |
transitionResult = true; |
| 2233 |
break; |
| 2234 |
} |
| 2235 |
else |
| 2236 |
{ |
| 2237 |
result = false; |
| 2238 |
break LOOP; |
| 2239 |
} |
| 2240 |
} |
| 2241 |
} |
| 2242 |
} |
| 2243 |
} |
| 2244 |
|
| 2245 |
if (!transitionResult) |
| 2246 |
{ |
| 2247 |
result = false; |
| 2248 |
break LOOP; |
| 2249 |
} |
| 2250 |
} |
| 2251 |
} |
| 2252 |
|
| 2253 |
if (result) |
| 2254 |
{ |
| 2255 |
for (Map.Entry<XSDElementDeclaration, XSDElementDeclaration> entry : elementMap.entrySet()) |
| 2256 |
{ |
| 2257 |
XSDElementDeclaration subXSDElementDeclaration = entry.getKey(); |
| 2258 |
XSDElementDeclaration superXSDElementDeclaration = entry.getValue(); |
| 2259 |
|
| 2260 |
if (superXSDElementDeclaration.isNillable() && !subXSDElementDeclaration.isNillable()) |
| 2261 |
{ |
| 2262 |
result = false; |
| 2263 |
if (diagnose) |
| 2264 |
{ |
| 2265 |
getDiagnosticTarget(subXSDElementDeclaration).createDiagnostic |
| 2266 |
(XSDDiagnosticSeverity.ERROR_LITERAL, |
| 2267 |
"rcase-NameAndTypeOK.2", |
| 2268 |
subXSDElementDeclaration.getURI()); |
| 2269 |
} |
| 2270 |
else |
| 2271 |
{ |
| 2272 |
break; |
| 2273 |
} |
| 2274 |
} |
| 2275 |
|
| 2276 |
if (superXSDElementDeclaration.getTypeDefinition() instanceof XSDSimpleTypeDefinition) |
| 2277 |
{ |
| 2278 |
if (superXSDElementDeclaration.getConstraint() == XSDConstraint.FIXED_LITERAL && |
| 2279 |
superXSDElementDeclaration.getLexicalValue() != null && |
| 2280 |
(subXSDElementDeclaration.getConstraint() != XSDConstraint.FIXED_LITERAL || |
| 2281 |
!((XSDSimpleTypeDefinition)superXSDElementDeclaration.getTypeDefinition()).equalLiterals |
| 2282 |
(superXSDElementDeclaration.getElement(), superXSDElementDeclaration.getLexicalValue(), subXSDElementDeclaration.getElement(), subXSDElementDeclaration.getLexicalValue()))) |
| 2283 |
{ |
| 2284 |
result = false; |
| 2285 |
if (diagnose) |
| 2286 |
{ |
| 2287 |
getDiagnosticTarget(subXSDElementDeclaration).createDiagnostic |
| 2288 |
(XSDDiagnosticSeverity.ERROR_LITERAL, |
| 2289 |
"rcase-NameAndTypeOK.4", |
| 2290 |
subXSDElementDeclaration.getLexicalValue(), |
| 2291 |
subXSDElementDeclaration.getURI()); |
| 2292 |
} |
| 2293 |
else |
| 2294 |
{ |
| 2295 |
break; |
| 2296 |
} |
| 2297 |
} |
| 2298 |
} |
| 2299 |
|
| 2300 |
if (!subXSDElementDeclaration.getDisallowedSubstitutions().containsAll |
| 2301 |
(superXSDElementDeclaration.getDisallowedSubstitutions())) |
| 2302 |
{ |
| 2303 |
result = false; |
| 2304 |
if (diagnose) |
| 2305 |
{ |
| 2306 |
getDiagnosticTarget(subXSDElementDeclaration).createDiagnostic |
| 2307 |
(XSDDiagnosticSeverity.ERROR_LITERAL, |
| 2308 |
"rcase-NameAndTypeOK.6", |
| 2309 |
subXSDElementDeclaration.getURI()); |
| 2310 |
} |
| 2311 |
else |
| 2312 |
{ |
| 2313 |
break; |
| 2314 |
} |
| 2315 |
} |
| 2316 |
|
| 2317 |
XSDTypeDefinition badType = |
| 2318 |
subXSDElementDeclaration.getTypeDefinition().getBadTypeDerivation |
| 2319 |
(superXSDElementDeclaration.getTypeDefinition(), false, true); |
| 2320 |
if (badType != null) |
| 2321 |
{ |
| 2322 |
result = false; |
| 2323 |
if (diagnose) |
| 2324 |
{ |
| 2325 |
getDiagnosticTarget(subXSDElementDeclaration).createDiagnostic |
| 2326 |
(XSDDiagnosticSeverity.ERROR_LITERAL, |
| 2327 |
"rcase-NameAndTypeOK.7", |
| 2328 |
subXSDElementDeclaration.getURI(), |
| 2329 |
superXSDElementDeclaration.getTypeDefinition().getURI()); |
| 2330 |
} |
| 2331 |
else |
| 2332 |
{ |
| 2333 |
break; |
| 2334 |
} |
| 2335 |
} |
| 2336 |
} |
| 2337 |
} |
| 2338 |
} |
| 2339 |
|
| 2340 |
// if (!result) |
| 2341 |
// { |
| 2342 |
// printDFA(subset); |
| 2343 |
// printDFA(superSet); |
| 2344 |
// } |
| 2345 |
|
| 2346 |
return result; |
| 2347 |
} |
| 2348 |
|
| 2349 |
@Override |
| 2350 |
public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM) |
| 2351 |
{ |
| 2352 |
XSDParticleImpl clonedParticle = |
| 2353 |
(XSDParticleImpl)getXSDFactory().createXSDParticle(); |
| 2354 |
clonedParticle.isReconciling = true; |
| 2355 |
|
| 2356 |
if (isSetMinOccurs()) |
| 2357 |
{ |
| 2358 |
clonedParticle.setMinOccurs(getMinOccurs()); |
| 2359 |
} |
| 2360 |
if (isSetMaxOccurs()) |
| 2361 |
{ |
| 2362 |
clonedParticle.setMaxOccurs(getMaxOccurs()); |
| 2363 |
} |
| 2364 |
|
| 2365 |
clonedParticle.setContent((XSDParticleContent)getContent().cloneConcreteComponent(deep, shareDOM)); |
| 2366 |
|
| 2367 |
if (shareDOM && getElement() != null) |
| 2368 |
{ |
| 2369 |
clonedParticle.setElement(getElement()); |
| 2370 |
} |
| 2371 |
|
| 2372 |
clonedParticle.isReconciling = shareDOM; |
| 2373 |
return clonedParticle; |
| 2374 |
} |
| 2375 |
} |