Refine search
int bits = 0; for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) { if (packageMetaData.useForDatabaseStorage(idEObject.eClass(), eStructuralFeature)) { bits++; if (eStructuralFeature instanceof EAttribute) { EAttribute eAttribute = (EAttribute) eStructuralFeature; if (eAttribute.isMany()) { size += 4; for (Object v : ((List<?>) val)) { size += getPrimitiveSize(eAttribute.getEAttributeType(), v); size += getPrimitiveSize(eAttribute.getEAttributeType(), val); if (eReference.isMany()) { size += 4; for (Object v : ((List<?>) val)) {
if (eStructuralFeature instanceof EAttribute) { EAttribute eAttribute = (EAttribute)eStructuralFeature; if (eAttribute.getEType() instanceof EEnum) { stringBuffer.append(eAttribute.getEType().getName()); stringBuffer.append(TEXT_16); stringBuffer.append(eAttribute.getName()); stringBuffer.append(TEXT_17); if (eAttribute.isMany()) { importManager.getImport("java.util.List"); importManager.getImport("java.util.ArrayList"); stringBuffer.append(eAttribute.getEType().getInstanceClassName()); stringBuffer.append(TEXT_19); stringBuffer.append(eAttribute.getName()); stringBuffer.append(TEXT_20); stringBuffer.append(eAttribute.getEType().getInstanceClassName()); stringBuffer.append(TEXT_21); if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEByteArray() && eAttribute.getEAnnotation("file") != null) { importManager.getImport("javax.activation.DataHandler"); stringBuffer.append(eAttribute.getName()); stringBuffer.append(TEXT_17); stringBuffer.append(eAttribute.getEType().getInstanceClassName()); stringBuffer.append(TEXT_16); stringBuffer.append(eAttribute.getName());
public EAttribute createEAttribute(EClass eClass, String name, EDataType eDataType, Multiplicity multiplicity) { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); if (multiplicity == Multiplicity.MANY) { eAttribute.setUpperBound(-1); } if (!isNew(eClass)) { changes.add(new NewAttributeChange(this, eClass.getEAllStructuralFeatures().size(), eAttribute)); } eAttribute.setEType(eDataType); eClass.getEStructuralFeatures().add(eAttribute); return eAttribute; }
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; }
public ObjectIdentifier getOid(EClass eClass, EAttribute attribute, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException { if (attribute.getEAnnotation("singleindex") != null) { String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + attribute.getName(); byte[] queryBytes = null; if (value instanceof String) { queryBytes = ((String)value).getBytes(Charsets.UTF_8); } else if (value instanceof Integer) { queryBytes = BinUtils.intToByteArray((Integer)value); } else { throw new BimserverDatabaseException("Unsupported type " + value); } ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8); valueBuffer.putInt(pid); valueBuffer.putInt(-rid); valueBuffer.put(queryBytes); byte[] firstDuplicate = databaseInterface.get(indexTableName, valueBuffer.array()); if (firstDuplicate != null) { ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate); buffer.getInt(); // pid long oid = buffer.getLong(); return new ObjectIdentifier(oid, (short)oid); } } else { throw new UnsupportedOperationException(eClass.getName() + "." + attribute.getName() + " does not have a singleindex"); } return null; }
private void createEPackageMultiplicityManyContainmentNoOpposite() { EPackage ePackage = this.createNewEPackage("MyEPackage", "http://www.example.com/model", "model"); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("MyEClass"); EClass eOtherClass = EcoreFactory.eINSTANCE.createEClass(); eOtherClass.setName("YourEClass"); EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("MyAttribute"); eAttribute.setEType(EcorePackage.Literals.ESTRING); eAttribute.setLowerBound(0); eAttribute.setUpperBound(1); eClass.getEStructuralFeatures().add(eAttribute); EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName("children"); eReference.setEType(eOtherClass); eReference.setLowerBound(0); eReference.setUpperBound(-1); eReference.setContainment(true); eClass.getEStructuralFeatures().add(eReference); ePackage.getEClassifiers().add(eClass); ePackage.getEClassifiers().add(eOtherClass); this.registerEPackages(ePackage); }
documentRootEClass.setName("DocumentRoot"); ExtendedMetaData.INSTANCE.setName(documentRootEClass, ""); ExtendedMetaData.INSTANCE.setContentKind(documentRootEClass, ExtendedMetaData.MIXED_CONTENT); mixed.setName("mixed"); mixed.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry()); mixed.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); ExtendedMetaData.INSTANCE.setName(mixed, ":mixed"); ExtendedMetaData.INSTANCE.setFeatureKind(mixed, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); documentRootEClass.getEStructuralFeatures().add(mixed); xmlnsPrefixMap.setName("xMLNSPrefixMap"); xmlnsPrefixMap.setEType(EcorePackage.eINSTANCE.getEStringToStringMapEntry()); ExtendedMetaData.INSTANCE.setName(xsiSchemaLocation, "xsi:schemaLocation"); ExtendedMetaData.INSTANCE.setFeatureKind(xsiSchemaLocation, ExtendedMetaData.ATTRIBUTE_FEATURE); documentRootEClass.getEStructuralFeatures().add(xsiSchemaLocation); for (EClass eClass : cdaSnippet.eClass().getEAllSuperTypes()) { if (CDAPackage.eINSTANCE.getNsURI().equals(eClass.getEPackage().getNsURI()) && !"ClinicalStatement".equals(eClass.getName())) { snippetName = eClass.getName(); documentRootPackage.setName(CDAPackage.eNAME); documentRootPackage.setNsPrefix(CDAPackage.eNS_PREFIX); documentRootPackage.setNsURI(CDAPackage.eNS_URI); documentRootPackage.getEClassifiers().add(documentRootEClass);
@Test public void canConvertBetweenEPackageAndXMI() { EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("MyEPackage"); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("MyEClass"); EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("MyAttribute"); eAttribute.setEType(EcorePackage.Literals.ESTRING); eAttribute.setLowerBound(0); eAttribute.setUpperBound(1); eClass.getEStructuralFeatures().add(eAttribute); EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName("self"); eReference.setEType(eClass); eReference.setUpperBound(-1); eReference.setLowerBound(0); eClass.getEStructuralFeatures().add(eReference); ePackage.getEClassifiers().add(eClass); EAttribute eAttribute2 = Iterables.getOnlyElement(eClass2.getEAttributes()); assertNotNull(eAttribute2); assertEquals("MyAttribute", eAttribute2.getName()); assertEquals(0, eAttribute2.getLowerBound()); assertEquals(1, eAttribute2.getUpperBound()); assertEquals(EcorePackage.Literals.ESTRING, eAttribute2.getEType()); EReference eReference2 = Iterables.getOnlyElement(eClass2.getEReferences()); assertNotNull(eReference2);
throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId()); 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"); throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\""); if (value instanceof List && eAttribute.isMany()) { List sourceList = (List)value; if (!eAttribute.isMany()) { throw new UserException("Attribute is not of type 'many'"); list.clear(); List asStringList = null; if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) { asStringList = (List)object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString")); asStringList.clear(); if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) { asStringList.add(String.valueOf(o)); if (eAttribute.isMany()) { throw new UserException("Attribute is not of type 'single'"); if (eAttribute.getEType() instanceof EEnum) { EEnum eEnum = (EEnum) eAttribute.getEType(); object.set(eAttribute.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance()); } else { object.set(eAttribute.getName(), value);
realType.setDomain(new RealType()); EAttribute attribute = modifySimpleType(realType, ifcComplexNumber); ifcComplexNumber.getEStructuralFeature("wrappedValueAsString").setUpperBound(2); attribute.setUpperBound(2); ifcComplexNumber.getEAnnotations().add(createWrappedAnnotation()); } else if (type.getName().equals("IfcNullStyle")) { wrappedValue.setName("wrappedValue"); wrappedValue.setEType(ifcNullStyleEnum); ifcNullStyleWrapper.getEAnnotations().add(createWrappedAnnotation()); ifcNullStyleWrapper.getEStructuralFeatures().add(wrappedValue); } else if (type.getName().equals("IfcLineIndex")) { EClass ifcLineIndex = getOrCreateEClass(type.getName()); realType.setDomain(new IntegerType()); EAttribute attribute = modifySimpleType(realType, ifcLineIndex); attribute.setLowerBound(2); attribute.setUpperBound(-1); ifcLineIndex.getEAnnotations().add(createWrappedAnnotation()); } else if (type.getName().equals("IfcArcIndex")) { realType.setDomain(new IntegerType()); EAttribute attribute = modifySimpleType(realType, ifcArcIndex); attribute.setUpperBound(3); attribute.setLowerBound(3); ifcArcIndex.getEAnnotations().add(createWrappedAnnotation());
if (eAttribute.getEType() instanceof EEnum) { stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_36); stringBuffer.append(eAttribute.getEType().getName()); stringBuffer.append(TEXT_37); stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_38); if (eAttribute.isMany()) { stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_40); stringBuffer.append(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get"); stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_41); stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_42); stringBuffer.append(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() ? "is" : "get"); stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_41); if (eAttribute.getEType() instanceof EEnum) { stringBuffer.append(StringUtils.firstUpperCase(eAttribute.getName())); stringBuffer.append(TEXT_76); stringBuffer.append(eAttribute.getEType().getName()); stringBuffer.append(TEXT_37);
protected void copyEDataTypeAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) { EDataType eDataType = eAttribute.getEAttributeType(); EFactory eFactory = eDataType.getEPackage().getEFactoryInstance(); if (targetEAttribute != null && targetEAttribute.isChangeable()) { EDataType targetEDataType = targetEAttribute .getEAttributeType(); EFactory targetEFactory = targetEDataType.getEPackage() .getEFactoryInstance(); if (targetEAttribute.isMany()) { @SuppressWarnings("unchecked") EList<Object> copyValues = (EList<Object>) copyEObject .eGet(targetEAttribute); if (eAttribute.isMany()) { EList<?> values = (EList<?>) eObject.eGet(eAttribute); for (int i = 0, size = values.size(); i < size; i++) { copyValues.add(i, targetEFactory.createFromString( targetEDataType, eFactory.convertToString( eDataType, values.get(i)))); copyEObject.eSet(targetEAttribute, targetEFactory .createFromString(targetEDataType, eFactory .convertToString(eDataType, eAttribute.isMany() ? ((EList<?>) eObject.eGet(eAttribute)).get(0) : eObject.eGet(eAttribute))));
private void doRealDerivedAttributes() { for (EntityDefinition entityDefinition : schema.getEntities()) { for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) { EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName()); if (!found) { EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setDerived(true); eAttribute.setName(attributeName.getName()); if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) { eAttribute.setUpperBound(3); eAttribute.setUnique(false); EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType(); eAttribute.setEType(type); eAttribute.setUnsettable(true); // TODO find out eClass.getEStructuralFeatures().add(eAttribute); if (type == EcorePackage.eINSTANCE.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setName(attributeName.getName() + "AsString"); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation()); doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation()); doubleStringAttribute.setUnsettable(true); // TODO doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
EClass cls = (EClass) schemaPack.getEClassifier(ent.getName()); EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setName(attrib.getName()); eAttribute.setUpperBound(-1); eAttribute.setUnique(false); eAttribute.setEType(EcorePackage.eINSTANCE.getELong()); eAttribute.setUnsettable(expAttrib.isOptional()); cls.getEStructuralFeatures().add(eAttribute); return; if (nt instanceof EnumerationType) { EAttribute enumAttrib = eFactory.createEAttribute(); enumAttrib.setUnsettable(expAttrib.isOptional()); enumAttrib.setName(attrib.getName()); EClassifier eType = schemaPack.getEClassifier(nt.getName()); enumAttrib.setEType(eType); EClass cls = (EClass) schemaPack.getEClassifier(ent.getName()); cls.getEStructuralFeatures().add(enumAttrib); if (wrapped) { EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setUnsettable(expAttrib.isOptional()); eAttribute.setName(attrib.getName()); if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) { eAttribute.setUpperBound(3); eAttribute.setUnique(false); EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType(); eAttribute.setEType(type);
private void addTwoDimensionalArray(String entityName, String attribName) { EClassifier finalType = null; if (entityName.equals("IfcBSplineSurface") && attribName.equals("ControlPointsList")) { finalType = schemaPack.getEClassifier("IfcCartesianPoint"); } else if (entityName.equals("IfcCartesianPointList3D") && attribName.equals("CoordList")) { finalType = schemaPack.getEClassifier("IfcLengthMeasure"); } else if (entityName.equals("IfcColourRgbList") && attribName.equals("ColourList")) { finalType = schemaPack.getEClassifier("IfcNormalisedRatioMeasure"); } else if (entityName.equals("IfcIndexedTriangleTextureMap") && attribName.equals("TexCoordIndex")) { finalType = EcorePackage.eINSTANCE.getELong(); if (containerClass == null) { containerClass = EcoreFactory.eINSTANCE.createEClass(); containerClass.setName("ListOf" + finalType.getName()); finalAttribute.setName("List"); finalAttribute.setEType(finalType); finalAttribute.setUpperBound(-1); containerClass.getEAttributes().add(finalAttribute); stringAttribute.setName("ListAsString"); stringAttribute.setEType(EcorePackage.eINSTANCE.getEString()); stringAttribute.setUpperBound(-1); containerClass.getEAttributes().add(stringAttribute); finalReference.setName("List"); finalReference.setEType(finalType); finalReference.setUpperBound(-1); containerClass.getEReferences().add(finalReference);
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"); 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); 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);
private EAttribute x(DefinedType type, EClass testType) { EAttribute wrapperAttrib = eFactory.createEAttribute(); wrapperAttrib.setName("wrappedValue"); if (type.getDomain() instanceof IntegerType) { wrapperAttrib.setEType(ePackage.getELong()); } else if (type.getDomain() instanceof RealType) { wrapperAttrib.setEType(ePackage.getEDouble()); } else if (type.getDomain() instanceof StringType) { wrapperAttrib.setEType(ePackage.getEString()); } else if (type.getDomain() instanceof BooleanType) { wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate")); } else if (type.getDomain() instanceof NumberType) { wrapperAttrib.setEType(ePackage.getEDouble()); } else if (type.getDomain() instanceof BinaryType) { wrapperAttrib.setEType(ePackage.getEByteArray()); } else if (type.getDomain() instanceof LogicalType) { wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate")); wrapperAttrib.setUnsettable(true); testType.getEStructuralFeatures().add(wrapperAttrib); if (wrapperAttrib.getEType() == ePackage.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setEType(ePackage.getEString()); doubleStringAttribute.setName("wrappedValueAsString"); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation()); doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation()); doubleStringAttribute.setUnsettable(true); testType.getEStructuralFeatures().add(doubleStringAttribute);
@Override public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException { EClass eClass = eAttribute.getEContainingClass(); KeyValueStore keyValueStore = database.getKeyValueStore(); for (EClass subClass : schema.getSubClasses(eClass)) { try { if (subClass.getEAnnotation("nodatabase") == null) { RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession); try { Record record = recordIterator.next(); ByteBuffer buffer = ByteBuffer.wrap(record.getValue()); PackageMetaData packageMetaData = database.getMetaDataManager().getPackageMetaData(subClass.getEPackage().getName()); int newUnsettedLength = packageMetaData.getUnsettedLength(subClass); int previousUnsettedLength = packageMetaData.getUnsettedLength(subClass, eAttribute); newBuffer.put(buffer); keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession); record = recordIterator.next();
for (Long key : map.keySet()) { EObject object = map.get(key); System.out.println("#" + key + " " + object.eClass().getName()); for (EAttribute attribute : object.eClass().getEAllAttributes()) { System.out.println("\t" + attribute.getName() + "(" + attribute.getEType().getName() + "): " + object.eGet(attribute)); for (EReference reference : object.eClass().getEAllReferences()) { System.out.println("\t" + reference.getName() + "(" + reference.getEReferenceType().getName() + "): "); if (object.eGet(reference) instanceof EObjectResolvingEList) { EObjectResolvingEList<EObject> referencedObjectList = (EObjectResolvingEList<EObject>)object.eGet(reference); if (referencedObjectList != null && referencedObjectList.size() > 0) { if (reference.getEReferenceType().getEStructuralFeature("wrappedValue") != null) { for (Object obj : referencedObjectList) { Object wrappedValue = ((EObject)obj).eGet(reference.getEReferenceType().getEStructuralFeature("wrappedValue"));
private static Object convertSinglePersistableObjectToEAttributeValue(final EAttribute eAttribute, final Object value) { if (value == null) { // null is always null, conversions make no sense here return null; } if (eAttribute.getEAttributeType() instanceof EEnum) { // for EEnums, we store the 'literal' representation, so we have to convert back now EEnum eEnum = (EEnum) eAttribute.getEAttributeType(); if (value instanceof String == false) { throw new EObjectPersistenceException("Tried to deserialize value for EEnum-typed EAttribute '" + eAttribute.getEContainingClass().getName() + "#" + eAttribute.getName() + "', but the stored object (class: '" + value.getClass().getName() + "' is not a literal string: '" + value + "'!"); } EEnumLiteral enumLiteral = eEnum.getEEnumLiteralByLiteral((String) value); if (enumLiteral == null) { throw new EObjectPersistenceException("Tried to deserialize a value for EEnum-typed EAttribute '" + eAttribute.getEContainingClass().getName() + "#" + eAttribute.getName() + "', but the stored literal '" + value + "' has no representation in the EEnum '" + eEnum.getName() + "'!"); } return enumLiteral; } // anything else remains as-is return value; }