Creating a Coins container

Uit COINS2
Ga naar: navigatie, zoeken

This page describes the most basic steps to make for exporting a Coins Container via programming. The code samples are made in C#. It is also possible to use other Microsoft DotNet languges. It is also possible to use the COINS 2.0 API from Java.

Download

You can find the Coins API on github-coins2.0-SDK.

Go to Release

Github1.jpg








Download the latest ZIP or Tar.gz file.

Github2.jpg








Unpack this in a folder. In the "dist" folder you find the important dll's that we use in the samples.

  • dist\sdk\dll, contains coins-api.dll and coins-cli.exe
  • dist\sdk\jar, contains coins-api.jar and coins-cli.jar
  • dist\library\dll, contains cbim.dll and qudt.dll
  • dist\library\jar, contains cbim.jar and qudt.jar

For C# we need the following files: coins-api.dll, cbim.dll and qudt.dll.

Next to this, we need IKVM to interope between Java and .NET. Go to IKVM-files and download the latest version. Unpack this file into a folder.

In the "bin" folder you find the dll's that we need for the samples:

  • bin\IKVM.Runtime.dll
  • bin\IKVM.OpenJDK.XML.Parse.dll
  • bin\IKVM.OpenJDK.XML.API.dll
  • bin\IKVM.OpenJDK.Util.dll
  • bin\IKVM.OpenJDK.Text.dll
  • bin\IKVM.OpenJDK.SwingAWT.dll
  • bin\IKVM.OpenJDK.Security.dll
  • bin\IKVM.OpenJDK.Remoting.dll
  • bin\IKVM.OpenJDK.Management.dll
  • bin\IKVM.OpenJDK.Jdbc.dll
  • bin\IKVM.OpenJDK.Core.dll
  • bin\IKVM.OpenJDK.Beans.dll

Now, you are ready for programming.

Outline

Creating a Coins Container file (.ccr) typically consists of the following steps:

  1. Start a project in a DotNET or Java IDE.
  2. Instantiate a CoinsContainer instance.
  3. Interact with the CoinsContainer with the use of some interaction classes.
  4. Optionally trigger some post-processing.
  5. Export the CoinsContainer to a file.

Setting up the IDE (Integrated Development Environment)

  • For C#, open the File / New Project / Classic Desktop / Empty Project.
  • Add the following references Project / Add References:
Csharp-references.png








Coins-api.dll and cbim.dll

You can program the interface by using the coins-api.dll. This is a very generic approach. However, you can generate libraries as well. For example the cbim.dll contains code for all elements from the core model, like the Assembly or Object. We will start with the cbim.dll. This shows how less code is needed to program this. Next to that we will show the approach via coins-api.dll.

Simple sample via cbim.dll

In general this sample first creates a Coins container, called ccr. Than, a new Coins Object is created called bench. This object is added to the Coins container. The name of this bench is set to "couch". This information is exported to the Coins container.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using nl.coinsweb.cbim;
using nl.coinsweb.sdk;
using nl.coinsweb.sdk.jena;

namespace HelloCoinsWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        void sample1a()
        {
            // Start container
            JenaModelFactory factory = new JenaModelFactory();
            JenaCoinsContainer ccr = new JenaCoinsContainer(factory, "http://demo.nl#"); 

            // Create individual
            // because Object exists in other namespaces as well, we must specify which object we want to use here
            nl.coinsweb.cbim.Object bench = new nl.coinsweb.cbim.Object(ccr);
    
            // Set property
            bench.setName("couch");

            // Export container
            ccr.export("D:\\bench1a.ccr");
        }

        private void btnSample1_Click(object sender, EventArgs e)
        {
            sample1a();
            this.Close();
        }
    }
}

When you view the contents of the exported file (see Bestand:Bench1a.ccr) you will find the information about the bench in the BIM folder. In the "content.rdf" file all the information is stored. More detailled information about the structure and how you can create this file manually is described in this OWL and Coins sample. In this case we use RDF/XML before the export language. It shows:

<rdf:RDF
    xmlns="http://demo.nl#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:coins2="http://www.coinsweb.nl/cbim-2.0.rdf#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xml:base="http://demo.nl#">
  <owl:Ontology rdf:about="">
    <owl:imports rdf:resource="http://www.coinsweb.nl/units-2.0.rdf#"/>
    <owl:imports rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#"/>
    <coins2:containerId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">2866dee8-bdbb-49a9-9e53-423da45cd5f0</coins2:containerId>
    <coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
  </owl:Ontology>
  <coins2:Object rdf:about="#09a9b4c3-5c52-45e6-ac74-7a96055d961e">
    <coins2:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">couch</coins2:name>
    <coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2016-05-19T16:35:30.213Z</coins2:creationDate>
    <coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
  </coins2:Object>
</rdf:RDF>

However, all the Coins-elements that are put into a Coins Container must be typed as a CoinsContainerObject. This can be executed by adding the following line to the code:

ccr.batchAddCoinsContainerObjectType()

This must be set before the export will be executed.

Therefore, the export changes as well. This results in:

<rdf:RDF
   xmlns="http://demo.nl#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:coins2="http://www.coinsweb.nl/cbim-2.0.rdf#"
   xmlns:owl="http://www.w3.org/2002/07/owl#"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 xml:base="http://demo.nl#">
 <coins2:CoinsContainerObject rdf:about="">
   <owl:imports rdf:resource="http://www.coinsweb.nl/units-2.0.rdf#"/>
   <owl:imports rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#"/>
   <coins2:containerId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ae2a9922-d2b6-4747-96ac-dd1adac39213</coins2:containerId>
   <coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
   <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
 </coins2:CoinsContainerObject>
 <coins2:CoinsContainerObject rdf:about="#701f43e7-409e-47cf-832d-ec450e87d792">
   <coins2:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">couch</coins2:name>
   <coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2016-07-12T10:55:09.696Z</coins2:creationDate>
   <coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
   <rdf:type rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#Object"/>
 </coins2:CoinsContainerObject>
</rdf:RDF>

Simple sample via coins-api.dll

Here you have to tell the RunTimeCoinsObject that it is a cbim-2.0:Object. In this sample all the Container-items are typed as a CoinsContainerObject

void sample1b()
{
   // Start container
   JenaModelFactory factory = new JenaModelFactory();
   JenaCoinsContainer ccr = new JenaCoinsContainer(factory, "http://demo.nl#");

   // Create individual
   RuntimeCoinsObject bench = new RuntimeCoinsObject(ccr, "http://www.coinsweb.nl/cbim-2.0.rdf#Object"); 

   // Set property
   bench.setLiteralValue("http://demo.nl#hasName", "couch");

   // Add ContainerObjectType to all items
   ccr.batchAddCoinsContainerObjectType();

   // Export container
   ccr.export("D:\\bench1b.ccr");
}

When you view the contents of the exported file (see Bestand:Bench1b.ccr) you will find the information about the bench in the BIM folder. In the "content.rdf" file all the information is stored.