|
|||||||||||||||||||
| This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover. | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ContentUseState.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 |
/* |
|
| 2 |
* JBind |
|
| 3 |
* |
|
| 4 |
* Copyright (c) by Stefan Wachter. All rights reserved. |
|
| 5 |
* |
|
| 6 |
* Usage, modification, and redistribution is subject to license terms that are |
|
| 7 |
* available at 'http://www.jbind.org'. The JBind license is like the |
|
| 8 |
* 'Apache Software License V 1.1'. |
|
| 9 |
*/ |
|
| 10 |
package org.jbind.xml.instance.use; |
|
| 11 |
|
|
| 12 |
import org.jbind.xml.base.IHasLocation; |
|
| 13 |
import org.jbind.xml.core.content.IContentDesc; |
|
| 14 |
import org.jbind.xml.core.content.IUseState; |
|
| 15 |
import org.jbind.xml.msg.XmlException; |
|
| 16 |
import org.jbind.xml.msg.XmlMessages; |
|
| 17 |
|
|
| 18 |
public abstract class ContentUseState implements IUseState {
|
|
| 19 |
|
|
| 20 |
private int myUseCounter = 0; |
|
| 21 |
|
|
| 22 |
private IUseState myParent = null; |
|
| 23 |
|
|
| 24 |
private IContentDesc myContentDesc = null; |
|
| 25 |
|
|
| 26 | 7377 |
public ContentUseState(IContentDesc aContent, IUseState aParent) {
|
| 27 | 7377 |
myContentDesc = aContent; |
| 28 | 7377 |
myParent = aParent; |
| 29 |
} |
|
| 30 |
|
|
| 31 | 7495 |
public IContentDesc getContentDesc() {
|
| 32 | 7495 |
return myContentDesc; |
| 33 |
} |
|
| 34 |
|
|
| 35 | 4979 |
public IUseState getParent() {
|
| 36 | 4979 |
return myParent; |
| 37 |
} |
|
| 38 |
|
|
| 39 | 1528 |
public int getUseCounter() {
|
| 40 | 1528 |
return myUseCounter; |
| 41 |
} |
|
| 42 |
|
|
| 43 | 5263 |
protected void incrementUseCounter() {
|
| 44 | 5263 |
myUseCounter++; |
| 45 |
} |
|
| 46 |
|
|
| 47 | 11476 |
protected boolean mayIncrementUseCounter() {
|
| 48 | 11476 |
return myContentDesc.getRange().isUnbounded() || (myUseCounter < myContentDesc.getRange().getMaxOccurs()); |
| 49 |
} |
|
| 50 |
|
|
| 51 | 3482 |
public final void reset() {
|
| 52 | 3482 |
myUseCounter = 0; |
| 53 | 3482 |
doReset(); |
| 54 |
} |
|
| 55 |
|
|
| 56 | 3482 |
protected void doReset() {}
|
| 57 |
|
|
| 58 | 3488 |
public void isValidEnd(IHasLocation aHasLocation) throws XmlException {
|
| 59 | 3488 |
if ((myUseCounter < myContentDesc.getRange().getMinOccurs()) && !(myContentDesc.isEmptiable() && (myUseCounter == 0))) {
|
| 60 | 18 |
throw new XmlException(XmlMessages.cmMinOccursNotSatisfied(myContentDesc.getDesc(), myContentDesc.getLocation(), aHasLocation)); |
| 61 |
} |
|
| 62 | 3470 |
doIsValidEnd(aHasLocation); |
| 63 |
} |
|
| 64 |
|
|
| 65 |
protected abstract void doIsValidEnd(IHasLocation aHasLocation) throws XmlException; |
|
| 66 |
|
|
| 67 |
} |
|
| 68 |
|
|
||||||||||