Show TOC

Background documentationCode Examples for Working with the UCD Locate this document in the navigation structure

 

This section provides the following examples:

  • Checking Whether a Namespace Exists

  • Getting a Namespace

  • Creating a Namespace

Example

Checking Whether a Namespace Exists

Syntax Syntax

  1. 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;
    		}
    	}
    
End of the code.
Getting a Namespace

Syntax Syntax

  1. 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;
    	}
    
End of the code.
Creating a Namespace

Syntax Syntax

  1. 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);
    	}
    
End of the code.