コード例 #1
0
  public VirtualFile generate(VirtualFile basedir) throws DatabaseException {
    GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
    genModel.setRuntimeVersion(GenRuntimeVersion.EMF25);
    genModel.setComplianceLevel(GenJDKLevel.JDK60_LITERAL);
    genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
    genModel.setRootExtendsClass("org.bimserver.emf.IdEObjectImpl");
    genModel.setRootExtendsInterface("org.bimserver.emf.IdEObject");
    genModel.setSuppressContainment(true);
    genModel.setCodeFormatting(true);
    genModel.setCopyrightText(StringUtils.readFromFile(new File("copyright.txt")));
    genModel.setCanGenerate(true);
    genModel.setModelDirectory("test");
    genModel.setModelName("model name");
    genModel.setForceOverwrite(true);
    genModel.setSuppressNotification(false);
    genModel.setContainmentProxies(false);
    genModel.setBinaryCompatibleReflectiveMethods(false);
    genModel.setPublicConstructors(false);
    genModel.setMinimalReflectiveMethods(true); // More code, but faster
    genModel.setUpdateClasspath(false);

    genModel.initialize(schema.getEPackages());

    GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(
        GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
    Generator generator = new Generator();
    generator.setInput(genModel);
    generator.generate(
        genModel,
        GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE,
        new BasicMonitor.Printing(System.out));

    //		List<GenPackage> genPackages = createGenPackages(genModel, basedir);
    //		generatePackages(genModel, genPackages, basedir);

    return basedir;
  }
コード例 #2
0
 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();
 }