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

The following examples show how to use org.eclipse.emf.ecore.EAttribute#getEType() . 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: 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 2
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 3
Source File: ISimpleNameProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected EAttribute getNameEAttribute(EObject target) {
	for (EAttribute eAttribute : target.eClass().getEAllAttributes()) {
		if ("name".equals(eAttribute.getName()) && eAttribute.getEType() == EcorePackage.Literals.ESTRING) {
			return eAttribute;
		}
	}
	return null;
}
 
Example 4
Source File: IRenameStrategy2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EAttribute getNameEAttribute(EObject target) {
	for (EAttribute attribute : target.eClass().getEAllAttributes()) {
		if ("name".equals(attribute.getName()) && EcorePackage.Literals.ESTRING == attribute.getEType()) {
			return attribute;
		}
	}
	return null;
}
 
Example 5
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
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);
	}
	return wrapperAttrib;
}
 
Example 6
Source File: SampleTemplateGenerator.java    From M2Doc with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the sample template {@link XWPFDocument}. The returned {@link XWPFDocument} should be {@link XWPFDocument#close() closed} by the
 * caller.
 * 
 * @param variableName
 *            the variable name
 * @param eCls
 *            the variable {@link EClass}
 * @return the created sample template {@link XWPFDocument}
 * @throws IOException
 *             if the sample template can't be read
 * @throws InvalidFormatException
 *             if the sample template can't be read
 */
@SuppressWarnings("resource")
public XWPFDocument generate(String variableName, EClass eCls) throws InvalidFormatException, IOException {
    final InputStream is = SampleTemplateGenerator.class.getResourceAsStream("/resources/sampleTemplate.docx");
    final OPCPackage pkg = OPCPackage.open(is);

    String featureName = eCls.getEAllAttributes().get(0).getName();
    for (EAttribute attribute : eCls.getEAllAttributes()) {
        if (attribute.getEType() == EcorePackage.eINSTANCE.getEString()) {
            featureName = attribute.getName();
            break;
        }
    }

    final StringBuilder builder = new StringBuilder();
    final byte[] buffer = new byte[BUFFER_SIZE];
    final PackagePart part = pkg.getPart(PackagingURIHelper.createPartName("/word/document.xml"));
    try (InputStream partIS = part.getInputStream()) {
        int nbBytes = partIS.read(buffer);
        while (nbBytes != -1) {
            builder.append(new String(buffer, 0, nbBytes));
            nbBytes = partIS.read(buffer);
        }
    }
    String xml = builder.toString().replace(VARIABLE_NAME_TAG, variableName);
    xml = xml.replace(FEATURE_NAME_TAG, featureName);

    try (OutputStream partOS = part.getOutputStream()) {
        partOS.write(xml.getBytes("UTF-8"));
    }

    final XWPFDocument res = new XWPFDocument(pkg);

    final TemplateCustomProperties customProperties = new TemplateCustomProperties(res);
    customProperties.setM2DocVersion(M2DocUtils.VERSION);
    customProperties.getVariables().put(variableName, eCls.getEPackage().getName() + "::" + eCls.getName());
    final Set<String> packages = new LinkedHashSet<>();
    packages.add(eCls.getEPackage().getNsURI());
    for (EClass superCls : eCls.getEAllSuperTypes()) {
        packages.add(superCls.getEPackage().getNsURI());
    }
    customProperties.getPackagesURIs().addAll(packages);
    customProperties.save();

    return res;
}