Académique Documents
Professionnel Documents
Culture Documents
Service Bibliotheque :
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(name="GestionBiblio")
public class GestionBiblio {
private static List<Livre> livres = new ArrayList<Livre>();
@WebMethod
public void ajouterLivre(string titre, string auteur, string categorie, string id, int
nb){
Livre livre = new Livre(titre,auteur,categorie,id,nb);
livres.add(livre);
}
@WebMethod
public List<Livre> rechercherLivre(string titre){
List<Livre> liste = new ArrayList<Livre>();
foreach(Livre livre : livres)
If(livre.getTitre().equals(titre)) liste.add(livre);
return liste;
}
@WebMethod
public void emprunterLivre(string cne, string id){
foreach(Livre livre : livres)
If(livre.getId().equals(id) && livre.getNombreExemplaire() > 0){
livre.setNombreExemplaire(livre.getNombreExemplaire() - 1);
return;
}
}
@WebMethod
public List<Livre> consulterLivre(){
Collections.sort(livres, new Comparator<Livre>(){
public int compare(Livre l1, Livre l2){
return l1.getCategorie().compareTo(l2.getCategorie());
}
});
return livres;
}
}
Publication du service :
import javax.xml.ws.Endpoint;
public class SOAPPublisher {
public static void main(String[] args) {
Endpoint endpoint = Endpoint.publish("http://biblio", new GestionBiblio());
JOptionPane.showMessageDialog( null, "Eteindre le serveur");
endpoint.stop();
}
}