C++: Some code cleanup
[smartapi.git] / Examples / Java / CoffeeMakerFor10Cups / src / acme / MainClass.java
1 package acme;
2
3 import acme.model.CoffeeMakerFor10Cups;
4 import smartapi.common.DATATYPE;
5 import smartapi.common.NS;
6 import smartapi.common.Tools;
7 import smartapi.model.Address;
8 import smartapi.model.Device;
9 import smartapi.model.ValueObject;
10 import smartapi.rdf.Variant;
11
12 public class MainClass {
13
14         private final String myIdentity = "http://acme.com/smartapi/CCoffeeMaker";
15         
16         public MainClass()
17         {
18         }
19
20         public static void main(String[] args)
21         {
22                 MainClass mainClass = new MainClass();
23                 // You can use your newly created CoffeeMakerFor10Cups in two ways
24                 // either:
25                 mainClass.useWithNewClass();
26                 // or:
27                 mainClass.useAsType();
28         }
29         
30         /**
31          * Example on how to use your newly created custom class.
32          */
33         public void useWithNewClass()
34         {
35                 // add your prefix mapping
36                 NS.addPrefix("acme", "http://smart-api.io/ontology/1.0/acme#");
37                 
38                 // create object as an instance of your newly created class
39                 CoffeeMakerFor10Cups coffeeMakerFor10Cups = new CoffeeMakerFor10Cups(myIdentity);
40                 
41                 // you can set your own property with setCupConstraints method
42                 ValueObject cupConstraints = new ValueObject();
43                 cupConstraints.setDataType(DATATYPE.INT);
44                 cupConstraints.setValue(new Variant(6));
45                 cupConstraints.setMinimum(new Variant(2));
46                 cupConstraints.setMaximum(new Variant(10));
47                 coffeeMakerFor10Cups.setCupConstraints(cupConstraints);
48                 
49                 // you can use all methods provided by Device class
50                 Address address = new Address();
51                 address.setCity("Paris");
52                 coffeeMakerFor10Cups.setAddress(address);
53                 
54                 // print out for testing purposes
55                 System.out.println(Tools.toString(coffeeMakerFor10Cups));
56                 
57         }
58
59         /**
60          * Example on how to use your newly created concepts directly without implementing 
61          * new classes.
62          */
63         public void useAsType()
64         {
65                 // add your prefix mapping
66                 NS.addPrefix("acme", "http://smart-api.io/ontology/1.0/acme#");
67
68                 // create object as an instance of Device
69                 Device coffeeMakerFor10Cups = new Device(myIdentity);
70                 
71                 // add type seas:CoffeeMakerFor10Cups for the device
72                 coffeeMakerFor10Cups.addType("acme:CoffeeMakerFor10Cups");
73                 
74                 // you can set your own property with add() method
75                 ValueObject cupConstraints = new ValueObject();
76                 cupConstraints.setDataType(DATATYPE.INT);
77                 cupConstraints.setValue(new Variant(6));
78                 cupConstraints.setMinimum(new Variant(2));
79                 cupConstraints.setMaximum(new Variant(10));
80                 coffeeMakerFor10Cups.add("acme:cupConstraints", cupConstraints);
81                 
82                 // you can use all methods provided by Device class
83                 Address address = new Address();
84                 address.setCity("Paris");
85                 coffeeMakerFor10Cups.setAddress(address);
86                 
87                 // print out for testing purposes
88                 System.out.println(Tools.toString(coffeeMakerFor10Cups));
89                 
90         }
91         
92 }