Problem:
- Product Name: VisiBroker Java
- Product Version: 4.5.1 and later
- Product Component: IOR/Component
- Platform/OS Version: All
- JDK/Compiler Version: JDK 1.3 and later
How to add a new component that would contain generic information like PID to an IOR?
Resolution:
Please follow these steps:
1. Install IORCreationInterceptor. Please refer to the "interceptors/ior_creation" example directory to see how this is done.
2. During the create() method of the IORCreationInterceptor installed, obtain the process ID, check for a null component in the profile, and create/add the component to the profile.
Below is the code sample:
// SampleIORCreationInterceptor.java
import com.inprise.vbroker.PortableServerExt.*;
import com.inprise.vbroker.IOP.*;
import com.inprise.vbroker.IIOP.*;
public class SampleIORCreationInterceptor implements IORCreationInterceptor {
protected org.omg.CORBA.ORB _orb;
public SampleIORCreationInterceptor(org.omg.CORBA.ORB orb) {
_orb = orb;
}
public void create(org.omg.PortableServer.POA poa, IORValueHolder ior) {
System.out.println("============>SampleIORCreationInterceptor: create");
com.inprise.vbroker.orb.ORB thisORB= (com.inprise.vbroker.orb.ORB) _orb;
ComponentValue [] myNewCompList = null;
if (thisORB == null) {
System.out.println("null ORB");
System.exit(0);
}
com.inprise.vbroker.properties.PropertyManager pm = thisORB.getPropertyManager();
int processID = pm.getInt("vbroker.orb.procId");
for (int i=0; i<ior.value.profiles.length ; i ) {
if (((ProfileBodyValue)ior.value.profiles).components == null) {
myNewCompList = new ComponentValue[1];
myNewCompList[0] = new GenericIDComponentImpl(thisORB, processID);
} else {
int len = ((ProfileBodyValue)ior.value.profiles).components.length;
myNewCompList = new ComponentValue[1 len];
System.arraycopy(((ProfileBodyValue)ior.value.profiles).components, 0, myNewCompList, 0, len);
myNewCompList[len] = new GenericIDComponentImpl(thisORB, processID);
}
((ProfileBodyValue)ior.value.profiles).components = myNewCompList;
}//end for loop
}// end create()
}
The two supporting classes, GenericIDComponentImpl and TAG_GENERIC_ID, are as follows:
//GenericIDComponentImpl.java
import com.inprise.vbroker.orb.ORB;
import com.inprise.vbroker.CORBA.portable.*;
import com.inprise.vbroker.IOP.*;
public class GenericIDComponentImpl implements ComponentValue, Cloneable {
final ORB _orb;
int _GenericID;
TaggedComponent _component;
public GenericIDComponentImpl(ORB orb, int gID) {
_orb = orb;
_GenericID=gID;
}
public GenericIDComponentImpl(ORB orb, EntityRegistry registry, TaggedComponent component) {
_orb = orb;
if (component == null || component.tag != TAG_GENERIC_ID.value) {
throw new org.omg.CORBA.BAD_PARAM("Invalid tagged component: " component);
}
_component=component;
}
public int tag() {
return TAG_GENERIC_ID.value;
}
public com.inprise.vbroker.IOP.ComponentValue copy() {
try {
return (com.inprise.vbroker.IOP.ComponentValue)this.clone();
} catch(CloneNotSupportedException e) {
throw new org.omg.CORBA.INTERNAL(e.toString());
}
}
public int type() {
if(_component!=null) {
// need to demarshal
InputStream input = (InputStream)_orb.create_cdr_input_stream(_component.component_data);
input.byteOrder(input.read_boolean());
_GenericID = input.read_ulong();
input.destroy();
_component=null;
}
return _GenericID;
}
public boolean matchesTemplate(com.inprise.vbroker.IOP.ComponentValue template) {
if (!(template instanceof GenericIDComponentImpl)) {
return false;
}
return ((GenericIDComponentImpl) template).tag()==tag();
}
public TaggedComponent toTaggedComponent() {
TaggedComponent component=_component;
if(component==null) {
OutputStream output = (OutputStream)_orb.create_cdr_output_stream();
output.write_boolean(ORB.JAVA_ENDIAN);
output.write_ulong(type());
component = new TaggedComponent(this.tag(), output.toByteArray());
output.destroy();
}
return component;
}
public String prettyPrint() {
StringBuffer sb=new StringBuffer("GENERIC_ID Component: ");
sb.append("Process ID = " type());
return sb.toString();
}
public String[] _truncatable_ids() {
return new String[0];
}
}
//TAG_GENERIC_ID.java
public interface TAG_GENERIC_ID {
public final static int value = (int)9112001;
}
Support Case # 523087
#Security
#IOR
#Java
#component
#VisiBroker




