API Jena

bpr25's Avatar, Join Date: Aug 2011
Newbie Member
Hi,

I have an interface with 4 labels, 4 textfields and some buttons like "Add", "modify, "next", etc. The user will enter name, first name, birth date, etc. After clicking the button "add", the information that he has entered will be added on rdf file. The "next" (in french "Suivant") button didn't work. When i click on "next" button, nothing appears on textfields. There is nothing in the textfields.
Can you help me please?
Thanks.


Code:
    
    //ActionAdd
    public class ActionAjoutPersonne extends Onto implements ActionListener
    {
        
        public void actionPerformed(ActionEvent evt)
        {
                    
            Onto f;
                        
            f = new Onto();
    
            
            for(int i=0;i<4;i++)
            {
                
                            
                tabTF[i].getText();    
                Resource p1 = model.createResource(uriBase+tabTF[0].getText());
                p1.addProperty(RDF.type, f.personne);
                
                if (i==0) 
                {
                    p1.addProperty(f.aPourPrenom, tabTF[i].getText());
                    
                }
                if (i==1)
                {
                    p1.addProperty(f.aPourNom, tabTF[i].getText());
                }
                if (i==2)
                {
                    
                    p1.addProperty(f.aDateNaiss, tabTF[i].getText());
                }
                if (i==3)
                {
                    if (tabTF[i].getText().equals("F"))
                    {
                        p1.addProperty(f.aGenre, tabTF[i].getText());
                        p1.addProperty(RDF.type, f.femme);
                    }
                    else 
                        if (tabTF[i].getText().equals("H"))
                        {
                            p1.addProperty(f.aGenre, tabTF[i].getText());
                            p1.addProperty(RDF.type, f.homme);
                        }
                }
                
                StringWriter sw = new StringWriter();
                model.write(sw, "RDF/XML-ABBREV");
                String owlCode = sw.toString();
                File file = new File("d:/teste20.rdf");
                try{
                    FileWriter fw = new FileWriter(file);
                    fw.write(owlCode);
                    fw.close();
                } catch(FileNotFoundException fnfe){
                    fnfe.printStackTrace();} 
                catch(IOException ioe){
                        ioe.printStackTrace();
                }    
                
            }
            
        }
        }
    
    //ActionNext
    class ActionSuivant extends Onto implements ActionListener
    {
        public void actionPerformed(ActionEvent evt)
        {
                    
            Onto s = new Onto();
            int indice=1;
            String []M= new String [10];
            
            //Read RDF File
            InputStream in = FileManager.get().open("d:\teste20.rdf");
            if (in == null) 
            {
              throw new IllegalArgumentException("File: " + "d:\teste20.rdf" + " not found");
            }
            s.model.read(in, null);
                
            //Search instances of Personne Class            
            ExtendedIterator instances=s.personne.listInstances();
                    
            indice++;
            for(int p=0;p<10;p++) //10 instances
            {
                while (instances.hasNext())
                {
                     Individual thisInstance = (Individual) instances.next();
                     M[p]= thisInstance.getLocalName();
                     
                    if(p==indice)
                    {                                      tabTF[0].setText((thisInstance.getPropertyResourceValue(s.aPourPrenom)).toString());
                      tabTF[1].setText((thisInstance.getPropertyResourceValue(s.aPourNom)).toString());
                      tabTF[2].setText((thisInstance.getPropertyResourceValue(s.aDateNaiss)).toString());
                    }
                 }
             }
        }
    }
}
alssadi's Avatar
Banned
where do you store your data , and in what kind of format , is next mean next or next mean new record
bpr25's Avatar, Join Date: Aug 2011
Newbie Member
Hi, thanks for your answer.

The format is "RDF/XML-ABBREV". When the code below is executed, a window appears with 4 text fields and buttons Next, back, add, modify and remove. The button Next means move to the next instance of the Person class and displays the values of DatatypeProperties for this instance in text fields.
One click on Next button -> display on text fields values for the DatatypeProperties of Instance 1; Two clicks on Next button -> display on text fields values for the DatatypeProperties of Instance 2; etc.
But this button doesn't work. The text fields are empty.

Code:
    //ontology
    public class Onto 
    {
        (...)   
        public Onto (){
        model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
        (...)        
        //Classes
        (...)       
        
        //Sub-classes
        (...)
        
        }
    //ActionAdd for Add button- It works!
    public class ActionAjoutPersonne extends Onto implements ActionListener
    {
        
        public void actionPerformed(ActionEvent evt)
        {
                  
            Onto f;
                        
            f = new Onto();
    
            
            for(int i=0;i<4;i++)
            {
                
                            
                tabTF[i].getText();    
                Resource p1 = model.createResource(uriBase+tabTF[0].getText());
                p1.addProperty(RDF.type, f.personne);
                
                if (i==0) 
                {
                    p1.addProperty(f.aPourPrenom, tabTF[i].getText());
                    
                }
                if (i==1)
                {
                    p1.addProperty(f.aPourNom, tabTF[i].getText());
                }
                if (i==2)
                {
                    
                    p1.addProperty(f.aDateNaiss, tabTF[i].getText());
                }
                if (i==3)
                {
                    if (tabTF[i].getText().equals("F"))
                    {
                        p1.addProperty(f.aGenre, tabTF[i].getText());
                        p1.addProperty(RDF.type, f.femme);
                    }
                    else 
                        if (tabTF[i].getText().equals("H"))
                        {
                            p1.addProperty(f.aGenre, tabTF[i].getText());
                            p1.addProperty(RDF.type, f.homme);
                        }
                }
                
                StringWriter sw = new StringWriter();
                model.write(sw, "RDF/XML-ABBREV");
                String owlCode = sw.toString();
                File file = new File("d:/teste20.rdf");
                try{
                    FileWriter fw = new FileWriter(file);
                    fw.write(owlCode);
                    fw.close();
                } catch(FileNotFoundException fnfe){
                    fnfe.printStackTrace();} 
                catch(IOException ioe){
                        ioe.printStackTrace();
                }    
                
            }
            
        }
        }
    
    //ActionNext - for next button: it does not work
    class ActionSuivant extends Onto implements ActionListener
    {
        public void actionPerformed(ActionEvent evt)
        {
                    
            Onto s = new Onto();
            int indice=1;
            String []M= new String [10];
            
            //Read RDF File
            InputStream in = FileManager.get().open("d:\teste20.rdf");
            if (in == null) 
            {
              throw new IllegalArgumentException("File: " + "d:\teste20.rdf" + " not found");
            }
            s.model.read(in, null);
                
            //Search instances of Personne Class            
            ExtendedIterator instances=s.personne.listInstances();
                    
            indice++;
            for(int p=0;p<10;p++) //10 instances
            {
                while (instances.hasNext())
                {
                     Individual thisInstance = (Individual) instances.next();
                     M[p]= thisInstance.getLocalName();
                     
                    if(p==indice)
                    { 
                      tabTF[0].setText((thisInstance.getPropertyResourceValue(s.aPourPrenom)).toString());
                      tabTF[1].setText((thisInstance.getPropertyResourceValue(s.aPourNom)).toString());
                      tabTF[2].setText((thisInstance.getPropertyResourceValue(s.aDateNaiss)).toString());
                    }
                 }
             }
        }
    }
    
   
    }