Bench with subobjects
This sample uses the same bench as in the previous sample. In this example the bench contains of three subobjects:
We have to tell the bench that it is both an Object and an Assembly. We call this Multi-Typing. Therefore, you can use the method addType.
Multiple typed objects can be cast to the preferred type in order to have access to functions/methods belonging to this type. The next code snippet casts a Bench object to an Assembly.
Assembly benchAsAssembly = (Assembly)bench.@as(typeof(Assembly));
Below, the relations has been programmed for the support-left only. This support-left is both an object and a part. Via the ContainsRelation the bench and the support-left are connected to each other.:
// Start container JenaModelFactory factory = new JenaModelFactory(); JenaCoinsContainer ccr = new JenaCoinsContainer(factory, "http://demo.nl#"); // Create individual nl.coinsweb.cbim.Object bench = new nl.coinsweb.cbim.Object(ccr); nl.coinsweb.cbim.Object supportLeft = new nl.coinsweb.cbim.Object(ccr); ContainsRelation crel = new ContainsRelation(ccr); // Individual with multiple types bench.addType(typeof(Assembly)); Assembly benchAsAssembly = (Assembly)bench.@as(typeof(Assembly)); supportLeft.addType(typeof(Part)); // Configure ContainsRelation crel.setHasPart((Part)supportLeft.@as(typeof(Part))); benchAsAssembly.addHasContainsRelation(crel); // Set property bench.setName("Couch"); supportLeft.setName("Support Left Side"); // Export container ccr.export("D:\\assembly.ccr");
All Coins objects that are put into a Coins Container, must be typed CoinsContainerObject.
Therefore, this line of code is needed: