Coverage Report - org.jscsi.target.settings.entry.Use
 
Classes in this File Line Coverage Branch Coverage Complexity
Use
0%
0/21
0%
0/29
15
Use$1
0%
0/1
N/A
15
 
 1  
 package org.jscsi.target.settings.entry;
 2  
 
 3  
 
 4  
 import org.jscsi.parser.ProtocolDataUnit;
 5  
 import org.jscsi.parser.login.LoginStage;
 6  
 import org.jscsi.target.connection.stage.fullfeature.TextNegotiationStage;
 7  
 import org.jscsi.target.connection.stage.login.LoginOperationalParameterNegotiationStage;
 8  
 
 9  
 
 10  
 /**
 11  
  * Instances of this class are used by {@link Entry} objects to determine during which circumstances a parameter may be
 12  
  * negotiated or declared.
 13  
  * <p>
 14  
  * The factors to consider are:
 15  
  * <ul>
 16  
  * <li>the current stage of the connection</li>
 17  
  * <li>whether that connection is the leading connection, i.e. the initial connection in the enclosing session.</li>
 18  
  * <li>if the <i>key-value</i> pair relating to the parameter was part of the first {@link ProtocolDataUnit} sent over
 19  
  * the connection</i>
 20  
  * </ul>
 21  
  * 
 22  
  * @author Andreas Ergenzinger
 23  
  */
 24  0
 public enum Use {
 25  
     /**
 26  
      * The parameter may be negotiated by a leading connection in the {@link LoginOperationalParameterNegotiationStage}
 27  
      * only.
 28  
      */
 29  0
     LEADING_LOPNS,
 30  
     /**
 31  
      * The parameter may be negotiated by any connection in the {@link LoginOperationalParameterNegotiationStage}.
 32  
      */
 33  0
     LOPNS,
 34  
     /**
 35  
      * The parameter may be negotiated by any connection in the {@link LoginOperationalParameterNegotiationStage} or in
 36  
      * the Full Feature Phase (specifically the {@link TextNegotiationStage}).
 37  
      */
 38  0
     LOPNS_AND_FFP,
 39  
     /**
 40  
      * The parameter may be negotiated by any connection in the Full Feature Phase (specifically the
 41  
      * {@link TextNegotiationStage}).
 42  
      */
 43  0
     FFP,
 44  
     /**
 45  
      * The parameter may only be declared in the initial {@link ProtocolDataUnit}.
 46  
      */
 47  0
     INITIAL,
 48  
     /**
 49  
      * The parameter may only be declared in the initial {@link ProtocolDataUnit} or by any PDU sent as part of the
 50  
      * {@link TextNegotiationStage} in the Full Feature Phase.
 51  
      */
 52  0
     INITIAL_AND_FFP;
 53  
 
 54  
     /**
 55  
      * This method can be used for checking if a specified {@link Use} permits negotiating its associated parameter
 56  
      * given a situation described by several parameters.
 57  
      * 
 58  
      * @param use describes the conditions
 59  
      * @param loginStage specifies the stage of phase
 60  
      * @param leadingConnection <code>true</code> if and only if the connection is the leading connection of its session
 61  
      * @param initialPdu <code>true</code> if and only if the {@link ProtocolDataUnit} is the first PDU sent over the
 62  
      *            connection
 63  
      * @return <code>true</code> if and only if all requirements of the <i>use</i> parameter have been met
 64  
      */
 65  
     private static boolean checkUse (final Use use, final LoginStage loginStage, final boolean leadingConnection, final boolean initialPdu) {
 66  0
         switch (use) {
 67  
             case LEADING_LOPNS :
 68  0
                 if (leadingConnection && loginStage == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION) return true;
 69  0
                 return false;
 70  
             case LOPNS :
 71  0
                 if (loginStage == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION) return true;
 72  0
                 return false;
 73  
             case LOPNS_AND_FFP :
 74  0
                 if (loginStage == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION || loginStage == LoginStage.FULL_FEATURE_PHASE) return true;
 75  0
                 return false;
 76  
             case FFP :
 77  0
                 if (loginStage == LoginStage.FULL_FEATURE_PHASE) return true;
 78  0
                 return false;
 79  
             case INITIAL_AND_FFP :
 80  0
                 if (initialPdu && loginStage == LoginStage.FULL_FEATURE_PHASE) return true;
 81  
                 // fall through
 82  
             case INITIAL :
 83  0
                 if (initialPdu && (loginStage == LoginStage.SECURITY_NEGOTIATION || loginStage == LoginStage.LOGIN_OPERATIONAL_NEGOTIATION)) return true;
 84  0
                 return false;
 85  
             default :
 86  0
                 return false;// unreachable
 87  
         }
 88  
     }
 89  
 
 90  
     /**
 91  
      * This method can be used for checking if this {@link Use} instance permits negotiating its associated parameter
 92  
      * given a situation described by the passed parameters.
 93  
      * 
 94  
      * @param loginStage specifies the stage of phase
 95  
      * @param leadingConnection <code>true</code> if and only if the connection is the leading connection of its session
 96  
      * @param initialPdu <code>true</code> if and only if the {@link ProtocolDataUnit} is the first PDU sent over the
 97  
      *            connection
 98  
      * @return <code>true</code> if and only if all requirements of this {@link Use} instance have been met
 99  
      */
 100  
     public boolean checkUse (final LoginStage loginStage, final boolean leadingConnection, final boolean initialPdu) {
 101  0
         return checkUse(this, loginStage, leadingConnection, initialPdu);
 102  
     }
 103  
 }