com.pureinfo.dolphinview.common.model.ResourceMetadata.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.dolphinview.common.model.ResourceMetadata.java

Source

/**
 * PureInfo Dolphin
 * @(#)CommonResource.java   1.0 Aug 25, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.dolphinview.common.model;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

import com.pureinfo.force.exception.CheckUtils;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.xml.IXMLSupporter;
import com.pureinfo.force.xml.XMLUtil;

/**
 * <P>
 * Created on Aug 25, 2005 11:22:09 AM <BR>
 * Last modified on Aug 25, 2005
 * </P>
 * The resource that defined common.
 * 
 * @author Freeman.Hu
 * @version 1.0, Aug 25, 2005
 * @since Dolphin 1.0
 */
public class ResourceMetadata implements IXMLSupporter {
    public final static String TYPE_JAVASCRIPT = "javascript";

    public final static String ELEMENT_RESOURCE = "resource";

    public final static String ATTRIBUTE_ID = "id";

    public final static String ATTRIBUTE_TYPE = "type";

    public final static String ATTRIBUTE_PATH = "path";

    /**
     * the resource id
     */
    private String m_sId;

    /**
     * the type of the resource
     */
    private String m_sType;

    /**
     * the path where the resource is located
     */
    private String m_sPath;

    public ResourceMetadata(String _sId, String _sType, String _sPath) {
        setId(_sId);
        setType(_sType);
        setPath(_sPath);
    }

    /**
     * Constructor
     *  
     */
    public ResourceMetadata() {

        // TODO Auto-generated constructor stub
    }

    public String getId() {
        return m_sId;
    }

    public void setId(String id) {
        m_sId = id;
    }

    public String getPath() {
        return m_sPath;
    }

    public void setPath(String path) {
        m_sPath = path;
    }

    public String getType() {
        return m_sType;
    }

    public void setType(String type) {
        m_sType = type;
    }

    /**
     * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
     */
    public void toXMLElement(Element _element) throws PureException {
        throw new UnsupportedOperationException("if you want to use this operation,please implement it yourself");
    }

    /**
     * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
     */
    public void fromXML(Element _element) throws PureException {
        CheckUtils.checkRequestNotNull(_element);
        CheckUtils.checkElementName(_element, ELEMENT_RESOURCE);

        setId(XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_ID));
        setType(XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_TYPE));
        setPath(XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_PATH));
    }

    /**
     * @param _element
     * @throws PureException
     */
    public static void readResources(Element _element, Map _container) throws PureException {
        CheckUtils.checkRequestNotNull(_element);

        List resEleList = _element.elements(ELEMENT_RESOURCE);
        for (Iterator iter = resEleList.iterator(); iter.hasNext();) {
            Element resEle = (Element) iter.next();
            ResourceMetadata res = new ResourceMetadata();
            res.fromXML(resEle);
            _container.put(res.getId(), res);
        }
    }
}