/* une idée de ce qui était attendu à la première session nfp121 2007...

-1-
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
public class Main1 implements SujetExamen {
    public void extraire(Class c) {extraire(c, System.out);}
    public void extraire(Class c, OutputStream out) {
	PrintStream sortie = new PrintStream(out);
	sortie.println(c.getName());
	for (Method m : c.getDeclaredMethods()) {sortie.println(m);}
    }
}

-2-
public class Main2 extends Main1{
    public void extraire(Class c, OutputStream out) {
	super.extraire(c, out);
	// extraire les sous-classes
	PrintStream sortie = new PrintStream(out);
	for (Class sc : c.getDeclaredClasses()) {extraire(sc, out);}
    }
  }
-3-
bouton.addActionListener( new ActionListener(){
             public void actionPerformed(ActionEvent ae){
                 try{Class cl = Class.forName(nomDeLaClasse.getText());          
                           ByteArrayOutputStream baos=new ByteArrayOutputStream();
                           se.extraire(cl , baos); contenu.setText(baos.toString());  
                }catch(ClassNotFoundException e){ contenu.setText(e.getMessage());}}});

-4-
import java.lang.reflect.Method;

import org.jdom.*;
import org.jdom.output.*;

public class Main4 extends Main2{
   private  org.jdom.Element racine;
   private  org.jdom.Document document;
   private  XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());   
    public void extraire(Class c, Writer out){
      racine = new Element("classes"); document = new Document(racine);
      Element classe=extraireClasse(c); racine.addContent(classe);
      try{  sortie.output(document, out); out.close();
        }catch(Exception e){e.printStackTrace();}
    } 
    public Element extraireClasse(Class c){
        Element classe = new Element("classe");
        classe.setAttribute(new Attribute("nom",c.getName()));
        extraireMéthodes(classe ,  c);
        for(Class cl: c.getDeclaredClasses()){classe.addContent(extraireClasse(cl));}
        return classe;
    }
    public void extraireMéthodes(Element classe , Class c){
        try{for(Method m : c.getDeclaredMethods()){
                Element meth = new Element("methode");
                meth.setAttribute(new Attribute("nom",m.getName()));
                meth.setAttribute(new Attribute("typeRetour", m.getReturnType().getName()));
                for(Class pt : m.getParameterTypes()){
                    Element param = new Element("parametre");
                    param.setAttribute(new Attribute("type",pt.getName()));
                    meth.addContent(param);}
                classe.addContent(meth);}
        }catch(Exception e){e.printStackTrace();}   
    }
}