Save This Page
Home » openjdk-7 » net » sf » rvpf » metadata » [javadoc | source]
    1   /**
    2    * Related Values Processing Framework.
    3    * 
    4    * Copyright (C) 2003 Serge Brisson.
    5    * 
    6    * This software is distributable under LGPL license.
    7    * See details at the bottom of this file.
    8    * 
    9    * $Header: /cvsroot/rvpf/RVPF/java/src/net/sf/rvpf/metadata/PointEntity.java,v 1.17 2003/10/24 16:11:27 sfb Exp $
   10    */
   11   package net.sf.rvpf.metadata;
   12   
   13   import java.util.Collections;
   14   import java.util.Iterator;
   15   import java.util.LinkedList;
   16   import java.util.List;
   17   
   18   import net.sf.rvpf.content.Content;
   19   import net.sf.rvpf.processor.engine.Transform;
   20   import net.sf.rvpf.store.Store;
   21   
   22   /** Point Entity.
   23    * 
   24    * @author Serge Brisson
   25    * @version $Revision: 1.17 $
   26    */
   27   public class PointEntity extends ParamsEntity implements Point {
   28   
   29       // Public Class Constants.
   30       
   31       public static final String PREFIX = "P";
   32   
   33       // Instance Properties.
   34   
   35       /**
   36        */
   37       public Content getContent() {
   38           return (Content) this.content.getInstance();
   39       }
   40   
   41       /** Gets the Content Entity for this Point.
   42        * 
   43        * @return The Content Entity.
   44        */
   45       public ContentEntity getContentEntity() {
   46           return this.content;
   47       }
   48   
   49       /** Sets the Content Entity for this Point.
   50        * 
   51        * @param content The Content Entity.
   52        */
   53       public void setContentEntity(ContentEntity content) {
   54           this.content = content;
   55       }
   56   
   57       /**
   58        */
   59       public List getFilters() {
   60           if (this.filters == null) return Collections.EMPTY_LIST;
   61   
   62           return this.filters;
   63       }
   64   
   65       /**
   66        */
   67       public List getInputs() {
   68           List inputs;
   69           
   70           if (this.inputRelations == null) inputs = Collections.EMPTY_LIST;
   71           else inputs = Collections.unmodifiableList(this.inputRelations);
   72   
   73           return inputs;
   74       }
   75   
   76       /**
   77        */
   78       public int getLevel() {
   79           return this.level;
   80       }
   81   
   82       /** Gets the Origin Entity for this Point.
   83        * 
   84        * @return The Origin Entity.
   85        */
   86       public OriginEntity getOriginEntity() {
   87           return this.origin;
   88       }
   89   
   90       /** Sets the Origin Entity for this Point.
   91        * 
   92        * @param origin The Origin Entity.
   93        */
   94       public void setOriginEntity(OriginEntity origin) {
   95           this.origin = origin;
   96       }
   97   
   98       /**
   99        */
  100       public String getPrefix() {
  101           return PREFIX;
  102       }
  103   
  104       /**
  105        */
  106       public List getResults() {
  107           List results;
  108           
  109           if (this.resultRelations == null) results = Collections.EMPTY_LIST;
  110           else results = Collections.unmodifiableList(this.resultRelations);
  111   
  112           return results;
  113       }
  114   
  115       /**
  116        */
  117       public Store getStore() {
  118           return (Store) this.store.getInstance();
  119       }
  120   
  121       /** Gets the Store Entity for this Point.
  122        * 
  123        * @return The Store Entity.
  124        */
  125       public StoreEntity getStoreEntity() {
  126           return this.store;
  127       }
  128   
  129       /** Sets the Store Entity for this Point.
  130        * 
  131        * @param store The Store Entity.
  132        */
  133       public void setStoreEntity(StoreEntity store) {
  134           this.store = store;
  135       }
  136   
  137       /**
  138        */
  139       public Transform getTransform() {
  140           if (this.transform == null) return null;
  141   
  142           return this.transform.getTransform();
  143       }
  144   
  145       /** Gets the Transform Entity for this Point.
  146        * 
  147        * @return The Transform Entity.
  148        */
  149       public TransformEntity getTransformEntity() {
  150           return this.transform;
  151       }
  152   
  153       /** Sets the Transform Entity for this Point.
  154        * 
  155        * @param transform The Transform Entity.
  156        */
  157       public void setTransformEntity(TransformEntity transform) {
  158           this.transform = transform;
  159       }
  160   
  161       /**
  162        */
  163       public UUID getUUID() {
  164           return this.uuid;
  165       }
  166       
  167       /** Sets this Point's UUID.
  168        * 
  169        * @param uuid The UUID.
  170        */
  171       public void setUUID(UUID uuid) {
  172           this.uuid = uuid;
  173       }
  174   
  175       // Public Instance Methods.
  176       
  177       /** Adds a FilterEntity to this Point.
  178        * 
  179        * @param filter The FilterEntity.
  180        */
  181       public void addFilterEntity(FilterEntity filter) {
  182           if (this.filters == null) this.filters = new LinkedList();
  183   
  184           this.filters.add(filter);
  185       }
  186   
  187       /** Adds an input relation.
  188        * 
  189        * @param inputRelation The input relation.
  190        */
  191       public void addInputRelation(Relation inputRelation) {
  192           if (this.inputRelations == null) this.inputRelations = new LinkedList();
  193           
  194           this.inputRelations.add(inputRelation);
  195           
  196           inputRelation.getPointEntity().addResultRelation(inputRelation);
  197       }
  198   
  199       /** Adjust the level of this Point's dependants.
  200        */
  201       public void adjustLevel() throws TopologicalErrorException {
  202           adjustLevel(0);
  203       }
  204   
  205       /** Implements Comparable.
  206        *
  207        * @param other An other PointEntity.
  208        * @return A negative integer, zero, or a positive integer.
  209        */    
  210       public int compareTo(Object other) {
  211           int comparison;
  212   
  213           comparison = this.level - ((PointEntity) other).level;
  214           if (comparison == 0) {
  215               comparison = this.uuid.compareTo(((PointEntity) other).uuid);
  216           }
  217   
  218           return comparison;
  219       }
  220   
  221       /** Asks if the content implements an interface.
  222        *
  223        * @param name The name of the ClassDef representing the interface.
  224        * @return True if the interface is implemented.
  225        */
  226       public boolean contentIs(String name) {
  227           if (this.content == null) return false;
  228   
  229           return this.content.is(name);
  230       }
  231   
  232       /** Sets up this Point.
  233        * 
  234        * @param metadata The Metadata.
  235        * @return True if successful.
  236        */
  237       public boolean setUp(Metadata metadata) {
  238           if (this.content != null) {
  239               if (!this.content.setUp(metadata)) return false;
  240           }
  241           if (this.store != null) {
  242               if (!this.store.setUp(metadata)) return false;
  243           }
  244           if (this.transform != null) {
  245               if (!this.transform.setUp(metadata)) return false;
  246           } 
  247           for (Iterator i = getInputs().iterator(); i.hasNext(); ) {
  248               ((Relation) i.next()).setUp(metadata);
  249           }
  250   
  251           return true;
  252       }
  253   
  254       /** Tears down what has been set up.
  255        */
  256       public void tearDown() {
  257           for (Iterator i = getInputs().iterator(); i.hasNext(); ) {
  258               ((Relation) i.next()).tearDown();
  259           }
  260           if (this.transform != null) this.transform.tearDown();
  261           if (this.store != null) this.store.tearDown();
  262           if (this.content != null) this.content.tearDown();
  263       }
  264   
  265       /** Returns a String representation of itself.
  266        *
  267        * @return The String representation of its UUID.
  268        */
  269       public String toString() {
  270           return getIdent() != null? getIdent():
  271               getName() != null? getName():
  272               this.uuid != null? this.uuid.toString(): null;
  273       }
  274   
  275       // Private Methods.
  276   
  277       private void addResultRelation(Relation resultRelation) {
  278           if (this.resultRelations == null) this.resultRelations = new LinkedList();
  279           
  280           this.resultRelations.add(resultRelation);
  281       }
  282   
  283       private void adjustLevel(int level) throws TopologicalErrorException {
  284           if (this.busy) throw new TopologicalErrorException(this);
  285   
  286           if (level > this.level) {
  287               this.level = level;
  288               this.busy = true;
  289   
  290               for (Iterator i = getResults().iterator(); i.hasNext(); ) {
  291                   Result result = (Result) i.next();
  292                   PointEntity point = (PointEntity) result.getResultPoint();
  293   
  294                   if (point != this) point.adjustLevel(this.level + 1);
  295               }
  296   
  297               this.busy = false;
  298           }
  299       }
  300   
  301       // Instance Attributes.
  302   
  303       private boolean busy = false;
  304       private ContentEntity content = null;
  305       private List filters = null;
  306       private List inputRelations = null;
  307       private int level = -1;
  308       private OriginEntity origin = null;
  309       private List resultRelations = null;
  310       private StoreEntity store = null;
  311       private TransformEntity transform = null;
  312       private UUID uuid = null;
  313   
  314       // Nested Classes.
  315       
  316       public static class TopologicalErrorException extends Exception {
  317           
  318           // Constructors.
  319           
  320           private TopologicalErrorException(Point point) {
  321               super(point.toString());
  322           }
  323       }
  324   }
  325   
  326   // $Log: PointEntity.java,v $
  327   // Revision 1.17  2003/10/24 16:11:27  sfb
  328   // Added filters.
  329   //
  330   
  331   /*
  332    * This is free software; you can redistribute it and/or modify
  333    * it under the terms of the GNU Lesser General Public License
  334    * as published by the Free Software Foundation; either version 2.1
  335    * of the License, or (at your option) any later version.
  336    *
  337    * This software is distributed in the hope that it will be useful,
  338    * but WITHOUT ANY WARRANTY; without even the implied warranty of
  339    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  340    * Lesser General Public License for more details.
  341    *
  342    * You should have received a copy of the GNU Lesser General Public
  343    * License along with this software; if not, write to the Free Software
  344    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  345    */

Save This Page
Home » openjdk-7 » net » sf » rvpf » metadata » [javadoc | source]