本文整理汇总了Java中org.eclipse.emf.ecore.EPackage.Registry类的典型用法代码示例。如果您正苦于以下问题:Java Registry类的具体用法?Java Registry怎么用?Java Registry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Registry类属于org.eclipse.emf.ecore.EPackage包,在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registSysMLPackages
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Register all the SysML default packages
*
* @param packageRegistry
*/
private void registSysMLPackages(Registry packageRegistry) {
// Register all default SYSML packages
packageRegistry.put(SysmlPackage.eNS_URI, SysmlPackage.eINSTANCE);
packageRegistry.put(ActivitiesPackage.eNS_URI, ActivitiesPackage.eINSTANCE);
packageRegistry.put(AllocationsPackage.eNS_URI, AllocationsPackage.eINSTANCE);
packageRegistry.put(BlocksPackage.eNS_URI, BlocksPackage.eINSTANCE);
packageRegistry.put(ConstraintsPackage.eNS_URI, ConstraintsPackage.eINSTANCE);
packageRegistry.put(InteractionsPackage.eNS_URI, InteractionsPackage.eINSTANCE);
packageRegistry.put(ModelelementsPackage.eNS_URI, ModelelementsPackage.eINSTANCE);
packageRegistry.put(PortandflowsPackage.eNS_URI, PortandflowsPackage.eINSTANCE);
packageRegistry.put(RequirementsPackage.eNS_URI, RequirementsPackage.eINSTANCE);
packageRegistry.put(StatemachinesPackage.eNS_URI, StatemachinesPackage.eINSTANCE);
packageRegistry.put(UsecasesPackage.eNS_URI, UsecasesPackage.eINSTANCE);
packageRegistry.put(UsecasesPackage.eNS_URI, UsecasesPackage.eINSTANCE);
}
示例2: testExternalFormOfEReference
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
@Test public void testExternalFormOfEReference() throws Exception {
Registry registry = EPackage.Registry.INSTANCE;
Set<String> uris = Sets.newHashSet(registry.keySet());
for (String string : uris) {
EPackage ePackage = registry.getEPackage(string);
TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(ePackage, true);
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof EReference) {
EReference ref = (EReference) next;
String externalForm = EcoreUtil2.toExternalForm(ref);
assertEquals(ref.toString() + " - " + externalForm, ref, EcoreUtil2.getEReferenceFromExternalForm(registry,externalForm));
}
}
}
}
示例3: testExternalFormOfEReferenceNoNPE
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* This test assumes that an EPackage with indexed references is no longer available.
*/
@Test public void testExternalFormOfEReferenceNoNPE() throws Exception {
EReference reference = EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE;
URI uri = EcoreUtil.getURI(reference);
String externalForm = uri.toString();
EReference foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, externalForm);
assertSame(reference, foundReference);
String brokenExternalFrom = makeInvalid(externalForm);
assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenExternalFrom));
String shortExternalForm = EcoreUtil2.toExternalForm(reference);
foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, shortExternalForm);
assertSame(reference, foundReference);
String brokenShortExternalFrom = makeInvalid(shortExternalForm);
assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
brokenShortExternalFrom = shortExternalForm.replace('A', 'a');
assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
}
示例4: handle
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
private void handle(final HawkModelElementAdditionEvent ev) {
final Registry registry = getResourceSet().getPackageRegistry();
final EClass eClass = HawkResourceImpl.getEClass(ev.metamodelURI, ev.typeName, registry);
final EObject existing = nodeIdToEObjectMap.get(ev.id);
if (existing == null) {
final EObject eob = createInstance(eClass);
nodeIdToEObjectMap.put(ev.id, eob);
synchronized(classToEObjectsMap) {
final EList<EObject> instances = classToEObjectsMap.get(eClass);
if (instances != null) {
instances.add(eob);
}
}
addToResource(ev.vcsItem.repoURL, ev.vcsItem.path, eob);
LOGGER.debug("Added a new {} with ID {}", eob.eClass().getName(), ev.id);
instanceInserted(eob, eob.eClass());
} else {
LOGGER.warn("We already have a {} with ID {}: cannot create a {} there", existing.eClass().getName(), ev.id, eClass.getName());
}
}
示例5: getEClass
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
private static EClass getEClass(final String metamodelUri, final String typeName,
final Registry packageRegistry) {
final EPackage pkg = packageRegistry.getEPackage(metamodelUri);
if (pkg == null) {
throw new NoSuchElementException(String.format(
"Could not find EPackage with URI '%s' in the registry",
metamodelUri));
}
final EClassifier eClassifier = pkg.getEClassifier(typeName);
if (!(eClassifier instanceof EClass)) {
throw new NoSuchElementException(String.format(
"Received an element of type '%s', which is not an EClass",
eClassifier));
}
final EClass eClass = (EClass) eClassifier;
return eClass;
}
示例6: getEClass
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
private static EClass getEClass(final String metamodelUri, final String typeName,
final Registry packageRegistry) {
final EPackage pkg = packageRegistry.getEPackage(metamodelUri);
if (pkg == null) {
throw new NoSuchElementException(String.format(
"Could not find EPackage with URI '%s' in the registry %s",
metamodelUri, packageRegistry));
}
final EClassifier eClassifier = pkg.getEClassifier(typeName);
if (!(eClassifier instanceof EClass)) {
throw new NoSuchElementException(String.format(
"Received an element of type '%s', which is not an EClass",
eClassifier));
}
final EClass eClass = (EClass) eClassifier;
return eClass;
}
示例7: registerEPackageFromEcore
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Registers a EPackage in {@link Registry} according to its {@code prefix} and {@code uri}, from an Ecore file.
* <p>
* The targeted Ecore file must be present in {@code /resources/ecore}.
*/
protected static void registerEPackageFromEcore(String prefix, String uri) {
File file = getResourceFile(ECORE_PATH.replaceAll("\\{name\\}", prefix));
EPackage ePackage = null;
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(ECORE, new EcoreResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry());
rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
Resource r = rs.getResource(URI.createFileURI(file.toString()), true);
EObject eObject = r.getContents().get(0);
if (eObject instanceof EPackage) {
ePackage = (EPackage) eObject;
rs.getPackageRegistry().put(ePackage.getNsURI(), ePackage);
}
assertThat(ePackage).isNotNull(); // "EPackage does not exist"
Registry.INSTANCE.put(uri, ePackage);
}
示例8: getAvailablePackages
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Gets all available EPackages from the EPackageRegistry.
*
* @param filterKnown weather known packages should be filtered or not.
* @return the available packages
*
*/
public static Set<EPackage> getAvailablePackages(boolean filterKnown) {
Registry registry = EPackage.Registry.INSTANCE;
HashSet<Entry<String, Object>> entries = new LinkedHashSet<Entry<String, Object>>(registry.entrySet());
Set<EPackage> packages = new LinkedHashSet<EPackage>();
for (Entry<String, Object> entry : entries) {
if (!filterKnown || !isKnownPackage(entry.getKey())) {
try {
EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(entry.getKey());
packages.add(ePackage);
// BEGIN SUPRESS CATCH EXCEPTION
} catch (RuntimeException e) {
// END SUPRESS CATCH EXCEPTION
WorkspaceUtil.logWarning("Failed to load EPackage", e);
}
}
}
return packages;
}
示例9: getAllEClasses
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Iterates over all registered EPackages in order to retrieve all available
* EClasses, excluding abstract classes and interfaces, and returns them as
* a Set.
*
* @return a set of all EClasses that are contained in registered EPackages
* @see Registry
*/
public List<EClass> getAllEClasses() {
if (allEClasses == null) {
allEClasses = new ArrayList<EClass>();
Registry registry = EPackage.Registry.INSTANCE;
// for all registered EPackages
for (Entry<String, Object> entry : new LinkedHashSet<Entry<String, Object>>(registry.entrySet())) {
EPackage ePackage = registry.getEPackage(entry.getKey());
for (EClass eClass : getAllEClasses(ePackage)) {
// no abstracts or interfaces
if (canHaveInstance(eClass)) {
allEClasses.add(eClass);
}
}
}
}
return allEClasses;
}
示例10: getAllModelElementEClasses
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Retrieve all EClasses from the ECore package registry.
*
* @return a set of EClasses
*/
public static Set<EClass> getAllModelElementEClasses() {
if (registryEClasses != null) {
return new LinkedHashSet<EClass>(registryEClasses);
}
final Set<EClass> result = new LinkedHashSet<EClass>();
final Registry registry = EPackage.Registry.INSTANCE;
for (Entry<String, Object> entry : new LinkedHashSet<Entry<String, Object>>(registry.entrySet())) {
try {
final EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(entry.getKey());
result.addAll(getAllModelElementEClasses(ePackage));
}
// BEGIN SUPRESS CATCH EXCEPTION
catch (RuntimeException exception) {
Activator.getDefault().logException("Failed to load model package " + entry.getKey(), exception);
// END SUPRESS CATCH EXCEPTION
}
}
registryEClasses = result;
return result;
}
示例11: getAllRootEPackages
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Returns all EPackages on the root level that are currently registered in
* the registry.
*
* @return a Set of all root EPackages
* @see Registry
*/
public Set<EPackage> getAllRootEPackages() {
// were the root packages computed before?
if (rootModelPackages != null) {
return rootModelPackages;
}
rootModelPackages = new LinkedHashSet<EPackage>();
Registry registry = EPackage.Registry.INSTANCE;
for (Entry<String, Object> entry : registry.entrySet()) {
EPackage ePackage = registry.getEPackage(entry.getKey());
// is the current EPackage a root package?
if (ePackage.getESuperPackage() == null) {
rootModelPackages.add(ePackage);
}
}
return rootModelPackages;
}
示例12: getAllEClasses
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Iterates over all registered EPackages in order to retrieve all available
* EClasses, excluding abstract classes and interfaces, and returns them as
* a Set.
*
* @return a set of all EClasses that are contained in registered EPackages
* @see Registry
*/
public List<EClass> getAllEClasses() {
// were all EClasses computed before?
if (allEClasses != null) {
return allEClasses;
}
allEClasses = new LinkedList<EClass>();
Registry registry = EPackage.Registry.INSTANCE;
// for all registered EPackages
for (Entry<String, Object> entry : registry.entrySet()) {
EPackage ePackage = registry.getEPackage(entry.getKey());
for (EClass eClass : getAllEClasses(ePackage)) {
// no abstracts or interfaces
if (canHaveInstance(eClass)) {
allEClasses.add(eClass);
}
}
}
return allEClasses;
}
示例13: initResourceSet
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
/**
* Initialize the UML resourceSet and register all the packages by default
*
* @return resourceSet
* @throws IOException
*/
public ResourceSet initResourceSet() throws IOException {
String method = "InitResourceSet_initResourceSet(): ";
long startTime = System.currentTimeMillis();
MyLog.info(method + "start");
ResourceSet resourceSet = new ResourceSetImpl();
Registry packageRegistry = resourceSet.getPackageRegistry();
// Read the namespace configuration file
String namespaceConfigPath = FileLocator
.toFileURL(Activator.getDefault().getBundle().getEntry(NAMESPACE_CONFIG_FILE_PAHT)).getPath();
File namespaceConfigFile = new File(namespaceConfigPath);
Properties properties = new Properties();
properties.load(new FileInputStream(namespaceConfigFile));
// Load and register the self-definition namespaces
for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
packageRegistry.put(value, UMLPackage.eINSTANCE);
}
registSysMLPackages(packageRegistry);
// Add the load option
resourceSet.getLoadOptions().put(XMIResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
// Define the extension to factory map
Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
UMLResourceFactoryImpl umlResourceFactory = new UMLResourceFactoryImpl();
extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION, umlResourceFactory);
MyLog.info(method + "end with " + (System.currentTimeMillis() - startTime) + " millisecond");
MyLog.info();
return resourceSet;
}
示例14: testClone
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
@Test public void testClone() throws Exception {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
EPackage.Registry.INSTANCE.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE);
ResourceSetImpl rs = new ResourceSetImpl();
Resource r1 = rs.createResource(URI.createURI("foo.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
Resource r2 = rs.createResource(URI.createURI("bar.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
EClass a = EcoreFactory.eINSTANCE.createEClass();
a.setName("a");
EClass b = EcoreFactory.eINSTANCE.createEClass();
r1.getContents().add(a);
b.setName("b");
b.getESuperTypes().add(a);
r2.getContents().add(b);
ResourceSetImpl clone = EcoreUtil2.clone(new ResourceSetImpl(), rs);
EList<Resource> list = clone.getResources();
Resource resA = list.get(0);
assertEquals(URI.createURI("foo.xmi"),resA.getURI());
assertNotSame(resA, r1);
Resource resB = list.get(1);
assertEquals(URI.createURI("bar.xmi"),resB.getURI());
assertNotSame(resB, r2);
EClass a1 = (EClass)resA.getContents().get(0);
EClass b1 = (EClass)resB.getContents().get(0);
assertEquals("a", a1.getName());
assertNotSame(a, a1);
assertEquals("b", b1.getName());
assertNotSame(b, b1);
assertSame(b1.getESuperTypes().get(0),a1);
assertSame(b.getESuperTypes().get(0),a);
}
示例15: createEObject
import org.eclipse.emf.ecore.EPackage.Registry; //导入依赖的package包/类
private EObject createEObject(final ModelElement me) throws IOException {
final Registry registry = getResourceSet().getPackageRegistry();
final EClass eClass = getEClass(me.metamodelUri, me.typeName, registry);
final EObject obj = createInstance(eClass);
if (me.isSetId()) {
nodeIdToEObjectMap.put(me.id, obj);
synchronized(classToEObjectsMap) {
final EList<EObject> instances = classToEObjectsMap.get(eClass);
if (instances != null) {
instances.add(obj);
}
}
}
if (me.isSetAttributes()) {
final EFactory factory = registry.getEFactory(eClass.getEPackage().getNsURI());
for (final AttributeSlot s : me.attributes) {
SlotDecodingUtils.setFromSlot(factory, eClass, obj, s);
}
} else if (!descriptor.getLoadingMode().isGreedyAttributes()) {
getLazyResolver().putLazyAttributes(me.id, obj);
}
return obj;
}