    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.InfobitException;
    9   import com.infodesire.infobit.InfobitSecurityException;
    10
    11  import com.infodesire.infobit.data.Infobit;
    12
    13  import org.apache.commons.logging.Log;
    14  import org.apache.commons.logging.LogFactory;
    15
    16  import java.util.Collection;
    17  import java.util.HashSet;
    18  import java.util.HashMap;
    19  import java.util.Map;
    20  import java.util.Set;
    21  import java.util.TreeMap;
    22
    23  /***
    24   * This class represents a script version in the dependency graph of content and
    25   * nodes.
    26   *
    27   * @author    peter2
    28   * @created   1. September 2003
    29   * @version   $Revision: 1.1 $
    30   */
    31  class ScriptNode extends ContentNode {
    32
    33      private final static Log _log = LogFactory.getLog(ScriptNode.class);
    34
    35      /***
    36       * The name of the template infobit
    37       */
    38      private InfobitNode _templateNode;
    39
    40      /***
    41       * The template infobit, to be set on resolution
    42       */
    43      private Infobit _template;
    44
    45      /***
    46       * Maps reference names to buffer representation of target infobits. Map of
    47       * <code>String</code> to {@link InfobitNode}.
    48       */
    49      private Map     _linkedNodes = new HashMap();
    50
    51      /***
    52       * Inversion of {@link _linkedNodes}, maps <code>String</code> to {@link
    53       * InfobitNode}.
    54       */
    55      private Map     _linkedKeys = new HashMap();
    56
    57      /***
    58       * Resolution of referenced infobit nodes. Maps every key of {@link
    59       * #_linkedNodes} to the bound {@link InfobitNode}s.
    60       */
    61      private Map     _links = new TreeMap();
    62
    63
    64      /***
    65       * Gets the root dependency and the dependcy implied by the the template.
    66       *
    67       * @return   The Dependencies value
    68       */
    69      Collection getDependencies() {
    70          if (_templateNode == null) {
    71              String m = "unresolved template dependency: " +
    72                  _templateNode.getName();
    73              _log.fatal(m);
    74              throw new IllegalStateException(m);
    75          }
    76
    77          Collection dep = super.getDependencies();
    78          dep.add(_templateNode);
    79          dep.addAll(_linkedNodes.values());
    80
    81          return dep;
    82      }
    83
    84
    85      /***
    86       * Defines the template dependency.
    87       *
    88       * @param node  The new TemplateNode value
    89       */
    90      void setTemplateNode(InfobitNode node) {
    91          _templateNode = node;
    92      }
    93
    94
    95      /***
    96       * Adds a link to the script. The link target is treated as a dependency to
    97       * resolve.
    98       *
    99       * @param key    The key which <code>value</code> is linked to
    100      * @param value  The value linked to <code>key</code>
    101      */
    102     void addLink(String key, InfobitNode value) {
    103         _linkedNodes.put(key, value);
    104         _linkedKeys.put(value, key);
    105     }
    106
    107
    108     /***
    109      * Resolves the root and the template dependency.
    110      *
    111      * @param dependency  Description of Parameter
    112      * @param value       Description of Parameter
    113      */
    114     void resolveDependency(BufferNode dependency, Object value) {
    115         if (dependency == _templateNode) {
    116             _template = (Infobit) value;
    117         }
    118         else if (_linkedNodes.values().contains(dependency)) {
    119             InfobitNode node = (InfobitNode) dependency;
    120             String key = (String) _linkedKeys.get(node);
    121             Infobit resolved = (Infobit) value;
    122             _links.put(key, resolved);
    123         }
    124         else {
    125             super.resolveDependency(dependency, value);
    126         }
    127     }
    128
    129
    130     /***
    131      * DOCUMENT METHOD
    132      *
    133      * @return                              The created version
    134      * @exception InfobitException          Description of Exception
    135      * @exception InfobitSecurityException  Description of Exception
    136      */
    137     Object persistBuffer() throws InfobitException, InfobitSecurityException {
    138         if (_infobit == null) {
    139             String m = "Unresolved infobit dependency";
    140             _log.fatal(m);
    141             throw new IllegalStateException(m);
    142         }
    143
    144         if (_links.size() < _linkedNodes.size()) {
    145             String m = "Unresolved link dependencies";
    146             _log.fatal(m);
    147             throw new IllegalStateException(m);
    148         }
    149
    150         _manager.createScript(_infobit, _name, _template, _links, _keywords);
    151
    152         return resolveVersion();
    153     }
    154
    155 }

This page was automatically generated by Maven