Search in sources :

Example 1 with MetaDataManager

use of org.bimserver.emf.MetaDataManager in project BIMserver by opensourceBIM.

the class SConverterGenerator method generate.

public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    /**
     ****************************************************************************
     * Copyright (C) 2009-2017  BIMserver.org
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU Affero General Public License for more details.
     *
     * You should have received a copy of the GNU Affero General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     ****************************************************************************
     */
    stringBuffer.append(TEXT_2);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(Licenser.getCommentedLicenseText(new File("license.txt")));
    stringBuffer.append(TEXT_4);
    try {
        Object[] argumentsArray = (Object[]) argument;
        MetaDataManager metaDataManager = (MetaDataManager) argumentsArray[0];
        @SuppressWarnings("unchecked") Set<EPackage> ePackages = (Set<EPackage>) argumentsArray[1];
        for (EPackage ePackage : ePackages) {
            for (EClassifier eClassifier : ePackage.getEClassifiers()) {
                if (eClassifier instanceof EClass) {
                    EClass eClass = (EClass) eClassifier;
                    stringBuffer.append(TEXT_5);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_6);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_7);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_8);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_9);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_10);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_11);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_12);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_13);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_14);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_15);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_16);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_17);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_18);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_19);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_20);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_21);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_22);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_23);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_24);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_25);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_26);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_27);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_28);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_29);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_30);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_31);
                    if (metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass) != null && !metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass).isEmpty()) {
                        for (EClass subClass : metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass)) {
                            stringBuffer.append(TEXT_32);
                            stringBuffer.append(metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass).iterator().next() == subClass ? "" : "else ");
                            stringBuffer.append(TEXT_33);
                            stringBuffer.append(subClass.getName());
                            stringBuffer.append(TEXT_34);
                            stringBuffer.append(subClass.getName());
                            stringBuffer.append(TEXT_35);
                        }
                    }
                    stringBuffer.append(TEXT_36);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_37);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_38);
                    if (eClass.getEAnnotation("nodatabase") == null) {
                        stringBuffer.append(TEXT_39);
                    }
                    for (EAttribute eAttribute : eClass.getEAllAttributes()) {
                        if (eAttribute.getEType() instanceof EEnum) {
                            stringBuffer.append(TEXT_40);
                            stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                            stringBuffer.append(TEXT_41);
                            stringBuffer.append(eAttribute.getEType().getName());
                            stringBuffer.append(TEXT_42);
                            stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                            stringBuffer.append(TEXT_43);
                        } else {
                            if (eAttribute.isMany()) {
                                stringBuffer.append(TEXT_44);
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_45);
                                stringBuffer.append(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get");
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_46);
                            } else {
                                stringBuffer.append(TEXT_47);
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_48);
                                stringBuffer.append(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get");
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_49);
                            }
                        }
                    }
                    for (EReference eReference : eClass.getEAllReferences()) {
                        if (eReference.isMany()) {
                            if (eReference.getEAnnotation("embedsreference") != null) {
                                stringBuffer.append(TEXT_50);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_51);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_52);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_53);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_54);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_55);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_56);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_57);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_58);
                            } else {
                                stringBuffer.append(TEXT_59);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_60);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_61);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_62);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_63);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_64);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_65);
                            }
                        } else {
                            if (eReference.getEAnnotation("embedsreference") != null) {
                                stringBuffer.append(TEXT_66);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_67);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_68);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_69);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_70);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_71);
                            } else {
                                stringBuffer.append(TEXT_72);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_73);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_74);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_75);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_76);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_77);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_78);
                            }
                        }
                    }
                    stringBuffer.append(TEXT_79);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_80);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_81);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_82);
                    stringBuffer.append(StringUtils.firstUpperCase(eClass.getEPackage().getName()));
                    stringBuffer.append(TEXT_83);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_84);
                    if (eClass.getEAnnotation("nodatabase") == null) {
                        stringBuffer.append(TEXT_85);
                    }
                    stringBuffer.append(TEXT_86);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_87);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_88);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_89);
                    stringBuffer.append(StringUtils.firstUpperCase(eClass.getEPackage().getName()));
                    stringBuffer.append(TEXT_90);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_91);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_92);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_93);
                    stringBuffer.append(eClass.getName());
                    stringBuffer.append(TEXT_94);
                    if (!metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass).isEmpty()) {
                        for (EClass subClass : metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass)) {
                            stringBuffer.append(TEXT_95);
                            stringBuffer.append(metaDataManager.getPackageMetaData(ePackage.getName()).getDirectSubClasses(eClass).iterator().next() == subClass ? "" : "else ");
                            stringBuffer.append(TEXT_96);
                            stringBuffer.append(subClass.getName());
                            stringBuffer.append(TEXT_97);
                            stringBuffer.append(subClass.getName());
                            stringBuffer.append(TEXT_98);
                        }
                    }
                    for (EAttribute eAttribute : eClass.getEAllAttributes()) {
                        if (eAttribute.getEType() instanceof EEnum) {
                            stringBuffer.append(TEXT_99);
                            stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                            stringBuffer.append(TEXT_100);
                            stringBuffer.append(eAttribute.getEType().getName());
                            stringBuffer.append(TEXT_101);
                            stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                            stringBuffer.append(TEXT_102);
                        } else {
                            if (eAttribute.isMany()) {
                                stringBuffer.append(TEXT_103);
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_104);
                                stringBuffer.append(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get");
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_105);
                            } else {
                                stringBuffer.append(TEXT_106);
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_107);
                                stringBuffer.append(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get");
                                stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName()));
                                stringBuffer.append(TEXT_108);
                            }
                        }
                    }
                    for (EReference eReference : eClass.getEAllReferences()) {
                        if (eReference.isMany()) {
                            if (eReference.getEAnnotation("embedsreference") != null) {
                                stringBuffer.append(TEXT_109);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_110);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_111);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_112);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_113);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_114);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_115);
                            } else {
                                stringBuffer.append(TEXT_116);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_117);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_118);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_119);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_120);
                                stringBuffer.append(eReference.getName());
                                stringBuffer.append(TEXT_121);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_122);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getEType().getEPackage().getName()));
                                stringBuffer.append(TEXT_123);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_124);
                            }
                        } else {
                            if (eReference.getEAnnotation("embedsreference") != null) {
                                stringBuffer.append(TEXT_125);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_126);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_127);
                            } else {
                                stringBuffer.append(TEXT_128);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_129);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_130);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getEType().getEPackage().getName()));
                                stringBuffer.append(TEXT_131);
                                stringBuffer.append(eReference.getEType().getName());
                                stringBuffer.append(TEXT_132);
                                stringBuffer.append(StringUtils.firstUpperCase(eReference.getName()));
                                stringBuffer.append(TEXT_133);
                            }
                        }
                    }
                    stringBuffer.append(TEXT_134);
                } else if (eClassifier instanceof EEnum) {
                    EEnum eEnum = (EEnum) eClassifier;
                    stringBuffer.append(TEXT_135);
                    stringBuffer.append(eEnum.getName());
                    stringBuffer.append(TEXT_136);
                    stringBuffer.append(eEnum.getName());
                    stringBuffer.append(TEXT_137);
                    stringBuffer.append(eEnum.getName());
                    stringBuffer.append(TEXT_138);
                    stringBuffer.append(eEnum.getName());
                    stringBuffer.append(TEXT_139);
                    stringBuffer.append(eEnum.getName());
                    stringBuffer.append(TEXT_140);
                    stringBuffer.append(eEnum.getName());
                    stringBuffer.append(TEXT_141);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    stringBuffer.append(TEXT_142);
    return stringBuffer.toString();
}
Also used : Set(java.util.Set) MetaDataManager(org.bimserver.emf.MetaDataManager) File(java.io.File)

