/** * Configure the resource set in the same manner as the software model extractor. * * @param cacheFileDirs * The cache directories. * @param jarPaths * The jar files to register. * @return The prepared resource set. */ private ResourceSet prepareResourceSetAsDoneByExtractor(List<String> cacheFileDirs, List<String> jarPaths) { ResourceSet rs = new SPLevoResourceSet(); Map<Object, Object> options = rs.getLoadOptions(); options.put(JavaClasspath.OPTION_USE_LOCAL_CLASSPATH, Boolean.TRUE); options.put(JavaClasspath.OPTION_REGISTER_STD_LIB, Boolean.TRUE); options.put(IJavaOptions.DISABLE_LAYOUT_INFORMATION_RECORDING, Boolean.TRUE); options.put(IJavaOptions.DISABLE_LOCATION_MAP, Boolean.TRUE); Factory originalFactory = new JavaSourceOrClassFileResourceFactoryImpl(); EPackage.Registry.INSTANCE.put("http://www.emftext.org/java", JavaPackage.eINSTANCE); JavaClasspath javaClasspath = JavaClasspath.get(rs); Map<String, Object> factoryMap = rs.getResourceFactoryRegistry().getExtensionToFactoryMap(); for (String jarPath : jarPaths) { javaClasspath.registerClassifierJar(URI.createFileURI(jarPath)); } factoryMap.put("java", new JavaSourceOrClassFileResourceCachingFactoryImpl(originalFactory, cacheFileDirs)); return rs; }
private void initResourceSet(ResourceSet rs, List<String> sourceModelPaths, boolean loadLayoutInformation) { final Boolean disableLayoutOption = loadLayoutInformation ? Boolean.FALSE : Boolean.TRUE; final Map<Object, Object> options = rs.getLoadOptions(); options.put(JavaClasspath.OPTION_USE_LOCAL_CLASSPATH, Boolean.TRUE); options.put(JavaClasspath.OPTION_REGISTER_STD_LIB, Boolean.TRUE); options.put(IJavaOptions.DISABLE_EMF_VALIDATION, Boolean.TRUE); options.put(IJavaOptions.DISABLE_LAYOUT_INFORMATION_RECORDING, disableLayoutOption); options.put(IJavaOptions.DISABLE_LOCATION_MAP, disableLayoutOption); options.put(ResourceHandlingOptions.USE_PLATFORM_RESOURCE, ResourceHandlingOptions.USE_PLATFORM_RESOURCE.getDefault()); Factory originalFactory = new JavaSourceOrClassFileResourceFactoryImpl(); Factory cachedJaMoPPFactory = new JavaSourceOrClassFileResourceCachingFactoryImpl(originalFactory, sourceModelPaths); JavaClasspath.get(rs); Map<String, Object> factoryMap = rs.getResourceFactoryRegistry().getExtensionToFactoryMap(); factoryMap.put("java", cachedJaMoPPFactory); // DesignDecision No caching for byte code resources to improve performance factoryMap.put("class", originalFactory); }
/** * Initializes OCL Pivot in case this is used by a metamodel. */ private static void initializeOCL() { // Register Pivot globally (resourceSet == null). org.eclipse.ocl.examples.pivot.OCL.initialize(null); String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT; EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLInvocationDelegateFactory.Global()); EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLSettingDelegateFactory.Global()); EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI, new OCLValidationDelegateFactory.Global()); OCLinEcoreStandaloneSetup.doSetup(); org.eclipse.ocl.examples.pivot.model.OCLstdlib.install(); }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionPlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new eu.hyvar.feature.expression.resource.hyexpression.util.HyexpressionRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new eu.hyvar.feature.expression.resource.hyexpression.util.HyexpressionRuntimeUtil().isEclipsePlatformAvailable()) { new eu.hyvar.feature.expression.resource.hyexpression.util.HyexpressionEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionResourceFactory()); } }
public Factory getFactoryForURI(URI uri) { URI trimmedURI = uri.trimFileExtension(); String secondaryFileExtension = trimmedURI.fileExtension(); Factory factory = factories.get(secondaryFileExtension); if (factory == null) { factory = factories.get(""); } return factory; }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestPlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new eu.hyvar.mspl.manifest.resource.hymanifest.util.HymanifestRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new eu.hyvar.mspl.manifest.resource.hymanifest.util.HymanifestRuntimeUtil().isEclipsePlatformAvailable()) { new eu.hyvar.mspl.manifest.resource.hymanifest.util.HymanifestEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestResourceFactory()); } }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingPlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new eu.hyvar.feature.mapping.resource.hymapping.util.HymappingRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new eu.hyvar.feature.mapping.resource.hymapping.util.HymappingRuntimeUtil().isEclipsePlatformAvailable()) { new eu.hyvar.feature.mapping.resource.hymapping.util.HymappingEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingResourceFactory()); } }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsPlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new eu.hyvar.feature.constraint.resource.hyconstraints.util.HyconstraintsRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new eu.hyvar.feature.constraint.resource.hyconstraints.util.HyconstraintsRuntimeUtil().isEclipsePlatformAvailable()) { new eu.hyvar.feature.constraint.resource.hyconstraints.util.HyconstraintsEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsResourceFactory()); } }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(eu.hyvar.context.contextValidity.resource.hyvalidityformula.mopp.HyvalidityformulaPlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new eu.hyvar.context.contextValidity.resource.hyvalidityformula.util.HyvalidityformulaRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new eu.hyvar.context.contextValidity.resource.hyvalidityformula.util.HyvalidityformulaRuntimeUtil().isEclipsePlatformAvailable()) { new eu.hyvar.context.contextValidity.resource.hyvalidityformula.util.HyvalidityformulaEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new eu.hyvar.context.contextValidity.resource.hyvalidityformula.mopp.HyvalidityformulaResourceFactory()); } }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavaluePlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new eu.hyvar.dataValues.resource.hydatavalue.util.HydatavalueRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new eu.hyvar.dataValues.resource.hydatavalue.util.HydatavalueRuntimeUtil().isEclipsePlatformAvailable()) { new eu.hyvar.dataValues.resource.hydatavalue.util.HydatavalueEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavalueResourceFactory()); } }
/** * Adds all registered resource factory extensions to the given map. Such * extensions can be used to register multiple resource factories for the same * file extension. */ public void getResourceFactoryExtensions(Map<String, Factory> factories) { if (Platform.isRunning()) { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IConfigurationElement configurationElements[] = extensionRegistry.getConfigurationElementsFor(de.darwinspl.preferences.resource.dwprofile.mopp.DwprofilePlugin.EP_ADDITIONAL_EXTENSION_PARSER_ID); for (IConfigurationElement element : configurationElements) { try { String type = element.getAttribute("type"); Resource.Factory factory = (Resource.Factory) element.createExecutableExtension("class"); if (type == null) { type = ""; } Resource.Factory otherFactory = factories.get(type); if (otherFactory != null) { Class<?> superClass = factory.getClass().getSuperclass(); while(superClass != Object.class) { if (superClass.equals(otherFactory.getClass())) { factories.put(type, factory); break; } superClass = superClass.getClass(); } } else { factories.put(type, factory); } } catch (CoreException ce) { new de.darwinspl.preferences.resource.dwprofile.util.DwprofileRuntimeUtil().logError("Exception while getting default options.", ce); } } } }
protected void init() { if (factories == null) { factories = new LinkedHashMap<String, Factory>(); } if (new de.darwinspl.preferences.resource.dwprofile.util.DwprofileRuntimeUtil().isEclipsePlatformAvailable()) { new de.darwinspl.preferences.resource.dwprofile.util.DwprofileEclipseProxy().getResourceFactoryExtensions(factories); } if (factories.get("") == null) { factories.put("", new de.darwinspl.preferences.resource.dwprofile.mopp.DwprofileResourceFactory()); } }
private Resource reload(IFile file) { final URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); Factory factory = ResourceFactoryRegistryImpl.INSTANCE.getFactory(uri); Resource resource = factory.createResource(uri); ResourceSet resourceSet = new ResourceSetImpl(); TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet); resourceSet.getResources().add(resource); try { resource.load(Collections.EMPTY_MAP); } catch (IOException e) { throw new IllegalStateException("Error loading resource", e); } return resource; }
public static Resource loadResource(String filename) { URI uri = URI.createPlatformResourceURI(filename, true); Factory factory = ResourceFactoryRegistryImpl.INSTANCE.getFactory(uri); Resource resource = factory.createResource(uri); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResources().add(resource); try { resource.load(Collections.EMPTY_MAP); return resource; } catch (IOException e) { throw new IllegalStateException("Error loading resource", e); } }
public Factory getFactory(URI uri, String contentType) { String fileExtensionToCheck = getFileExtension(uri); if (shallForwardToExtensionMap(fileExtensionToCheck)) { return (Factory) registry.getExtensionToFactoryMap().get(fileExtensionToCheck); } return registry.getFactory(uri, contentType); }
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 static Resource copy(final Factory factory, final Resource resource) { final Resource newResource = factory.createResource(resource.getURI()); newResource.setTimeStamp(resource.getTimeStamp()); newResource.setModified(resource.isModified()); newResource.getContents().addAll(EcoreUtil.copyAll(resource.getContents())); return newResource; }
public Map<String, Factory> getResourceFactoriesMap() { return factories; }
public Factory createResourceFactory() { return new eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionResourceFactory(); }
public void registerResourceFactory() { // if no resource factory registered, register delegator if (Factory.Registry.INSTANCE.getExtensionToFactoryMap().get(getSyntaxName()) == null) { Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(getSyntaxName(), new eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionResourceFactoryDelegator()); } }
public Factory createResourceFactory() { return new eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestResourceFactory(); }
public void registerResourceFactory() { // if no resource factory registered, register delegator if (Factory.Registry.INSTANCE.getExtensionToFactoryMap().get(getSyntaxName()) == null) { Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(getSyntaxName(), new eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestResourceFactoryDelegator()); } }
public Factory createResourceFactory() { return new eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingResourceFactory(); }
public void registerResourceFactory() { // if no resource factory registered, register delegator if (Factory.Registry.INSTANCE.getExtensionToFactoryMap().get(getSyntaxName()) == null) { Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(getSyntaxName(), new eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingResourceFactoryDelegator()); } }