Package org.xorm

Source Code of org.xorm.ObjectId

/*
    $Header: /cvsroot/xorm/xorm/src/org/xorm/ObjectId.java,v 1.4 2002/10/01 01:51:52 wbiggs Exp $

    This file is part of XORM.

    XORM 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 2 of the License, or
    (at your option) any later version.

    XORM 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 XORM; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.xorm;

import java.io.Serializable;
import javax.jdo.JDOFatalException;

/**
* The shared ObjectId class used to represent datastore identity.
*/
public class ObjectId implements Serializable {
    // These are public as specified in JDO 5.4.2, Datastore Identity
    public Class mappedClass;
    public Object id;

    // This method is required for spec adherence
    public ObjectId() { }

    public ObjectId(String mangledId) {
  // De-mangle the ID
  int p = mangledId.indexOf(';');
  if (p == -1) {
      throw new JDOFatalException("Badly formatted object ID");
  }
  try {
      mappedClass = Class.forName(mangledId.substring(0,p));
  } catch (ClassNotFoundException e) {
      throw new JDOFatalException("Unknown object class " + mangledId.substring(0,p));
  }
  id = mangledId.substring(p+1);
    }

    /** Constructs a new ObjectId for the given class and argument. */
    public ObjectId(Class mappedClass, Object id) {
  this.mappedClass = mappedClass;
  this.id = id;
    }

    /**
     * Returns the String representation of this ObjectId,
     * which is simply getId().toString() with a null check.
     * This value can later be used with PersistenceManager.
     * newObjectIdInstance().
     */
    public String toString() {
  return mappedClass.getName() + ';' + ((id == null) ? "" : id.toString());
    }

    public boolean equals(Object o) {
  if (o == this) return true;
  if (o == null) return false;
  if (!(o instanceof ObjectId)) return false;
  ObjectId other = (ObjectId) o;
  boolean e1 = (mappedClass == null) ?
      (other.mappedClass == null) : (mappedClass.equals(other.mappedClass));
  boolean e2 = (id == null) ?
      (other.id == null) : (id.equals(other.id));
  return e1 && e2;
    }
}
TOP

Related Classes of org.xorm.ObjectId

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.