Example 2 with MetaDataManager

use of org.bimserver.emf.MetaDataManager in project BIMserver by opensourceBIM.

the class ServiceInterfaceObjectGenerator method generate.

public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    /**
     ****************************************************************************
     * Copyright (C) 2009-2017  BIMserver.org
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU Affero General Public License for more details.
     *
     * You should have received a copy of the GNU Affero General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     ****************************************************************************
     */
    stringBuffer.append(TEXT_2);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(Licenser.getCommentedLicenseText(new File("license.txt")));
    stringBuffer.append(TEXT_4);
    Object[] arguments = (Object[]) argument;
    EClassifier eClassifier = (EClassifier) arguments[0];
    ImportManager importManager = (ImportManager) arguments[1];
    MetaDataManager metaDataManager = (MetaDataManager) arguments[2];
    importManager.mark(stringBuffer);
    boolean hasLists = false;
    if (eClassifier instanceof EClass) {
        EClass eClass = (EClass) eClassifier;
        for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
            if (eStructuralFeature.isMany()) {
                hasLists = true;
                break;
            }
        }
        importManager.getImport("javax.xml.bind.annotation.XmlRootElement");
        importManager.getImport("org.bimserver.shared.meta.*");
        stringBuffer.append(TEXT_5);
        importManager.getImport("javax.xml.bind.annotation.XmlTransient");
        if (metaDataManager.getPackageMetaData(eClassifier.getEPackage().getName()).getDirectSubClasses(eClass) != null && !metaDataManager.getPackageMetaData(eClassifier.getEPackage().getName()).getDirectSubClasses(eClass).isEmpty()) {
            importManager.getImport("javax.xml.bind.annotation.XmlSeeAlso");
            stringBuffer.append(TEXT_6);
            java.util.Set<EClass> subClasses = metaDataManager.getPackageMetaData(eClassifier.getEPackage().getName()).getDirectSubClasses(eClass);
            int i = 0;
            for (EClass subClass : subClasses) {
                stringBuffer.append(TEXT_7);
                stringBuffer.append(subClass.getName());
                stringBuffer.append(TEXT_8);
                if (i != subClasses.size() - 1) {
                    stringBuffer.append(TEXT_9);
                }
                i++;
            }
            stringBuffer.append(TEXT_10);
        }
        stringBuffer.append(TEXT_11);
        stringBuffer.append(eClass.getName());
        if (!eClass.getESuperTypes().isEmpty()) {
            stringBuffer.append(TEXT_12);
            for (EClass eSuperClass : eClass.getESuperTypes()) {
                stringBuffer.append(TEXT_13);
                stringBuffer.append(eSuperClass.getName());
            }
        }
        stringBuffer.append(TEXT_14);
        stringBuffer.append(eClass.getEAnnotation("nodatabase") != null ? "SBase" : "SDataBase");
        stringBuffer.append(TEXT_15);
        if (eClass.getEAnnotation("nodatabase") == null) {
            stringBuffer.append(TEXT_16);
        }
        stringBuffer.append(TEXT_17);
        for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
            if (eStructuralFeature.getEAnnotation("notinserviceinterface") == null) {
                if (eStructuralFeature instanceof EAttribute) {
                    EAttribute eAttribute = (EAttribute) eStructuralFeature;
                    if (eAttribute.getEType() instanceof EEnum) {
                        stringBuffer.append(TEXT_18);
                        stringBuffer.append(eAttribute.getEType().getName());
                        stringBuffer.append(TEXT_19);
                        stringBuffer.append(eAttribute.getName());
                        stringBuffer.append(TEXT_20);
                    } else {
                        if (eAttribute.isMany()) {
                            importManager.getImport("java.util.List");
                            importManager.getImport("java.util.ArrayList");
                            stringBuffer.append(TEXT_21);
                            stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                            stringBuffer.append(TEXT_22);
                            stringBuffer.append(eAttribute.getName());
                            stringBuffer.append(TEXT_23);
                            stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                            stringBuffer.append(TEXT_24);
                        } else {
                            if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEByteArray() && eAttribute.getEAnnotation("file") != null) {
                                importManager.getImport("javax.activation.DataHandler");
                                stringBuffer.append(TEXT_25);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_26);
                            } else {
                                stringBuffer.append(TEXT_27);
                                stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                                stringBuffer.append(TEXT_28);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_29);
                            }
                        }
                    }
                } else if (eStructuralFeature instanceof EReference) {
                    EReference eReference = (EReference) eStructuralFeature;
                    if (eReference.isMany()) {
                        importManager.getImport("java.util.List");
                        importManager.getImport("java.util.ArrayList");
                        if (eReference.getEAnnotation("embedsreference") != null) {
                            stringBuffer.append(TEXT_30);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_31);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_32);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_33);
                        } else {
                            stringBuffer.append(TEXT_34);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_35);
                        }
                    } else {
                        if (eReference.getEAnnotation("embedsreference") != null) {
                            stringBuffer.append(TEXT_36);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_37);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_38);
                        } else {
                            stringBuffer.append(TEXT_39);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_40);
                        }
                    }
                }
            }
        }
        if (eClass.getEAnnotation("nodatabase") == null) {
            stringBuffer.append(TEXT_41);
        }
        stringBuffer.append(TEXT_42);
        stringBuffer.append(eClass.getName());
        stringBuffer.append(TEXT_43);
        for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
            stringBuffer.append(TEXT_44);
            stringBuffer.append(eStructuralFeature.getName());
            stringBuffer.append((eStructuralFeature instanceof EReference && !eStructuralFeature.isMany() && eStructuralFeature.getEAnnotation("embedsreference") == null) ? "Id" : "");
            stringBuffer.append(TEXT_45);
            stringBuffer.append(eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get");
            stringBuffer.append(StringUtils.firstUpperCase(eStructuralFeature.getName()));
            stringBuffer.append((eStructuralFeature instanceof EReference && !eStructuralFeature.isMany() && eStructuralFeature.getEAnnotation("embedsreference") == null) ? "Id" : "");
            stringBuffer.append(TEXT_46);
        }
        if (eClass.getEAnnotation("nodatabase") == null) {
            stringBuffer.append(TEXT_47);
        }
        stringBuffer.append(TEXT_48);
        if (hasLists) {
            importManager.getImport("java.util.List");
            stringBuffer.append(TEXT_49);
        }
        stringBuffer.append(TEXT_50);
        for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
            if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDate()) {
                importManager.getImport("java.util.Date");
            } else if (eStructuralFeature.getEType().getName().equals("DataHandler")) {
                importManager.getImport("javax.activation.DataHandler");
            }
            boolean useId = (eStructuralFeature instanceof EReference && !eStructuralFeature.isMany() && eStructuralFeature.getEAnnotation("embedsreference") == null);
            stringBuffer.append(TEXT_51);
            stringBuffer.append(eStructuralFeature.getName());
            stringBuffer.append((eStructuralFeature instanceof EReference && !eStructuralFeature.isMany() && eStructuralFeature.getEAnnotation("embedsreference") == null) ? "Id" : "");
            stringBuffer.append(TEXT_52);
            stringBuffer.append(StringUtils.firstUpperCase(eStructuralFeature.getName()));
            stringBuffer.append(useId ? "Id" : "");
            stringBuffer.append(TEXT_53);
            stringBuffer.append(GenerateUtils.getType(eStructuralFeature));
            stringBuffer.append(TEXT_54);
        }
        if (eClass.getEAnnotation("nodatabase") == null) {
            stringBuffer.append(TEXT_55);
        }
        stringBuffer.append(TEXT_56);
        for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
            if (eStructuralFeature.getEAnnotation("notinserviceinterface") == null) {
                if (eStructuralFeature instanceof EAttribute) {
                    EAttribute eAttribute = (EAttribute) eStructuralFeature;
                    if (eAttribute.getEType() instanceof EEnum) {
                        stringBuffer.append(TEXT_57);
                        stringBuffer.append(eAttribute.getEType().getName());
                        stringBuffer.append(TEXT_58);
                        stringBuffer.append(GenerateUtils.makeGetter(eAttribute));
                        stringBuffer.append(TEXT_59);
                        stringBuffer.append(eAttribute.getName());
                        stringBuffer.append(TEXT_60);
                        stringBuffer.append(GenerateUtils.makeSetter(eAttribute));
                        stringBuffer.append(TEXT_61);
                        stringBuffer.append(eAttribute.getEType().getName());
                        stringBuffer.append(TEXT_62);
                        stringBuffer.append(eAttribute.getName());
                        stringBuffer.append(TEXT_63);
                        stringBuffer.append(eAttribute.getName());
                        stringBuffer.append(TEXT_64);
                        stringBuffer.append(eAttribute.getName());
                        stringBuffer.append(TEXT_65);
                    } else {
                        if (eAttribute.isMany()) {
                            stringBuffer.append(TEXT_66);
                            stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                            stringBuffer.append(TEXT_67);
                            stringBuffer.append(GenerateUtils.makeGetter(eAttribute));
                            stringBuffer.append(TEXT_68);
                            stringBuffer.append(eAttribute.getName());
                            stringBuffer.append(TEXT_69);
                            stringBuffer.append(GenerateUtils.makeSetter(eAttribute));
                            stringBuffer.append(TEXT_70);
                            stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                            stringBuffer.append(TEXT_71);
                            stringBuffer.append(eAttribute.getName());
                            stringBuffer.append(TEXT_72);
                            stringBuffer.append(eAttribute.getName());
                            stringBuffer.append(TEXT_73);
                            stringBuffer.append(eAttribute.getName());
                            stringBuffer.append(TEXT_74);
                        } else {
                            if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEByteArray() && eAttribute.getEAnnotation("file") != null) {
                                stringBuffer.append(TEXT_75);
                                stringBuffer.append(GenerateUtils.makeGetter(eAttribute));
                                stringBuffer.append(TEXT_76);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_77);
                                stringBuffer.append(GenerateUtils.makeSetter(eAttribute));
                                stringBuffer.append(TEXT_78);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_79);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_80);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_81);
                            } else {
                                stringBuffer.append(TEXT_82);
                                stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                                stringBuffer.append(TEXT_83);
                                stringBuffer.append(GenerateUtils.makeGetter(eAttribute));
                                stringBuffer.append(TEXT_84);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_85);
                                stringBuffer.append(GenerateUtils.makeSetter(eAttribute));
                                stringBuffer.append(TEXT_86);
                                stringBuffer.append(eAttribute.getEType().getInstanceClassName());
                                stringBuffer.append(TEXT_87);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_88);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_89);
                                stringBuffer.append(eAttribute.getName());
                                stringBuffer.append(TEXT_90);
                            }
                        }
                    }
                } else if (eStructuralFeature instanceof EReference) {
                    EReference eReference = (EReference) eStructuralFeature;
                    if (eReference.isMany()) {
                        if (eReference.getEAnnotation("embedsreference") != null) {
                            stringBuffer.append(TEXT_91);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_92);
                            stringBuffer.append(GenerateUtils.makeGetter(eReference));
                            stringBuffer.append(TEXT_93);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_94);
                            stringBuffer.append(GenerateUtils.makeSetter(eReference));
                            stringBuffer.append(TEXT_95);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_96);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_97);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_98);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_99);
                        } else {
                            stringBuffer.append(TEXT_100);
                            stringBuffer.append(GenerateUtils.makeGetter(eReference));
                            stringBuffer.append(TEXT_101);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_102);
                            stringBuffer.append(GenerateUtils.makeSetter(eReference));
                            stringBuffer.append(TEXT_103);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_104);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_105);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_106);
                        }
                    } else {
                        if (eReference.getEAnnotation("embedsreference") != null) {
                            stringBuffer.append(TEXT_107);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_108);
                            stringBuffer.append(GenerateUtils.makeGetter(eReference));
                            stringBuffer.append(TEXT_109);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_110);
                            stringBuffer.append(GenerateUtils.makeSetter(eReference));
                            stringBuffer.append(TEXT_111);
                            stringBuffer.append(eReference.getEType().getName());
                            stringBuffer.append(TEXT_112);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_113);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_114);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_115);
                        } else {
                            stringBuffer.append(TEXT_116);
                            stringBuffer.append(GenerateUtils.makeGetter(eReference));
                            stringBuffer.append(TEXT_117);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_118);
                            stringBuffer.append(GenerateUtils.makeSetter(eReference));
                            stringBuffer.append(TEXT_119);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_120);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_121);
                            stringBuffer.append(eReference.getName());
                            stringBuffer.append(TEXT_122);
                        }
                    }
                }
            }
        }
        if (eClass.getEAnnotation("nodatabase") == null) {
            stringBuffer.append(TEXT_123);
            stringBuffer.append(eClass.getName());
            stringBuffer.append(TEXT_124);
            stringBuffer.append(eClass.getName());
            stringBuffer.append(TEXT_125);
        }
    } else if (eClassifier instanceof EEnum) {
        EEnum eEnum = (EEnum) eClassifier;
        stringBuffer.append(TEXT_126);
        stringBuffer.append(eEnum.getName());
        stringBuffer.append(TEXT_127);
        for (EEnumLiteral eEnumLiteral : eEnum.getELiterals()) {
            stringBuffer.append(TEXT_128);
            stringBuffer.append(eEnumLiteral.getName());
            stringBuffer.append(TEXT_129);
            stringBuffer.append(eEnumLiteral.getValue());
            stringBuffer.append(TEXT_130);
            stringBuffer.append(eEnum.getELiterals().get(eEnum.getELiterals().size() - 1) == eEnumLiteral ? ";" : ",");
        }
        stringBuffer.append(TEXT_131);
        stringBuffer.append(eEnum.getName());
        stringBuffer.append(TEXT_132);
    }
    importManager.writeImports(stringBuffer);
    stringBuffer.append(TEXT_133);
    return stringBuffer.toString();
}
Also used : MetaDataManager(org.bimserver.emf.MetaDataManager) File(java.io.File)

