Basically my Combond name is
Level1->Level2->object
so all I want to do is to fist see if
Level1->Level2 naming contexts exist, if not create them
and then bind the objec to them
But Sun returns NotFound when I am trying to use
bind_new_context and I just cannot figure out why
(my naming server is OmniOrb, and it appears that I can do things
if my Contexts are not combound (that is there is only Level1)
here is the code
what am I doing wrong?
---------------------------
org.omg.CosNaming.NameComponent lvl1Name=new
org.omg.CosNaming.NameComponent("Level1","kind1");
org.omg.CosNaming.NameComponent lvl2Name=new
org.omg.CosNaming.NameComponent("Level2","kind2");
org.omg.CosNaming.NameComponent[] nameTree1={lvl1Name};
org.omg.CosNaming.NameComponent[] nameTree2={lvl2Name};
org.omg.CosNaming.NameComponent[] nameTree=new
org.omg.CosNaming.NameComponent[2];
nameTree[0]=lvl1Name;
nameTree[1]=lvl2Name;
NamingContext currContext=null;
try{
//fails when tree is more than 1
currContext=rootContext.bind_new_context(nameTree);
}
catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex)
{
System.out.println("nameTree already bound");
}
catch (org.omg.CosNaming.NamingContextPackage.NotFound ex)
{
System.out.println("BIGPROBLEM nameTree not found: "+ex);
}
/* Now, bind the server to the naming context tree we have done
above */
NameComponent lvl3Name=
new NameComponent("OBJNM__monster__2800","aa_bbb");
NameComponent[] last={lvl1Name,lvl2Name,lvl3Name};
try
{
currContext.bind(last,obj);
}
catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex)
{
// if the context already exists then we just need to bind the object
//to that naming context
currContext.rebind(last, obj);
}
-------------------------
I also tried to bind piece by piece, but I do not think it is possible
because while I can bind_new_context for level 1 and then for level2
if both level1 and level2 exist (created by another server)
the there is no way for me to get the NamingContext
of the Level1->Level2
I tried bind_context (nameTree,newContext) and the newContext
never gets reset to anything valid;
thank you in advance,
VSP
Think of the naming graph to be much like a file system with contexts
being subdirectories or folders and object bindings to be like files.
Just like in the file system, where you need to make sure
all sub directories/folders in the path to create a file, in CosNaming
you need to make sure each
intermediate naming context object exists. Your approach of binding
"piece by piece" is correct and should work. The naming context of
Level1->Level2 can be obtained by invoking resolve
on the root name context with nameTree as the name. Alternatively, you
can bind last (name) to obj by invoking bind on the root name context.
Hope this helps...
Raghu
That is true, if I think of it
I cannot go to a root file system and do
mkdir Level1/Level2
I have to do either
1)
Mkdir Level1
cd Level1
mkdir Level2
or
2)
mkdir Level1
mkdir Level1/Level2
The 2) option worked for me.
I cannot however understand how in corba
I can do the first way, when Level1 and Level 2 already exist
for example, I cannot understand how to
obtain a NamingContext of a second level
when Level 1 and Level 2 already exist
When I try
curr=bind_new_context on level 1 it throughs exception that it is
already bound
that's fine, but it also does NOT assign anything to 'curr'
when I then try
curr=null;
...
catch (AlreadyBound )
{
rootContext.bind_context( Level1, curr)
}
that does not work either (curr remains empty)
so how do I 'walk' a graph when first level and second level are
NamingContextes and not object
?
thank you
Thank you very much for reply That is true, if I think of it I cannot go to a root file system and do mkdir Level1/Level2 I have to do either 1) Mkdir Level1 cd Level1 mkdir Level2 or 2) mkdir Level1 mkdir Level1/Level2 The 2) option worked for me. I cannot however understand how in corba I can do the first way, when Level1 and Level 2 already exist for example, I cannot understand how to obtain a NamingContext of a second level when Level 1 and Level 2 already exist
When I try
curr=bind_new_context on level 1 it throughs exception that it is
already bound
that's fine, but it also does NOT assign anything to 'curr'
when I then try
curr=null;
...
catch (AlreadyBound )
{
rootContext.bind_context( Level1, curr)
}
that does not work either (curr remains empty)
so how do I 'walk' a graph when first level and second level are
NamingContextes and not object
?