MyDigitalLife

Development Notes

JavaFx

Avoiding “Access restriction: The type ‘Alert’ is not API (restriction on required library ‘C:\Program Files\Java\jdk1.8.0_73\jre\lib\ext\jfxrt.jar’)”

Background: Eclipse access restrictions
Eclipse has a mechanism called access restrictions to prevent you from accidentally using classes which Eclipse thinks are not part of the public API. Usually, Eclipse is right about that, in both senses: We usually do not want to use something which is not part of the public API. And Eclipse is usually right about what is and what isn’t part of the public API.

Problem
Now, there can be situations, where you want to use public Non-API, like sun.misc (you shouldn’t, unless you know what you’re doing). And there can be situations, where Eclipse is not really right (which is the case for ‘jfxrt.jar’). In that case, we get this error in Eclipse.

Solution
The solution is to change the access restrictions:

  • Go to the properties of the Java project, i.e. by selecting “Properties” from the context menu of the project in the “Package Explorer”.
  • Go to “Java Build Path”, tab “Libraries”.
  • Expand the library entry
  • select “Access rules”, “Edit…” and “Add…” a “Resolution: Accessible” with a corresponding rule pattern.
    In this case “javafx/**”.

EMF – Sirius – EcoreTools

Creating an Eclipse Modeling (maven) project

Don’t use ‘New Ecore Modeling Project’! This way you don’t have control over the name of the representations file (.aird file).
Suppose you want to create the following modeling project:
Project name: goedegep.finan.mortgage.model
Ecore Model file: Mortgage.ecore
Java package: goedegep.finan.mortgage.model
Instead:

  • Create a java project (File – New – Java Project).
    Project name: goedegep.finan.mortgage.model.
    On the page ‘Java Settings’, tab ‘Source’: delete the proposed ‘source folder’.
    On the page ‘Java Settings’, ‘Default output folder’: change ‘bin’ to ‘target’.
  • Create the ‘model’ directory.
  • Create the ecore model file, e.g. Mortgage.ecore.
    Set the following properties on the package in this file:
    Name: model (this determines the name of the source code package)
    Ns Prefix: mortgage
    Ns URI: http://www.goedegep.org/mortgage
  • Create the Sirius Representations File.
    Select ‘Initialization from a semantic resource’ and select the created ecore file. Give it the same name as the ecore file.
  • Now make it a Modeling Project via “Configure / Convert to Modeling Project”.
  • Create the first class diagram and start to create the model.
  • Create the EMF Generator Model file (.genmodel file). In this file make sure to set:
    on the model: Model / Model Directory: <project>/src/main/java
    on the package: All / Base Package to e.g. goedegep.finan.mortgage.
    on the package: All / Prefix to e.g. Mortgage (start with a capital, this determines the name of e.g. MortgageFactory.java)
  • If you’re not creating a plug-in, in the .genmodel file clear the field: Model / Model Plug-in ID.
  • Execute ‘Generate Model Code’.
  • Now make it a Maven Project via “Configure / Convert to Maven Project”.

Renaming an Eclipse Modeling (maven) project

  • Right click on the project and chose ‘Refactor/Rename’ and enter the new name.
  • Renaming the project, means that the folder name of the project changes, this isn’t updated in the top-level pom.
    In the top-level pom, under <modules>, change the project name (folder name) manually.
  • Renaming a project usually also means changing the maven groupId/artifactId.
    Change the groupId/artifactId in the top-level pom (where it is a <dependency>).
    Search in all pom files for the old groupId or artifactId and manually change them to the new values.
  • Renaming the model package
    Using refactoring, rename the package.
    Next update the model:

     

    • In the .ecore file update the ‘Name’ and ‘Ns URI’.
    • In the .genmodel file, top level, update the ‘Edit Directory’, ‘Edit Plug-in Class’, ‘Edit Plug-in ID’, ‘Editor Directory’,’Editor Plug-in Class’, ‘Editor Plug-in ID’, ‘Model Directory’, ‘Model Plug-in ID’, ‘Tests Plug-in ID’ and ‘Test Suite Class’.
    • In the .genmodel file, top level package, update the ‘Base Package, ‘Prefix’ and ‘Package’.

Generating an EMF model from an XSD file

Requirements
Use Eclipse Modeling, as this installation already includes all required features.

  • Create the EMF Project
    If you use Working Sets, select the Working Set to which you want to add the new project. This way the name of the Working Set will already be filled in in the wizard.
    Start an EMF Project wizard: New -> Other… -> Eclipse Modeling Framework -> EMF Project
    Enter your project name, e.g. ‘goedegep.gpx10.model’. I use ‘model’ for all EMF data model packages.
    If you use Working Sets, select the Working Set to which this project is to be added.
    Click 'Next' to go to the next page.
    From the Model Importers on this page, select XML Schema and click 'Next' to go to the next page.
    Enter a URI for the .xsd file to use, or select one via 'Browse File System ...' or 'Browse Workspace ...'. Press 'Load' to load the file. This will report any errors in loading the .xsd file.
    I don’t know what the option Create XML Schema to Ecore Map does, I don’t select it.
    Enter a Generator model file name, e.g. ‘GPX10.genmodel’. Note that the extension always has to be ‘.genmodel’.
    On the next page enter the File Name for the ecore file to be generated. Note that here you cannot change the package name!
    Click finish.
    You now have an Eclipse project (e.g. ‘goedegep.gpx10.model’), with in the ‘model’ folder an ecore model file (e.g. GPS10.ecore) and a genmodel file (e.g. ‘GPS10.genmodel’).
  • Update the ecore model file
    Open the ecore file and show the ‘Properties’ view.
    In the model select the package. This probably doesn’t have the name you want, so change it (e.g. to ‘model’). The same applies to the ‘Ns Prefix’.
  • Update the genmodel file
    Properties:
    • Model level – Model/Model directory
      Update to your project layout style. E.g. if you use maven set it to e.g. ‘/goedegep.gpx10.model/src/main/java’.
    • Model level If you’re not creating a plug-in, in the .genmodel file clear the field: Model / Model Plug-in ID.
    • Package level – All/Base Package
      Set this to name you want, e.g. ‘goedegep.gpx10’ (So the complete package name will be ‘goedegep.gpx10.model’).
    • Package level – All/Prefix
      This is the prefix for a.o. the Factory and Package classes. Set it e.g. to ‘GPX10’ to get ‘GPX10Factory.java’ and ‘GPX10Package.java’.
  • Create a Sirius Representations File
    This needed to create a class diagram.
    Select the ‘model’ folder, right click and chose New -> Other -> Sirius -> Representations File.
    Select ‘Initialization from a semantic resource’ and select your ecore file. Give the representations file the same name as the ecore file. Select the ‘Design’ viewpoint if you want to create a class diagram.
  • Convert your project to a ‘Modeling Project’
    Right click on your project and select ‘Configure -> Convert to Modeling Project’.
  • Generate the model code
    Select the model in the genmodel file, right click and select ‘Generate Model Code’.
    By now you have the model code!
  • Create a class diagram
    Double click on the representations file to open it.
    Click on ‘New…’ and select ‘Design/Entities in a Class Diagram’. Click ‘Next’, ‘Finish’ and enter the name of the class diagram file.
    When the diagram opens, you can double click in the top left corner to fill the diagram with all the classes of the model.
  • Making your project a maven project
    If you use maven this is the moment to make it a maven project.
    Right click on your project and select ‘Configure -> Convert to Maven Project’.

Using external models

If you use an external model, use “Reload…” from the context menu in the genmodel. The imported model should be ‘checked’ in the bottom half and ‘unchecked’ in the top half.

HTTP

Hypertext Transfer Protocol (HTTP) is an application-layer protocol for transmitting hypermedia documents, such as HTML. It was designed for communication between web browsers and web servers, but it can also be used for other purposes. HTTP follows a classical client-server model, with a client opening a connection to make a request, then waiting until it receives a response.
See https://developer.mozilla.org/en-US/docs/Web/HTTP for HTTP tutorials.