public static Resource loadRefModel(String refontoumlpath) throws IOException { ResourceSet rset = new ResourceSetImpl(); rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put("refontouml",new RefOntoUMLResourceFactoryImpl()); rset.getPackageRegistry().put(RefOntoUML.RefOntoUMLPackage.eNS_URI, RefOntoUML.RefOntoUMLPackage.eINSTANCE); File file = new File(refontoumlpath); URI fileURI = URI.createFileURI(file.getAbsolutePath()); Resource resource = rset.createResource(fileURI); /**Load options that significantly improved the performance of loading EMF Model instances*/ Map<Object,Object> loadOptions = ((XMLResourceImpl)resource).getDefaultLoadOptions(); loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl()); loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE); resource.load(loadOptions); return resource; }
/** * Delivers a map of options for loading resources. Especially {@link XMLResource#OPTION_DEFER_IDREF_RESOLUTION} * which speeds up loading * due to our id based resources. * * @return map of options for {@link XMIResource} or {@link XMLResource}. */ @SuppressWarnings("rawtypes") public static synchronized Map<Object, Object> getResourceLoadOptions() { if (resourceLoadOptions == null) { resourceLoadOptions = new LinkedHashMap<Object, Object>(); resourceLoadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE); resourceLoadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE); resourceLoadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE); resourceLoadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl()); resourceLoadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap()); resourceLoadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); resourceLoadOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); } return resourceLoadOptions; }
protected static Map<Object, Object> getLoadOptions(XMIResourceImpl resource) { Map<Object, Object> options = resource.getDefaultLoadOptions(); options.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE); options.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE); options.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.TRUE); options.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl()); options.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap<Object, Object>()); resource.setIntrinsicIDToEObjectMap(new HashMap<String, EObject>()); return options; }