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;
  }
Example #2
0
  @Override
  public void migrate(Schema schema, DatabaseSession databaseSession) {
    EClass serializerPluginConfiguration =
        schema.createEClass(
            schema.getEPackage("store"),
            "MessagingSerializerPluginConfiguration",
            schema.getEClass("store", "PluginConfiguration"));
    EClass userSettings = schema.getEClass("store", "UserSettings");
    EReference serializerSettingsReference =
        schema.createEReference(
            serializerPluginConfiguration, "userSettings", userSettings, Multiplicity.SINGLE);
    EReference settingsSerializerReference =
        schema.createEReference(
            userSettings,
            "messagingSerializerPlugins",
            serializerPluginConfiguration,
            Multiplicity.MANY);

    settingsSerializerReference.setEOpposite(serializerSettingsReference);
    serializerSettingsReference.setEOpposite(settingsSerializerReference);

    EClass serverSettings = schema.getEClass("store", "ServerSettings");
    schema.createEAttribute(
        serverSettings, "allowCreateValidatedUser", EcorePackage.eINSTANCE.getEBoolean());

    EClass version = schema.getEClass("store", "Version");

    EClass serverInfo = schema.getEClass("store", "ServerInfo");
    EReference versionReference =
        schema.createEReference(serverInfo, "version", version, Multiplicity.SINGLE);
    versionReference.getEAnnotations().add(createEmbedsReferenceAnnotation());
  }
 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();
 }
Example #4
0
  @Override
  public void migrate(Schema schema, DatabaseSession databaseSession) {
    schema.loadEcore("ifc4.ecore", getClass().getResourceAsStream("IFC4.ecore"));
    EClass project = schema.getEClass("store", "Project");
    schema.createEAttribute(project, "schema", EcorePackage.eINSTANCE.getEString());
    EClass revisionSummaryType = schema.getEClass("store", "RevisionSummaryType");
    schema.createEAttribute(revisionSummaryType, "schema", EcorePackage.eINSTANCE.getEString());
    EClass projectSmall = schema.getEClass("store", "ProjectSmall");
    schema.createEAttribute(projectSmall, "schema", EcorePackage.eINSTANCE.getEString());

    schema.createEPackage("geometry");

    EClass geometryInfo = schema.createEClass("geometry", "GeometryInfo");
    EClass vector3f = schema.createEClass("geometry", "Vector3f");
    schema.createEAttribute(vector3f, "x", EcorePackage.eINSTANCE.getEFloat(), Multiplicity.SINGLE);
    schema.createEAttribute(vector3f, "y", EcorePackage.eINSTANCE.getEFloat(), Multiplicity.SINGLE);
    schema.createEAttribute(vector3f, "z", EcorePackage.eINSTANCE.getEFloat(), Multiplicity.SINGLE);
    EReference min =
        schema.createEReference(geometryInfo, "minBounds", vector3f, Multiplicity.SINGLE);
    min.getEAnnotations().add(createEmbedsReferenceAnnotation());
    min.getEAnnotations().add(createHiddenAnnotation());
    EReference max =
        schema.createEReference(geometryInfo, "maxBounds", vector3f, Multiplicity.SINGLE);
    max.getEAnnotations().add(createEmbedsReferenceAnnotation());
    max.getEAnnotations().add(createHiddenAnnotation());
    vector3f.getEAnnotations().add(createHiddenAnnotation());
    geometryInfo.getEAnnotations().add(createHiddenAnnotation());
    schema.createEAttribute(
        geometryInfo,
        "startVertex",
        EcorePackage.eINSTANCE.getEIntegerObject(),
        Multiplicity.SINGLE);
    schema.createEAttribute(
        geometryInfo,
        "startIndex",
        EcorePackage.eINSTANCE.getEIntegerObject(),
        Multiplicity.SINGLE);
    schema.createEAttribute(
        geometryInfo,
        "primitiveCount",
        EcorePackage.eINSTANCE.getEIntegerObject(),
        Multiplicity.SINGLE);

    EClass geometryData = schema.createEClass("geometry", "GeometryData");
    schema.createEAttribute(
        geometryData, "indices", EcorePackage.eINSTANCE.getEByteArray(), Multiplicity.SINGLE);
    schema.createEAttribute(
        geometryData, "vertices", EcorePackage.eINSTANCE.getEByteArray(), Multiplicity.SINGLE);
    schema.createEAttribute(
        geometryData, "normals", EcorePackage.eINSTANCE.getEByteArray(), Multiplicity.SINGLE);
    geometryData.getEAnnotations().add(createNoLazyLoadAnnotation());
    geometryData.getEAnnotations().add(createHiddenAnnotation());

    schema
        .createEReference(geometryInfo, "data", geometryData, Multiplicity.SINGLE)
        .getEAnnotations()
        .add(createNoLazyLoadAnnotation());

    EClass ifcProductIfc2x3tc1 = schema.getEClass("ifc2x3tc1", "IfcProduct");
    EClass ifcProductIfc4 = schema.getEClass("ifc4", "IfcProduct");
    schema
        .createEReference(ifcProductIfc2x3tc1, "geometry", geometryInfo, Multiplicity.SINGLE)
        .getEAnnotations()
        .add(createHiddenAnnotation());
    schema
        .createEReference(ifcProductIfc4, "geometry", geometryInfo, Multiplicity.SINGLE)
        .getEAnnotations()
        .add(createHiddenAnnotation());

    EClass geometryInstance = schema.createEClass("geometry", "GeometryInstance");
    schema.createEReference(
        geometryInstance,
        "data",
        schema.getEClass("geometry", "GeometryData"),
        Multiplicity.SINGLE);
    schema.createEAttribute(
        geometryInstance,
        "transformation",
        EcorePackage.eINSTANCE.getEByteArray(),
        Multiplicity.SINGLE);
    geometryInstance.getEAnnotations().add(createHiddenAnnotation());

    schema.createEReference(
        schema.getEClass("geometry", "GeometryInfo"),
        "instance",
        geometryInstance,
        Multiplicity.SINGLE);
    schema.createEAttribute(geometryData, "materials", EcorePackage.eINSTANCE.getEByteArray());
    schema.createEAttribute(
        geometryData, "materialIndices", EcorePackage.eINSTANCE.getEByteArray());
    schema.createEAttribute(
        geometryInfo,
        "transformation",
        EcorePackage.eINSTANCE.getEByteArray(),
        Multiplicity.SINGLE);
  }