Java Code Examples for org.eclipse.emf.ecore.EClass#getEAllStructuralFeatures()

The following examples show how to use org.eclipse.emf.ecore.EClass#getEAllStructuralFeatures() . 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: DatabaseReadingStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private HashMapWrappedVirtualObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass) throws BimserverDatabaseException {
	HashMapWrappedVirtualObject eObject = new HashMapWrappedVirtualObject(eClass);
	for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
		if (eStructuralFeature.isMany()) {
		} else {
			if (eStructuralFeature.getEType() instanceof EDataType) {
				Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer);
				eObject.setAttribute((EAttribute) eStructuralFeature, primitiveValue);
			} else {
				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 = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
					eObject.setReference((EReference) eStructuralFeature, readEmbeddedValue(eStructuralFeature, buffer, referenceClass));
				}
			}
		}
	}
	return eObject;
}
 
Example 2
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 3
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private IdEObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass, QueryInterface query) throws BimserverDatabaseException {
	IdEObject eObject = createInternal(eClass, query);
	for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
		if (eStructuralFeature.isMany()) {
			// Not implemented
		} else {
			if (eStructuralFeature.getEType() instanceof EDataType) {
				Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer, query);
				((IdEObjectImpl) eObject).setLoaded();
				eObject.eSet(eStructuralFeature, primitiveValue);
			} else {
				buffer.order(ByteOrder.LITTLE_ENDIAN);
				short cid = buffer.getShort();
				buffer.order(ByteOrder.BIG_ENDIAN);
				if (cid == -1) {
					// null, do nothing
				} else if (cid < 0) {
					// non minus one and negative cid means value is embedded in record
					EClass referenceClass = database.getEClassForCid((short) (-cid));
					eObject.eSet(eStructuralFeature, readEmbeddedValue(eStructuralFeature, buffer, referenceClass, query));
				}
			}
		}
	}
	return eObject;
}
 
Example 4
Source File: CheckUnsettable.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
	int nrFeatures = 0;
	int nrUnsettableFeatures = 0;
	for (EClassifier eClassifier : Ifc2x3tc1Package.eINSTANCE.getEClassifiers()) {
		if (eClassifier instanceof EClass) {
			EClass eClass = (EClass)eClassifier;
			for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
				nrFeatures++;
				if (eStructuralFeature.isUnsettable()) {
					nrUnsettableFeatures++;
				} else {
					System.out.println(eClass.getName() + "." + eStructuralFeature.getName());
				}
			}
		}
	}
	System.out.println(nrUnsettableFeatures + " / " + nrFeatures);
}
 
Example 5
Source File: OrderedEmfFormatter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static List<EStructuralFeature> getAllFeatures(EClass clazz) {
	List<EStructuralFeature> features = new ArrayList<>(clazz.getEAllStructuralFeatures());
	Collections.sort(features, new Comparator<EStructuralFeature>() {
		@Override
		public int compare(EStructuralFeature o1, EStructuralFeature o2) {
			return o1.getName().compareTo(o2.getName());
		}
	});
	return features;
}
 
Example 6
Source File: TypeHierarchyHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void pushFeaturesUp(EClassInfo info, Collection<EClass> traversedClasses) {
	EClass eClass = info.getEClass();
	if (info.isGenerated()) {
		if (traversedClasses.add(eClass)) {
			if (eClass.getESuperTypes().isEmpty())
				return;
			for(EClass superType: eClass.getESuperTypes()) {
				EClassInfo superInfo = (EClassInfo) infos.getInfoOrNull(superType);
				pushFeaturesUp(superInfo, traversedClasses);
			}
			Map<String, EStructuralFeature> allFeatures = Maps.newLinkedHashMap();
			Set<String> skippedNames = Sets.newLinkedHashSet();
			for(EStructuralFeature feature: eClass.getEAllStructuralFeatures()) {
				if (feature.getEContainingClass() != eClass) {
					if (allFeatures.containsKey(feature.getName())) {
						allFeatures.remove(feature.getName());
					} else if (skippedNames.add(feature.getName())) {
						allFeatures.put(feature.getName(), feature);
					}
				}
			}
			Iterator<EStructuralFeature> iter = eClass.getEStructuralFeatures().iterator();
			while(iter.hasNext()) {
				EStructuralFeature declared = iter.next();
				EStructuralFeature existing = allFeatures.get(declared.getName());
				if (existing != null) {
					EClassifier compatibleType = EcoreUtil2.getCompatibleType(declared.getEType(), existing.getEType(), grammar);
					if (compatibleType != null) {
						iter.remove();
						existing.setEType(compatibleType);
					}
				}
			}
		}
	}
}
 
