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.context;
004:
005: import org.apache.xmlbeans.XmlObject;
006:
007: import com.tc.config.schema.IllegalConfigurationChangeHandler;
008: import com.tc.config.schema.dynamic.BooleanConfigItem;
009: import com.tc.config.schema.dynamic.ConfigItem;
010: import com.tc.config.schema.dynamic.FileConfigItem;
011: import com.tc.config.schema.dynamic.IntConfigItem;
012: import com.tc.config.schema.dynamic.StringArrayConfigItem;
013: import com.tc.config.schema.dynamic.StringConfigItem;
014:
015: public class MockConfigContext implements ConfigContext {
016:
017: private int numIllegalConfigurationChangeHandlers;
018: private IllegalConfigurationChangeHandler returnedIllegalConfigurationChangeHandler;
019:
020: private int numEnsureRepositoryProvides;
021: private Class lastEnsureClass;
022: private RuntimeException exceptionOnEnsureRepositoryProvides;
023:
024: private int numItemCreateds;
025: private ConfigItem lastItemCreated;
026:
027: private int numHasDefaultFors;
028: private String lastHasDefaultForXPath;
029: private boolean returnedHasDefaultFor;
030:
031: private int numBeans;
032: private XmlObject returnedBean;
033:
034: private int numIsOptionals;
035: private String lastIsOptionalXPath;
036: private boolean returnedIsOptional;
037:
038: private int numDefaultFors;
039: private String lastDefaultForXPath;
040: private XmlObject returnedDefaultFor;
041:
042: public MockConfigContext() {
043: this .returnedIllegalConfigurationChangeHandler = null;
044: this .exceptionOnEnsureRepositoryProvides = null;
045: this .returnedBean = null;
046: this .returnedHasDefaultFor = false;
047: this .returnedIsOptional = false;
048: this .returnedDefaultFor = null;
049:
050: reset();
051: }
052:
053: public void reset() {
054: this .numIllegalConfigurationChangeHandlers = 0;
055:
056: this .numEnsureRepositoryProvides = 0;
057: this .lastEnsureClass = null;
058:
059: this .numItemCreateds = 0;
060: this .lastItemCreated = null;
061:
062: this .numHasDefaultFors = 0;
063: this .lastHasDefaultForXPath = null;
064:
065: this .numIsOptionals = 0;
066: this .lastIsOptionalXPath = null;
067:
068: this .numDefaultFors = 0;
069: this .lastDefaultForXPath = null;
070:
071: this .numBeans = 0;
072: }
073:
074: public IllegalConfigurationChangeHandler illegalConfigurationChangeHandler() {
075: ++this .numIllegalConfigurationChangeHandlers;
076: return this .returnedIllegalConfigurationChangeHandler;
077: }
078:
079: public void ensureRepositoryProvides(Class theClass) {
080: ++this .numEnsureRepositoryProvides;
081: this .lastEnsureClass = theClass;
082: if (this .exceptionOnEnsureRepositoryProvides != null)
083: throw this .exceptionOnEnsureRepositoryProvides;
084: }
085:
086: public int getNumBeans() {
087: return numBeans;
088: }
089:
090: public int getNumEnsureRepositoryProvides() {
091: return numEnsureRepositoryProvides;
092: }
093:
094: public Class getLastEnsureClass() {
095: return lastEnsureClass;
096: }
097:
098: public boolean hasDefaultFor(String xpath) {
099: ++this .numHasDefaultFors;
100: this .lastHasDefaultForXPath = xpath;
101: return this .returnedHasDefaultFor;
102: }
103:
104: public XmlObject defaultFor(String xpath) {
105: ++this .numDefaultFors;
106: this .lastDefaultForXPath = xpath;
107: return this .returnedDefaultFor;
108: }
109:
110: public Object syncLockForBean() {
111: return this ;
112: }
113:
114: public boolean isOptional(String xpath) {
115: ++this .numIsOptionals;
116: this .lastIsOptionalXPath = xpath;
117: return this .returnedIsOptional;
118: }
119:
120: public XmlObject bean() {
121: ++this .numBeans;
122: return this .returnedBean;
123: }
124:
125: public void itemCreated(ConfigItem item) {
126: ++this .numItemCreateds;
127: this .lastItemCreated = item;
128: }
129:
130: public IntConfigItem intItem(String xpath) {
131: return null;
132: }
133:
134: public StringConfigItem stringItem(String xpath) {
135: return null;
136: }
137:
138: public StringArrayConfigItem stringArrayItem(String xpath) {
139: return null;
140: }
141:
142: public FileConfigItem fileItem(String xpath) {
143: return null;
144: }
145:
146: public BooleanConfigItem booleanItem(String xpath) {
147: return null;
148: }
149:
150: public BooleanConfigItem booleanItem(String xpath,
151: boolean defaultValue) {
152: return null;
153: }
154:
155: public FileConfigItem substitutedFileItem(String xpath) {
156: return null;
157: }
158:
159: public ConfigItem getLastItemCreated() {
160: return lastItemCreated;
161: }
162:
163: public int getNumItemCreateds() {
164: return numItemCreateds;
165: }
166:
167: public String getLastHasDefaultForXPath() {
168: return lastHasDefaultForXPath;
169: }
170:
171: public int getNumHasDefaultFors() {
172: return numHasDefaultFors;
173: }
174:
175: public void setReturnedHasDefaultFor(boolean returnedHasDefaultFor) {
176: this .returnedHasDefaultFor = returnedHasDefaultFor;
177: }
178:
179: public void setReturnedBean(XmlObject returnedBean) {
180: this .returnedBean = returnedBean;
181: }
182:
183: public String getLastIsOptionalXPath() {
184: return lastIsOptionalXPath;
185: }
186:
187: public int getNumIsOptionals() {
188: return numIsOptionals;
189: }
190:
191: public void setReturnedIsOptional(boolean returnedIsOptional) {
192: this .returnedIsOptional = returnedIsOptional;
193: }
194:
195: public String getLastDefaultForXPath() {
196: return lastDefaultForXPath;
197: }
198:
199: public int getNumDefaultFors() {
200: return numDefaultFors;
201: }
202:
203: public void setReturnedDefaultFor(XmlObject returnedDefaultFor) {
204: this .returnedDefaultFor = returnedDefaultFor;
205: }
206:
207: public int getNumIllegalConfigurationChangeHandlers() {
208: return numIllegalConfigurationChangeHandlers;
209: }
210:
211: public void setReturnedIllegalConfigurationChangeHandler(
212: IllegalConfigurationChangeHandler returnedIllegalConfigurationChangeHandler) {
213: this .returnedIllegalConfigurationChangeHandler = returnedIllegalConfigurationChangeHandler;
214: }
215:
216: public FileConfigItem configRelativeSubstitutedFileItem(String xpath) {
217: return null;
218: }
219:
220: }
|