Package net.sf.chellow.physical

Source Code of net.sf.chellow.physical.PersistentEntity

/*******************************************************************************
*
*  Copyright (c) 2005, 2009 Wessex Water Services Limited
*  This file is part of Chellow.
*
*  Chellow is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  Chellow 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 General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with Chellow.  If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/

package net.sf.chellow.physical;

import net.sf.chellow.monad.HttpException;
import net.sf.chellow.monad.Invocation;
import net.sf.chellow.monad.MethodNotAllowedException;
import net.sf.chellow.monad.NotFoundException;
import net.sf.chellow.monad.Urlable;
import net.sf.chellow.monad.types.MonadObject;
import net.sf.chellow.monad.types.UriPathElement;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public abstract class PersistentEntity extends MonadObject implements Urlable {
  private Long id;

  public PersistentEntity() {
  }

  public Long getId() {
    return id;
  }

  protected void setId(Long id) {
    this.id = id;
  }

  public UriPathElement getUriId() throws HttpException {
    return new UriPathElement(id.toString());
  }

  public Element toXml(Document doc, String elementName) throws HttpException {
    Element element = (Element) super.toXml(doc, elementName);

    element.setAttribute("id", id.toString());
    return element;
  }

  public boolean equals(Object obj) {
    boolean isEqual = false;

    if (obj instanceof PersistentEntity) {
      isEqual = ((PersistentEntity) obj).getId().equals(getId());
    }
    return isEqual;
  }

  public int hashCode() {
    return id == null ? super.hashCode() : id.intValue();
  }

  public void httpDelete(Invocation inv) throws HttpException {
    throw new MethodNotAllowedException();
  }

  public void httpGet(Invocation inv) throws HttpException {
    throw new MethodNotAllowedException();
  }

  public void httpPost(Invocation inv) throws HttpException {
    throw new MethodNotAllowedException();
  }

  public Urlable getChild(UriPathElement uriId) throws HttpException {
    throw new NotFoundException();
  }
}
TOP

Related Classes of net.sf.chellow.physical.PersistentEntity

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.