Java Code Examples for org.eclipse.emf.ecore.EAttribute#isMany()

The following examples show how to use org.eclipse.emf.ecore.EAttribute#isMany() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultEObjectLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected EStructuralFeature getLabelFeature(EClass eClass) {
	EAttribute result = null;
	for (EAttribute eAttribute : eClass.getEAllAttributes()) {
		if (!eAttribute.isMany() && eAttribute.getEType().getInstanceClass() != FeatureMap.Entry.class) {
			if ("name".equalsIgnoreCase(eAttribute.getName())) {
				result = eAttribute;
				break;
			} else if (result == null) {
				result = eAttribute;
			} else if (eAttribute.getEAttributeType().getInstanceClass() == String.class
					&& result.getEAttributeType().getInstanceClass() != String.class) {
				result = eAttribute;
			}
		}
	}
	return result;
}
 
Example 2
Source File: ByteBufferVirtualObject.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void setAttribute(EAttribute eAttribute, Object value) throws BimserverDatabaseException {
		if (eAttribute.isMany()) {
			throw new UnsupportedOperationException("Feature isMany not supported by setAttribute");
		} else {
			if (eAttribute.getEType() instanceof EEnum) {
				writeEnum(eAttribute, value);
			} else if (eAttribute.getEType() instanceof EClass) {
				if (value == null) {
					ensureCapacity(buffer.position(), 2);
					buffer.order(ByteOrder.LITTLE_ENDIAN);
					buffer.putShort((short) -1);
					buffer.order(ByteOrder.BIG_ENDIAN);
				} else if (value instanceof WrappedVirtualObject) {
					ByteBuffer otherBuffer = ((WrappedVirtualObject) value).write();
					ensureCapacity(buffer.position(), otherBuffer.position());
					buffer.put(otherBuffer.array(), 0, otherBuffer.position());
//					writeWrappedValue(getPid(), getRid(), (WrappedVirtualObject) value, getPackageMetaData());
				} else {
					throw new UnsupportedOperationException("??");
				}
			} else if (eAttribute.getEType() instanceof EDataType) {
				writePrimitiveValue(eAttribute, value);
			}
		}
		incrementFeatureCounter(eAttribute);
	}
 
Example 3
Source File: Scaler.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private void setDoubleAsStringValues(IdEObject idEObject) {
	for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) {
		if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
			EStructuralFeature asStringFeature = idEObject.eClass().getEStructuralFeature(eAttribute.getName() + "AsString");
			if (asStringFeature != null) {
				if (eAttribute.isMany()) {
					List list = (List) idEObject.eGet(eAttribute);
					List listAsString = (List) idEObject.eGet(asStringFeature);
					for (int i = 0; i < list.size(); i++) {
						listAsString.set(i, "" + list.get(i));
					}
				} else {
					idEObject.eSet(asStringFeature, "" + idEObject.eGet(eAttribute));
				}
			}
		}
	}
}
 
Example 4
Source File: RecordSizeEstimater.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private int estimateBufferSize(EClass eClass) {
	int size = 0;
	for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
		if (eStructuralFeature instanceof EAttribute) {
			EAttribute eAttribute = (EAttribute)eStructuralFeature;
			if (eAttribute.isMany()) {
				size += 2 + AVERAGE_PRIMITIVE_LIST_SIZE * getPrimitiveSize((EDataType) eAttribute.getEType());
			} else {
				size += getPrimitiveSize((EDataType) eAttribute.getEType());
			}
		} else if (eStructuralFeature instanceof EReference) {
			EReference eReference = (EReference)eStructuralFeature;
			if (eReference.isMany()) {
				size += 2 + AVERAGE_REFERENCE_LIST_SIZE * 10;
			} else {
				size += 10;
			}
		}
	}
	return size;
}
 
Example 5
Source File: InstanceImpl.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the value of an instance's attribute
 *
 * @param <V>
 * @param attribute
 * @return Value
 */
@SuppressWarnings("unchecked")
private <V> V getAttributeValue(EAttribute attribute) {
    final Slot slot = getSlot(attribute);
    if (slot == null) {
        if (attribute.isMany()) {
            return (V) new UpdatingList(this, attribute);
        } else if (attribute.getEType().getInstanceClass() != null
                && Collection.class.isAssignableFrom(attribute.getEType().getInstanceClass())) {//Patch for Notation model
            return (V) new UpdatingList(this, attribute);
        } else if (attribute.getDefaultValue() != null) {
            return (V) attribute.getDefaultValue();
        }
        return null;
    }
    final EList<Object> values = new UpdatingList(this, attribute,
            ((AttributeSlot) slot).getValues());
    if (attribute.isMany()) {
        return (V) values;
    } else if (!values.isEmpty()) {
        return (V) values.get(0);
    }
    return null;
}
 
Example 6
Source File: AddAttributeChange.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());

	HashMapVirtualObject object = transaction.get(oid);
	if (object == null) {
		Query query = new Query(packageMetaData);
		QueryPart queryPart = query.createQueryPart();
		queryPart.addOid(oid);

		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}
	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
	if (eAttribute == null) {
		throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (!eAttribute.isMany()) {
		throw new UserException("Attribute is not of type 'many'");
	}
	
	object.addListItem(eAttribute, value);
}
 
Example 7
Source File: RemoveAttributeChange.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());

	HashMapVirtualObject object = transaction.get(oid);
	if (object == null) {
		Query query = new Query(packageMetaData);
		QueryPart queryPart = query.createQueryPart();
		queryPart.addOid(oid);

		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}
	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
	if (eAttribute == null) {
		throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (eAttribute.isMany()) {
		List list = (List)object.get(eAttribute.getName());
		list.remove(index);
	}
}