View Javadoc
1   package au.gov.amsa.ais.message;
2   
3   import au.gov.amsa.ais.AisExtractor;
4   import au.gov.amsa.ais.AisExtractorFactory;
5   import au.gov.amsa.ais.AisMessage;
6   import au.gov.amsa.ais.AisMessageType;
7   import au.gov.amsa.ais.HasMmsi;
8   import au.gov.amsa.ais.Util;
9   
10  public abstract class AbstractAisBStaticDataReport implements AisMessage, HasMmsi {
11  	
12  	public final static int PART_NUMBER_A = 0;
13  	public final static int PART_NUMBER_B = 1;
14  	
15  	private final AisExtractor extractor;
16  	private final String source;
17      private final int messageId;
18      private final int repeatIndicator;
19      private final int mmsi;
20      private final int partNumber;
21      
22      public static int extractPartNumber(AisExtractorFactory factory, String message, int padBits) {
23      	AisExtractor extractor = factory.create(message, 50, padBits);
24      	
25      	return extractor.getValue(38, 40);
26      }
27      
28      protected AbstractAisBStaticDataReport(int partNumber,
29      									   AisExtractorFactory factory, 
30      									   String source,
31      									   AisExtractor extractor) {
32          this.source = source;
33          this.extractor = extractor;
34          messageId = extractor.getMessageId();
35          Util.checkMessageId(getMessageId(), AisMessageType.STATIC_DATA_REPORT);
36          repeatIndicator = extractor.getValue(6, 8);
37          mmsi = extractor.getValue(8, 38);
38          this.partNumber = partNumber;
39      }
40  
41  	protected AisExtractor getExtractor() {
42  		return extractor;
43  	}
44  	
45      @Override
46      public int getMessageId() {
47          return messageId;
48      }
49  
50      public int getRepeatIndicator() {
51          return repeatIndicator;
52      }
53  
54      @Override
55      public int getMmsi() {
56          return mmsi;
57      }
58      
59  	public int getPartNumber() {
60  		return partNumber;
61  	}
62  
63  	@Override
64  	public String getSource() {
65  		return source;
66  	}
67  }