001 /**
002 * <copyright>
003 * </copyright>
004 *
005 * $Id$
006 */
007 package com.hammurapi.reasoning.spi.model.util;
008
009 import com.hammurapi.config.Factory;
010 import com.hammurapi.config.Named;
011 import com.hammurapi.config.NamedObjectDefinition;
012 import com.hammurapi.config.ObjectDefinition;
013 import com.hammurapi.config.PropertySource;
014
015 import com.hammurapi.party.CommonObject;
016 import com.hammurapi.reasoning.spi.model.*;
017
018 import java.util.List;
019
020 import org.eclipse.emf.ecore.EClass;
021 import org.eclipse.emf.ecore.EObject;
022
023 /**
024 * <!-- begin-user-doc -->
025 * The <b>Switch</b> for the model's inheritance hierarchy.
026 * It supports the call {@link #doSwitch(EObject) doSwitch(object)}
027 * to invoke the <code>caseXXX</code> method for each class of the model,
028 * starting with the actual class of the object
029 * and proceeding up the inheritance hierarchy
030 * until a non-null result is returned,
031 * which is the result of the switch.
032 * <!-- end-user-doc -->
033 * @see com.hammurapi.reasoning.spi.model.ModelPackage
034 * @generated
035 */
036 public class ModelSwitch<T> {
037 /**
038 * The cached model package
039 * <!-- begin-user-doc -->
040 * <!-- end-user-doc -->
041 * @generated
042 */
043 protected static ModelPackage modelPackage;
044
045 /**
046 * Creates an instance of the switch.
047 * <!-- begin-user-doc -->
048 * <!-- end-user-doc -->
049 * @generated
050 */
051 public ModelSwitch() {
052 if (modelPackage == null) {
053 modelPackage = ModelPackage.eINSTANCE;
054 }
055 }
056
057 /**
058 * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result.
059 * <!-- begin-user-doc -->
060 * <!-- end-user-doc -->
061 * @return the first non-null result returned by a <code>caseXXX</code> call.
062 * @generated
063 */
064 public T doSwitch(EObject theEObject) {
065 return doSwitch(theEObject.eClass(), theEObject);
066 }
067
068 /**
069 * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result.
070 * <!-- begin-user-doc -->
071 * <!-- end-user-doc -->
072 * @return the first non-null result returned by a <code>caseXXX</code> call.
073 * @generated
074 */
075 protected T doSwitch(EClass theEClass, EObject theEObject) {
076 if (theEClass.eContainer() == modelPackage) {
077 return doSwitch(theEClass.getClassifierID(), theEObject);
078 }
079 else {
080 List<EClass> eSuperTypes = theEClass.getESuperTypes();
081 return
082 eSuperTypes.isEmpty() ?
083 defaultCase(theEObject) :
084 doSwitch(eSuperTypes.get(0), theEObject);
085 }
086 }
087
088 /**
089 * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result.
090 * <!-- begin-user-doc -->
091 * <!-- end-user-doc -->
092 * @return the first non-null result returned by a <code>caseXXX</code> call.
093 * @generated
094 */
095 protected T doSwitch(int classifierID, EObject theEObject) {
096 switch (classifierID) {
097 case ModelPackage.RULE_SET: {
098 RuleSet ruleSet = (RuleSet)theEObject;
099 T result = caseRuleSet(ruleSet);
100 if (result == null) result = caseNamedObjectDefinition(ruleSet);
101 if (result == null) result = caseNamed(ruleSet);
102 if (result == null) result = caseObjectDefinition(ruleSet);
103 if (result == null) result = caseFactory(ruleSet);
104 if (result == null) result = casePropertySource(ruleSet);
105 if (result == null) result = caseCommonObject(ruleSet);
106 if (result == null) result = defaultCase(theEObject);
107 return result;
108 }
109 case ModelPackage.RULE: {
110 Rule rule = (Rule)theEObject;
111 T result = caseRule(rule);
112 if (result == null) result = caseNamedObjectDefinition(rule);
113 if (result == null) result = caseNamed(rule);
114 if (result == null) result = caseObjectDefinition(rule);
115 if (result == null) result = caseFactory(rule);
116 if (result == null) result = casePropertySource(rule);
117 if (result == null) result = caseCommonObject(rule);
118 if (result == null) result = defaultCase(theEObject);
119 return result;
120 }
121 default: return defaultCase(theEObject);
122 }
123 }
124
125 /**
126 * Returns the result of interpreting the object as an instance of '<em>Rule Set</em>'.
127 * <!-- begin-user-doc -->
128 * This implementation returns null;
129 * returning a non-null result will terminate the switch.
130 * <!-- end-user-doc -->
131 * @param object the target of the switch.
132 * @return the result of interpreting the object as an instance of '<em>Rule Set</em>'.
133 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
134 * @generated
135 */
136 public T caseRuleSet(RuleSet object) {
137 return null;
138 }
139
140 /**
141 * Returns the result of interpreting the object as an instance of '<em>Rule</em>'.
142 * <!-- begin-user-doc -->
143 * This implementation returns null;
144 * returning a non-null result will terminate the switch.
145 * <!-- end-user-doc -->
146 * @param object the target of the switch.
147 * @return the result of interpreting the object as an instance of '<em>Rule</em>'.
148 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
149 * @generated
150 */
151 public T caseRule(Rule object) {
152 return null;
153 }
154
155 /**
156 * Returns the result of interpreting the object as an instance of '<em>Common Object</em>'.
157 * <!-- begin-user-doc -->
158 * This implementation returns null;
159 * returning a non-null result will terminate the switch.
160 * <!-- end-user-doc -->
161 * @param object the target of the switch.
162 * @return the result of interpreting the object as an instance of '<em>Common Object</em>'.
163 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
164 * @generated
165 */
166 public T caseCommonObject(CommonObject object) {
167 return null;
168 }
169
170 /**
171 * Returns the result of interpreting the object as an instance of '<em>Factory</em>'.
172 * <!-- begin-user-doc -->
173 * This implementation returns null;
174 * returning a non-null result will terminate the switch.
175 * <!-- end-user-doc -->
176 * @param object the target of the switch.
177 * @return the result of interpreting the object as an instance of '<em>Factory</em>'.
178 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
179 * @generated
180 */
181 public T caseFactory(Factory object) {
182 return null;
183 }
184
185 /**
186 * Returns the result of interpreting the object as an instance of '<em>Named</em>'.
187 * <!-- begin-user-doc -->
188 * This implementation returns null;
189 * returning a non-null result will terminate the switch.
190 * <!-- end-user-doc -->
191 * @param object the target of the switch.
192 * @return the result of interpreting the object as an instance of '<em>Named</em>'.
193 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
194 * @generated
195 */
196 public T caseNamed(Named object) {
197 return null;
198 }
199
200 /**
201 * Returns the result of interpreting the object as an instance of '<em>Property Source</em>'.
202 * <!-- begin-user-doc -->
203 * This implementation returns null;
204 * returning a non-null result will terminate the switch.
205 * <!-- end-user-doc -->
206 * @param object the target of the switch.
207 * @return the result of interpreting the object as an instance of '<em>Property Source</em>'.
208 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
209 * @generated
210 */
211 public T casePropertySource(PropertySource object) {
212 return null;
213 }
214
215 /**
216 * Returns the result of interpreting the object as an instance of '<em>Object Definition</em>'.
217 * <!-- begin-user-doc -->
218 * This implementation returns null;
219 * returning a non-null result will terminate the switch.
220 * <!-- end-user-doc -->
221 * @param object the target of the switch.
222 * @return the result of interpreting the object as an instance of '<em>Object Definition</em>'.
223 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
224 * @generated
225 */
226 public T caseObjectDefinition(ObjectDefinition object) {
227 return null;
228 }
229
230 /**
231 * Returns the result of interpreting the object as an instance of '<em>Named Object Definition</em>'.
232 * <!-- begin-user-doc -->
233 * This implementation returns null;
234 * returning a non-null result will terminate the switch.
235 * <!-- end-user-doc -->
236 * @param object the target of the switch.
237 * @return the result of interpreting the object as an instance of '<em>Named Object Definition</em>'.
238 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
239 * @generated
240 */
241 public T caseNamedObjectDefinition(NamedObjectDefinition object) {
242 return null;
243 }
244
245 /**
246 * Returns the result of interpreting the object as an instance of '<em>EObject</em>'.
247 * <!-- begin-user-doc -->
248 * This implementation returns null;
249 * returning a non-null result will terminate the switch, but this is the last case anyway.
250 * <!-- end-user-doc -->
251 * @param object the target of the switch.
252 * @return the result of interpreting the object as an instance of '<em>EObject</em>'.
253 * @see #doSwitch(org.eclipse.emf.ecore.EObject)
254 * @generated
255 */
256 public T defaultCase(EObject object) {
257 return null;
258 }
259
260 } //ModelSwitch