Hashtable composite_context= new Hashtable();
if (contexts != null) {
Vector newNames = new Vector();
for (int i = 0; i < contexts.length; i++) {
if(!looseCoupling) {
NamingContext nc = getServerImpl().getNamingContext(
contexts[i].getNamingContext().getId());
if (nc == null) {
getServerImpl().addNamingContext(contexts[i]);
newNames.addElement(contexts[i].getCompositeName());
}
// Else the naming context has already been
// added by an other server that is the (new)
// owner of this context.
} else {
NamingContext nc;
try{
nc = getServerImpl().getNamingContext(contexts[i].getCompositeName());
}catch(MissingRecordException mre){
nc=null;
}catch( MissingContextException mce){
nc=null;
}
if(nc == null){
nc = getServerImpl().newNamingContext( getId(),null,contexts[i].getCompositeName());
contexts[i].getNamingContext().setOwnerId(getId());
}
Enumeration enumRecord = contexts[i].getNamingContext().getEnumRecord();
while (enumRecord.hasMoreElements()) {
Record record =(Record) enumRecord.nextElement();
Record r = nc.getRecord(record.getName());
if (r == null)
nc.addRecord(record);
if(record instanceof ContextRecord){
CompositeName parentPath = contexts[i].getCompositeName();
record_compositeName.put(record,parentPath);
}
}
composite_context.put(contexts[i].getCompositeName(),nc);
}
}
if(looseCoupling){
Enumeration enumKeyRecord = record_compositeName.keys();
while(enumKeyRecord.hasMoreElements()) {
Record recor =(Record)enumKeyRecord.nextElement();
CompositeName cn =(CompositeName)((CompositeName)(record_compositeName.get(recor))).clone();
cn.add(recor.getName());
if(composite_context.containsKey(cn)){
NamingContext nc =(NamingContext)composite_context.get(cn);
((ContextRecord)recor).setId(nc.getId());
}
}
Enumeration enumContext = composite_context.elements();
while(enumContext.hasMoreElements()) {
NamingContext nc =(NamingContext)enumContext.nextElement();
getServerImpl().storeNamingContext(nc);
}
}