类org.eclipse.emf.ecore.EFactory源码实例Demo

下面列出了怎么用org.eclipse.emf.ecore.EFactory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-core   文件: SerializationUtilTest.java
@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());
}
 
源代码2 项目: dsl-devkit   文件: AbstractTypeProviderTest.java
@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);
}
 
源代码3 项目: bonita-studio   文件: FactoryHelper.java
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);
	}

}
 
源代码4 项目: bonita-studio   文件: FactoryHelper.java
/**
 * 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);
}
 
源代码5 项目: gef   文件: DotEObjectFormatter.java
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 + "'";
}
 
源代码6 项目: bonita-studio   文件: FactoryHelper.java
@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);
}
 
源代码7 项目: graphical-lsp   文件: WFGraphExtension.java
@Override
public EFactory getEFactory() {
	return WfgraphFactory.eINSTANCE;
}
 
源代码8 项目: xtext-core   文件: SimpleAttributeResolverTest.java
@Test public void testGetUnknownValue() {
	EFactory fact = factory.createEFactory();
	String name = nameResolver.getValue(fact);
	assertNull(name);
}
 
源代码9 项目: bonita-studio   文件: ReleaseUtils.java
/** {@inheritDoc} */
@Override
public EFactory getEFactory(String nsURI) {
	return delegate.getEFactory(nsURI);
}
 
源代码10 项目: bonita-studio   文件: FactoryHelper.java
private FactoryHelper() {
	nsURIToFactoryMap = new LinkedHashMap<String, Class<? extends EFactory>>();
	wildcardsUsageMap = new HashMap<String, Boolean>();
	readExtensionPoint();
}
 
源代码11 项目: graphical-lsp   文件: GraphExtension.java
/**
 * Returns the EFactory for this {@link GraphExtension}
 * 
 * @return
 */
EFactory getEFactory();
 
 类所在包
 类方法
 同包方法