Hello,
I have followed the links below to create AbstractPortalComponent to store user data in UCD, I was able to create the namespace but unable to bind the object to context
http://help.sap.com/saphelp_nw73ehp1/helpdata/en/4A/8E1BCE28E24DD8ABD9F4DE05E5587D/content.htm
Here is my sample code. Error is object of TestClass is not supported. Whenever I tried to bind the object context, I am getting either Naming exception or Obj is not supported.
Any idea?
public class TestUCD extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
String namespace = "TestNamespace";
if(!namespaceExists(namespace))
{
try {
INamespace ns = createNamespace(namespace);
IPcdContext defaulContext = ns.getContext();
TestClass obj = new TestCalss();
obj.setName("hello");
defaulContext.bind("Test123", obj);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private IPcdContext getUcdContext() throws NamingException
{
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.UCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, UMFactory.getAuthenticator().getLoggedInUser());
env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);
InitialContext ctx = new InitialContext(env);
return (IPcdContext) ctx.lookup("pcd:portal_content/TestUCD");
}
private INamespace createNamespace(String myNamespace) throws NamingException
{
IPcdContext ucdContext = getUcdContext();
INamespaceManager namespaceManager = (INamespaceManager) PortalRuntime.getRuntimeResources().getService (INamespaceManager.KEY);
INamespaceDescriptor myNamespaceDesc = (INamespaceDescriptor) namespaceManager.instantiateDescriptor(myNamespace);
ucdContext.bind(myNamespace, myNamespaceDesc);
return getNamespace(myNamespace);
}
private INamespace getNamespace(String myNamespace) throws NamingException
{
IPcdContext ucdContext = getUcdContext();
ucdContext.addToEnvironment(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
INamespace namespace = (INamespace) ucdContext.lookup(myNamespace);
return namespace;
}
private boolean namespaceExists(String myNamespace)
{
try
{
IPcdContext ucdContext = getUcdContext();
ucdContext.addToEnvironment(Constants.REQUESTED_ASPECT, IPcdAttribute.ASPECT_EXISTENCE);
Boolean exists = (Boolean) ucdContext.lookup(myNamespace);
return exists.booleanValue();
}
catch (NamingException e)
{
return false;
}
}
}