Example 7
Source File: Database.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public void initInternalStructure(DatabaseSession databaseSession) throws BimserverLockConflictException, BimserverDatabaseException {
	RecordIterator recordIterator = keyValueStore.getRecordIterator(CLASS_LOOKUP_TABLE, databaseSession);
	try {
		Record record = recordIterator.next();
		while (record != null) {
			String packageAndClassName = BinUtils.byteArrayToString(record.getValue());
			String packageName = packageAndClassName.substring(0, packageAndClassName.indexOf("_"));
			String className = packageAndClassName.substring(packageAndClassName.indexOf("_") + 1);
			EClass eClass = (EClass) getEClassifier(packageName, className);
			
			// TODO geometry?
			boolean transactional = !(eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE);

			keyValueStore.openTable(databaseSession, packageAndClassName, transactional);
			
			for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
				if (eStructuralFeature.getEAnnotation("singleindex") != null) {
					String indexTableName = eClass.getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
					try {
						keyValueStore.openIndexTable(databaseSession, indexTableName, transactional);
					} catch (DatabaseNotFoundException e) {
					}
				}
			}
			
			Short cid = BinUtils.byteArrayToShort(record.getKey());
			cidToEclass[cid] = eClass;
			eClassToCid.put(eClass, cid);
			record = recordIterator.next();
		}
	} finally {
		recordIterator.close();
	}
}
 
Example 8
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private int calculateUnsettedLength(EClass eClass, EAttribute skipAttribute) {
	int fieldCounter = 0;
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
		if (feature == skipAttribute) {
			continue;
		}
		if (this.useForDatabaseStorage(eClass, feature)) {
			fieldCounter++;
		}
	}
	int unsettedLength = (int) Math.ceil(fieldCounter / 8.0);
	unsettedLengths.put(eClass, unsettedLength);
	return unsettedLength;
}
 
Example 9
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void buildUseForSerializationSet(EClass eClass) {
		if (this.getSchemaDefinition() != null) {
			if (!useForSerialization.containsKey(eClass)) {
				Set<EStructuralFeature> set = new HashSet<>();
				for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
					EntityDefinition entityBN = this.getSchemaDefinition().getEntityBN(eClass.getName());
//					if (eStructuralFeature.getEAnnotation("hidden") != null) {
						
//						if (eStructuralFeature.getEAnnotation("asstring") == null) {
//						} else {
//							if (entityBN.isDerived(eStructuralFeature.getName().substring(0, eStructuralFeature.getName().length() - 8))) {
//							} else {
//								set.add(eStructuralFeature);
//							}
//						}
//					}
					if (entityBN != null) {
						Attribute attribute = entityBN.getAttributeBNWithSuper(eStructuralFeature.getName());
						if (attribute != null && attribute instanceof ExplicitAttribute) {
							if (!entityBN.isDerived(eStructuralFeature.getName()) || entityBN.isDerivedOverride(eStructuralFeature.getName())) {
								set.add(eStructuralFeature);
							}
						}
					}
				}
				useForSerialization.put(eClass, set);
			}
		}
	}
 
