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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
| package fr.corba.parking;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.omg.CORBA.Context;
import org.omg.CORBA.ContextList;
import org.omg.CORBA.DomainManager;
import org.omg.CORBA.ExceptionList;
import org.omg.CORBA.NVList;
import org.omg.CORBA.NamedValue;
import org.omg.CORBA.Object;
import org.omg.CORBA.Policy;
import org.omg.CORBA.Request;
import org.omg.CORBA.SetOverrideType;
import org.omg.CosNaming.NamingContext;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import ParkingAuto.Historique;
import ParkingAuto.Localisation;
import ParkingAuto.Mairie;
import ParkingAuto.MairieHelper;
import ParkingAuto.Parking;
import ParkingAuto.ParkingPOA;
public class ParkingImpl extends ParkingPOA implements Parking {
private int numParking;
private String nomParking;
private int nbPlacesTotal;
private int nbPlacesoqp;
private int prixHoraire;
private Historique[] historiques;
private boolean libre = true;
private Localisation localisation;
private int cmp = 0; // compteur pour le tableau Historique
public static Mairie mairie;
private String[] args;
public ParkingImpl(String nom, Localisation loc,String[] args){
this.localisation = loc;
this.nomParking = nom;
this.args = args;
this.initMairie();
}
public ParkingImpl(){
}
public Historique[] getHistorique() {
// TODO Auto-generated method stub
return this.historiques;
}
/**
* Initialise la connexion avec la mairie
*/
private void initMairie(){
try {
// Intialisation de l'orb
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
// Saisie du nom de l'objet (si utilisation du service de nommage)
System.out.println("Quel objet Corba voulez-vous contacter ?");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String idObj = in.readLine();
// Recuperation du naming service
org.omg.CosNaming.NamingContext nameRoot =
org.omg.CosNaming.NamingContextHelper.narrow(orb.string_to_object("corbaloc:iiop:1.2@172.18.37.77:2001/NameService"));
// Construction du nom a rechercher
org.omg.CosNaming.NameComponent[] nameToFind = new org.omg.CosNaming.NameComponent[1];
nameToFind[0] = new org.omg.CosNaming.NameComponent(idObj,"");
// Recherche aupres du naming service
org.omg.CORBA.Object distantMairie = nameRoot.resolve(nameToFind);
System.out.println("Objet '" + idObj + "' trouve aupres du service de noms. IOR de l'objet :");
System.out.println(orb.object_to_string(distantMairie));
// Utilisation directe de l'IOR (SAUF utilisation du service de nommage)
// org.omg.CORBA.Object distantMairie = orb.string_to_object("IOR:000...");
// Casting de l'objet CORBA au type convertisseur euro
mairie = MairieHelper.narrow(distantMairie);
// traitement
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Envoie le dernier mouvemen de véhicule (entrée ou sortie)
*/
private void sendHistorique(){
mairie.addInfoParking(historiques[cmp],this.numParking);
}
public Mairie getMairie(){
return this.mairie;
}
public void entrerParrking(String dateArrivee){
this.nbPlacesoqp++;
if (this.nbPlacesoqp==this.nbPlacesTotal){
libre= false;
}
this.historiques[cmp] = new HistoriqueImpl(dateArrivee,Historique.ENTREE);
sendHistorique();
cmp ++;
}
public void sortirParrking(String dateSortie) {
// TODO Auto-generated method stub
this.nbPlacesoqp--;
if (this.nbPlacesoqp<this.nbPlacesTotal){
libre= true;
}
this.historiques[cmp] = new HistoriqueImpl(dateSortie,Historique.SORTIE);
sendHistorique();
cmp ++;
}
public Localisation getLocalisation() {
// TODO Auto-generated method stub
return this.localisation;
}
public int getNbPlacesTotal() {
// TODO Auto-generated method stub
return this.nbPlacesTotal;
}
public int getNbPlacesoqp() {
// TODO Auto-generated method stub
return this.nbPlacesoqp;
}
public String getNomParking() {
// TODO Auto-generated method stub
return this.nomParking;
}
public int getPrixHoraire() {
// TODO Auto-generated method stub
return this.prixHoraire;
}
public void setLocalisation(Localisation locP) {
// TODO Auto-generated method stub
this.localisation =locP;
}
public void setNbPlacesTotal(int nbPlacesTotal) {
// TODO Auto-generated method stub
this.nbPlacesTotal = nbPlacesTotal;
}
public void setNbPlacesoqp(int nbPlacesoqp) {
// TODO Auto-generated method stub
this.nbPlacesoqp = nbPlacesoqp;
}
public void setNomParking(String nomParking) {
// TODO Auto-generated method stub
this.nomParking = nomParking;
}
public void setPrixHoraire(int prixHoraire) {
// TODO Auto-generated method stub
this.prixHoraire = prixHoraire;
}
public Request _create_request(Context ctx, String operation,
NVList arg_list, NamedValue result) {
// TODO Auto-generated method stub
return null;
}
public Request _create_request(Context ctx, String operation,
NVList arg_list, NamedValue result, ExceptionList exclist,
ContextList ctxlist) {
// TODO Auto-generated method stub
return null;
}
public Object _duplicate() {
// TODO Auto-generated method stub
return null;
}
public DomainManager[] _get_domain_managers() {
// TODO Auto-generated method stub
return null;
}
public Object _get_interface_def() {
// TODO Auto-generated method stub
return null;
}
public Policy _get_policy(int policy_type) {
// TODO Auto-generated method stub
return null;
}
public int _hash(int maximum) {
// TODO Auto-generated method stub
return 0;
}
public boolean _is_a(String repositoryIdentifier) {
// TODO Auto-generated method stub
return false;
}
public boolean _is_equivalent(Object other) {
// TODO Auto-generated method stub
return false;
}
public boolean _non_existent() {
// TODO Auto-generated method stub
return false;
}
public void _release() {
// TODO Auto-generated method stub
}
public Request _request(String operation) {
// TODO Auto-generated method stub
return null;
}
public Object _set_policy_override(Policy[] policies,
SetOverrideType set_add) {
// TODO Auto-generated method stub
return null;
}
public int getNumParking() {
// TODO Auto-generated method stub
return this.numParking;
}
public void setNumParking(int numParking) {
this.numParking = numParking;
// TODO Auto-generated method stub
}
public void start(){
try {
// Intialisation de l'ORB
//************************
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
// Gestion du POA
//****************
// Recuperation du POA
POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
// Creation du servant
//*********************
// Activer le servant au sein du POA et recuperer son ID
byte[] parkingId = rootPOA.activate_object(this);
// Activer le POA manager
rootPOA.the_POAManager().activate();
// Enregistrement dans le service de nommage
//*******************************************
// Recuperation du naming service
NamingContext nameRoot=org.omg.CosNaming.NamingContextHelper.narrow(orb.string_to_object("corbaloc:iiop:1.2@172.18.37.77:2001/NameService"));
// Construction du nom a enregistrer
org.omg.CosNaming.NameComponent[] nameToRegister = new org.omg.CosNaming.NameComponent[1];
nameToRegister[0] = new org.omg.CosNaming.NameComponent(this.nomParking,"");
// Enregistrement de l'objet CORBA dans le service de noms
nameRoot.rebind(nameToRegister,rootPOA.servant_to_reference(this));
System.out.println("==> Nom '"+ this.nomParking + "' est enregistre dans le service de noms.");
String IORServant = orb.object_to_string(rootPOA.servant_to_reference(this));
System.out.println("L'objet possede la reference suivante :");
System.out.println(IORServant);
// Lancement de l'ORB et mise en attente de requete
//**************************************************
orb.run();
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Donner le nom du parking : ");
String nom = in.readLine();
System.out.println("Coordonnées X : ");
int x = Integer.parseInt(in.readLine());
System.out.println("Coordonnées Y : ");
int y = Integer.parseInt(in.readLine());
ParkingImpl parking = new ParkingImpl(nom, new LocalisationImpl(x,y),args);
Mairie mairie = parking.getMairie();
System.out.println("Enregistrent du parking au niveau de la mairie");
mairie.addNewParking(parking);
System.out.println("Ajout du parking au niveau de la mairie");
// Lancement du serveur de parking
parking.start();
}
} |
Partager