    View Javadoc
    1   /*
    2    * Copyright (c) 2003
    3    * Information Desire GmbH
    4    * All rights reserved.
    5    */
    6   package com.infodesire.infobit.external.impl;
    7
    8   import com.infodesire.infobit.data.Infobit;
    9   import com.infodesire.infobit.data.Version;
    10
    11  import org.apache.commons.logging.Log;
    12  import org.apache.commons.logging.LogFactory;
    13
    14  import java.util.ArrayList;
    15  import java.util.Collection;
    16  import java.util.Date;
    17  import java.util.HashSet;
    18  import java.util.Iterator;
    19  import java.util.List;
    20  import java.util.Set;
    21
    22  /***
    23   * This class represents generic content in the dependency graph of content and
    24   * nodes.
    25   *
    26   * @author    peter2
    27   * @created   1. September 2003
    28   * @version   $Revision: 1.1 $
    29   */
    30  abstract class ContentNode extends BufferNode {
    31
    32      private final static Log _log = LogFactory.getLog(ContentNode.class);
    33
    34      /***
    35       * Buffer node representation of the infobit this versions provides content
    36       * for
    37       */
    38      protected InfobitNode _infobitNode;
    39
    40      /***
    41       * The infobit which this version provides content to
    42       */
    43      protected Infobit _infobit;
    44
    45      /***
    46       * The name of the version
    47       */
    48      protected String _name;
    49
    50      /***
    51       * The creation date of the content version.
    52       */
    53      protected Date  _date;
    54
    55      /***
    56       * The creator of the version
    57       */
    58      protected String _author;
    59
    60      /***
    61       * All keywords attached to the content, if applicable. Set of <code>String</code>
    62       * .
    63       */
    64      protected Set   _keywords = new HashSet();
    65
    66
    67      /***
    68       * Restricts creation access.
    69       */
    70      protected ContentNode() {
    71      }
    72
    73
    74      /***
    75       * Conveniency method to get a version by name. As precondition, The
    76       * requested version is required to exist.
    77       *
    78       * @return   The version of {@link _infobit} identified by {@link _name}
    79       */
    80      protected Version resolveVersion() {
    81          Version version = null;
    82
    83          for (Iterator i = _infobit.getVersions().iterator();
    84              version == null && i.hasNext(); ) {
    85              Version v = (Version) i.next();
    86
    87              if (v.getName().equals(_name)) {
    88                  version = v;
    89              }
    90          }
    91
    92          if (version == null) {
    93              String m = "Failed precondition: missing version " + _name;
    94              _log.fatal(m);
    95              throw new RuntimeException(m);
    96          }
    97
    98          return version;
    99      }
    100
    101
    102     /***
    103      * Gets the name of the content version.
    104      *
    105      * @return   The Name value
    106      */
    107     String getName() {
    108         return _name;
    109     }
    110
    111
    112     /***
    113      * Returns the infobit node this version node depends on.
    114      *
    115      * @return   The Dependencies value
    116      */
    117     Collection getDependencies() {
    118         if (_infobitNode == null) {
    119             throw new IllegalStateException("Infobit dependency not set.");
    120         }
    121
    122         List dep = new ArrayList();
    123         dep.add(_infobitNode);
    124
    125         return dep;
    126     }
    127
    128
    129     /***
    130      * Defines the name of the content version. For use on initialization only.
    131      *
    132      * @param name  The new Name value
    133      */
    134     void setName(String name) {
    135         _name = name;
    136     }
    137
    138
    139     /***
    140      * Defines the creation date.
    141      *
    142      * @param date  The new Date value
    143      */
    144     void setDate(Date date) {
    145         _date = date;
    146     }
    147
    148
    149     /***
    150      * Defines the author.
    151      *
    152      * @param author  The new Author value
    153      */
    154     void setAuthor(String author) {
    155         _author = author;
    156     }
    157
    158
    159     /***
    160      * Sets the buffer node representation of the infobit this version provides
    161      * content to.
    162      *
    163      * @param node  The new InfobitNode value
    164      */
    165     void setInfobitNode(InfobitNode node) {
    166         _infobitNode = node;
    167     }
    168
    169
    170     /***
    171      * Resolves the common dependency on the infobit to which content is
    172      * provided.
    173      *
    174      * @param dependency  Description of Parameter
    175      * @param value       Description of Parameter
    176      */
    177     void resolveDependency(BufferNode dependency, Object value) {
    178         final String tag = getClass().getName() + ": resolveDependency: ";
    179         _log.trace(tag + "enter");
    180
    181         if (value == null) {
    182             throw new NullPointerException("resolved value");
    183         }
    184
    185         if (dependency == _infobitNode) {
    186             _infobit = (Infobit) value;
    187         }
    188         else {
    189             String m = "Assertion failed: expected infobit dependency";
    190             _log.fatal(m);
    191             throw new RuntimeException(m);
    192         }
    193
    194         _log.trace(tag + "exit");
    195     }
    196
    197
    198     /***
    199      * Adds a keyword on the version. Keywords are persisted in the order they
    200      * have been added.
    201      *
    202      * @param keyword  The next keyword applicable to the content
    203      */
    204     void addKeyword(String keyword) {
    205         if (!_keywords.contains(keyword)) {
    206             _keywords.add(keyword);
    207         }
    208     }
    209 }

This page was automatically generated by Maven