public static AdapterFactory getAdapterFactory(Object object) { EditingDomain domain = null; if (object instanceof EditingDomain) { domain = (EditingDomain) object; } else { domain = AdapterFactoryEditingDomain.getEditingDomainFor(object); } if (domain instanceof AdapterFactoryEditingDomain) { AdapterFactoryEditingDomain aDomain = (AdapterFactoryEditingDomain) domain; AdapterFactory adapterFactory = aDomain.getAdapterFactory(); if (adapterFactory != null) { return adapterFactory; } } return new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); }
public static Programme load(final String path) { try { Programme _xblockexpression = null; { ResourceSetImpl _resourceSetImpl = new ResourceSetImpl(); final ResourceSetImpl rs = _resourceSetImpl; RobotPackage.eINSTANCE.eClass(); Map<String,Object> _extensionToFactoryMap = Registry.INSTANCE.getExtensionToFactoryMap(); XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); URI _createURI = URI.createURI(path); final Resource res = rs.getResource(_createURI, true); Map<Object,Object> _emptyMap = Collections.<Object, Object>emptyMap(); res.load(_emptyMap); EList<EObject> _contents = res.getContents(); Iterable<Programme> _filter = Iterables.<Programme>filter(_contents, Programme.class); Programme _head = IterableExtensions.<Programme>head(_filter); _xblockexpression = (_head); } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
public FactoryWrapper(Registry registry) { super(); this.fileExtensions = FileExtensionRegistry.getInstance().getFileExtensions(); this.registry = registry; for (String fileExtension : fileExtensions) { registry.getExtensionToFactoryMap().put(fileExtension, new TextbasedCDOResourceFactoryImpl()); registry.getExtensionToFactoryMap().put( String.format("%s.%s", fileExtension, TextbasedCDOResourceFactoryImpl.getAdditionalFileExtension()), new TextbasedCDOResourceFactoryImpl()); } }
public static String convertToXML(EObject eObject, Map<String, Object> options) { List<? extends EObject> contents = Collections.singletonList(eObject); options.put(XMLResource.OPTION_ROOT_OBJECTS, contents); boolean temporaryResource = false; Resource resource = eObject.eResource(); EObject eRoot = null; if (resource == null || !(resource instanceof XMLResource)) { ResourceSet resourceSet = createResourceSet(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMLResourceFactoryImpl()); resource = resourceSet.createResource(URI.createURI("")); temporaryResource = true; eRoot = EcoreUtil.getRootContainer(eObject); resource.getContents().add(eRoot); } try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { resource.save(stream, options); String string; if (options.get(XMLResource.OPTION_ENCODING) != null) { string = stream.toString(options.get(XMLResource.OPTION_ENCODING).toString()); } else { string = stream.toString(); } return string; } catch (IOException e) { throw new IllegalStateException("Error converting " + eObject + " to string", e); } } finally { if (temporaryResource) { resource.getContents().remove(eRoot); } } }
public static EObject createFromXML(String xml) { ResourceSet resourceSet = createResourceSet(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMLResourceFactoryImpl()); Resource resource = resourceSet.createResource(URI.createURI("createFromString.xml")); InputStream stream = new ByteArrayInputStream(xml.getBytes()); try { resource.load(stream, null); } catch (IOException e) { throw new IllegalStateException("Error creating EObject from string " + xml, e); } return resource.getContents().remove(0); }
public static Resource copy(final Resource resource) { final ResourceSet set = resource.getResourceSet(); final Registry registry; if (set != null) registry = set.getResourceFactoryRegistry(); else registry = Registry.INSTANCE; final Factory factory = registry.getFactory(resource.getURI()); if (factory == null) throw new RuntimeException("No resource factory found for URI '" + resource.getURI() + "'"); return copy(factory, resource); }
public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { System.out.println("Starting XMI generation..."); final Registry registery = Registry.INSTANCE; final Map<String,Object> map = registery.getExtensionToFactoryMap(); XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); final XMIResourceFactoryImpl xmiRes = _xMIResourceFactoryImpl; map.put(LanguageGenerator.LANGUAGE_EXTENSION, xmiRes); ResourceSetImpl _resourceSetImpl = new ResourceSetImpl(); final ResourceSetImpl resSet = _resourceSetImpl; String _plus = (LanguageGenerator.GEN_PATH + File.separator); String _plus_1 = (_plus + LanguageGenerator.FILE_NAME); final URI uri = URI.createURI(_plus_1); final Resource res = resSet.createResource(uri); String _plus_2 = ("Resource created at \"" + LanguageGenerator.GEN_PATH); String _plus_3 = (_plus_2 + File.separator); String _plus_4 = (_plus_3 + LanguageGenerator.FILE_NAME); String _plus_5 = (_plus_4 + "\""); System.out.println(_plus_5); EList<EObject> _contents = res.getContents(); EList<EObject> _contents_1 = resource.getContents(); _contents.addAll(_contents_1); try { res.save(Collections.EMPTY_MAP); } catch (final Throwable _t) { if (_t instanceof IOException) { final IOException e = (IOException)_t; e.printStackTrace(); } else { throw Exceptions.sneakyThrow(_t); } } System.out.println("Generation completed"); }
public static FactoryWrapper createFactoryWrapper(Registry registry) { return new FactoryWrapper(registry); }
/** * Invoke this after creating a dynamic package and all its classes to * ensure that: * * a) all feature IDs are set before CDO creates parallel CDOFeatures for * them * * b) the package is registered globally so that it is available for sharing * * This fixes the -1 ArrayIndexOutOfBoundsException problem when sharing * your model */ public static void finalizeDynamicModel(EPackage pkg) { try { ReflectionUtils.invoke(pkg, "fixEClassifiers"); } catch (Throwable t) { if (!CommonPlugin.isJunitRunning()) { LogUtil.error("error in finalization", t); } } EPackage.Registry.INSTANCE.put(pkg.getNsURI(), pkg); }