Search in sources :

Example 1 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project BIMserver by opensourceBIM.

the class DatabaseSession method readList.

@SuppressWarnings("unchecked")
private Object readList(IdEObject idEObject, EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, QueryInterface query, TodoList todoList, EStructuralFeature feature) throws BimserverDatabaseException {
    if (feature.getEType() instanceof EEnum) {
    } else if (feature.getEType() instanceof EClass) {
        if (buffer.capacity() == 1 && buffer.get(0) == -1) {
            buffer.position(buffer.position() + 1);
        } else {
            /*
				 * TODO There still is a problem with this,
				 * when readReference (and all calls beyond
				 * that call) alter (by opposites) this
				 * list, this list can potentially grow too
				 * large
				 * 
				 * Only can happen with non-unique
				 * references
				 */
            int listSize = buffer.getInt();
            AbstractEList<Object> list = (AbstractEList<Object>) idEObject.eGet(feature);
            for (int i = 0; i < listSize; i++) {
                if (feature.getEAnnotation("twodimensionalarray") != null) {
                    IdEObjectImpl newObject = createInternal((EClass) feature.getEType(), query);
                    Object result = readList(newObject, originalQueryClass, buffer, model, query, todoList, newObject.eClass().getEStructuralFeature("List"));
                    if (result != null) {
                        newObject.eSet(newObject.eClass().getEStructuralFeature("List"), result);
                    }
                    list.addUnique(newObject);
                } else {
                    IdEObject referencedObject = null;
                    buffer.order(ByteOrder.LITTLE_ENDIAN);
                    short cid = buffer.getShort();
                    buffer.order(ByteOrder.BIG_ENDIAN);
                    if (cid == -1) {
                    // null, do nothing
                    } else if (cid < 0) {
                        // negative cid means value is
                        // embedded
                        // in record
                        EClass referenceClass = database.getEClassForCid((short) (-cid));
                        if (referenceClass == null) {
                            throw new BimserverDatabaseException("No class found for cid " + (-cid));
                        }
                        referencedObject = readWrappedValue(feature, buffer, referenceClass, query);
                    } else if (cid > 0) {
                        // positive cid means value is a
                        // reference
                        // to another record
                        EClass referenceClass = database.getEClassForCid(cid);
                        if (referenceClass == null) {
                            throw new BimserverDatabaseException("Cannot find class with cid " + cid);
                        }
                        buffer.position(buffer.position() - 2);
                        referencedObject = readReference(originalQueryClass, buffer, model, idEObject, feature, referenceClass, query, todoList);
                    }
                    if (referencedObject != null) {
                        if (!feature.getEType().isInstance(referencedObject)) {
                            throw new BimserverDatabaseException(referencedObject.getClass().getSimpleName() + " cannot be stored in list of type " + feature.getEType().getName() + " for feature " + feature.getName());
                        }
                        if (feature.isUnique()) {
                            list.add(referencedObject);
                        } else {
                            list.addUnique(referencedObject);
                        }
                    }
                }
            }
        }
    } else if (feature.getEType() instanceof EDataType) {
        int listSize = buffer.getInt();
        BasicEList<Object> list = new BasicEList<Object>(listSize);
        for (int i = 0; i < listSize; i++) {
            Object reference = readPrimitiveValue(feature.getEType(), buffer, query);
            if (reference != null) {
                list.addUnique(reference);
            }
        }
        return list;
    }
    return null;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) AbstractEList(org.eclipse.emf.common.util.AbstractEList) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) EDataType(org.eclipse.emf.ecore.EDataType) BasicEList(org.eclipse.emf.common.util.BasicEList) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnum(org.eclipse.emf.ecore.EEnum)

Example 2 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project BIMserver by opensourceBIM.

the class StructureAnalyzer method start.

