// $Id: StructureComponentRelation.java,v 1.1 2006/05/20 17:02:06 Sasha Buzko Exp $ // // Copyright (c) 2000-2002 San Diego Supercomputer Center (SDSC), // a facility operated jointly by the University of California, // San Diego (UCSD) and General Atomics, San Diego, California, USA. // // Users and possessors of this source code are hereby granted a // nonexclusive, royalty-free copyright and design patent license to // use this code in individual software. License is not granted for // commercial resale, in whole or in part, without prior written // permission from SDSC. This source is provided "AS IS" without express // or implied warranty of any kind. // // For further information, please see: http://mbt.sdsc.edu // // History: // $Log: StructureComponentRelation.java,v $ // Revision 1.1 2006/05/20 17:02:06 Sasha Buzko // Updated version // // Revision 1.1 2006/04/30 20:14:05 Sasha Buzko // New version of the app // // Revision 1.1 2006/04/15 19:42:27 Sasha Buzko // Initial commit // // Revision 1.1 2005/11/13 04:35:26 Administrator // *** empty log message *** // // Revision 1.2 2003/04/23 17:40:15 moreland // Removed StructureComponentID/scid and replaced it with a "structure" field // in the StructureComponent base class. // Changed "getType" method to "getStructureComponentType" to return dynamic // SC type (ie: class name). // // Revision 1.1 2002/10/24 17:54:01 moreland // Provides implementation for the improved Structure API/implementation. // // Revision 1.0 2002/09/24 23:38:39 moreland // package edu.sdsc.mbt; /** * A class used to store a single relationship description between two * StructureComponent types (much like a relational link between * tables in a database). This class is used by the StructureComponentRegistry * to define the relationship model for StructureComponent objects. *

* For example, the Conformation type relates to Atom type by means * of an implied reference between the Conformation class's start_residue * and end_residue fields, and the Atom class's residue_id field. A * Conformation object therfore "relates" to a set of Atom values. *

* @author John L. Moreland */ public abstract class StructureComponentRelation implements java.io.Serializable { /** * The name of this Relation */ private String name = null; private String subject_type = null; private String object_type = null; /** * Constructor. */ public StructureComponentRelation( String name, String subject_type, String object_type ) { this.name = name; this.subject_type = subject_type; this.object_type = object_type; } /** * Returns the name of this StructureComponentRelation object. */ public final String getName() { return name; } /** * Returns the subject type of this StructureComponentRelation * object. */ public final String getSubjectType() { return subject_type; } /** * Returns the object type of this StructureComponentRelation * object. */ public final String getObjectType() { return object_type; } /** * Tests to see if one StructureComponent instance is related to * another. This method first checks to see if the subject and object * types have a defined relation. Then a specific comparision to see * if the instances are directly linked is performed by calling the * abstract "isLinked" method. *

*/ public final boolean isRelated( StructureComponent subject, StructureComponent object ) { // Are the subject and object related at all? if ( subject.getStructureComponentType() != subject_type ) return false; if ( object.getStructureComponentType() != object_type ) return false; // Are the subject and object linked? return isLinked( subject, object ); } /** * Tests to see if one StructureComponent instance is linked to * another. This method is called by the parent class's "isRelated" * method. *

* Example: *

*

	 * StructureComponentRelation residue_relation =
	 *     new StructureComponentRelation( name, subject_type, object_type )
	 * {
	 *     abstract boolean isRelated( StructureComponent subject,
	 *         StructureComponent object )
	 *     {
	 *         // Cast the StructureComponent objects to the correct types.
	 *         Conformation conformation = (Conformation) subject;
	 *         Atom atom = (Atom) object;
	 *         
	 *         // Does the Atom's residue_id fall between the
	 *         // Conformation's start_residue and end_residue values?
	 *         if ( atom.residue_id < conformation.start_residue )
	 *             return false;
	 *         if ( atom.residue_id > conformation.end_residue )
	 *             return false;
	 *         return true;
	 *     }
	 * };
	 * 
*

*/ protected abstract boolean isLinked( StructureComponent subject, StructureComponent object ); private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { out.defaultWriteObject(); } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { in.defaultReadObject(); } }