# org.omg.CORBA\_2\_3.portable

***

**1. Creating a Dynamic Invocation Interface**

```java
import org.omg.CORBA_2_3.portable.DynamicInvocation;

// Create a DII object
DynamicInvocation dii = new DynamicInvocation();

// Set operation name
dii.operation_name("get_name");

// Set argument values
dii.arguments()[0] = "John";

// Invoke the operation
Object result = dii.invoke();
```

**2. Using the DII to Invoke a Typed Operation**

```java
import org.omg.CORBA_2_3.portable.DynamicInvocation;
import org.omg.CORBA.Any;

// Create a DII object
DynamicInvocation dii = new DynamicInvocation();

// Set operation name
dii.operation_name("get_name");

// Set argument types
dii.argument_types()[0] = Any.from_type("string");

// Invoke the operation
Object result = dii.invoke();
```

**3. Getting the Invocation Context**

```java
import org.omg.CORBA_2_3.portable.DynamicInvocation;
import org.omg.CORBA_2_3.portable.InvocationContext;

// Create a DII object
DynamicInvocation dii = new DynamicInvocation();

// Get the invocation context
InvocationContext context = dii.get_invocation_context();

// Access invocation context data
System.out.println(context.operation());
```

**4. Using an Outbound Request**

```java
import org.omg.CORBA_2_3.portable.ORBInitInfo;
import org.omg.CORBA_2_3.portable.ObjectImpl;
import org.omg.CORBA_2_3.portable.OutputStream;
import org.omg.CORBA_2_3.portable.Request;

// Create an ORB initialization info object
ORBInitInfo info = new ORBInitInfo();

// Create an ORB object
ORB orb = ORB.init(info, null);

// Create an object implementation
ObjectImpl obj = new ObjectImpl();

// Create an output stream
OutputStream os = new OutputStream();

// Create a request
Request request = orb.create_request(obj, "get_name", os, null);

// Send the request
request.send_oneway();
```

**5. Using an Inbound Request**

```java
import org.omg.CORBA_2_3.portable.ORBInitInfo;
import org.omg.CORBA_2_3.portable.ObjectImpl;
import org.omg.CORBA_2_3.portable.InputStream;
import org.omg.CORBA_2_3.portable.Request;

// Create an ORB initialization info object
ORBInitInfo info = new ORBInitInfo();

// Create an ORB object
ORB orb = ORB.init(info, null);

// Create an object implementation
ObjectImpl obj = new ObjectImpl();

// Create an input stream
InputStream is = new InputStream();

// Create a request
Request request = orb.create_request(obj, "get_name", null, is);

// Receive the request
request.receive();

// Process the request
String name = (String) request.get_arguments().[0];
```

**6. Creating an Object Reference**

```java
import org.omg.CORBA_2_3.portable.ObjectImpl;
import org.omg.CORBA_2_3.portable.ObjectReferenceFactory;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Create an object reference factory
ObjectReferenceFactory factory = orb.object_reference_factory();

// Create an object reference
ObjectReference ref = factory.create_object_reference(new ObjectImpl());
```

**7. Resolving an Object Reference**

```java
import org.omg.CORBA_2_3.portable.ObjectReference;
import org.omg.CORBA_2_3.portable.ObjectImpl;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Create an object reference
ObjectReference ref = new ObjectReference(new ObjectImpl());

// Resolve the object reference
Object obj = ref.resolve(orb);
```

**8. Creating an Object Group**

```java
import org.omg.CORBA_2_3.portable.ObjectGroup;
import org.omg.CORBA_2_3.portable.ObjectImpl;

// Create an object group
ObjectGroup group = new ObjectGroup();

// Add an object to the group
group.add(new ObjectImpl());
```

**9. Removing an Object from a Group**

```java
import org.omg.CORBA_2_3.portable.ObjectGroup;
import org.omg.CORBA_2_3.portable.ObjectImpl;

// Create an object group
ObjectGroup group = new ObjectGroup();

// Remove an object from the group
group.remove(new ObjectImpl());
```

**10. Getting the Object Group Members**

```java
import org.omg.CORBA_2_3.portable.ObjectGroup;
import org.omg.CORBA_2_3.portable.ObjectImpl;

// Create an object group
ObjectGroup group = new ObjectGroup();

// Get the group members
Object[] members = group.members();
```

**11. Creating an Object Adapter**

```java
import org.omg.CORBA_2_3.portable.ObjectAdapter;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Create an object adapter
ObjectAdapter adapter = orb.create_adapter(new ObjectAdapterFactory(), true);
```

**12. Activating an Object**

```java
import org.omg.CORBA_2_3.portable.ObjectImpl;
import org.omg.CORBA_2_3.portable.ObjectAdapter;

// Create an object implementation
ObjectImpl obj = new ObjectImpl();

// Activate the object
ObjectAdapter adapter = new ObjectAdapter();
adapter.activate(obj);
```

**13. Deactivating an Object**

```java
import org.omg.CORBA_2_3.portable.ObjectImpl;
import org.omg.CORBA_2_3.portable.ObjectAdapter;

// Create an object implementation
ObjectImpl obj = new ObjectImpl();

// Deactivate the object
ObjectAdapter adapter = new ObjectAdapter();
adapter.deactivate(obj);
```

