X


import org...

Jak cię złapią, to znaczy, że oszukiwałeś. Jak nie, to znaczy, że posłużyłeś się odpowiednią taktyką.
omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
class InterestServant extends _InterestImplBase {
// Implement the Get − Set Procedures for the Member
// variables
string name;
string ssn;
double principal;
int years;
float rate;
public String Name()
{
return name;
}
public void Name(String arg)
{
name =arg;
}
public String Ssn()
{
return ssn;
}
public void Ssn(String arg)
{
ssn = arg;
}
public double Principal()
{
return principal;
}
454
Chapter 18: Introducing CORBA
public void Principal(double arg)
{
principal = arg;
}
public float Rate()
{
return rate;
}
public void Rate(float arg)
{
rate = arg;
}
public int Years()
{
return years;
}
public void Years(int arg)
{
years = arg;
}
// Implement the method to calculate simple interest
public double calculateInterest()
{
return (principal * years * rate / 100);
}
}
public class InterestServer {
public static void main(String args[]) {
try {
// Create the ORB
ORB orb = ORB.init(args,null);
// Create an instance of the servant object (object
// implementation)
InterestServant IntRef = new InterestServant();
orb.connect(IntRef);
// Get the initial root context and narrow it to the
// Naming Context object
org.omg.CORBA.Object objtRef =
orb.resolve_initial_references("NameService");
NamingContext nctRef = NamingContextHelper.narrow(objtRef);
// Create a new Name component for the Interest object
NameComponent nct = new NameComponent("Interest",""); NameComponent path[] = {nct};
// Attach the Interest object's namecomponent into the //
Naming Service
455
Chapter 18: Introducing CORBA
nctRef.rebind(path,IntRef);
// Wait for client's requests
java.lang.Object sync = new java.lang.Object();
synchronized(sync){
sync.wait();
}
}catch(Exception e) {
System.out.println("Error" + e);
e.printStackTrace(System.out);
} // end of try−catch
} // end of main
} // end of class InterestServer
Step 4: Coding the Client
Create a file named InterestClient.java by opening the text editor.
1.
Import the InterestApp and other relevant CORBA packages:
2.
import InterestApp.*;
import omg.org.CORBA.*;
import omg.org.CosNaming.*;
import java.io.*;
The next statement is the class definition, which defines the Client class and calls the main function.
3.
(Because CORBA functions may cause system exceptions at runtime, it is good practice to include a try−catch block.)
public class InterestClient {
public static void main(String args[]){
try {
// Code goes here
}catch(Exception e) {
System.out.println("Message:" + e);
e.printStackTrace();
}
}
}
Declare a variable called interestAmount to hold the value of the calculated interest and initialize it to 4.
0.0.
Use the init() method to create and initialize the ORB (each server is required to have one). The init() 5.
method has two parameters, the first of which is the command line argument for the main method, and the second of which contains application−specific properties (which is a Property object). For this example, assume that you do not have application−specific properties — that is, pass null for that parameter. In some situations, the first parameter of the method may also be null.
// Create ORB
ORB orb = ORB.init(args,null);
The preceding code returns an instance of the ORB.
The next step is to get an initial object reference, using the COS Naming Service provided with the 6.
Java IDL. In order to use the Cos Naming Service, import the org.omg.CosNaming package:
// get the root naming context
456
Chapter 18: Introducing CORBA
org.omg.CORBA.Object contextobj =
orb.resolve_initial_references("NameService");
The method resolve_initial_references is used to get an initial object reference from the Naming Services. The string "NameService" is passed as a parameter for the resolve_initial_references method.
Narrow the initial object reference obtained from a generic CORBA object, to a specific 7.
Powered by wordpress | Theme: simpletex | © Jak cię złapią, to znaczy, że oszukiwałeś. Jak nie, to znaczy, że posłużyłeś się odpowiednią taktyką.

Drogi użytkowniku!

W trosce o komfort korzystania z naszego serwisu chcemy dostarczać Ci coraz lepsze usługi. By móc to robić prosimy, abyś wyraził zgodę na dopasowanie treści marketingowych do Twoich zachowań w serwisie. Zgoda ta pozwoli nam częściowo finansować rozwój świadczonych usług.

Pamiętaj, że dbamy o Twoją prywatność. Nie zwiększamy zakresu naszych uprawnień bez Twojej zgody. Zadbamy również o bezpieczeństwo Twoich danych. Wyrażoną zgodę możesz cofnąć w każdej chwili.

 Tak, zgadzam się na nadanie mi "cookie" i korzystanie z danych przez Administratora Serwisu i jego partnerów w celu dopasowania treści do moich potrzeb. Przeczytałem(am) Politykę prywatności. Rozumiem ją i akceptuję.

 Tak, zgadzam się na przetwarzanie moich danych osobowych przez Administratora Serwisu i jego partnerów w celu personalizowania wyświetlanych mi reklam i dostosowania do mnie prezentowanych treści marketingowych. Przeczytałem(am) Politykę prywatności. Rozumiem ją i akceptuję.

Wyrażenie powyższych zgód jest dobrowolne i możesz je w dowolnym momencie wycofać poprzez opcję: "Twoje zgody", dostępnej w prawym, dolnym rogu strony lub poprzez usunięcie "cookies" w swojej przeglądarce dla powyżej strony, z tym, że wycofanie zgody nie będzie miało wpływu na zgodność z prawem przetwarzania na podstawie zgody, przed jej wycofaniem.