/** * This class shows how to create an instance of the */ import com.hp.hpl.jena.daml.*; import com.hp.hpl.jena.daml.common.DAMLModelImpl; import com.hp.hpl.mesa.rdf.jena.vocabulary.*; import com.hp.hpl.mesa.rdf.jena.model.*; import java.io.*; import java.util.Iterator; public class GEMOntology3 { String uri="http://www.servogrid.org/schemas/GEMOntology"; String namespace=uri+"#"; DAMLModel model,instanceModel; DAMLInstance computeResInst1,computeResInst2; DAMLInstance gemCodeInst1,gemCodeInst2,gemCodeInst3; DAMLDatatype xsdString; public GEMOntology3(String filename) throws RDFException, IOException{ //Create the model model=new DAMLModelImpl(); model.read(new FileReader(filename),uri); //Create the classes we need. DAMLClass computeResources =(DAMLClass)model.getDAMLValue(uri+"#ComputeResources"); DAMLClass gemCode =(DAMLClass)model.getDAMLValue(uri+"#GEMCode"); //Create an instance model. instanceModel=new DAMLModelImpl(); //Create a Compute Resource instance computeResInst1 =instanceModel.createDAMLInstance(computeResources,null); computeResInst1.addProperty(RDF.value,"Grids"); computeResInst2 =instanceModel.createDAMLInstance(computeResources,null); computeResInst2.addProperty(RDF.value,"Danube"); //Create a GEMCode instance and assign some standard //RDF values gemCodeInst1=instanceModel.createDAMLInstance(gemCode,null); gemCodeInst1.addProperty(RDF.value,"Disloc"); gemCodeInst2=instanceModel.createDAMLInstance(gemCode,null); gemCodeInst2.addProperty(RDF.value,"Simplex"); gemCodeInst3=instanceModel.createDAMLInstance(gemCode,null); gemCodeInst3.addProperty(RDF.value,"GMT"); //Get some properties from the ontology DAMLProperty hasCode =(DAMLProperty)model.getDAMLValue(uri+"#"+"hasCode"); computeResInst1.accessProperty(hasCode).add(gemCodeInst1); computeResInst1.accessProperty(hasCode).add(gemCodeInst2); computeResInst2.accessProperty(hasCode).add(gemCodeInst3); //Write it out RDFWriter abbrev=instanceModel.getWriter("RDF/XML-ABBREV"); abbrev.setNsPrefix("gem",uri+"#"); abbrev.write(instanceModel,new OutputStreamWriter(System.out),"HTTP://foobar"); } public void iterate(){ Iterator iter=model.listDAMLClasses(); while(iter.hasNext()){ DAMLClass c=(DAMLClass)iter.next(); System.out.println(c.toString()); } } public void dump(OutputStream out) throws RDFException { System.out.println("RDF/XML\n"); model.write(new PrintWriter(out),"RDF/XML-ABBREV",uri); } public static void main(String[] args) throws Exception{ GEMOntology3 gd3=new GEMOntology3(args[0]); // gd3.dump(System.out); } }