    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.InfobitManager;
    10  import com.infodesire.infobit.InfobitSecurityException;
    11
    12  import com.infodesire.infobit.data.Acl;
    13
    14  import java.util.Collection;
    15  import java.util.HashSet;
    16  import java.util.Set;
    17
    18  /***
    19   * This class describes a generic item to import.
    20   *
    21   * @author    peter2
    22   * @created   August 28, 2003
    23   * @version   $Revision: 1.1 $
    24   */
    25  abstract class BufferNode {
    26
    27      /***
    28       * Denotes the state of a node during depth-first search before the seach
    29       * has discovered the node.
    30       */
    31      final static int WHITE = 0;
    32
    33      /***
    34       * Denotes the state of a node during depth-first search while the children
    35       * of the node are being processed.
    36       */
    37      final static int GRAY = 1;
    38
    39      /***
    40       * Denotes the state of a node during depth-first search after all children
    41       * of the node have been processed.
    42       */
    43      final static int BLACK = 2;
    44
    45      /***
    46       * The collaborating manager
    47       */
    48      protected InfobitManager _manager;
    49
    50      /***
    51       * The ACL used to persist the node
    52       */
    53      protected Acl   _acl;
    54
    55      /***
    56       * The state of the node during depth-first search. Legal values are
    57       * constraint to {@link #WHITE}, {@link #GRAY} and {@link #BLACK}.
    58       */
    59      private int     _color = WHITE;
    60
    61      /***
    62       * A unique, ascending integer indicating the time when the node was first
    63       * decovered during depth-first search.
    64       */
    65      private int     _discoverTime;
    66
    67      /***
    68       * A unique, ascending integer indicating when depth-first search has
    69       * traversed all children of the node.
    70       */
    71      private int     _completeTime;
    72
    73      /***
    74       * The system ID of the location of the represented element, or <code>null</code>
    75       * if not available.
    76       */
    77      private String  _systemID;
    78
    79      /***
    80       * The line of the location of the represented element, or <code>0</code> if
    81       * not available
    82       */
    83      private int     _line;
    84
    85      /***
    86       * Set of all {@link BufferEdge edges} leaving this node
    87       */
    88      private Set     _edges = new HashSet();
    89
    90      /***
    91       * Set of all <em>incomming</em> edges. Set of {@link BufferEdge}.
    92       */
    93      private Set     _dependents = new HashSet();
    94
    95
    96      /***
    97       * Restricted base class initialization.
    98       */
    99      protected BufferNode() {
    100     }
    101
    102
    103     /***
    104      * Gets the {@link #setColor state} of the node during depth-first search.
    105      *
    106      * @return   The Colur value
    107      */
    108     int getColor() {
    109         return _color;
    110     }
    111
    112
    113     /***
    114      * Gets the {@link #setDiscoverTime time of discovery}.
    115      *
    116      * @return   The DiscoverTime value
    117      */
    118     int getDiscoverTime() {
    119         return _discoverTime;
    120     }
    121
    122
    123     /***
    124      * Gets the {@link #setCompleteTime completion time} of the node.
    125      *
    126      * @return   The CompleteTime value
    127      */
    128     int getCompleteTime() {
    129         return _completeTime;
    130     }
    131
    132
    133     /***
    134      * Retrieves the collaborating infobit manager.
    135      *
    136      * @return   The Manager value
    137      */
    138     InfobitManager getManager() {
    139         return _manager;
    140     }
    141
    142
    143     /***
    144      * Interface method defining all nodes (ie infobits or infobit versions)
    145      * which the current node depends on.
    146      *
    147      * @return   Collection of <code>BufferEdge</code>s the current node
    148      *      immediately depends on
    149      */
    150     abstract Collection getDependencies();
    151
    152
    153     /***
    154      * Gets all edges <em>leaving</em> the present node (edges to dependencies.
    155      *
    156      * @return   A callee-owned set of {@link BufferEdge}s
    157      */
    158     Set getEdges() {
    159         return _edges;
    160     }
    161
    162
    163     /***
    164      * Gets all incomming edges.
    165      *
    166      * @return   Callee-owned set of {@link BufferEdge}
    167      */
    168     Set getDependents() {
    169         return _dependents;
    170     }
    171
    172
    173     /***
    174      * Defines the state of the node during depth-first search.
    175      *
    176      * @param color  The state, with legal value restricted to {@link #WHITE},
    177      *      {@link #GRAY} and {@link #BLACK}
    178      */
    179     void setColor(int color) {
    180         _color = color;
    181     }
    182
    183
    184     /***
    185      * Defines the <q>time</q> when the node was first discovered during
    186      * depth-first search.
    187      *
    188      * @param t  The new DiscoverTime value
    189      */
    190     void setDiscoverTime(int t) {
    191         _discoverTime = t;
    192     }
    193
    194
    195     /***
    196      * Defines the <q>timestamp</q> when depth-first has completed proccessing
    197      * the node.
    198      *
    199      * @param t  The new CompleteTime value
    200      */
    201     void setCompleteTime(int t) {
    202         _completeTime = t;
    203     }
    204
    205
    206     /***
    207      * Provides the collaborating buffer manager. The buffer manger needs
    208      * sufficient permissions to create the infobits to be imported.
    209      *
    210      * @param manager  The collaborating manager
    211      */
    212     void setManager(InfobitManager manager) {
    213         _manager = manager;
    214     }
    215
    216
    217     /***
    218      * Defines the acl used to persist the node.
    219      *
    220      * @param acl  The new Acl value
    221      */
    222     void setAcl(Acl acl) {
    223         _acl = acl;
    224     }
    225
    226
    227     /***
    228      * Defines the location of the representing XML.
    229      *
    230      * @param systemID  The system ID of the location
    231      * @param line      The line of the location
    232      */
    233     void setLocation(String systemID, int line) {
    234         _systemID = systemID;
    235         _line = line;
    236     }
    237
    238
    239     /***
    240      * Interface method called to resolve the specified dependency.
    241      *
    242      * @param dependency  The resolved depdendcy. Constraint to be contained in
    243      *      {@link #getDependencies} of the current node.
    244      * @param value       The persited instance represented by <code>dependency</code>
    245      *      . The actual subtype depends on the actual kind of the dependency.
    246      */
    247     abstract void resolveDependency(BufferNode dependency, Object value);
    248
    249
    250     /***
    251      * Interface method to persist the item (infobit or version) represented by
    252      * the buffer. The method is called after all {@link #getDependencies
    253      * dependencies} of the current node have been {@link #resolveDependency
    254      * resolved}.
    255      *
    256      * @return                              If the node represents an infobit,
    257      *      it is returned; if it represents a version, <code>null</code> is
    258      *      returned.
    259      * @exception InfobitException          Indicates a generic error.
    260      * @exception InfobitSecurityException  Description of Exception
    261      */
    262     abstract Object persistBuffer()
    263          throws InfobitException, InfobitSecurityException;
    264
    265
    266     /***
    267      * Yields the system ID of the location where the represented XML element
    268      * starts.
    269      *
    270      * @return   Description of the Returned Value
    271      */
    272     String locateSystemID() {
    273         return _systemID;
    274     }
    275
    276
    277     /***
    278      * Yields line information on the location where the represented XML element
    279      * starts.
    280      *
    281      * @return   Description of the Returned Value
    282      */
    283     int locateLine() {
    284         return Math.max(0, _line);
    285     }
    286
    287
    288     /***
    289      * Convenience method to define a dependency on the specified node. In
    290      * particular, the specified node is connected to the current node by an
    291      * {@link BufferEdge edge}.
    292      *
    293      * @param dependency  The node on which the current instance depends
    294      * @return            The edge added to reach <code>dependency</code>
    295      */
    296     BufferEdge addDependency(BufferNode dependency) {
    297         BufferEdge edge = new BufferEdge(dependency);
    298         _edges.add(edge);
    299         dependency.addDependent(edge);
    300
    301         return edge;
    302     }
    303
    304
    305     /***
    306      * Registers an edge incident to the node.
    307      *
    308      * @param edge  The feature to be added to the Dependent attribute
    309      */
    310     void addDependent(BufferEdge edge) {
    311         _dependents.add(edge);
    312     }
    313
    314 }
    315

This page was automatically generated by Maven