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

The following examples show how to use org.eclipse.emf.ecore.EAttribute#getName() . 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: Ecore2XtextGrammarCreator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public CharSequence idAssignment(final EClass it) {
  CharSequence _xblockexpression = null;
  {
    final EAttribute idAttr = Ecore2XtextExtensions.idAttribute(it);
    CharSequence _xifexpression = null;
    if ((idAttr != null)) {
      StringConcatenation _builder = new StringConcatenation();
      String _name = idAttr.getName();
      _builder.append(_name);
      _builder.append("=");
      String _assignedRuleCall = Ecore2XtextExtensions.assignedRuleCall(idAttr);
      _builder.append(_assignedRuleCall);
      _xifexpression = _builder;
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 2
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends IdEObject> List<T> query(EAttribute attribute, Object value) throws BimserverLockConflictException, BimserverDatabaseException {
	List<T> result = new ArrayList<>();
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + attribute.getEContainingClass().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);
		}
		List<byte[]> duplicates = database.getKeyValueStore().getDuplicates(indexTableName, queryBytes, this);
		for (byte[] indexValue : duplicates) {
			ByteBuffer buffer = ByteBuffer.wrap(indexValue);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			result.add((T) get(oid, OldQuery.getDefault()));
		}
	}
	return result;
}
 
Example 3
Source File: ASTGraphProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param eobj
 *            will be non-null and not a proxy
 * @return may return null
 */
private String getDescription(EObject eobj) {
	final List<String> lines = new ArrayList<>();
	// attributes
	for (EAttribute a : eobj.eClass().getEAllAttributes()) {
		String line = a.getName() + ": \t" + eobj.eGet(a);
		lines.add(line);
	}
	String result = lines.isEmpty() ? null : Joiner.on('\n').join(lines);
	return result;
}
 
Example 4
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static String assignedRuleCall(final EAttribute it) {
  String _xifexpression = null;
  boolean _isPrefixBooleanFeature = Ecore2XtextExtensions.isPrefixBooleanFeature(it);
  if (_isPrefixBooleanFeature) {
    String _name = it.getName();
    String _plus = ("\'" + _name);
    _xifexpression = (_plus + "\'");
  } else {
    _xifexpression = UniqueNameUtil.uniqueName(it.getEType());
  }
  return _xifexpression;
}
 
Example 5
Source File: QueryNamesAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public ObjectIdentifier getOidOfGuidAlternative(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 BimserverDatabaseException("Name queries are not implemented yet");
	}
	return null;
}
 
Example 6
Source File: QueryClassificationsAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: QueryGuidsAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public ObjectIdentifier getOidOfGuidAlternative(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("Attribute " + attribute.getName() + " does not have the \"singleindex\" annotation");
	}
	return null;
}
 
Example 8
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends IdEObject> T querySingle(EAttribute attribute, Object value, int pid, int rid) throws BimserverLockConflictException, BimserverDatabaseException {
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + attribute.getEContainingClass().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);
		}
		boolean perRecordVersioning = perRecordVersioning(attribute.getEContainingClass());
		if (!perRecordVersioning) {
			ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
			valueBuffer.putInt(pid);
			valueBuffer.putInt(-rid);
			valueBuffer.put(queryBytes);
			queryBytes = valueBuffer.array();
		}
		byte[] firstDuplicate = database.getKeyValueStore().get(indexTableName, queryBytes, this);
		if (firstDuplicate != null) {
			ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			return (T) get(oid, OldQuery.getDefault());
		}
	} else {
		throw new UnsupportedOperationException(attribute.getContainerClass().getName() + "." + attribute.getName() + " does not have a \"singleindex\"");
	}
	return null;
}
 
Example 9
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;
}
 
Example 10
Source File: StringAttributeParser.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected String createEmptyStringLabel(EAttribute attribute) {
	return "<" + attribute.getName() + ">";
}