private String lazyMetamodelRegistration(String metamodelPath){ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); ResourceSet rs = new ResourceSetImpl(); // Enables extended meta-data, weird we have to do this but well... final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(EPackage.Registry.INSTANCE); rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); Resource r = rs.getResource(URI.createFileURI(metamodelPath), true); EObject eObject = r.getContents().get(0); // A meta-model might have multiple packages we assume the main package is the first one listed if (eObject instanceof EPackage) { EPackage p = (EPackage)eObject; System.out.println(p.getNsURI()); EPackage.Registry.INSTANCE.put(p.getNsURI(), p); return p.getNsURI(); } return null; }
/** * @throws ParseException */ @Override protected Object getJavaObjectFromTrimmed(String string, Object defaultObject) throws ParseException { try { if (eDataType.getInstanceClassName() != null && eDataType.getInstanceClassName().equalsIgnoreCase(BigDecimal.class.getName())) { double value = Double.parseDouble(string); BasicExtendedMetaData bemd = new BasicExtendedMetaData(); int factionDigits = bemd.getFractionDigitsFacet(eDataType); String minInclusiveString = bemd.getMinInclusiveFacet(eDataType); if (minInclusiveString != null) { int minInclusive = Integer.parseInt(minInclusiveString); if (value < minInclusive) { value = 360 - Math.abs(value); // See SPF-9712 } } return eFactoryInstance.createFromString(eDataType, String.format("%." + factionDigits + "f", value)); } return eFactoryInstance.createFromString(eDataType, string); } catch (Exception e) { if (e instanceof ParseException) { throw (ParseException) e; } throw new ParseException(e.getMessage(), 0); } }
/** * 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); }
/** * Creates an instance of the resource factory. <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated */ public persistenceResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, persistencePackage.eINSTANCE); }
public ModelLoader() { resourceSet = new ResourceSetImpl(); final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(resourceSet.getPackageRegistry()); resourceSet.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); }
public static void init(ResourceSet resourceSet, String path) { Resource_Set = resourceSet; Extended_Meta_Data = new BasicExtendedMetaData(resourceSet.getPackageRegistry()); Package_Map = new HashMap<String, EPackage>(); Text_Attribute = (EAttribute) XMLTypeFactory.eINSTANCE.createXMLTypeDocumentRoot().eClass().getEStructuralFeature("text"); Path = path; }
public static EPackage readEcore (String ecorePath) { ResourceSet ecoreResourceSet = new ResourceSetImpl(); URI ecoreURI = URI.createFileURI(ecorePath); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); ecoreResourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(ecoreResourceSet.getPackageRegistry()); ecoreResourceSet.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); Resource ecoreResource = ecoreResourceSet.getResource(ecoreURI,true); EPackage ecoremodel = (EPackage) ecoreResource.getContents().get(0); ecoreResource.getResourceSet().getPackageRegistry().put(ecoremodel.getNsURI(),ecoremodel); EPackage.Registry.INSTANCE.put(ecoremodel.getNsURI(), ecoremodel); return ecoremodel; }
/** * Loads the EMF representation of a Simulink model. * * @param fileNameWithoutExtension * the file to load specified by its name * @return the loaded SimulinkModel root EMF model object * @throws SimulinkApiException */ public SimulinkModel loadSimulinkModel(String fileNameWithoutExtension) throws SimulinkApiException { // Register a resource factory for the extension "simulink" Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; Map<String, Object> m = reg.getExtensionToFactoryMap(); m.put("simulink", new XMIResourceFactoryImpl()); // Obtain a new resource set ResourceSet rs = new ResourceSetImpl(); final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry()); rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); // The model will be saved to the root of the project for now under the // given name. // TODO save path may come from an extension or properties file String path = fileNameWithoutExtension + ".simulink"; // Load the resource Resource loadResource = rs.getResource(URI.createURI(path), true); Object resourceContent = loadResource.getContents().get(0); // Make a log entry if the root object isn't a SimulinkModel if (!(resourceContent instanceof SimulinkModel)) logger.error("The given resource contained no SimulinkModel as a root element!"); // Return the root EMF model object // Also throws an exception when invalid cast occurs return (SimulinkModel) resourceContent; }
@Before public void setup() { // We need the TOGAF model for some of the tests, but the plugin has no update site. // Instead, we use the Ecore file in resources/metamodels. However, while EMFViews works // with the Ecore file, the code in EclDelegate assumes that metamodels are registered in // the EMF package registry. // // To work around this issue, we load the EPackage from the Ecore file into the package registry. // // See: https://stackoverflow.com/a/9389901 Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap() .put("ecore", new EcoreResourceFactoryImpl()); ResourceSet rs = new ResourceSetImpl(); // enable extended metadata final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry()); rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); Resource r = rs.getResource(resourceURI("metamodels/contentfwk.ecore"), true); EObject eObject = r.getContents().get(0); if (eObject instanceof EPackage) { EPackage p = (EPackage) eObject; EPackage.Registry.INSTANCE.put(p.getNsURI(), p); } else { throw new IllegalStateException("Error loading TOGAF metamodel for testing"); } }
public BasicExtendedMetaData.EPackageExtendedMetaData getExtendedMetaData() { return ePackageExtendedMetaData; }
public void setExtendedMetaData(BasicExtendedMetaData.EPackageExtendedMetaData ePackageExtendedMetaData) { this.ePackageExtendedMetaData = ePackageExtendedMetaData; }
public BasicExtendedMetaData.EClassifierExtendedMetaData getExtendedMetaData() { return eClassifierExtendedMetaData; }
public void setExtendedMetaData(BasicExtendedMetaData.EClassifierExtendedMetaData eClassifierExtendedMetaData) { this.eClassifierExtendedMetaData = eClassifierExtendedMetaData; }
public BasicExtendedMetaData.EStructuralFeatureExtendedMetaData getExtendedMetaData() { return eStructuralFeatureExtendedMetaData; }
public void setExtendedMetaData(BasicExtendedMetaData.EStructuralFeatureExtendedMetaData eStructuralFeatureExtendedMetaData) { this.eStructuralFeatureExtendedMetaData = eStructuralFeatureExtendedMetaData; }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public BeansResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, BeansPackage.eINSTANCE); }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Qt48XmlschemaQwtEnhancedResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, Qt48XmlschemaQwtEnhancedPackage.eINSTANCE); }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Qt48XmlSchemaResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, Qt48XmlSchemaPackage.eINSTANCE); }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Qt48XmlschemaResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, Qt48XmlschemaPackage.eINSTANCE); }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EsmConfigResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, EsmConfigPackage.eINSTANCE); }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NupnResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, NupnPackage.eINSTANCE); }
/** * Creates an instance of the resource factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public CatalogResourceFactoryImpl() { super(); extendedMetaData = new BasicExtendedMetaData(new EPackageRegistryImpl(EPackage.Registry.INSTANCE)); extendedMetaData.putPackage(null, CatalogPackage.eINSTANCE); }