Generic method to get ObjectID from unique Name

When your using Portal SPI or POrtal Controller SPI to either read portal information or modify it, you will notice that most of the methods take com.ibm.portal.ObjectID as argument. So far i used object specific methods to get the ObjectID from unique name

But it seems that you can use the following method to look up ObjectID from JNDI COntext


private ObjectID getObjectID(String uniqueNameStr){
try {
InitialContext ctx = new InitialContext();
final Name uniqueName = new CompositeName("portal:uniquename");
uniqueName.add(uniqueNameStr);
ObjectID oidForUniqueName = (ObjectID) ctx.lookup(uniqueName);
return oidForUniqueName;
} catch (InvalidNameException e) {
e.printStackTrace(System.out);
} catch (NamingException e) {
e.printStackTrace(System.out);
}
return null;
}


You can call this method with unique name of either page, portlet or navigation node and it will return you the instance of com.ibm.portal.ObjectID for that unique name.

I tried calling it for a page, portlet and Portlet Window like this

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering DynamicUIPortlet.doView()");
PrintWriter out = response.getWriter();
out.println("com.webspherenotes.popup.static " +
getObjectID("com.webspherenotes.popup.static") +"
");
out.println("com.webspherenotes.popup.control " +
getObjectID("com.webspherenotes.popup.control") +"
");
out.println("com.webspherenotes.popup.portlet " +
getObjectID("com.webspherenotes.popup.portlet") +"
");
System.out.println("Exiting DynamicUIPortlet.doView()");
}


I am calling the getObjectID() method with different unique names and printing output in the doView() method this is what i get