001: /**
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */package com.tc.config.schema.defaults;
004:
005: import org.apache.xmlbeans.SchemaType;
006: import org.apache.xmlbeans.XmlException;
007: import org.apache.xmlbeans.XmlObject;
008:
009: /**
010: * A mock {@link DefaultValueProvider}, for use in tests.
011: */
012: public class MockDefaultValueProvider implements DefaultValueProvider {
013:
014: private int numDefaultFors;
015: private XmlObject returnedDefaultFor;
016: private SchemaType lastBaseType;
017: private String lastXPath;
018: private XmlException defaultForException;
019: private int numHasDefaults;
020: private SchemaType lastHasDefaultsSchemaType;
021: private String lastHasDefaultsXPath;
022: private boolean returnedHasDefault;
023: private int numIsOptionals;
024: private boolean returnedIsOptional;
025: private int numPossibleForXPathToHaveDefaults;
026: private String lastPossibleForXPathToHaveDefaultsXPath;
027: private boolean returnedPossibleForXPathToHaveDefault;
028:
029: public MockDefaultValueProvider() {
030: this .returnedDefaultFor = null;
031: this .defaultForException = null;
032: this .returnedHasDefault = false;
033: this .returnedIsOptional = false;
034: this .returnedPossibleForXPathToHaveDefault = false;
035:
036: reset();
037: }
038:
039: public void reset() {
040: this .numDefaultFors = 0;
041: this .lastBaseType = null;
042: this .lastXPath = null;
043: this .numHasDefaults = 0;
044: this .lastHasDefaultsSchemaType = null;
045: this .lastHasDefaultsXPath = null;
046: this .numIsOptionals = 0;
047: this .numPossibleForXPathToHaveDefaults = 0;
048: this .lastPossibleForXPathToHaveDefaultsXPath = null;
049: }
050:
051: public XmlObject defaultFor(SchemaType baseType, String xpath)
052: throws XmlException {
053: ++this .numDefaultFors;
054: this .lastBaseType = baseType;
055: this .lastXPath = xpath;
056:
057: if (this .defaultForException != null)
058: throw this .defaultForException;
059:
060: return this .returnedDefaultFor;
061: }
062:
063: public boolean hasDefault(SchemaType baseType, String xpath) {
064: ++this .numHasDefaults;
065: this .lastHasDefaultsSchemaType = baseType;
066: this .lastHasDefaultsXPath = xpath;
067: return this .returnedHasDefault;
068: }
069:
070: public boolean isOptional(SchemaType baseType, String xpath) {
071: ++this .numIsOptionals;
072: this .lastBaseType = baseType;
073: this .lastXPath = xpath;
074: return this .returnedIsOptional;
075: }
076:
077: public boolean possibleForXPathToHaveDefault(String xpath) {
078: ++this .numPossibleForXPathToHaveDefaults;
079: this .lastPossibleForXPathToHaveDefaultsXPath = xpath;
080: return this .returnedPossibleForXPathToHaveDefault;
081: }
082:
083: public SchemaType getLastBaseType() {
084: return lastBaseType;
085: }
086:
087: public String getLastXPath() {
088: return lastXPath;
089: }
090:
091: public int getNumDefaultFors() {
092: return numDefaultFors;
093: }
094:
095: public void setReturnedDefaultFor(XmlObject returnedDefaultFor) {
096: this .returnedDefaultFor = returnedDefaultFor;
097: }
098:
099: public void setDefaultForException(XmlException defaultForException) {
100: this .defaultForException = defaultForException;
101: }
102:
103: public int getNumHasDefaults() {
104: return numHasDefaults;
105: }
106:
107: public int getNumIsOptionals() {
108: return numIsOptionals;
109: }
110:
111: public int getNumPossibleForXPathToHaveDefaults() {
112: return numPossibleForXPathToHaveDefaults;
113: }
114:
115: public void setReturnedHasDefault(boolean returnedHasDefault) {
116: this .returnedHasDefault = returnedHasDefault;
117: }
118:
119: public void setReturnedIsOptional(boolean returnedIsOptional) {
120: this .returnedIsOptional = returnedIsOptional;
121: }
122:
123: public void setReturnedPossibleForXPathToHaveDefault(
124: boolean returnedPossibleForXPathToHaveDefault) {
125: this .returnedPossibleForXPathToHaveDefault = returnedPossibleForXPathToHaveDefault;
126: }
127:
128: public SchemaType getLastHasDefaultsSchemaType() {
129: return lastHasDefaultsSchemaType;
130: }
131:
132: public String getLastHasDefaultsXPath() {
133: return lastHasDefaultsXPath;
134: }
135:
136: public String getLastPossibleForXPathToHaveDefaultsXPath() {
137: return lastPossibleForXPathToHaveDefaultsXPath;
138: }
139:
140: }
|