Skip to content

Commit

Permalink
add the correction of the TP 3 and 4
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneRoot committed Nov 23, 2012
1 parent f957516 commit bc8639b
Show file tree
Hide file tree
Showing 76 changed files with 1,738 additions and 0 deletions.
42 changes: 42 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/Client.java
@@ -0,0 +1,42 @@
import java.io.* ;
import org.omg.CORBA.* ;

public class Client
{
public static void main(String args[])
{
int nombre ;
int res ;

if( args.length < 2 )
{
System.out.println( "Usage: java Client <ior> <nombre>" ) ;
System.exit( 1 ) ;
}

// initialiser l'ORB.
try
{
ORB orb = ORB.init( args, null ) ;
System.out.println( "0) ORB initialise'") ;

String ior = args[0] ;
System.out.println( "1) IOR lue : " + ior ) ;

org.omg.CORBA.Object obj = orb.string_to_object(args[0]) ;
Icarre service = IcarreHelper.narrow(obj) ;
System.out.println("2) Reference obtenue a partir de l'IOR") ;

nombre = Integer.parseInt(args[1]) ;
System.out.println("3) Nombre lu sur la ligne de commande : " + nombre) ;

res = service.carre(nombre) ;
System.out.println("4) Le serveur a trouve' un carre de : " + res) ;
}
catch( org.omg.CORBA.SystemException ex )
{
System.err.println( "Erreur !!" ) ;
ex.printStackTrace() ;
}
}
}
4 changes: 4 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/Icarre.idl
@@ -0,0 +1,4 @@
interface Icarre
{
long carre(in long source) ;
} ;
11 changes: 11 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/IcarreImpl.java
@@ -0,0 +1,11 @@
import org.omg.CORBA.* ;

public class IcarreImpl
extends _IcarreImplBase
{
public int carre (int source)
{
System.out.println( "carre : requete recue pour le nombre : " + source ) ;
return source * source ;
}
}
22 changes: 22 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/Serveur.java
@@ -0,0 +1,22 @@
import org.omg.CORBA.* ;

public class Serveur
{
public static void main(String[] args)
{
try
{
//init ORB
ORB orb = ORB.init(args, null ) ;

IcarreImpl myobj = new IcarreImpl() ;
String ior = orb.object_to_string( myobj ) ;
System.out.println( ior ) ;

orb.run() ;
}

catch( org.omg.CORBA.SystemException ex ) { ex.printStackTrace() ; }
// catch( org.omg.CORBA.UserException ex ) { ex.printStackTrace() ; }
}
}
2 changes: 2 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/clean
@@ -0,0 +1,2 @@
\rm -f *~ \#* pok *Operations.java *Helper.java *Holder.java *POA.java annu.ior iorfile.java *.class _*
\rm -f Icarre.java
5 changes: 5 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/compile
@@ -0,0 +1,5 @@
set -v
idlj -fall -oldImplBase Icarre.idl
javac IcarreImpl.java
javac Serveur.java
javac Client.java
Binary file added ls6/pdi/3_corba_correction/1-Carre/pok.ps
Binary file not shown.
5 changes: 5 additions & 0 deletions ls6/pdi/3_corba_correction/1-Carre/reponse.txt
@@ -0,0 +1,5 @@
Un IOR minimal (tel que spécifié par le General Inter-ORB protocol) encode les éléments suivants :
- l'adresse IP de la machine hôte ;
- le numéro de port sur lequel l'application CORBA est en écoute sur cette machine ;
- une chaîne de caractères définissant la classe de l'objet distant sur laquelle la méthode sera invoquée ;
- La clé de l'objet, qui est utilisée par l'ORB du serveur pour identifier l'objet.
42 changes: 42 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/Client.java
@@ -0,0 +1,42 @@
import java.io.* ;
import org.omg.CORBA.* ;

