📄 persistencedescriptionmap.java
字号:
/*
* OPIAM Suite
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package opiam.admin.faare.config.javabeans;
import opiam.admin.faare.MessageUtil;
import opiam.admin.faare.exception.PersistenceException;
import org.apache.log4j.Logger;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* This class corresponds to the top level element of the faare_mapping.xml file.<br>
* It stores LDAP server configuration and mapped objects definition.
*/
public class PersistenceDescriptionMap implements java.io.Serializable
{
/** Instance of logger. */
private static Logger _logger = Logger.getLogger(PersistenceDescriptionMap.class);
/** List of mapped objects. Key = class name, value = class (class instanceOf JBClassDescriptor). */
private Map descMap = new HashMap();
/** LDAP server configuration. */
private JBLdapConfig ldapConfig;
/**
* Returns the mapped objects table.
* @return Mapped objects table.
*/
public Map getDescMap()
{
return descMap;
}
/**
* Sets the mapped objects table.
* @param adescMap The mapped objects table to set
*/
public void setDescMap(Map adescMap)
{
this.descMap = adescMap;
}
/**
* Adds a mapped object descriptor to the list.
*
* @param classDesc mapped object descriptor to add
*/
public void addClass(JBClassDescriptor classDesc)
{
descMap.put(classDesc.getName(), classDesc);
}
/**
* Gets a mapped object descriptor from the class name.
*
* @param className requested class name
*
* @return mapped object descriptor
*
* @throws PersistenceException if class is not found
*/
public JBClassDescriptor getClassDescriptor(String className)
throws PersistenceException
{
JBClassDescriptor result = (JBClassDescriptor) descMap.get(className);
if (result == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_MAPPING_OBJECTCLASS_NOT_FOUND", "getClassDescriptor"));
}
return result;
}
/**
* Gets the class of a mapped object from its object class.
* @param enum list of object classes
* @return Class of the mapped object
* @throws PersistenceException if no object class or if not found
*/
public Class getClass(Enumeration enum) throws PersistenceException
{
if (enum == null)
{
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_ARGUMENT_NULL", "enum", "getClass", "PersistenceLDAP"));
}
Class result = null;
Set ldapOcSet = new HashSet();
String s;
StringBuffer msg = new StringBuffer();
// On construit une liste de type HashSet avec les objectclass envoy閟
// Ceci pour faciliter la comparaison
while (enum.hasMoreElements())
{
s = ((String) enum.nextElement()).toLowerCase().trim();
_logger.debug("getClass s : " + s);
ldapOcSet.add(s);
msg.append(s + " ");
}
//On r閏up鑢e la liste des HashSet contenant toutes les listes d'objectclass
//d閒inis dans le fichier de mapping
//On va chercher la liste qui correpond et renvoyer la classe correspondante
HashSet h = null;
String cls;
Object[] sortedClasses = descMap.values().toArray();
Arrays.sort(sortedClasses);
Iterator descIt = (Arrays.asList(sortedClasses)).iterator();
JBClassDescriptor classDesc = null;
while (descIt.hasNext())
{
_logger.debug("descIt.hasNext() ");
classDesc = (JBClassDescriptor) descIt.next();
if (classDesc.isObjectClassMatched(ldapOcSet))
{
return classDesc.getTheClass();
}
}
// no match found
_logger.error(MessageUtil.formatMessage(
"MSG_MAPPING_OBJECTCLASS_NOT_FOUND", msg.toString()));
throw new PersistenceException(MessageUtil.formatMessage(
"MSG_MAPPING_OBJECTCLASS_NOT_FOUND", msg.toString()));
}
/**
* Returns the LDAP server configuration.
* @return LDAP server configuration.
*/
public JBLdapConfig getLdapConfig()
{
return ldapConfig;
}
/**
* Sets the LDAP server configuration..
* @param aldapConfig The LDAP server configuration to set
*/
public void setLdapConfig(JBLdapConfig aldapConfig)
{
this.ldapConfig = aldapConfig;
}
/**
* Displays the persistence configuration.
*
* @return String formatted configuration.
*/
public String toString()
{
StringBuffer buf = new StringBuffer();
java.util.Iterator it = null;
if (descMap != null)
{
buf.append("Map components of descMap = ");
buf.append(System.getProperty("line.separator"));
it = descMap.keySet().iterator();
Object key;
while (it.hasNext())
{
buf.append("...");
key = it.next();
buf.append(key);
buf.append(" = ");
buf.append(descMap.get(key));
buf.append(System.getProperty("line.separator"));
}
}
buf.append("ldapConfig = ");
buf.append(ldapConfig);
buf.append(System.getProperty("line.separator"));
return buf.toString();
}
// end of toString method
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -