1 package org.eclipse.emf.codegen.ecore.templates.model.tests; 2 3 import org.eclipse.emf.codegen.ecore.genmodel.*; 4 5 public class PackageExample 6 { 7 protected static String nl; 8 public static synchronized PackageExample create(String lineSeparator) 9 { 10 nl = lineSeparator; 11 PackageExample result = new PackageExample(); 12 nl = null; 13 return result; 14 } 15 16 protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; 17 protected final String TEXT_1 = ""; 18 protected final String TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * "; 19 protected final String TEXT_3 = "Id"; 20 protected final String TEXT_4 = NL + " */" + NL + "package "; 21 protected final String TEXT_5 = ";" + NL; 22 protected final String TEXT_6 = NL + NL + "/**" + NL + " * <!-- begin-user-doc -->" + NL + " * A sample utility for the '<em><b>"; 23 protected final String TEXT_7 = "</b></em>' package." + NL + " * <!-- end-user-doc -->" + NL + " * @generated" + NL + " */" + NL + "public class "; 24 protected final String TEXT_8 = NL + "{"; 25 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 "; 26 protected final String TEXT_10 = " copyright = \""; 27 protected final String TEXT_11 = "\";"; 28 protected final String TEXT_12 = NL + "\t"; 29 protected final String TEXT_13 = NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * Load all the argument file paths or URIs as instances of the model." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @param args the file paths or URIs." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static void main(String[] args)" + NL + "\t{" + NL + "\t\t// Create a resource set to hold the resources." + NL + "\t\t//" + NL + "\t\t"; 30 protected final String TEXT_14 = " resourceSet = new "; 31 protected final String TEXT_15 = "();" + NL + "\t\t" + NL + "\t\t// Register the appropriate resource factory to handle all file extentions." + NL + "\t\t//" + NL + "\t\tresourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put" + NL + "\t\t\t(Resource.Factory.Registry.DEFAULT_EXTENSION, " + NL + "\t\t\t new "; 32 protected final String TEXT_16 = "());" + NL + "" + NL + "\t\t// Register the package to ensure it is available during loading." + NL + "\t\t//" + NL + "\t\tresourceSet.getPackageRegistry().put" + NL + "\t\t\t("; 33 protected final String TEXT_17 = ".eNS_URI, " + NL + "\t\t\t "; 34 protected final String TEXT_18 = ".eINSTANCE);" + NL + " " + NL + "\t\t// If there are no arguments, emit an appropriate usage message." + NL + "\t\t//" + NL + "\t\tif (args.length == 0)" + NL + "\t\t{"; 35 protected final String TEXT_19 = NL + "\t\t\tSystem.out.println(\"Enter a list of file paths or URIs that have content like this:\");" + NL + "\t\t\ttry" + NL + "\t\t\t{" + NL + "\t\t\t\t"; 36 protected final String TEXT_20 = " resource = resourceSet.createResource("; 37 protected final String TEXT_21 = ".createURI(\"http:///My."; 38 protected final String TEXT_22 = "\"));"; 39 protected final String TEXT_23 = NL + "\t\t\t\t"; 40 protected final String TEXT_24 = " documentRoot = "; 41 protected final String TEXT_25 = ".eINSTANCE.create"; 42 protected final String TEXT_26 = "();" + NL + "\t\t\t\t"; 43 protected final String TEXT_27 = " root = "; 44 protected final String TEXT_28 = ".eINSTANCE.create"; 45 protected final String TEXT_29 = "();" + NL + "\t\t\t\tdocumentRoot.set"; 46 protected final String TEXT_30 = "(root);" + NL + "\t\t\t\tresource.getContents().add(documentRoot);"; 47 protected final String TEXT_31 = NL + "\t\t\t\t"; 48 protected final String TEXT_32 = " root = "; 49 protected final String TEXT_33 = ".eINSTANCE.create"; 50 protected final String TEXT_34 = "();" + NL + "\t\t\t\tresource.getContents().add(root);"; 51 protected final String TEXT_35 = NL + "\t\t\t\tresource.save("; 52 protected final String TEXT_36 = ".out, null);" + NL + "\t\t\t}" + NL + "\t\t\tcatch ("; 53 protected final String TEXT_37 = " exception) " + NL + "\t\t\t{" + NL + "\t\t\t\texception.printStackTrace();" + NL + "\t\t\t}"; 54 protected final String TEXT_38 = NL + "\t\t\tSystem.out.println(\"Enter a list of file paths or URIs\");"; 55 protected final String TEXT_39 = NL + "\t\t}" + NL + "\t\telse" + NL + "\t\t{" + NL + "\t\t\t// Iterate over all the arguments." + NL + "\t\t\t//" + NL + "\t\t\tfor (int i = 0; i < args.length; ++i)" + NL + "\t\t\t{" + NL + "\t\t\t\t// Construct the URI for the instance file." + NL + "\t\t\t\t// The argument is treated as a file path only if it denotes an existing file." + NL + "\t\t\t\t// Otherwise, it's directly treated as a URL." + NL + "\t\t\t\t//" + NL + "\t\t\t\t"; 56 protected final String TEXT_40 = " file = new "; 57 protected final String TEXT_41 = "(args[0]);" + NL + "\t\t\t\t"; 58 protected final String TEXT_42 = " uri = file.isFile() ? "; 59 protected final String TEXT_43 = ".createFileURI(file.getAbsolutePath()): URI.createURI(args[0]);" + NL + "" + NL + "\t\t\t\ttry" + NL + "\t\t\t\t{" + NL + "\t\t\t\t\t// Demand load resource for this file." + NL + "\t\t\t\t\t//" + NL + "\t\t\t\t\t"; 60 protected final String TEXT_44 = " resource = resourceSet.getResource(uri, true);" + NL + "\t\t\t\t\tSystem.out.println(\"Loaded \" + uri);" + NL + "" + NL + "\t\t\t\t\t// Validate the contents of the loaded resource." + NL + "\t\t\t\t\t//" + NL + "\t\t\t\t\tfor ("; 61 protected final String TEXT_45 = " j = resource.getContents().iterator(); j.hasNext(); )" + NL + "\t\t\t\t\t{" + NL + "\t\t\t\t\t\t"; 62 protected final String TEXT_46 = " eObject = ("; 63 protected final String TEXT_47 = ")j.next();" + NL + "\t\t\t\t\t\t"; 64 protected final String TEXT_48 = " diagnostic = "; 65 protected final String TEXT_49 = ".INSTANCE.validate(eObject);" + NL + "\t\t\t\t\t\tif (diagnostic.getSeverity() != Diagnostic.OK)" + NL + "\t\t\t\t\t\t{" + NL + "\t\t\t\t\t\t\tprintDiagnostic(diagnostic, \"\");" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t}" + NL + "\t\t\t\tcatch ("; 66 protected final String TEXT_50 = " exception) " + NL + "\t\t\t\t{" + NL + "\t\t\t\t\tSystem.out.println(\"Problem loading \" + uri);" + NL + "\t\t\t\t\texception.printStackTrace();" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * Prints diagnostics with indentation." + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @param diagnostic the diagnostic to print." + NL + "\t * @param indent the indentation for printing." + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected static void printDiagnostic(Diagnostic diagnostic, String indent)" + NL + "\t{" + NL + "\t\tSystem.out.print(indent);" + NL + "\t\tSystem.out.println(diagnostic.getMessage());" + NL + "\t\tfor (Iterator i = diagnostic.getChildren().iterator(); i.hasNext(); )" + NL + "\t\t{" + NL + "\t\t\tprintDiagnostic((Diagnostic)i.next(), indent + \" \");" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "} //"; 67 protected final String TEXT_51 = NL; 68 69 public String generate(Object argument) 70 { 71 StringBuffer stringBuffer = new StringBuffer (); 72 73 87 88 GenPackage genPackage = (GenPackage)argument; GenModel genModel = genPackage.getGenModel(); 89 90 String _System = genModel.getImportedName("java.lang.System"); 91 String _String = genModel.getImportedName("java.lang.String"); 92 String _RuntimeException = genModel.getImportedName("java.lang.RuntimeException"); 93 String _File = genModel.getImportedName("java.io.File"); 94 String _Iterator = genModel.getImportedName("java.util.Iterator"); 95 String _Diagnostic = genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic"); 96 String _URI = genModel.getImportedName("org.eclipse.emf.common.util.URI"); 97 String _EObject = genModel.getImportedName("org.eclipse.emf.ecore.EObject"); 98 String _Diagnostician = genModel.getImportedName("org.eclipse.emf.ecore.util.Diagnostician"); 99 String _Resource = genModel.getImportedName("org.eclipse.emf.ecore.resource.Resource"); 100 String _ResourceSet = genModel.getImportedName("org.eclipse.emf.ecore.resource.ResourceSet"); 101 String _ResourceSetImpl = genModel.getImportedName("org.eclipse.emf.ecore.resource.impl.ResourceSetImpl"); 102 103 stringBuffer.append(TEXT_1); 104 stringBuffer.append(TEXT_2); 105 stringBuffer.append("$"); 106 stringBuffer.append(TEXT_3); 107 stringBuffer.append("$"); 108 stringBuffer.append(TEXT_4); 109 stringBuffer.append(genPackage.getTestsPackageName()); 110 stringBuffer.append(TEXT_5); 111 genModel.markImportLocation(stringBuffer); 112 stringBuffer.append(TEXT_6); 113 stringBuffer.append(genPackage.getPackageName()); 114 stringBuffer.append(TEXT_7); 115 stringBuffer.append(genPackage.getExampleClassName()); 116 stringBuffer.append(TEXT_8); 117 if (genModel.getCopyrightText() != null) { 118 stringBuffer.append(TEXT_9); 119 stringBuffer.append(_String); 120 stringBuffer.append(TEXT_10); 121 stringBuffer.append(genModel.getCopyrightText()); 122 stringBuffer.append(TEXT_11); 123 stringBuffer.append(genModel.getNonNLS()); 124 stringBuffer.append(TEXT_12); 125 } 126 stringBuffer.append(TEXT_13); 127 stringBuffer.append(_ResourceSet); 128 stringBuffer.append(TEXT_14); 129 stringBuffer.append(_ResourceSetImpl); 130 stringBuffer.append(TEXT_15); 131 stringBuffer.append(genPackage.getResource() == GenResourceKind.NONE_LITERAL ? genModel.getImportedName("org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl") : genPackage.getImportedResourceFactoryClassName()); 132 stringBuffer.append(TEXT_16); 133 stringBuffer.append(genPackage.getImportedPackageInterfaceName()); 134 stringBuffer.append(TEXT_17); 135 stringBuffer.append(genPackage.getImportedPackageInterfaceName()); 136 stringBuffer.append(TEXT_18); 137 if (genPackage.getRootClass() != null) { GenClass rootClass = genPackage.getRootClass(); 138 stringBuffer.append(TEXT_19); 139 stringBuffer.append(_Resource); 140 stringBuffer.append(TEXT_20); 141 stringBuffer.append(_URI); 142 stringBuffer.append(TEXT_21); 143 stringBuffer.append(genPackage.getPrefix().toLowerCase()); 144 stringBuffer.append(TEXT_22); 145 if (genPackage.getRootFeature() != null) { GenFeature rootFeature = rootFeature = genPackage.getRootFeature(); GenClass documentRoot = rootFeature.getGenClass(); 146 stringBuffer.append(TEXT_23); 147 stringBuffer.append(documentRoot.getImportedInterfaceName()); 148 stringBuffer.append(TEXT_24); 149 stringBuffer.append(genPackage.getImportedFactoryInterfaceName()); 150 stringBuffer.append(TEXT_25); 151 stringBuffer.append(documentRoot.getName()); 152 stringBuffer.append(TEXT_26); 153 stringBuffer.append(rootClass.getImportedInterfaceName()); 154 stringBuffer.append(TEXT_27); 155 stringBuffer.append(genPackage.getImportedFactoryInterfaceName()); 156 stringBuffer.append(TEXT_28); 157 stringBuffer.append(rootClass.getName()); 158 stringBuffer.append(TEXT_29); 159 stringBuffer.append(rootFeature.getCapName()); 160 stringBuffer.append(TEXT_30); 161 } else { 162 stringBuffer.append(TEXT_31); 163 stringBuffer.append(rootClass.getImportedInterfaceName()); 164 stringBuffer.append(TEXT_32); 165 stringBuffer.append(genPackage.getImportedFactoryInterfaceName()); 166 stringBuffer.append(TEXT_33); 167 stringBuffer.append(rootClass.getName()); 168 stringBuffer.append(TEXT_34); 169 } 170 stringBuffer.append(TEXT_35); 171 stringBuffer.append(_System); 172 stringBuffer.append(TEXT_36); 173 stringBuffer.append(genModel.getImportedName("java.io.IOException")); 174 stringBuffer.append(TEXT_37); 175 } else { 176 stringBuffer.append(TEXT_38); 177 } 178 stringBuffer.append(TEXT_39); 179 stringBuffer.append(_File); 180 stringBuffer.append(TEXT_40); 181 stringBuffer.append(_File); 182 stringBuffer.append(TEXT_41); 183 stringBuffer.append(_URI); 184 stringBuffer.append(TEXT_42); 185 stringBuffer.append(_URI); 186 stringBuffer.append(TEXT_43); 187 stringBuffer.append(_Resource); 188 stringBuffer.append(TEXT_44); 189 stringBuffer.append(_Iterator); 190 stringBuffer.append(TEXT_45); 191 stringBuffer.append(_EObject); 192 stringBuffer.append(TEXT_46); 193 stringBuffer.append(_EObject); 194 stringBuffer.append(TEXT_47); 195 stringBuffer.append(_Diagnostic); 196 stringBuffer.append(TEXT_48); 197 stringBuffer.append(_Diagnostician); 198 stringBuffer.append(TEXT_49); 199 stringBuffer.append(_RuntimeException); 200 stringBuffer.append(TEXT_50); 201 stringBuffer.append(genPackage.getExampleClassName()); 202 genModel.emitSortedImports(); 203 stringBuffer.append(TEXT_51); 204 return stringBuffer.toString(); 205 } 206 } 207 | Popular Tags |