private void start() {
    limit = 1000000;
    try {
        out = new PrintWriter(Paths.get("structure.txt").toFile());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    int i = 0;
    // Ifc2x3tc1Package einstance = Ifc2x3tc1Package.eINSTANCE;
    // System.out.println(printClassifier("root", Ifc2x3tc1Package.eINSTANCE.getEClassifier("IfcWall"), new ArrayList<EClassifier>(), 0));
    // EList<EClassifier> classifiers = Ifc2x3tc1Package.eINSTANCE.getEClassifiers();
    EList<EClassifier> classifiers = new BasicEList<EClassifier>();
    classifiers.add(Ifc2x3tc1Package.eINSTANCE.getEClassifier("IfcWall"));
    for (EClassifier ecl : classifiers) {
        try {
            out2 = new PrintWriter(Paths.get("structure/" + ecl.getName() + ".txt").toFile());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        count = 0;
        int printClassifier = printClassifier("root", ecl, new ArrayList<EClassifier>(), 0);
        if (printClassifier == -1) {
            out2.println("TERMINATED AFTER " + limit + " REFERENCES");
        }
        String string = i + "\t" + printClassifier + "\t" + ecl.getName();
        System.out.println(string);
        out.println(string);
        out.flush();
        out2.close();
        i++;
    }
    out.close();
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) FileNotFoundException(java.io.FileNotFoundException) EClassifier(org.eclipse.emf.ecore.EClassifier) PrintWriter(java.io.PrintWriter)

Example 3 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project vorto by eclipse.

the class CodeGenTools method getReferencedTypes.

public static EList<Type> getReferencedTypes(Entity entity) {
    EList<Type> types = new BasicEList<Type>();
    for (Property property : entity.getProperties()) {
        types.addAll(getReferencedTypes(property));
    }
    types.add(entity.getSuperType());
    return types;
}
Also used : ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Type(org.eclipse.vorto.core.api.model.datatype.Type) BasicEList(org.eclipse.emf.common.util.BasicEList) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Example 4 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tmdm-studio-se by Talend.

the class UtilMockTest method testUpdateReferenceToXSDTypeDefinition.

@Test
public void testUpdateReferenceToXSDTypeDefinition() {
    // $NON-NLS-1$
    String method_getall = "getAllObject";
    // $NON-NLS-1$
    String method_updateref = "updateReferenceToXSDTypeDefinition";
    PowerMockito.mockStatic(Util.class);
    try {
        PowerMockito.when(Util.class, method_updateref, any(), any(XSDTypeDefinition.class), any(IStructuredContentProvider.class)).thenCallRealMethod();
        Object[] allNodes = {};
        XSDFactory factory = XSDFactory.eINSTANCE;
        XSDTypeDefinition[] newTypes = { factory.createXSDComplexTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
        for (XSDTypeDefinition newType : newTypes) {
            // 
            // 
            XSDElementDeclaration mockElementDecl = mock(XSDElementDeclaration.class);
            when(mockElementDecl.getTypeDefinition()).thenReturn(newType);
            // 
            // 
            XSDParticle xsdParticle1 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec2 = mock(XSDElementDeclaration.class);
            when(mockElementDec2.getTypeDefinition()).thenReturn(newType);
            when(xsdParticle1.getTerm()).thenReturn(mockElementDec2);
            // 
            // 
            XSDParticle xsdParticle2 = mock(XSDParticle.class);
            XSDParticle particle_c1 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec_c1 = mock(XSDElementDeclaration.class);
            when(mockElementDec_c1.getTypeDefinition()).thenReturn(newType);
            when(particle_c1.getContent()).thenReturn(mockElementDec_c1);
            XSDParticle particle_c2 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec_c2 = mock(XSDElementDeclaration.class);
            when(mockElementDec_c2.getTypeDefinition()).thenReturn(newType);
            when(particle_c2.getContent()).thenReturn(mockElementDec_c2);
            XSDParticle particle_c3 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec_c3 = mock(XSDElementDeclaration.class);
            when(mockElementDec_c3.getTypeDefinition()).thenReturn(factory.createXSDComplexTypeDefinition());
            when(particle_c3.getContent()).thenReturn(mockElementDec_c3);
            XSDModelGroup xsdModelGroup = mock(XSDModelGroup.class);
            EList<XSDParticle> elist = new BasicEList<XSDParticle>();
            elist.add(particle_c1);
            elist.add(particle_c2);
            elist.add(particle_c3);
            when(xsdModelGroup.getContents()).thenReturn(elist);
            when(xsdParticle2.getTerm()).thenReturn(xsdModelGroup);
            allNodes = new Object[] { mockElementDecl, xsdParticle1, xsdParticle2 };
            // 
            PowerMockito.when(Util.class, method_getall, any(), anyList(), any(IStructuredContentProvider.class)).thenReturn(allNodes);
            Util.updateReferenceToXSDTypeDefinition(new Object(), newType, mock(IStructuredContentProvider.class));
            Mockito.verify(mockElementDecl).setTypeDefinition(newType);
            Mockito.verify(mockElementDec2).setTypeDefinition(newType);
            Mockito.verify(mockElementDec_c1).setTypeDefinition(newType);
            Mockito.verify(mockElementDec_c2).setTypeDefinition(newType);
            if (newType instanceof XSDComplexTypeDefinition) {
                PowerMockito.verifyStatic();
                Util.updateChildrenReferenceToComplexType((XSDComplexTypeDefinition) newType);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) BasicEList(org.eclipse.emf.common.util.BasicEList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tmdm-studio-se by Talend.

the class UtilMockTest method testGetComplexTypes.

@Test
public void testGetComplexTypes() {
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDSchema xSchema = factory.createXSDSchema();
    List<XSDComplexTypeDefinition> complexTypes = Util.getComplexTypes(xSchema);
    assertNotNull(complexTypes);
    assertTrue(complexTypes.isEmpty());
    XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
    simpleTypeDefinition.setBaseTypeDefinition(// $NON-NLS-1$ );
    xSchema.resolveSimpleTypeDefinition(xSchema.getSchemaForSchemaNamespace(), "string"));
    xSchema.getContents().add(simpleTypeDefinition);
    complexTypes = Util.getComplexTypes(xSchema);
    assertNotNull(complexTypes);
    assertTrue(complexTypes.isEmpty());
    XSDComplexTypeDefinition baseComplexTypeDefinition = xSchema.resolveComplexTypeDefinition(xSchema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
    "anyType");
    XSDComplexTypeDefinition complexType1 = factory.createXSDComplexTypeDefinition();
    complexType1.setBaseTypeDefinition(baseComplexTypeDefinition);
    complexType1.setTargetNamespace(null);
    // $NON-NLS-1$
    complexType1.setName("ctype1");
    XSDComplexTypeDefinition complexType2 = factory.createXSDComplexTypeDefinition();
    // $NON-NLS-1$
    complexType2.setTargetNamespace("targetNameSpace");
    // $NON-NLS-1$
    complexType2.setName("ctype2");
    complexType2.setBaseTypeDefinition(baseComplexTypeDefinition);
    XSDComplexTypeDefinition complexType3 = factory.createXSDComplexTypeDefinition();
    complexType3.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
    // $NON-NLS-1$
    complexType3.setName("topLevelComplexType");
    complexType3.setBaseTypeDefinition(baseComplexTypeDefinition);
    EList<XSDTypeDefinition> contents = new BasicEList<XSDTypeDefinition>();
    contents.add(complexType1);
    contents.add(complexType2);
    contents.add(complexType3);
    XSDSchema spySchema = spy(xSchema);
    when(spySchema.getTypeDefinitions()).thenReturn(contents);
    complexTypes = Util.getComplexTypes(spySchema);
    assertNotNull(complexTypes);
    assertTrue(complexTypes.size() == 2);
    assertTrue(complexTypes.contains(complexType1));
    assertTrue(complexTypes.contains(complexType2));
    assertFalse(complexTypes.contains(complexType3));
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) BasicEList(org.eclipse.emf.common.util.BasicEList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)75 Test (org.junit.Test)25 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)16 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)16 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)16 EEFFeatureEditorDialog (org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 GridData (org.eclipse.swt.layout.GridData)16 TdExpression (org.talend.cwm.relational.TdExpression)11 EObject (org.eclipse.emf.ecore.EObject)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)9 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)9 ProductVersion (org.talend.utils.ProductVersion)9 Button (org.eclipse.swt.widgets.Button)8 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)6 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 Widget (org.eclipse.smarthome.model.sitemap.Widget)5