org.eclipse.emf.ecore.EFactory Java Examples

The following examples show how to use org.eclipse.emf.ecore.EFactory. 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: SerializationUtilTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFillIdToEObjectMap() {
	EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
	EClass root = createEClass(pack, "Root");
	EClass someType = createEClass(pack, "SomeType");

	EReference ref1 = addEReference(root, someType, "ref1", false);
	EReference ref2 = addEReference(root, someType, "ref2", true);

	EFactory factory = pack.getEFactoryInstance();
	EObject rootObject = factory.create(root);
	EObject someTypeObject1 = factory.create(someType);
	EObject someTypeObject2 = factory.create(someType);
	rootObject.eSet(ref1, someTypeObject1);
	rootObject.eSet(ref2, someTypeObject2);

	List<EObject> map = new ArrayList<>();
	SerializationUtil.fillIdToEObjectMap(rootObject, map);
	assertTrue(map.contains(rootObject));
	assertTrue(map.contains(someTypeObject1));
	assertFalse(map.contains(someTypeObject2));
	assertEquals(2, map.size());
}
 
Example #2
Source File: AbstractTypeProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void init() {
  EcoreFactory modelFactory = EcoreFactory.eINSTANCE;
  testModelPackage = modelFactory.createEPackage();
  testModelPackage.setName("TypeProviderTestEPackage");
  testModelPackage.setNsPrefix("typeprovidertestpackage");
  testModelPackage.setNsURI("http://testabstracttype");
  EFactory instanceFactory = testModelPackage.getEFactoryInstance();
  EClass clazz = createEClass("ExpressionContainer");
  expressionContainerReference = modelFactory.createEReference();
  clazz.getEStructuralFeatures().add(expressionContainerReference);
  expressionContainerReference.setName("expression");
  expressionContainerReference.setEType(typeModelPackage.getIExpression());
  expressionContainerReference.setContainment(true);
  expression1Container = instanceFactory.create(clazz);
  expression1Container.eSet(expressionContainerReference, expression1);
  expression2Container = instanceFactory.create(clazz);
  expression2Container.eSet(expressionContainerReference, expression2);
  expression3Container = instanceFactory.create(clazz);
  expression3Container.eSet(expressionContainerReference, expression3);
}
 
Example #3
Source File: FactoryHelper.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void registerFactory(IConfigurationElement configurationElement) {
	try {
		final String nsURI = configurationElement.getAttribute(NS_URI);
		final String bundle = configurationElement.getContributor().getName();
		final String className = configurationElement.getAttribute(CLASS);
		final Class<? extends EFactory> clazz = loadClass(bundle, className);
		if (nsURI == null || clazz == null) {
			return;
		}
		final boolean useWildcards = Boolean.parseBoolean(configurationElement.getAttribute(USE_WILDCARDS));
		nsURIToFactoryMap.put(nsURI, clazz);
		wildcardsUsageMap.put(nsURI, useWildcards);
	} catch (final ClassNotFoundException e) {
		MigrationPlugin.INSTANCE.log(e);
	}

}
 
Example #4
Source File: FactoryHelper.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link EFactory} registered for the given nsURI, taking wildcards into account, if such a factory
 * exists.
 *
 * @param nsURI
 * @return if there exists a factory registered for a matching nsURI, without any wildcards, it will be returned
 *         first. Otherwise, the method will return the first factory that it can match (using wildcards) to the
 *         given nsURI
 *         May return null.
 */
private Class<? extends EFactory> getEFactoryFromMap(String nsURI) {
	if (nsURI == null) {
		return null;
	}
	// if we have an exact match, that doesn't use wildcards, return the value from the factory map
	if (wildcardsUsageMap.get(nsURI) != null && !wildcardsUsageMap.get(nsURI)) {
		return nsURIToFactoryMap.get(nsURI);
	}
	// else, search if we can find a match using wildcards
	// if multiple matches exist, the first one will be returned
	for (final String uri : wildcardsUsageMap.keySet()) {
		if (wildcardsUsageMap.get(uri) && nsURI.matches(uri.replace("*", ".*"))) { //$NON-NLS-1$ //$NON-NLS-2$
			return nsURIToFactoryMap.get(uri);
		}
	}
	// fallback to factory map
	return nsURIToFactoryMap.get(nsURI);
}
 
Example #5
Source File: DotEObjectFormatter.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
protected String formatAttributeValue(EObject object, EAttribute feature,
		Object value) {
	if (value == null)
		return "null";
	EFactory factory = feature.getEAttributeType().getEPackage()
			.getEFactoryInstance();
	String stringVal = factory.convertToString(feature.getEAttributeType(),
			value);
	return "'" + stringVal + "'";
}
 
Example #6
Source File: FactoryHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static Class<? extends EFactory> loadClass(String bundleName,
	String clazz) throws ClassNotFoundException {
	final Bundle bundle = Platform.getBundle(bundleName);
	if (bundle == null) {
		MigrationPlugin.INSTANCE.log("Could not get bundle " + bundleName + " from platform."); //$NON-NLS-1$ //$NON-NLS-2$
	}
	return (Class<? extends EFactory>) bundle.loadClass(clazz);
}
 
Example #7
Source File: WFGraphExtension.java    From graphical-lsp with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public EFactory getEFactory() {
	return WfgraphFactory.eINSTANCE;
}
 
Example #8
Source File: SimpleAttributeResolverTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testGetUnknownValue() {
	EFactory fact = factory.createEFactory();
	String name = nameResolver.getValue(fact);
	assertNull(name);
}
 
Example #9
Source File: ReleaseUtils.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public EFactory getEFactory(String nsURI) {
	return delegate.getEFactory(nsURI);
}
 
Example #10
Source File: FactoryHelper.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private FactoryHelper() {
	nsURIToFactoryMap = new LinkedHashMap<String, Class<? extends EFactory>>();
	wildcardsUsageMap = new HashMap<String, Boolean>();
	readExtensionPoint();
}
 
Example #11
Source File: GraphExtension.java    From graphical-lsp with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the EFactory for this {@link GraphExtension}
 * 
 * @return
 */
EFactory getEFactory();