public class Client
{
public static void main(String args[])
{
int nombre ;
int res ;

if( args.length < 2 )
{
System.out.println( "Usage: java Client <ior> <nombre>" ) ;
System.exit( 1 ) ;
}

// initialiser l'ORB.
try
{
ORB orb = ORB.init( args, null ) ;
System.out.println( "0) ORB initialise'") ;

String ior = args[0] ;
System.out.println( "1) IOR lue : " + ior ) ;

org.omg.CORBA.Object obj = orb.string_to_object(args[0]) ;
Icarre service = IcarreHelper.narrow(obj) ;
System.out.println("2) Reference obtenue a partir de l'IOR") ;

nombre = Integer.parseInt(args[1]) ;
System.out.println("3) Nombre lu sur la ligne de commande : " + nombre) ;

res = service.carre(nombre) ;
System.out.println("4) Le serveur a trouve' un carre de : " + res) ;
}
catch( org.omg.CORBA.SystemException ex )
{
System.err.println( "Erreur !!" ) ;
ex.printStackTrace() ;
}
}
}
4 changes: 4 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/Icarre.idl
@@ -0,0 +1,4 @@
interface Icarre
{
void carre(in long source, out long resultat) ;
} ;
11 changes: 11 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/IcarreImpl.java
@@ -0,0 +1,11 @@
import org.omg.CORBA.* ;

public class IcarreImpl
extends _IcarreImplBase
{
public void carre (int source, IntHolder resultat)
{
System.out.println( "carre : requete recue pour le nombre : " + source ) ;
resultat.value = source*source ;
}
}
22 changes: 22 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/Serveur.java
@@ -0,0 +1,22 @@
import org.omg.CORBA.* ;

public class Serveur
{
public static void main(String[] args)
{
try
{
//init ORB
ORB orb = ORB.init(args, null ) ;

IcarreImpl myobj = new IcarreImpl() ;
String ior = orb.object_to_string( myobj ) ;
System.out.println( ior ) ;

orb.run() ;
}

catch( org.omg.CORBA.SystemException ex ) { ex.printStackTrace() ; }
// catch( org.omg.CORBA.UserException ex ) { ex.printStackTrace() ; }
}
}
2 changes: 2 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/clean
@@ -0,0 +1,2 @@
\rm -f *~ \#* pok *Operations.java *Helper.java *Holder.java *POA.java annu.ior iorfile.java *.class _*
\rm -f Icarre.java
5 changes: 5 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/compile
@@ -0,0 +1,5 @@
set -v
idlj -fall -oldImplBase Icarre.idl
javac IcarreImpl.java
javac Serveur.java
javac Client.java
Binary file added ls6/pdi/3_corba_correction/2-Carre_Holder/pok.ps
Binary file not shown.
113 changes: 113 additions & 0 deletions ls6/pdi/3_corba_correction/2-Carre_Holder/reponse.txt
@@ -0,0 +1,113 @@
En bref :
- Une classe Holder s'occupe de la gestion de paramètres modifiables (de type out ou inout) ; là où le language Java ne le permet pas.
- Une classe Holder est automatiquement générée par la projection IDL pour tout type ou toute classe qui y est définie.
- On a besoin d'une classe Holder lorsque l'on spécifie des types out ou inout dans les paramètres de l'interface IDL.