**14. Using an Exception Listener**

```java
import org.omg.CORBA_2_3.portable.ExceptionListener;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException;

// Create an ORB object
ORB orb = ORB.init();

// Register an exception listener
orb.register_exception_listener(new ExceptionListener() {
  public void exception_occurred(SystemException ex) {
    System.out.println("Exception occurred: " + ex);
  }
});
```

**15. Setting the Service Context**

```java
import org.omg.CORBA_2_3.portable.ServiceContext;
import org.omg.CORBA_2_3.portable.ObjectImpl;

// Create an object implementation
ObjectImpl obj = new ObjectImpl();

// Set the service context
ServiceContext context = new ServiceContext();
obj.set_service_context(context);
```

**16. Getting the Service Context**

```java
import org.omg.CORBA_2_3.portable.ServiceContext;
import org.omg.CORBA_2_3.portable.ObjectImpl;

// Create an object implementation
ObjectImpl obj = new ObjectImpl();

// Get the service context
ServiceContext context = obj.get_service_context();
```

**17. Using an Event Channel**

```java
import org.omg.CORBA_2_3.portable.EventChannel;
import org.omg.CORBA_2_3.portable.EventChannelFactory;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Create an event channel factory
EventChannelFactory factory = orb.event_channel_factory();

// Create an event channel
EventChannel channel = factory.create_event_channel();
```

**18. Publishing an Event**

```java
import org.omg.CORBA_2_3.portable.EventChannel;
import org.omg.CORBA_2_3.portable.Event;

// Create an event channel
EventChannel channel = new EventChannel();

// Create an event
Event event = new Event();

// Publish the event
channel.publish(event);
```

**19. Subscribing to an Event**

```java
import org.omg.CORBA_2_3.portable.EventChannel;
import org.omg.CORBA_2_3.portable.EventConsumer;
import org.omg.CORBA_2_3.portable.Event;

// Create an event channel
EventChannel channel = new EventChannel();

// Create an event consumer
EventConsumer consumer = new EventConsumer() {
  public void offer(Event event) {
    System.out.println("Received event: " + event);
  }
};

// Subscribe to the event channel
channel.subscribe(consumer);
```

**20. Using a Data Type Factory**

```java
import org.omg.CORBA_2_3.portable.DataTypeFactory;
import org.omg.CORBA.ORB;
import org.omg.CORBA.TypeCode;

// Create an ORB object
ORB orb = ORB.init();

// Create a data type factory
DataTypeFactory factory = orb.data_type_factory();

// Create a type code
TypeCode typeCode = factory.create_string_tc(10);
```

**21. Using a String Converter**

```java
import org.omg.CORBA_2_3.portable.StringConverter;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Create a string converter
StringConverter converter = orb.string_converter();

// Convert a string to an Any
Any any = converter.create("Hello, world!");
```

**22. Using an Any Converter**

```java
import org.omg.CORBA_2_3.portable.AnyConverter;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Any;

// Create an ORB object
ORB orb = ORB.init();

// Create an any converter
AnyConverter converter = orb.any_converter();

// Convert an Any to a string
String str = converter.to_string(any);
```

**23. Using a Type Code Converter**

```java
import org.omg.CORBA_2_3.portable.TypeCodeConverter;
import org.omg.CORBA.ORB;
import org.omg.CORBA.TypeCode;

// Create an ORB object
ORB orb = ORB.init();

// Create a type code converter
TypeCodeConverter converter = orb.type_code_converter();

// Convert a type code to a string
String str = converter.to_string(typeCode);
```

**24. Using an ID Converter**

```java
import org.omg.CORBA_2_3.portable.IdConverter;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Create an ID converter
IdConverter converter = orb.id_converter();

// Convert an ID to a string
String str = converter.to_string(id);
```

**25. Using an Initializer**

```java
import org.omg.CORBA_2_3.portable.Initializer;

// Initialize an object
Object obj = Initializer.initialize(obj);
```

**26. Using a Interceptor**

```java
import org.omg.CORBA_2_3.portable.Interceptor;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Register an interceptor
orb.register_interceptor(new Interceptor() {
  public ServiceContext intercept_request(ServiceContext ctx) {
    System.out.println("Intercepted request: " + ctx);
    return ctx;
  }
});
```

**27. Using a Policy Manager**

```java
import org.omg.CORBA_2_3.portable.PolicyManager;
import org.omg.CORBA.ORB;

// Create an ORB object
ORB orb = ORB.init();

// Get the policy manager
PolicyManager manager = orb.policy_manager();

// Set a policy
manager.set_policy(new Policy());
```

**28. Using an Object Reference Factory**

```java
import org.omg.CORBA_2_3.portable.ObjectReferenceFactory;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;

// Create an ORB object
ORB orb = ORB.init();

// Get the object reference factory
ObjectReferenceFactory factory = orb.object_reference_factory();

// Create an object reference
Object obj = factory.create_object_reference(new ObjectImpl());
```

**29. Using a String Output Stream**

```java
import org.omg.CORBA_2_3.portable.StringOutputStream;

// Create a string output stream
StringOutputStream out = new StringOutputStream();

// Write a string to the stream
out.write("Hello, world!");

// Get the string from the stream
String str = out.toString();
```

\*\*30. Using a String Input
