excercise 2 done

This commit is contained in:
2025-12-12 22:48:54 +01:00
parent a60e3de86a
commit 27259a12e0
123 changed files with 2946 additions and 1 deletions

View File

@@ -0,0 +1,98 @@
// Copyright and License
import GraphicsApp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
// because we need GraphicalObject we have to do an implementation of it here.
// reversing the HelloServer.java here
class Graph extends GraphicalObjectPOA {
private boolean filled;
private String name;
private ORB orb;
public Graph(String name, boolean filled) {
this.name = name;
this.filled = filled;
}
public void setORB(ORB orb_val) {
this.orb = orb_val;
}
// draw
public void draw() {
System.out.println("Drawing graph: " + name);
}
// show info
public void showInfo() {
System.out.println("Graph Info -> Name: " + name + ", Filled: " + filled);
}
// getter for is filled
public boolean is_filled() {
return filled;
}
// setter for is filled
public void is_filled(boolean value) {
this.filled = value;
}
// name getter, not setting it.
public String name() {
return name;
}
}
public class GraphicsClient
{
static Rectangle rect;
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get reference to rootpoa and activate the POAManager
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
// reversing steps from HelloServer here as well.
// create servant and register it with the ORB
Graph graph = new Graph("Circle", true);
graph.setORB(orb);
// get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(graph);
GraphicalObject object = GraphicalObjectHelper.narrow(ref);
// get the root naming context
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
// Use NamingContextExt instead of NamingContext. This is
// part of the Interoperable naming Service.
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
// resolve the Object Reference in Naming
String name = "Graphics";
rect = RectangleHelper.narrow(ncRef.resolve_str(name));
System.out.println("Obtained a handle on server object: " + rect);
rect.addObject(object);
rect.removeObjectAtPosition(0);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}