KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > templates > model > SwitchClass


1 package org.eclipse.emf.codegen.ecore.templates.model;
2
3 import java.util.*;
4 import org.eclipse.emf.codegen.ecore.genmodel.*;
5
6 public class SwitchClass
7 {
8   protected static String JavaDoc nl;
9   public static synchronized SwitchClass create(String JavaDoc lineSeparator)
10   {
11     nl = lineSeparator;
12     SwitchClass result = new SwitchClass();
13     nl = null;
14     return result;
15   }
16
17   protected final String JavaDoc NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18   protected final String JavaDoc TEXT_1 = "";
19   protected final String JavaDoc TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * ";
20   protected final String JavaDoc TEXT_3 = "Id";
21   protected final String JavaDoc TEXT_4 = NL + " */" + NL + "package ";
22   protected final String JavaDoc TEXT_5 = ";" + NL;
23   protected final String JavaDoc TEXT_6 = NL + NL + "/**" + NL + " * <!-- begin-user-doc -->" + NL + " * The <b>Switch</b> for the model's inheritance hierarchy." + NL + " * It supports the call {@link #doSwitch(EObject) doSwitch(object)}" + NL + " * to invoke the <code>caseXXX</code> method for each class of the model," + NL + " * starting with the actual class of the object" + NL + " * and proceeding up the inheritance hierarchy" + NL + " * until a non-null result is returned," + NL + " * which is the result of the switch." + NL + " * <!-- end-user-doc -->" + NL + " * @see ";
24   protected final String JavaDoc TEXT_7 = NL + " * @generated" + NL + " */" + NL + "public class ";
25   protected final String JavaDoc TEXT_8 = NL + "{";
26   protected final String JavaDoc TEXT_9 = NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
27   protected final String JavaDoc TEXT_10 = " copyright = \"";
28   protected final String JavaDoc TEXT_11 = "\";";
29   protected final String JavaDoc TEXT_12 = NL;
30   protected final String JavaDoc TEXT_13 = NL + "\t/**" + NL + "\t * The cached model package" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected static ";
31   protected final String JavaDoc TEXT_14 = " modelPackage;" + NL + "" + NL + "\t/**" + NL + "\t * Creates an instance of the switch." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
32   protected final String JavaDoc TEXT_15 = "()" + NL + "\t{" + NL + "\t\tif (modelPackage == null)" + NL + "\t\t{" + NL + "\t\t\tmodelPackage = ";
33   protected final String JavaDoc TEXT_16 = ".eINSTANCE;" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @return the first non-null result returned by a <code>caseXXX</code> call." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Object doSwitch(EObject theEObject)" + NL + "\t{" + NL + "\t\treturn doSwitch(theEObject.eClass(), theEObject);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @return the first non-null result returned by a <code>caseXXX</code> call." + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Object doSwitch(EClass theEClass, EObject theEObject)" + NL + "\t{" + NL + "\t\tif (theEClass.eContainer() == modelPackage)" + NL + "\t\t{" + NL + "\t\t\treturn doSwitch(theEClass.getClassifierID(), theEObject);" + NL + "\t\t}" + NL + "\t\telse" + NL + "\t\t{" + NL + "\t\t\t";
34   protected final String JavaDoc TEXT_17 = " eSuperTypes = theEClass.getESuperTypes();" + NL + "\t\t\treturn" + NL + "\t\t\t\teSuperTypes.isEmpty() ?" + NL + "\t\t\t\t\tdefaultCase(theEObject) :" + NL + "\t\t\t\t\tdoSwitch((EClass)eSuperTypes.get(0), theEObject);" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @return the first non-null result returned by a <code>caseXXX</code> call." + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Object doSwitch(int classifierID, EObject theEObject)" + NL + "\t{" + NL + "\t\tswitch (classifierID)" + NL + "\t\t{";
35   protected final String JavaDoc TEXT_18 = NL + "\t\t\tcase ";
36   protected final String JavaDoc TEXT_19 = ".";
37   protected final String JavaDoc TEXT_20 = ":" + NL + "\t\t\t{" + NL + "\t\t\t\t";
38   protected final String JavaDoc TEXT_21 = " ";
39   protected final String JavaDoc TEXT_22 = " = (";
40   protected final String JavaDoc TEXT_23 = ")theEObject;" + NL + "\t\t\t\tObject ";
41   protected final String JavaDoc TEXT_24 = " = case";
42   protected final String JavaDoc TEXT_25 = "(";
43   protected final String JavaDoc TEXT_26 = ");";
44   protected final String JavaDoc TEXT_27 = NL + "\t\t\t\tif (";
45   protected final String JavaDoc TEXT_28 = " == null) ";
46   protected final String JavaDoc TEXT_29 = " = case";
47   protected final String JavaDoc TEXT_30 = "(";
48   protected final String JavaDoc TEXT_31 = "(";
49   protected final String JavaDoc TEXT_32 = ")";
50   protected final String JavaDoc TEXT_33 = ");";
51   protected final String JavaDoc TEXT_34 = NL + "\t\t\t\tif (";
52   protected final String JavaDoc TEXT_35 = " == null) ";
53   protected final String JavaDoc TEXT_36 = " = defaultCase(theEObject);" + NL + "\t\t\t\treturn ";
54   protected final String JavaDoc TEXT_37 = ";" + NL + "\t\t\t}";
55   protected final String JavaDoc TEXT_38 = NL + "\t\t\tdefault: return defaultCase(theEObject);" + NL + "\t\t}" + NL + "\t}";
56   protected final String JavaDoc TEXT_39 = NL + NL + "\t/**" + NL + "\t * Returns the result of interpretting the object as an instance of '<em>";
57   protected final String JavaDoc TEXT_40 = "</em>'." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * This implementation returns null;" + NL + "\t * returning a non-null result will terminate the switch." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @param object the target of the switch." + NL + "\t * @return the result of interpretting the object as an instance of '<em>";
58   protected final String JavaDoc TEXT_41 = "</em>'." + NL + "\t * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Object case";
59   protected final String JavaDoc TEXT_42 = "(";
60   protected final String JavaDoc TEXT_43 = " object)" + NL + "\t{" + NL + "\t\treturn null;" + NL + "\t}";
61   protected final String JavaDoc TEXT_44 = NL + NL + "\t/**" + NL + "\t * Returns the result of interpretting the object as an instance of '<em>EObject</em>'." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * This implementation returns null;" + NL + "\t * returning a non-null result will terminate the switch, but this is the last case anyway." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @param object the target of the switch." + NL + "\t * @return the result of interpretting the object as an instance of '<em>EObject</em>'." + NL + "\t * @see #doSwitch(org.eclipse.emf.ecore.EObject)" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Object defaultCase(EObject object)" + NL + "\t{" + NL + "\t\treturn null;" + NL + "\t}" + NL + "" + NL + "} //";
62   protected final String JavaDoc TEXT_45 = NL;
63
64   public String JavaDoc generate(Object JavaDoc argument)
65   {
66     StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
67     
68 /**
69  * <copyright>
70  *
71  * Copyright (c) 2002-2004 IBM Corporation and others.
72  * All rights reserved. This program and the accompanying materials
73  * are made available under the terms of the Eclipse Public License v1.0
74  * which accompanies this distribution, and is available at
75  * http://www.eclipse.org/legal/epl-v10.html
76  *
77  * Contributors:
78  * IBM - Initial API and implementation
79  *
80  * </copyright>
81  */

82
83     GenPackage genPackage = (GenPackage)argument; GenModel genModel=genPackage.getGenModel();
84     stringBuffer.append(TEXT_1);
85     stringBuffer.append(TEXT_2);
86     stringBuffer.append("$");
87     stringBuffer.append(TEXT_3);
88     stringBuffer.append("$");
89     stringBuffer.append(TEXT_4);
90     stringBuffer.append(genPackage.getUtilitiesPackageName());
91     stringBuffer.append(TEXT_5);
92     genModel.addImport("org.eclipse.emf.ecore.EClass");
93     genModel.addImport("org.eclipse.emf.ecore.EObject");
94     if (!genPackage.hasJavaLangConflict() && !genPackage.getUtilitiesPackageName().equals(genPackage.getInterfacePackageName())) genModel.addImport(genPackage.getInterfacePackageName() + ".*");
95     genModel.markImportLocation(stringBuffer);
96     stringBuffer.append(TEXT_6);
97     stringBuffer.append(genPackage.getQualifiedPackageInterfaceName());
98     stringBuffer.append(TEXT_7);
99     stringBuffer.append(genPackage.getSwitchClassName());
100     stringBuffer.append(TEXT_8);
101     if (genModel.getCopyrightText() != null) {
102     stringBuffer.append(TEXT_9);
103     stringBuffer.append(genModel.getImportedName("java.lang.String"));
104     stringBuffer.append(TEXT_10);
105     stringBuffer.append(genModel.getCopyrightText());
106     stringBuffer.append(TEXT_11);
107     stringBuffer.append(genModel.getNonNLS());
108     stringBuffer.append(TEXT_12);
109     }
110     stringBuffer.append(TEXT_13);
111     stringBuffer.append(genPackage.getImportedPackageInterfaceName());
112     stringBuffer.append(TEXT_14);
113     stringBuffer.append(genPackage.getSwitchClassName());
114     stringBuffer.append(TEXT_15);
115     stringBuffer.append(genPackage.getImportedPackageInterfaceName());
116     stringBuffer.append(TEXT_16);
117     stringBuffer.append(genModel.getImportedName("java.util.List"));
118     stringBuffer.append(TEXT_17);
119     for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();
120     if (!genClass.isExternalInterface() && !genClass.isEObject() || genClass.isMapEntry()) { String JavaDoc result = "result".equals(genClass.getSafeUncapName()) ? "theResult" : "result";
121     stringBuffer.append(TEXT_18);
122     stringBuffer.append(genPackage.getImportedPackageInterfaceName());
123     stringBuffer.append(TEXT_19);
124     stringBuffer.append(genPackage.getClassifierID(genClass));
125     stringBuffer.append(TEXT_20);
126     stringBuffer.append(genClass.getImportedInterfaceName());
127     stringBuffer.append(TEXT_21);
128     stringBuffer.append(genClass.getSafeUncapName());
129     stringBuffer.append(TEXT_22);
130     stringBuffer.append(genClass.getImportedInterfaceName());
131     stringBuffer.append(TEXT_23);
132     stringBuffer.append(result);
133     stringBuffer.append(TEXT_24);
134     stringBuffer.append(genPackage.getClassUniqueName(genClass));
135     stringBuffer.append(TEXT_25);
136     stringBuffer.append(genClass.getSafeUncapName());
137     stringBuffer.append(TEXT_26);
138     for (Iterator b=genClass.getSwitchGenClasses().iterator(); b.hasNext();) { GenClass baseGenClass = (GenClass)b.next();
139     stringBuffer.append(TEXT_27);
140     stringBuffer.append(result);
141     stringBuffer.append(TEXT_28);
142     stringBuffer.append(result);
143     stringBuffer.append(TEXT_29);
144     stringBuffer.append(genPackage.getClassUniqueName(baseGenClass));
145     stringBuffer.append(TEXT_30);
146     if (genClass.isMapEntry()) {
147     stringBuffer.append(TEXT_31);
148     stringBuffer.append(baseGenClass.getImportedInterfaceName());
149     stringBuffer.append(TEXT_32);
150     }
151     stringBuffer.append(genClass.getSafeUncapName());
152     stringBuffer.append(TEXT_33);
153     }
154     stringBuffer.append(TEXT_34);
155     stringBuffer.append(result);
156     stringBuffer.append(TEXT_35);
157     stringBuffer.append(result);
158     stringBuffer.append(TEXT_36);
159     stringBuffer.append(result);
160     stringBuffer.append(TEXT_37);
161     }
162     }
163     stringBuffer.append(TEXT_38);
164     for (Iterator i=genPackage.getAllSwitchGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next();
165     stringBuffer.append(TEXT_39);
166     stringBuffer.append(genClass.getFormattedName());
167     stringBuffer.append(TEXT_40);
168     stringBuffer.append(genClass.getFormattedName());
169     stringBuffer.append(TEXT_41);
170     stringBuffer.append(genPackage.getClassUniqueName(genClass));
171     stringBuffer.append(TEXT_42);
172     stringBuffer.append(genClass.getImportedInterfaceName());
173     stringBuffer.append(TEXT_43);
174     }
175     stringBuffer.append(TEXT_44);
176     stringBuffer.append(genPackage.getSwitchClassName());
177     genModel.emitSortedImports();
178     stringBuffer.append(TEXT_45);
179     return stringBuffer.toString();
180   }
181 }
182
Popular Tags