En détail (rien de mieux que les explications de l'API corba) :

Support for out and inout parameter passing modes requires the use of additional holder classes.
Because the Java programming language does not support out or inout parameters, holder classes are needed as a means of passing a parameter that can be modified.
To support portable stubs and skeletons, holder classes also implement the org.omg.CORBA.portable.Streamable interface.

Holder classes are named by appending "Holder" to the name of the type.
The name of the type refers to its name in the Java programming language.
For example, a holder class for the interface named Account in the Java programming language would be named AccountHolder.

Holder classes are available for all of the basic IDL datatypes in the org.omg.CORBA package.
So, for example, there are already-defined classes for LongHolder, ShortHolder, FloatHolder, and so on.
Classes are also generated for all named user-defined IDL types except those defined by typedefs. (Note that in this context user defined includes types that are defined in OMG specifications such as those for the Interface Repository, and other OMG services.)

Each holder class has:

* a constructor from an instance
* a default constructor
* a public instance member, value which is the typed value.
* a method for reading an input stream and assigning the contents to the type's value field
* a method for writing the value of the value field to an output stream
* a method for getting the typecode of the type

The default constructor sets the value field to the default value for the type as defined by the Java language:

* false for boolean
* 0 for numeric and char types
* null for strings and object references

As an example, if the interface Account, defined in OMG IDL, were mapped to the Java programming language, the following holder class would be generated:

public final class AccountHolder implements
org.omg.CORBA.portable.Streamable
{
// field that holds an Account object
public Account value = null;

// default constructor
public AccountHolder ()
{
}

// creates a new AccountHolder from initialValue
public AccountHolder (Account initialValue)
{
value = initialValue;
}

// reads the contents of i and assigns the contents to value
public void _read (org.omg.CORBA.portable.InputStream i)
{
value = AccountHelper.read (i);
}

// writes value to o
public void _write (org.omg.CORBA.portable.OutputStream o)
{
AccountHelper.write (o, value);
}

// returns the typecode for Account
public org.omg.CORBA.TypeCode _type ()
{
return AccountHelper.type ();
}

}

For more information on Holder classes, see Chapter 1.4, Mapping for Basic Types in the OMG IDL to Java Language Mapping. The Holder classes defined in the package org.omg.CORBA are:

AnyHolder
AnySeqHolder
BooleanHolder
BooleanSeqHolder
ByteHolder
CharHolder
CharSeqHolder
CurrentHolder
DoubleHolder
DoubleSeqHolder
FixedHolder
FloatHolder
FloatSeqHolder
IntHolder
LongHolder
LongLongSeqHolder
LongSeqHolder
ObjectHolder
OctetSeqHolder
ParameterModeHolder
PolicyErrorHolder
PolicyListHolder
PrincipalHolder
ServiceInformationHolder
ShortHolder
ShortSeqHolder
StringHolder
StringSeqHolder
TypeCodeHolder
ULongLongSeqHolder
ULongSeqHolder
UnknownUserExceptionHolder
UShortSeqHolder
ValueBaseHolder
WCharSeqHolder
WrongTransactionHolder
WStringSeqHolder

42 changes: 42 additions & 0 deletions ls6/pdi/3_corba_correction/3-Carre_POA/Client.java
@@ -0,0 +1,42 @@
import java.io.* ;
import org.omg.CORBA.* ;

public class Client
{
public static void main(String args[])
{
int nombre ;
int res ;

if( args.length < 2 )
{
System.out.println( "Usage: java Client <ior> <nombre>" ) ;
System.exit( 1 ) ;
}

// initialiser l'ORB.
try
{
ORB orb = ORB.init( args, null ) ;
System.out.println( "0) ORB initialise'") ;

String ior = args[0] ;
System.out.println( "1) IOR lue : " + ior ) ;

org.omg.CORBA.Object obj = orb.string_to_object(args[0]) ;
Icarre service = IcarreHelper.narrow(obj) ;
System.out.println("2) Reference obtenue a partir de l'IOR") ;

nombre = Integer.parseInt(args[1]) ;
System.out.println("3) Nombre lu sur la ligne de commande : " + nombre) ;

res = service.carre(nombre) ;
System.out.println("4) Le serveur a trouve' un carre de : " + res) ;
}
catch( org.omg.CORBA.SystemException ex )
{
System.err.println( "Erreur !!" ) ;
ex.printStackTrace() ;
}
}
}
4 changes: 4 additions & 0 deletions ls6/pdi/3_corba_correction/3-Carre_POA/Icarre.idl
@@ -0,0 +1,4 @@
interface Icarre
{
long carre(in long source) ;
} ;
11 changes: 11 additions & 0 deletions ls6/pdi/3_corba_correction/3-Carre_POA/IcarreImpl.java
@@ -0,0 +1,11 @@
import org.omg.CORBA.* ;

public class IcarreImpl
extends IcarrePOA
{
public int carre (int source)
{
System.out.println( "carre : requete recue pour le nombre : " + source ) ;
return source * source ;
}
}

0 comments on commit bc8639b

Please sign in to comment.