Bonsoir voila je suis nouveau sur cet langage (Java) et j'ai un problème de récursivité je ne sais pas pourquoi ça ne marche pas voilà mon code;
Bon il marche dans un seul sens l'iterateur ne revient pas sur la valeur qui précède un traitement d'un appel.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.*;


public class Jena3 {

    /**
     * @param args
     */
    Model model;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Jena3 jen =new Jena3();
        jen.CreateModel();
        jen.ShowModel();
        jen.Affiche();
    }
    void Affiche()
    {
        Resource m=model.getResource("http://somewhere/JohnSmith");
        StmtIterator stm=m.listProperties();
        NavigateRecur(stm);
    }
    void CreateModel()
    {
        // some definitions
        String personURI    = "http://somewhere/JohnSmith";
        String givenName    = "John";
        String familyName   = "Smith";
        String fullName     = givenName + " " + familyName;
        
        // create an empty Model
         model = ModelFactory.createDefaultModel();

        // create the resource
        //   and add the properties cascading style
         model.createResource(personURI)
                 .addProperty(VCARD.FN, fullName)
                 .addProperty(VCARD.N,
                              model.createResource(personURI+"/A0")
                                   .addProperty(VCARD.Given, givenName)
                                   .addProperty(VCARD.Family, familyName));
    }
    void ShowModel()
    {
        model.write(System.out);
    }
    
    private void NavigateRecur(StmtIterator stm)
    {
        System.out.println("Iteration");
        if(stm.hasNext())
        {
            Statement aux=stm.nextStatement();
            RDFNode object=aux.getObject();
            if(object instanceof Resource)
            {
                NavigateRecur(model.getResource(object.toString()).listProperties());
            }
            else
            {
                System.out.println(object.toString());
            }
        }
    }
    

}
Cordialement