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();
}
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();
BasicEList<Object> list = (BasicEList<Object>) idEObject.eGet(feature);
list.grow(listSize);
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));
}
if (feature.isMany()) {
referencedObject = readEmbeddedValue(feature, buffer, referenceClass, query);
} else {
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;
}
use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.
the class MetadataTableWithFilter method getColumns.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.metadata.builder.connection.impl.MetadataTableImpl#getColumns()
*/
@Override
public EList<MetadataColumn> getColumns() {
EList<MetadataColumn> columns = metadataTable.getColumns();
EList<MetadataColumn> columnList = new BasicEList<MetadataColumn>(filterNames.size());
for (MetadataColumn column : columns) {
if (filterNames.contains(column.getName())) {
columnList.add(column);
}
}
return columnList;
}
use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.
the class CompositeIndicatorImpl method getLeafIndicators.
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT getLeafIndicators()
*/
public EList<Indicator> getLeafIndicators() {
EList<Indicator> leafIndicators = new BasicEList<Indicator>();
EList<Indicator> childIndicators = getChildIndicators();
for (Indicator indicator : childIndicators) {
if (indicator instanceof CompositeIndicator) {
leafIndicators.addAll(((CompositeIndicator) indicator).getLeafIndicators());
} else {
leafIndicators.add(indicator);
}
}
return leafIndicators;
}
use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.
the class SoftwareSystemManagerTest method testUpdateSoftwareSystem.
/**
* Test method for
* {@link org.talend.cwm.management.api.SoftwareSystemManager#updateSoftwareSystem(java.sql.Connection, orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)}
* .
*/
@Test
public void testUpdateSoftwareSystem() {
SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
PowerMockito.mockStatic(EMFSharedResources.class);
EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
Resource softwareSysResource = mock(Resource.class);
when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
EList<EObject> existedSystems = new BasicEList<EObject>();
when(softwareSysResource.getContents()).thenReturn(existedSystems);
when(emfSharedResourceMock.saveResource(softwareSysResource)).thenReturn(Boolean.TRUE);
try {
softwareSystemManger.updateSoftwareSystem(null);
Connection mockConnection = mock(Connection.class);
DatabaseMetaData mockDBMetaData = mock(DatabaseMetaData.class);
// Mocking Static Class
PowerMockito.mockStatic(DriverManager.class);
// $NON-NLS-1$
String sql = "jdbc:mysql://localhost:3306/tbi";
when(DriverManager.getConnection(sql)).thenReturn(mockConnection);
when(mockConnection.getMetaData()).thenReturn(mockDBMetaData);
// Mock database product name.
// $NON-NLS-1$
String mysqlDB = "MYSQL";
when(mockDBMetaData.getDatabaseProductName()).thenReturn(mysqlDB);
// Mock database product version
// $NON-NLS-1$
String version = "5.5";
when(mockDBMetaData.getDatabaseProductVersion()).thenReturn(version);
when(mockDBMetaData.getDatabaseMinorVersion()).thenReturn(5);
when(mockDBMetaData.getDatabaseMajorVersion()).thenReturn(5);
DatabaseConnection dbConn = ConnectionPackage.eINSTANCE.getConnectionFactory().createDatabaseConnection();
TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_NAME, mysqlDB);
TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_VERSION, version);
PowerMockito.mockStatic(ConvertionHelper.class);
// $NON-NLS-1$
when(ConvertionHelper.convert(dbConn, false, "")).thenReturn(null);
PowerMockito.mockStatic(MetadataFillFactory.class);
MetadataFillFactory metadataFillFactory = mock(MetadataFillFactory.class);
when(MetadataFillFactory.getDBInstance()).thenReturn(metadataFillFactory);
TypedReturnCode<java.sql.Connection> returnCode = new TypedReturnCode<Connection>(Boolean.TRUE);
returnCode.setObject(mockConnection);
when(metadataFillFactory.createConnection(null)).thenReturn(returnCode);
softwareSystemManger.updateSoftwareSystem(dbConn);
Assert.assertTrue(existedSystems.size() > 0);
SoftwareSystem newSoftwareSys = (SoftwareSystem) existedSystems.get(0);
Assert.assertEquals(mysqlDB, newSoftwareSys.getSubtype());
Assert.assertEquals(version, newSoftwareSys.getVersion());
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}
Aggregations