Example 10
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void buildUseForDatabaseStorage(EClass eClass) {
	if (this.getSchemaDefinition() != null) {
		Set<EStructuralFeature> set = new HashSet<>();
		for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
			EntityDefinition entityBN = this.getSchemaDefinition().getEntityBN(eClass.getName());
			if (entityBN == null) {
				set.add(eStructuralFeature);
			} else {
				if (!entityBN.isDerived(eStructuralFeature.getName())) {
					boolean derived = false;
					if (eStructuralFeature.getEAnnotation("hidden") != null) {
						if (eStructuralFeature.getEAnnotation("asstring") == null) {
						} else {
							if (entityBN.isDerived(eStructuralFeature.getName().substring(0, eStructuralFeature.getName().length() - 8))) {
								derived = true;
							} else {
								set.add(eStructuralFeature);
							}
						}
					}
					Attribute attribute = entityBN.getAttributeBNWithSuper(eStructuralFeature.getName());
					if (attribute == null) {
						// geometry, *AsString
						if (!derived) {
							set.add(eStructuralFeature);
						}
					} else {
						if (attribute instanceof ExplicitAttribute || attribute instanceof InverseAttribute) {
							if (!entityBN.isDerived(attribute.getName())) {
								set.add(eStructuralFeature);
							}
						}
					}
				}
			}
		}
		useForDatabaseStorage.put(eClass, set);
	}
}
 
Example 11
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate whether a slot is allowed with respect to the metamodel
 *
 * @param slot
 * @return true if it is allowed, false otherwise
 */
private boolean validate_validFeature(Slot slot) {
	final EClass contextClass = slot.getInstance().getEClass();
	final EList<EStructuralFeature> allowedFeatures = contextClass.getEAllStructuralFeatures();
	final boolean isAllowed = allowedFeatures.contains(slot.getEFeature());
	return isAllowed;
}
 
Example 12
Source File: IfcStepSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void write(IdEObject object) throws SerializerException, IOException {
	EClass eClass = object.eClass();
	if (eClass.getEAnnotation("hidden") != null) {
		return;
	}
	if (eClass.getEPackage() != getPackageMetaData().getEPackage()) {
		return;
	}
	print(DASH);
	long convertedKey = getExpressId(object);
	if (convertedKey == -1) {
		throw new SerializerException("Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
	}
	print(String.valueOf(convertedKey));
	print("= ");
	String upperCase = getPackageMetaData().getUpperCase(eClass);
	if (upperCase == null) {
		throw new SerializerException("Type not found: " + eClass.getName());
	}
	print(upperCase);
	print(OPEN_PAREN);
	boolean isFirst = true;
	EntityDefinition entityBN = getPackageMetaData().getSchemaDefinition().getEntityBN(object.eClass().getName());
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
		if (feature.getEAnnotation("hidden") == null && (entityBN != null && (!entityBN.isDerived(feature.getName()) || entityBN.isDerivedOverride(feature.getName())))) {
			EClassifier type = feature.getEType();
			if (type instanceof EEnum) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEnum(object, feature);
				isFirst = false;
			} else if (type instanceof EClass) {
				EReference eReference = (EReference)feature;
				if (!getPackageMetaData().isInverse(eReference)) {
					if (!isFirst) {
						print(COMMA);
					}
					writeEClass(object, feature);
					isFirst = false;
				}
			} else if (type instanceof EDataType) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEDataType(object, entityBN, feature);
				isFirst = false;
			}
		}
	}
	println(PAREN_CLOSE_SEMICOLON);
}
 
