net.sf.mpxj.CustomFieldContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mpxj Show documentation
Show all versions of mpxj Show documentation
Library that provides facilities to allow project information to be manipulated in Java and .Net. Supports a range of data formats: Microsoft Project Exchange (MPX), Microsoft Project (MPP,MPT), Microsoft Project Data Interchange (MSPDI XML), Microsoft Project Database (MPD), Planner (XML), Primavera (PM XML, XER, and database), Asta Powerproject (PP, MDB), Asta Easyplan (PP), Phoenix Project Manager (PPX), FastTrack Schedule (FTS), and the Standard Data Exchange Format (SDEF).
/*
* file: CustomFieldContainer.java
* author: Jon Iles
* copyright: (c) Packwood Software 2002-20015
* date: 28/04/2015
*/
/*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
package net.sf.mpxj;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.sf.mpxj.common.Pair;
import net.sf.mpxj.mpp.CustomFieldValueItem;
/**
* Container holding configuration details for all custom fields.
*/
public class CustomFieldContainer implements Iterable
{
/**
* Retrieve configuration details for a given custom field.
*
* @param field required custom field
* @return configuration detail
*/
public CustomField getCustomField(FieldType field)
{
CustomField result = m_configMap.get(field);
if (result == null)
{
result = new CustomField(field, this);
m_configMap.put(field, result);
}
return result;
}
/**
* Return the number of custom fields.
*
* @return number of custom fields
*/
public int size()
{
return m_configMap.values().size();
}
@Override public Iterator iterator()
{
return m_configMap.values().iterator();
}
/**
* Retrieve a custom field value by its unique ID.
*
* @param uniqueID custom field value unique ID
* @return custom field value
*/
public CustomFieldValueItem getCustomFieldValueItemByUniqueID(int uniqueID)
{
return m_valueMap.get(Integer.valueOf(uniqueID));
}
/**
* Add a value to the custom field value index.
*
* @param item custom field value
*/
public void registerValue(CustomFieldValueItem item)
{
m_valueMap.put(item.getUniqueID(), item);
}
/**
* Remove a value from the custom field value index.
*
* @param item custom field value
*/
public void deregisterValue(CustomFieldValueItem item)
{
m_valueMap.remove(item.getUniqueID());
}
/**
* When an alias for a field is added, index it here to allow lookup by alias and type.
*
* @param type field type
* @param alias field alias
*/
void registerAlias(FieldType type, String alias)
{
m_aliasMap.put(new Pair(type.getFieldTypeClass(), alias), type);
}
/**
* Retrieve a field from a particular entity using its alias.
*
* @param typeClass the type of entity we are interested in
* @param alias the alias
* @return the field type referred to be the alias, or null if not found
*/
public FieldType getFieldByAlias(FieldTypeClass typeClass, String alias)
{
return m_aliasMap.get(new Pair(typeClass, alias));
}
/**
* Because there seemingly is no deterministic method of mapping UDF ObjectIds from Primavera PM to FieldTypes,
* the aliasValueMap will store UDF values to be used by something that knows what alias maps to which FieldType.
* @author lsong
* @param alias custom field alias
* @param uid field container unique id
* @param value field value
*/
public void registerAliasValue(String alias, Integer uid, Object value)
{
if (!m_aliasValueMap.containsKey(alias))
{
m_aliasValueMap.put(alias, new HashMap());
}
m_aliasValueMap.get(alias).put(uid, value);
}
/**
* Importers with access to the ProjectFile containing this can determine how to
* use the values in the UDFAssignmentTypes in UDF containers.
* @author lsong
* @param alias custom field alias
* @param uid field container unique id
* @return field value
*/
public Object getAliasValue(String alias, Integer uid)
{
if (m_aliasValueMap.containsKey(alias))
{
return m_aliasValueMap.get(alias).get(uid);
}
return null;
}
private Map m_configMap = new HashMap();
private Map m_valueMap = new HashMap();
private Map, FieldType> m_aliasMap = new HashMap, FieldType>();
private Map> m_aliasValueMap = new HashMap>();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy