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 AdapterFactoryClass 7 { 8 protected static String nl; 9 public static synchronized AdapterFactoryClass create(String lineSeparator) 10 { 11 nl = lineSeparator; 12 AdapterFactoryClass result = new AdapterFactoryClass(); 13 nl = null; 14 return result; 15 } 16 17 protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; 18 protected final String TEXT_1 = ""; 19 protected final String TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * "; 20 protected final String TEXT_3 = "Id"; 21 protected final String TEXT_4 = NL + " */" + NL + "package "; 22 protected final String TEXT_5 = ";" + NL; 23 protected final String TEXT_6 = NL + NL + "/**" + NL + " * <!-- begin-user-doc -->" + NL + " * The <b>Adapter Factory</b> for the model." + NL + " * It provides an adapter <code>createXXX</code> method for each class of the model." + NL + " * <!-- end-user-doc -->" + NL + " * @see "; 24 protected final String TEXT_7 = NL + " * @generated" + NL + " */" + NL + "public class "; 25 protected final String TEXT_8 = " extends AdapterFactoryImpl" + NL + "{"; 26 protected final String 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 TEXT_10 = " copyright = \""; 28 protected final String TEXT_11 = "\";"; 29 protected final String TEXT_12 = NL; 30 protected final String 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 TEXT_14 = " modelPackage;" + NL + "" + NL + "\t/**" + NL + "\t * Creates an instance of the adapter factory." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic "; 32 protected final String TEXT_15 = "()" + NL + "\t{" + NL + "\t\tif (modelPackage == null)" + NL + "\t\t{" + NL + "\t\t\tmodelPackage = "; 33 protected final String TEXT_16 = ".eINSTANCE;" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Returns whether this factory is applicable for the type of the object." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @return whether this factory is applicable for the type of the object." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic boolean isFactoryForType(Object object)" + NL + "\t{" + NL + "\t\tif (object == modelPackage)" + NL + "\t\t{" + NL + "\t\t\treturn true;" + NL + "\t\t}" + NL + "\t\tif (object instanceof EObject)" + NL + "\t\t{" + NL + "\t\t\treturn ((EObject)object).eClass().getEPackage() == modelPackage;" + NL + "\t\t}" + NL + "\t\treturn false;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * The switch the delegates to the <code>createXXX</code> methods." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected "; 34 protected final String TEXT_17 = " modelSwitch =" + NL + "\t\tnew "; 35 protected final String TEXT_18 = "()" + NL + "\t\t{"; 36 protected final String TEXT_19 = NL + "\t\t\tpublic Object case"; 37 protected final String TEXT_20 = "("; 38 protected final String TEXT_21 = " object)" + NL + "\t\t\t{" + NL + "\t\t\t\treturn create"; 39 protected final String TEXT_22 = "Adapter();" + NL + "\t\t\t}"; 40 protected final String TEXT_23 = NL + "\t\t\tpublic Object defaultCase(EObject object)" + NL + "\t\t\t{" + NL + "\t\t\t\treturn createEObjectAdapter();" + NL + "\t\t\t}" + NL + "\t\t};" + NL + "" + NL + "\t/**" + NL + "\t * Creates an adapter for the <code>target</code>." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @param target the object to adapt." + NL + "\t * @return the adapter for the <code>target</code>." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter createAdapter(Notifier target)" + NL + "\t{" + NL + "\t\treturn (Adapter)modelSwitch.doSwitch((EObject)target);" + NL + "\t}" + NL; 41 protected final String TEXT_24 = NL + NL + "\t/**" + NL + "\t * Creates a new adapter for an object of class '{@link "; 42 protected final String TEXT_25 = " <em>"; 43 protected final String TEXT_26 = "</em>}'." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * This default implementation returns null so that we can easily ignore cases;" + NL + "\t * it's useful to ignore a case when inheritance will catch all the cases anyway." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @return the new adapter." + NL + "\t * @see "; 44 protected final String TEXT_27 = NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter create"; 45 protected final String TEXT_28 = "Adapter()" + NL + "\t{" + NL + "\t\treturn null;" + NL + "\t}"; 46 protected final String TEXT_29 = NL + NL + "\t/**" + NL + "\t * Creates a new adapter for the default case." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * This default implementation returns null." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @return the new adapter." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter createEObjectAdapter()" + NL + "\t{" + NL + "\t\treturn null;" + NL + "\t}" + NL + "" + NL + "} //"; 47 protected final String TEXT_30 = NL; 48 49 public String generate(Object argument) 50 { 51 StringBuffer stringBuffer = new StringBuffer (); 52 53 67 68 GenPackage genPackage = (GenPackage)argument; GenModel genModel=genPackage.getGenModel(); 69 stringBuffer.append(TEXT_1); 70 stringBuffer.append(TEXT_2); 71 stringBuffer.append("$"); 72 stringBuffer.append(TEXT_3); 73 stringBuffer.append("$"); 74 stringBuffer.append(TEXT_4); 75 stringBuffer.append(genPackage.getUtilitiesPackageName()); 76 stringBuffer.append(TEXT_5); 77 genModel.addImport("org.eclipse.emf.common.notify.Adapter"); 78 genModel.addImport("org.eclipse.emf.common.notify.Notifier"); 79 genModel.addImport("org.eclipse.emf.common.notify.impl.AdapterFactoryImpl"); 80 genModel.addImport("org.eclipse.emf.ecore.EObject"); 81 if (!genPackage.hasJavaLangConflict() && !genPackage.getUtilitiesPackageName().equals(genPackage.getInterfacePackageName())) genModel.addImport(genPackage.getInterfacePackageName() + ".*"); 82 genModel.markImportLocation(stringBuffer); 83 stringBuffer.append(TEXT_6); 84 stringBuffer.append(genPackage.getQualifiedPackageInterfaceName()); 85 stringBuffer.append(TEXT_7); 86 stringBuffer.append(genPackage.getAdapterFactoryClassName()); 87 stringBuffer.append(TEXT_8); 88 if (genModel.getCopyrightText() != null) { 89 stringBuffer.append(TEXT_9); 90 stringBuffer.append(genModel.getImportedName("java.lang.String")); 91 stringBuffer.append(TEXT_10); 92 stringBuffer.append(genModel.getCopyrightText()); 93 stringBuffer.append(TEXT_11); 94 stringBuffer.append(genModel.getNonNLS()); 95 stringBuffer.append(TEXT_12); 96 } 97 stringBuffer.append(TEXT_13); 98 stringBuffer.append(genPackage.getImportedPackageInterfaceName()); 99 stringBuffer.append(TEXT_14); 100 stringBuffer.append(genPackage.getAdapterFactoryClassName()); 101 stringBuffer.append(TEXT_15); 102 stringBuffer.append(genPackage.getImportedPackageInterfaceName()); 103 stringBuffer.append(TEXT_16); 104 stringBuffer.append(genPackage.getSwitchClassName()); 105 stringBuffer.append(TEXT_17); 106 stringBuffer.append(genPackage.getSwitchClassName()); 107 stringBuffer.append(TEXT_18); 108 for (Iterator i=genPackage.getAllSwitchGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next(); 109 stringBuffer.append(TEXT_19); 110 stringBuffer.append(genPackage.getClassUniqueName(genClass)); 111 stringBuffer.append(TEXT_20); 112 stringBuffer.append(genClass.getImportedInterfaceName()); 113 stringBuffer.append(TEXT_21); 114 stringBuffer.append(genPackage.getClassUniqueName(genClass)); 115 stringBuffer.append(TEXT_22); 116 } 117 stringBuffer.append(TEXT_23); 118 for (Iterator i=genPackage.getAllSwitchGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next(); 119 stringBuffer.append(TEXT_24); 120 stringBuffer.append(genClass.getQualifiedInterfaceName()); 121 stringBuffer.append(TEXT_25); 122 stringBuffer.append(genClass.getFormattedName()); 123 stringBuffer.append(TEXT_26); 124 stringBuffer.append(genClass.getQualifiedInterfaceName()); 125 stringBuffer.append(TEXT_27); 126 stringBuffer.append(genPackage.getClassUniqueName(genClass)); 127 stringBuffer.append(TEXT_28); 128 } 129 stringBuffer.append(TEXT_29); 130 stringBuffer.append(genPackage.getAdapterFactoryClassName()); 131 genModel.emitSortedImports(); 132 stringBuffer.append(TEXT_30); 133 return stringBuffer.toString(); 134 } 135 } 136 | Popular Tags |