Example 3 with MetaDataManager

use of org.bimserver.emf.MetaDataManager in project BIMserver by opensourceBIM.

the class TestManyRevisions method start.

private void start(String[] args) {
    try {
        Path home = Paths.get("home");
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
        pluginManager.setMetaDataManager(metaDataManager);
        try (BimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, "http://localhost:8080")) {
            BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
            try {
                SProject project = client.getServiceInterface().addProject("lots2", "ifc2x3tc1");
                Path[] files = new Path[] { Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc"), Paths.get("../TestData/data/AC11-FZK-Haus-IFC - Alt.ifc") };
                SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
                int fn = 0;
                for (int i = 0; i < 20; i++) {
                    System.out.println(i + ": " + files[fn].getFileName().toString());
                    client.checkin(project.getOid(), "comment" + i, deserializer.getOid(), false, Flow.SYNC, files[fn]);
                    fn = 1 - fn;
                }
            } catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) MetaDataManager(org.bimserver.emf.MetaDataManager) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginManager(org.bimserver.plugins.PluginManager) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException)

Example 4 with MetaDataManager

use of org.bimserver.emf.MetaDataManager in project BIMserver by opensourceBIM.

the class CodeMigrator method start.

private void start() {
    LOGGER.info("Starting code migrator...");
    Migrator migrator = new Migrator(null);
    int latestVersion = migrator.getLatestVersion();
    LOGGER.info("Migrating to version " + latestVersion);
    Schema schema = migrator.migrateSchemaTo(latestVersion);
    schema.writeToEcore(new File("models/models.ecore"));
    LOGGER.info("Model migrated to version " + latestVersion);
    LOGGER.info("Generating ServiceInterface objects...");
    Set<EPackage> ePackages = new LinkedHashSet<EPackage>();
    Path home = Paths.get("cmhome");
    if (!Files.exists(home)) {
        try {
            Files.createDirectories(home);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Path tmp = home.resolve("tmp");
    if (!Files.exists(tmp)) {
        try {
            Files.createDirectories(tmp);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    MetaDataManager metaDataManager = new MetaDataManager(tmp);
    metaDataManager.init();
    DataObjectGeneratorWrapper serviceGenerator = new DataObjectGeneratorWrapper(metaDataManager);
    for (EPackage ePackage : schema.getEPackages()) {
        if (!ePackage.getName().equals("ifc2x3tc1") && !ePackage.getName().equals("ifc4")) {
            ePackages.add(ePackage);
        }
    }
    serviceGenerator.generateDataObjects(ePackages);
    LOGGER.info("ServiceInterface objects successfully generated");
    SConverterGeneratorWrapper sConverterGenerator = new SConverterGeneratorWrapper(metaDataManager);
    sConverterGenerator.generate(ePackages);
    SServiceGeneratorWrapper serviceGeneratorWrapper = new SServiceGeneratorWrapper();
    serviceGeneratorWrapper.generate(ServiceInterface.class, StorePackage.eINSTANCE);
    LOGGER.info("Generating protocol buffers file and classes...");
    protocolBuffersGenerator = new ProtocolBuffersGenerator();
    for (Class<? extends PublicInterface> clazz : InterfaceList.getInterfaces()) {
        SService service = new SService(servicesMap, new SourceCodeFetcher() {

            @Override
            public String get(Class<?> clazz) {
                File javaFile = new File("../PluginBase/src/" + clazz.getName().replace(".", "/") + ".java");
                try {
                    return FileUtils.readFileToString(javaFile);
                } catch (IOException e) {
                    return null;
                }
            }
        }, clazz);
        servicesMap.add(service);
    }
    servicesMap.initialize();
    for (SService service : servicesMap.list()) {
        AdaptorGeneratorWrapper adaptorGeneratorWrapper = new AdaptorGeneratorWrapper();
        adaptorGeneratorWrapper.generate(service.getInterfaceClass(), service);
        AsyncServiceGeneratorWrapper asyncServiceGeneratorWrapper = new AsyncServiceGeneratorWrapper();
        asyncServiceGeneratorWrapper.generate(service.getInterfaceClass(), service);
        File protoFile = new File("../BimServerClientLib/src/org/bimserver/client/protocolbuffers/" + service.getInterfaceClass().getSimpleName() + ".proto");
        File descFile = new File("../BimServerClientLib/src/org/bimserver/client/protocolbuffers/" + service.getInterfaceClass().getSimpleName() + ".desc");
        protocolBuffersGenerator.generate(service.getInterfaceClass(), protoFile, descFile, this.knownServices.isEmpty(), service, knownShortNames);
        this.knownServices.add(service);
        this.knownShortNames.add(service.getInterfaceClass().getSimpleName());
    }
    SPackageGeneratorWrapper sPackageGeneratorWrapper = new SPackageGeneratorWrapper();
    sPackageGeneratorWrapper.generate(ePackages);
    LOGGER.info("Protocol buffers file and classes generated");
    // RealtimeReflectorFactoryBuilder reflectorBuilder = new RealtimeReflectorFactoryBuilder(InterfaceList.createSServicesMap(), new File("../PluginBase/genclasses"));
    // reflectorBuilder.newReflectorFactory();
    LOGGER.info("");
    LOGGER.info("Migration successfull");
    try {
        FileUtils.deleteDirectory(new File("cmhome"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(java.nio.file.Path) AdaptorGeneratorWrapper(org.bimserver.tools.generators.AdaptorGeneratorWrapper) DataObjectGeneratorWrapper(org.bimserver.tools.generators.DataObjectGeneratorWrapper) SPackageGeneratorWrapper(org.bimserver.tools.generators.SPackageGeneratorWrapper) MetaDataManager(org.bimserver.emf.MetaDataManager) IOException(java.io.IOException) EPackage(org.eclipse.emf.ecore.EPackage) SServiceGeneratorWrapper(org.bimserver.tools.generators.SServiceGeneratorWrapper) SConverterGeneratorWrapper(org.bimserver.tools.generators.SConverterGeneratorWrapper) AsyncServiceGeneratorWrapper(org.bimserver.tools.generators.AsyncServiceGeneratorWrapper) SourceCodeFetcher(org.bimserver.shared.meta.SourceCodeFetcher) File(java.io.File) ProtocolBuffersGenerator(org.bimserver.tools.generators.ProtocolBuffersGenerator) SService(org.bimserver.shared.meta.SService)

Example 5 with MetaDataManager

use of org.bimserver.emf.MetaDataManager in project BIMserver by opensourceBIM.

the class TriggerImportDataRemote method main.

public static void main(String[] args) {
    /*
		 * Args:
		 * 	0: Address of new server
		 *  1: Username
		 *  2: Password
		 *  3: Address of old server
		 *  4: Local path to incoming folder of old server, this local path has to be available on the new server, so you have to copy it from the old server
		 */
    try {
        Path home = Paths.get("home");
        Path tmp = home.resolve("tmp");
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        MetaDataManager metaDataManager = new MetaDataManager(tmp);
        pluginManager.setMetaDataManager(metaDataManager);
        try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, args[0])) {
            BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo(args[1], args[2]));
            client.getServiceInterface().importData(args[3], args[1], args[2], args[4]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) PluginManager(org.bimserver.plugins.PluginManager) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) PluginException(org.bimserver.shared.exceptions.PluginException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) MetaDataManager(org.bimserver.emf.MetaDataManager) BimServerClient(org.bimserver.client.BimServerClient) PluginException(org.bimserver.shared.exceptions.PluginException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)

Aggregations

MetaDataManager (org.bimserver.emf.MetaDataManager)10 Path (java.nio.file.Path)8 IOException (java.io.IOException)7 PluginManager (org.bimserver.plugins.PluginManager)7 PluginException (org.bimserver.shared.exceptions.PluginException)6 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)5 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)5 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)4 File (java.io.File)3 ProtocolBuffersBimServerClientFactory (org.bimserver.client.protocolbuffers.ProtocolBuffersBimServerClientFactory)3 SoapBimServerClientFactory (org.bimserver.client.soap.SoapBimServerClientFactory)3 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)3 BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)3 ServiceException (org.bimserver.shared.exceptions.ServiceException)3 MavenPluginRepository (org.bimserver.plugins.MavenPluginRepository)2 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 BimServerClient (org.bimserver.client.BimServerClient)1