EntityManager.java revision 8af80418ba1ec431c8027fa9668e5678658d3611
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: EntityManager.java,v 1.3 2008/06/25 05:41:44 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class has the responsibility of creating structural entities. A
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * structural entity is an entry which contains other entries (example: people
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * container). The information in the DIT (under "StructureTemplates") defines
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the structure . For example, when an Organization is created, it will contain
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * a "Groups" container. This class creates the structure of entities as defined
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the DIT.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class EntityManager implements IUMSConstants {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the instance of Entity Manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Instance of Entity manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If an exception occurs.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static synchronized EntityManager getEntityManager()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method will use methods provided by ConfigManager to get "Structure
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Template" information from the DIT. It will use this information to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * create the "Structural Entity".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param principal
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The Principal.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pObject
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The persistent object for which the entities apply.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pGUID
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The guid of the parent object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if an exception occurs.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void execute(java.security.Principal principal,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PersistentObject pObject, Guid pGUID) throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .getString(IUMSConstants.PERSISTENT_OBJECT_PARAM_NULL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("GETTING ENTITY FOR:CLASS:" + className + ",PARENT:"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster set = _configManager.getEntity(pGUID, className);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IUMSConstants.STRUCTURE_TEMPLATE_ATTRSET_NULL, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.CONFIG_MGR_ERROR, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster hm.put(attrValues[i], _parentObject.getGuid());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Guid parentGuid = (Guid) hm.get(childNodeName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set childSet = _configManager.getEntity(pGUID, childNodeName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.CONFIG_MGR_ERROR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create Object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PersistentObject pObj = createObject(attrSet, parentGuid, pGUID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method will determine which Structure Template entry to use if there
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is more than one returned from ConfigManagerUMS. It will make the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * determination based on the "filter" and "priority" attributes in each
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Structure Template atrribute set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pObject
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The persistentObject for which the Structure Template applies.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The Set containing multiple Structure Template attribute sets.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if an error occurs.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private AttrSet findEntity(PersistentObject pObject, Set set)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Loop through all attrSets in Set, and for each one:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // o use the filter to find the entry for which the Structure
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Template applies. If each of the attrSet filters finds
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // an entry, select the one with the highest priority (0 being
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // the highest).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String filter = attrSet.getAttribute(ENTITY_FILTER).getValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IUMSConstants.BAD_STRUCTURE_TEMPLATE_PRIORITY, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method creates a Persistent Object and adds it to a "parent"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Persistent Object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrSet
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The attribute set used to create the child object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param parentGUID
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The identifier for the "parent" Persistent object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param searchGuid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Where to get the CreationTemplate.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The child Persistent Object which was added to the parent.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if an exception occurs.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private PersistentObject createObject(AttrSet attrSet, Guid parentGuid,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Extract attributes from attribute sets.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Build an attribute set of name/value pairs which will
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // be used with the CreationTemplate to create the child
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Persistent Object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Attr tempAttr = attrSet.getAttribute(ENTITY_TEMPLATE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Attr attrAttr = attrSet.getAttribute(ENTITY_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.BAD_NAMING_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = attrValues[k].indexOf(NAME_TOKEN_DELIM);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.BAD_NAMING_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrValue = attrValues[k].substring(index + 1, attrValues[k]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Use the TemplateManager to get an instance of a CreationTemplate.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the class name from the CreationTemplate.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Instantiate the constructor which accepts the attribute set -
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // this creates the child object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Add the child object to the parent.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CreationTemplate ct = _templateMgr.getCreationTemplate(templateName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PersistentObject pObj = new PersistentObject(ct, attrSet);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String idValue = pObj.getAttribute(idAttr).getValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Guid childGuid = new Guid(idAttr + "=" + idValue + ","
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dataLayer.addEntry(_principal, childGuid, atts);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if an exception occurs.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _configManager = ConfigManagerUMS.getConfigManager();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _templateMgr = TemplateManager.getTemplateManager();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENTITY_CHILDNODE = "childNode";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENTITY_FILTER = "filter";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENTITY_PRIORITY = "priority";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENTITY_TEMPLATE = "template";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENTITY_NAME = "name";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String NAME_TOKEN_DELIM = "=";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static I18n i18n = I18n.getInstance(IUMSConstants.UMS_PKG);