Example 13
Source File: IfcStepStreamingSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void write(HashMapVirtualObject object) throws SerializerException, IOException {
	EClass eClass = object.eClass();

	if (eClass.getEPackage() == GeometryPackage.eINSTANCE) {
		return;
	}
	if (eClass.getEAnnotation("hidden") != null) {
		return;
	}
	print(DASH);
	long convertedKey = getExpressId(object);
	if (convertedKey == -1) {
		throw new SerializerException("Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
	}
	print(String.valueOf(convertedKey));
	print("= ");
	String upperCase = packageMetaData.getUpperCase(eClass);
	if (upperCase == null) {
		throw new SerializerException("Type not found: " + eClass.getName());
	}
	print(upperCase);
	print(OPEN_PAREN);
	boolean isFirst = true;
	
	EntityDefinition entityBN = getSchemaDefinition().getEntityBN(object.eClass().getName());
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {

		if (feature.getEAnnotation("hidden") == null && (entityBN != null && (!entityBN.isDerived(feature.getName()) || entityBN.isDerivedOverride(feature.getName())))) {
			EClassifier type = feature.getEType();
			if (type instanceof EEnum) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEnum(object, feature);
				isFirst = false;
			} else if (type instanceof EClass) {
				EReference eReference = (EReference)feature;
				if (!packageMetaData.isInverse(eReference)) {
					if (!isFirst) {
						print(COMMA);
					}
					writeEClass(object, feature);
					isFirst = false;
				}
			} else if (type instanceof EDataType) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEDataType(object, entityBN, feature);
				isFirst = false;
			}
		}
	}
	println(PAREN_CLOSE_SEMICOLON);
}
 
Example 14
Source File: EmfModelsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void dumpFeatures(final EClass eClassifier, final EObject obj) {
  EList<EStructuralFeature> _eAllStructuralFeatures = eClassifier.getEAllStructuralFeatures();
  for (final EStructuralFeature eStructuralFeature : _eAllStructuralFeatures) {
    try {
      String prefix = "get";
      if ((Objects.equal(eStructuralFeature.getEType(), EcorePackage.Literals.EBOOLEAN) && (eStructuralFeature.getUpperBound() == 1))) {
        prefix = "is";
      }
      String _firstUpper = Strings.toFirstUpper(eStructuralFeature.getName());
      final String getterName = (prefix + _firstUpper);
      final Method getter = obj.getClass().getMethod(getterName);
      boolean _isCustom = this.isCustom(getter);
      if (_isCustom) {
        String _name = eClassifier.getName();
        String _plus = (_name + ": Overridden getter ");
        String _plus_1 = (_plus + getterName);
        EmfModelsTest.LOGGER.debug(_plus_1);
      }
      boolean _isMany = eStructuralFeature.isMany();
      boolean _not = (!_isMany);
      if (_not) {
        boolean _isChangeable = eStructuralFeature.isChangeable();
        if (_isChangeable) {
          String _firstUpper_1 = Strings.toFirstUpper(eStructuralFeature.getName());
          final String setterName = ("set" + _firstUpper_1);
          final Method setter = obj.getClass().getMethod(setterName, 
            this.toJavaClass(eStructuralFeature.getEType()));
          boolean _isCustom_1 = this.isCustom(setter);
          if (_isCustom_1) {
            String _name_1 = eClassifier.getName();
            String _plus_2 = (_name_1 + ": Overridden setter ");
            String _name_2 = setter.getName();
            String _plus_3 = (_plus_2 + _name_2);
            EmfModelsTest.LOGGER.debug(_plus_3);
          }
        }
        if ((((eStructuralFeature instanceof EReference) && (!((EReference) eStructuralFeature).isContainment())) && 
          (((EReference) eStructuralFeature).getEOpposite() == null))) {
          String _firstUpper_2 = Strings.toFirstUpper(getterName);
          final String basicGetterName = ("basic" + _firstUpper_2);
          final Method basicGetter = obj.getClass().getMethod(basicGetterName);
          boolean _isCustom_2 = this.isCustom(basicGetter);
          if (_isCustom_2) {
            String _name_3 = eClassifier.getName();
            String _plus_4 = (_name_3 + ": Overridden basicGetter ");
            String _name_4 = basicGetter.getName();
            String _plus_5 = (_plus_4 + _name_4);
            EmfModelsTest.LOGGER.debug(_plus_5);
          }
        }
      }
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        e.printStackTrace();
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
}