Java tutorial
/** * PureInfo Quake * @(#)WfActivity.java 1.0 Oct 13, 2005 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.config.workflow.model; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.dom4j.Element; import com.pureinfo.force.PureFactory; import com.pureinfo.force.exception.PureException; import com.pureinfo.force.xml.IXMLSupporter; import com.pureinfo.force.xml.XMLUtil; import com.pureinfo.srm.config.workflow.WorkflowHelper; import com.pureinfo.srm.config.workflow.domain.IWorkflowMgr; /** * <P> * Created on Oct 13, 2005 11:23:50 PM <BR> * Last modified on Oct 13, 2005 * </P> * * @author Freeman.Hu * @version 1.0, Oct 13, 2005 * @since Quake 1.0 */ public class WfActivity implements IXMLSupporter { private static final Logger logger = Logger.getLogger(WfActivity.class); public final static String ELEMENT_ACTIVITY = "activity"; public final static String ATTRIBUTE_NAME = "name"; public final static String ELEMENT_ROLEREF = "role-ref"; public final static String ATTRIBUTE_ID = "id"; private String m_sName; private Map /* WfRole */ m_roles; public WfActivity() { } public WfActivity(String _sName) { m_sName = _sName; m_roles = new HashMap(); } public Map /* WfRole */ getRoles() { return m_roles; } public void setRoles(Map /* WfRole */ roles) { m_roles = roles; } public boolean check(List roleNames) { for (Iterator iter = roleNames.iterator(); iter.hasNext();) { if (m_roles.containsKey(iter.next())) return true; } return false; } public void setRoles(String _sRoleStr) throws PureException { String[] roles = StringUtils.split(_sRoleStr, ','); Map roleMap = new HashMap(); for (int i = 0; i < roles.length; i++) { WfRole role = WorkflowHelper.getRole(roles[i]); if (role == null) { logger.warn(roles[i] + " is not legel role id"); } else { roleMap.put(roles[i], role); } } m_roles = roleMap; } public String getName() { return m_sName; } /** * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element) */ public void toXMLElement(Element _element) throws PureException { _element.addAttribute(ATTRIBUTE_NAME, m_sName); if (m_roles == null) return; for (Iterator iter = m_roles.keySet().iterator(); iter.hasNext();) { Element role = _element.addElement(ELEMENT_ROLEREF); role.addAttribute(ATTRIBUTE_ID, (String) iter.next()); } } /** * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element) */ public void fromXML(Element _element) throws PureException { m_sName = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_NAME); List roleIdEles = _element.elements(ELEMENT_ROLEREF); m_roles = new HashMap(); IWorkflowMgr wfMgr = (IWorkflowMgr) PureFactory.getBean("IWorkflowMgr"); for (Iterator iter = roleIdEles.iterator(); iter.hasNext();) { Element roleIdEle = (Element) iter.next(); String sId = XMLUtil.getRequiredAttributeValue(roleIdEle, ATTRIBUTE_ID); WfRole role = wfMgr.getRole(sId); m_roles.put(sId, role); } } }