Show TOC

Code Examples for Working with the UCDLocate this document in the navigation structure

Use

This section provides the following examples:

  • Checking Whether a Namespace Exists

  • Getting a Namespace

  • Creating a Namespace

Example

Checking Whether a Namespace Exists

               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;
                }
        }

            

Getting a Namespace

               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;
        }

            

Creating a Namespace

               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);
        }