View Javadoc

1   package org.jscsi.target.scsi.modeSense;
2   
3   /**
4    * A builder object used during the initialization of new {@link ModeParameterList} objects.
5    * 
6    * @author Andreas Ergenzinger
7    */
8   public final class ModeParameterListBuilder {
9   
10      /**
11       * The {@link HeaderType} to be used by the {@link ModeParameterList}.
12       */
13      final HeaderType headerType;
14  
15      /**
16       * Contains all elements to be included in the list of {@link LogicalBlockDescriptor} objects of the
17       * {@link ModeParameterList}.
18       */
19      LogicalBlockDescriptor[] logicalBlockDescriptors;
20  
21      /**
22       * If the {@link ModeParameterList} uses a {@link HeaderType#MODE_PARAMETER_HEADER_10} and this value is
23       * <code>true</code>, then all contained MODE PARAMETER BLOCK DESCRIPTORs will have the LONG LBA (LOGICAL BLOCK
24       * ADDRESS) format.
25       * <p>
26       * The jSCSI Target supports only the short format.
27       */
28      boolean longLba = false;
29  
30      /**
31       * Contains all elements to be included in the list of {@link ModePage} objects of the {@link ModeParameterList}.
32       */
33      ModePage[] modePages;
34  
35      public ModeParameterListBuilder (final HeaderType headerType) {
36          this.headerType = headerType;
37      }
38  
39      public void setLogicalBlockDescriptors (final ShortLogicalBlockDescriptor logicalBlockDescriptor) {
40          final ShortLogicalBlockDescriptor[] array = new ShortLogicalBlockDescriptor[1];
41          array[0] = logicalBlockDescriptor;
42          setLogicalBlockDescriptors(array);
43      }
44  
45      public void setLogicalBlockDescriptors (final ShortLogicalBlockDescriptor[] logicalBlockDescriptors) {
46          this.logicalBlockDescriptors = logicalBlockDescriptors;
47          longLba = false;
48      }
49  
50      public void setLogicalBlockDescriptors (final LongLogicalBlockDescriptor[] logicalBlockDescriptors) {
51          this.logicalBlockDescriptors = logicalBlockDescriptors;
52          longLba = true;
53      }
54  
55      public void setModePages (final ModePage modePage) {
56          final ModePage[] array = new ModePage[1];
57          array[0] = modePage;
58          setModePages(array);
59      }
60  
61      public void setModePages (final ModePage[] modePages) {
62          this.modePages = modePages;
63      }
64  
65      /**
66       * This method is used for checking that all required members are initialized and their respective values compatible
67       * with each other.
68       * 
69       * @return <code>true</code> if everything is fine, <code>false</code> if not
70       */
71      boolean checkIntegrity () {
72          if (headerType == null) return false;
73          if (headerType == HeaderType.MODE_PARAMETER_HEADER_6 && longLba) return false;
74          return true;
75      }
76  }