public void generatePackages( GenModel genModel, List<GenPackage> genPackages, VirtualFile basedir) { for (GenPackage genPackage : genPackages) { genPackage.prepareCache(); genModel.setImportManager(new ImportManager("org.bimserver.models")); String packageClassPathImpl = MODEL_PACKAGE + genPackage.getPackageName() + ".impl."; packageClassPathImpl = packageClassPathImpl.replace(".", File.separator) + genPackage.getPackageClassName() + ".java"; VirtualFile packageVirtualFileImpl = basedir.createFile(packageClassPathImpl); packageVirtualFileImpl.setStringContent( new PackageClass().generate(new Object[] {genPackage, false, true})); genModel.setImportManager(new ImportManager("org.bimserver.models")); String packageClassPathInterface = MODEL_PACKAGE + genPackage.getPackageName() + "."; packageClassPathInterface = packageClassPathInterface.replace(".", File.separator) + genPackage.getPackageInterfaceName() + ".java"; VirtualFile packageVirtualFileInterface = basedir.createFile(packageClassPathInterface); packageVirtualFileInterface.setStringContent( new PackageClass().generate(new Object[] {genPackage, true, false})); genModel.setImportManager(new ImportManager("org.bimserver.models")); String factoryClassPathImpl = MODEL_PACKAGE + genPackage.getPackageName() + ".impl."; factoryClassPathImpl = factoryClassPathImpl.replace(".", File.separator) + genPackage.getFactoryClassName() + ".java"; VirtualFile factoryVirtualFileImpl = basedir.createFile(factoryClassPathImpl); factoryVirtualFileImpl.setStringContent( new FactoryClass().generate(new Object[] {genPackage, false, true})); genModel.setImportManager(new ImportManager("org.bimserver.models")); String factoryClassPathInterface = MODEL_PACKAGE + genPackage.getPackageName() + "."; factoryClassPathInterface = factoryClassPathInterface.replace(".", File.separator) + genPackage.getFactoryInterfaceName() + ".java"; VirtualFile factoryVirtualFileInterface = basedir.createFile(factoryClassPathInterface); factoryVirtualFileInterface.setStringContent( new FactoryClass().generate(new Object[] {genPackage, true, false})); genModel.setImportManager(new ImportManager("org.bimserver.models")); String adapterFactoryClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util."; adapterFactoryClassPath = adapterFactoryClassPath.replace(".", File.separator) + genPackage.getAdapterFactoryClassName() + ".java"; VirtualFile adapterFactoryVirtualFile = basedir.createFile(adapterFactoryClassPath); adapterFactoryVirtualFile.setStringContent(new AdapterFactoryClass().generate(genPackage)); genModel.setImportManager(new ImportManager("org.bimserver.models")); String switchClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util."; switchClassPath = switchClassPath.replace(".", File.separator) + genPackage.getSwitchClassName() + ".java"; VirtualFile switchClassVirtualFile = basedir.createFile(switchClassPath); switchClassVirtualFile.setStringContent(new SwitchClass().generate(genPackage)); genModel.setImportManager(new ImportManager("org.bimserver.models")); String xmlClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util."; xmlClassPath = xmlClassPath.replace(".", File.separator) + genPackage.getXMLProcessorClassName() + ".java"; VirtualFile xmlClassVirtualFile = basedir.createFile(xmlClassPath); xmlClassVirtualFile.setStringContent(new XMLProcessorClass().generate(genPackage)); genModel.setImportManager(new ImportManager("org.bimserver.models")); String resourceFactoryClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util."; resourceFactoryClassPath = resourceFactoryClassPath.replace(".", File.separator) + genPackage.getResourceFactoryClassName() + ".java"; VirtualFile resourceFactoryClassVirtualFile = basedir.createFile(resourceFactoryClassPath); resourceFactoryClassVirtualFile.setStringContent( new ResourceFactoryClass().generate(genPackage)); genModel.setImportManager(new ImportManager("org.bimserver.models")); String resourceClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util."; resourceClassPath = resourceClassPath.replace(".", File.separator) + genPackage.getResourceClassName() + ".java"; VirtualFile resourceClassVirtualFile = basedir.createFile(resourceClassPath); resourceClassVirtualFile.setStringContent(new ResourceClass().generate(genPackage)); // String validatorClassPath = "com.logiclabs.streamdb.models." + // genPackage.getPackageName() + ".util."; // validatorClassPath = validatorClassPath.replace(".", // File.separator) + genPackage.getValidatorClassName() + ".java"; // VirtualFile validatorClassVirtualFile = // basedir.createFile(validatorClassPath); // validatorClassVirtualFile.setStringContent(new // ValidatorClass().generate(genPackage)); for (GenClass genClass : genPackage.getGenClasses()) { genModel.setImportManager(new ImportManager("org.bimserver.models")); String implFileName = MODEL_PACKAGE + genPackage.getPackageName() + ".impl."; implFileName = implFileName.replace(".", File.separator) + genClass.getName() + "Impl.java"; VirtualFile implVirtualFile = basedir.createFile(implFileName); implVirtualFile.setStringContent( new org.eclipse.emf.codegen.ecore.templates.model.Class() .generate(new Object[] {genClass, false, true})); genModel.setImportManager(new ImportManager("org.bimserver.models")); String interfaceFileName = MODEL_PACKAGE + genPackage.getPackageName() + "."; interfaceFileName = interfaceFileName.replace(".", File.separator) + genClass.getName() + ".java"; VirtualFile interfaceVirtualFile = basedir.createFile(interfaceFileName); interfaceVirtualFile.setStringContent( new org.eclipse.emf.codegen.ecore.templates.model.Class() .generate(new Object[] {genClass, true, false})); } for (GenEnum genEnum : genPackage.getGenEnums()) { genModel.setImportManager(new ImportManager("org.bimserver.models")); String enumFileName = MODEL_PACKAGE + genPackage.getPackageName() + "."; enumFileName = enumFileName.replace(".", File.separator) + genEnum.getName() + ".java"; VirtualFile enumVirtualFile = basedir.createFile(enumFileName); enumVirtualFile.setStringContent(new EnumClass().generate(genEnum)); } } }
public List<GenPackage> createGenPackages(GenModel genModel, VirtualFile basedir) throws DatabaseException { ResourceSetImpl resourceSet = new ResourceSetImpl(); resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put("ecore", new EcoreResourceFactoryImpl()); Map<VirtualFile, Resource> resources = new HashMap<VirtualFile, Resource>(); genModel.initialize(schema.getEPackages()); for (GenPackage genPackage : genModel.getGenPackages()) { genPackage.setBasePackage("org.bimserver.models"); } for (EPackage ePackage : schema.getEPackages()) { // GenPackage genPackage = genModel.get // result.add(genPackage); // genModel.getGenPackages().add(genPackage); // genPackage.initialize(ePackage); // for (EClassifier eClassifier : ePackage.getEClassifiers()) { // if (eClassifier instanceof EClass) { // EClass eClass = (EClass) eClassifier; // GenClass genClass = GenModelFactory.eINSTANCE.createGenClass(); // genClass.initialize(eClass); // genPackage.getGenClasses().add(genClass); // for (EStructuralFeature eStructuralFeature : // eClass.getEStructuralFeatures()) { // GenFeature genFeature = // GenModelFactory.eINSTANCE.createGenFeature(); // genFeature.initialize(eStructuralFeature); // genFeature.setEcoreFeature(eStructuralFeature); // genClass.getGenFeatures().add(genFeature); // } // } else if (eClassifier instanceof EEnum) { // EEnum eEnum = (EEnum) eClassifier; // GenEnum genEnum = GenModelFactory.eINSTANCE.createGenEnum(); // genEnum.setEcoreEnum(eEnum); // genPackage.getGenEnums().add(genEnum); // for (EEnumLiteral eEnumLiteral : eEnum.getELiterals()) { // GenEnumLiteral genEnumLiteral = // GenModelFactory.eINSTANCE.createGenEnumLiteral(); // genEnumLiteral.setEcoreEnumLiteral(eEnumLiteral); // genEnum.getGenEnumLiterals().add(genEnumLiteral); // } // } else if (eClassifier instanceof EDataType) { // GenDataType genDataType = // GenModelFactory.eINSTANCE.createGenDataType(); // genDataType.setEcoreDataType((EDataType) eClassifier); // genPackage.getGenDataTypes().add(genDataType); // } // } Resource resource = resourceSet.createResource(URI.createURI(ePackage.getName() + ".ecore")); resource.getContents().add(ePackage); VirtualFile ecoreFile = basedir.createFile( MODEL_PACKAGE.replace(".", "/") + ePackage.getName() + "/impl/" + ePackage.getName() + ".ecore"); resources.put(ecoreFile, resource); } for (VirtualFile virtualFile : resources.keySet()) { try { Resource resource = resources.get(virtualFile); OutputStream openOutputStream = virtualFile.openOutputStream(); resource.save(openOutputStream, null); openOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return genModel.getGenPackages(); }