KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > defaults > MockDefaultValueProvider


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.defaults;
5
6 import org.apache.xmlbeans.SchemaType;
7 import org.apache.xmlbeans.XmlException;
8 import org.apache.xmlbeans.XmlObject;
9
10 /**
11  * A mock {@link DefaultValueProvider}, for use in tests.
12  */

13 public class MockDefaultValueProvider implements DefaultValueProvider {
14
15   private int numDefaultFors;
16   private XmlObject returnedDefaultFor;
17   private SchemaType lastBaseType;
18   private String JavaDoc lastXPath;
19   private XmlException defaultForException;
20   private int numHasDefaults;
21   private SchemaType lastHasDefaultsSchemaType;
22   private String JavaDoc lastHasDefaultsXPath;
23   private boolean returnedHasDefault;
24   private int numIsOptionals;
25   private boolean returnedIsOptional;
26   private int numPossibleForXPathToHaveDefaults;
27   private String JavaDoc lastPossibleForXPathToHaveDefaultsXPath;
28   private boolean returnedPossibleForXPathToHaveDefault;
29
30   public MockDefaultValueProvider() {
31     this.returnedDefaultFor = null;
32     this.defaultForException = null;
33     this.returnedHasDefault = false;
34     this.returnedIsOptional = false;
35     this.returnedPossibleForXPathToHaveDefault = false;
36
37     reset();
38   }
39
40   public void reset() {
41     this.numDefaultFors = 0;
42     this.lastBaseType = null;
43     this.lastXPath = null;
44     this.numHasDefaults = 0;
45     this.lastHasDefaultsSchemaType = null;
46     this.lastHasDefaultsXPath = null;
47     this.numIsOptionals = 0;
48     this.numPossibleForXPathToHaveDefaults = 0;
49     this.lastPossibleForXPathToHaveDefaultsXPath = null;
50   }
51
52   public XmlObject defaultFor(SchemaType baseType, String JavaDoc xpath) throws XmlException {
53     ++this.numDefaultFors;
54     this.lastBaseType = baseType;
55     this.lastXPath = xpath;
56
57     if (this.defaultForException != null) throw this.defaultForException;
58
59     return this.returnedDefaultFor;
60   }
61
62   public boolean hasDefault(SchemaType baseType, String JavaDoc xpath) {
63     ++this.numHasDefaults;
64     this.lastHasDefaultsSchemaType = baseType;
65     this.lastHasDefaultsXPath = xpath;
66     return this.returnedHasDefault;
67   }
68
69   public boolean isOptional(SchemaType baseType, String JavaDoc xpath) {
70     ++this.numIsOptionals;
71     this.lastBaseType = baseType;
72     this.lastXPath = xpath;
73     return this.returnedIsOptional;
74   }
75
76   public boolean possibleForXPathToHaveDefault(String JavaDoc xpath) {
77     ++this.numPossibleForXPathToHaveDefaults;
78     this.lastPossibleForXPathToHaveDefaultsXPath = xpath;
79     return this.returnedPossibleForXPathToHaveDefault;
80   }
81
82   public SchemaType getLastBaseType() {
83     return lastBaseType;
84   }
85
86   public String JavaDoc getLastXPath() {
87     return lastXPath;
88   }
89
90   public int getNumDefaultFors() {
91     return numDefaultFors;
92   }
93
94   public void setReturnedDefaultFor(XmlObject returnedDefaultFor) {
95     this.returnedDefaultFor = returnedDefaultFor;
96   }
97
98   public void setDefaultForException(XmlException defaultForException) {
99     this.defaultForException = defaultForException;
100   }
101
102   public int getNumHasDefaults() {
103     return numHasDefaults;
104   }
105
106   public int getNumIsOptionals() {
107     return numIsOptionals;
108   }
109
110   public int getNumPossibleForXPathToHaveDefaults() {
111     return numPossibleForXPathToHaveDefaults;
112   }
113
114   public void setReturnedHasDefault(boolean returnedHasDefault) {
115     this.returnedHasDefault = returnedHasDefault;
116   }
117
118   public void setReturnedIsOptional(boolean returnedIsOptional) {
119     this.returnedIsOptional = returnedIsOptional;
120   }
121
122   public void setReturnedPossibleForXPathToHaveDefault(boolean returnedPossibleForXPathToHaveDefault) {
123     this.returnedPossibleForXPathToHaveDefault = returnedPossibleForXPathToHaveDefault;
124   }
125
126   public SchemaType getLastHasDefaultsSchemaType() {
127     return lastHasDefaultsSchemaType;
128   }
129
130   public String JavaDoc getLastHasDefaultsXPath() {
131     return lastHasDefaultsXPath;
132   }
133
134   public String JavaDoc getLastPossibleForXPathToHaveDefaultsXPath() {
135     return lastPossibleForXPathToHaveDefaultsXPath;
136   }
137
138 }
139
Popular Tags