Next version of JABA
[jabaws.git] / datamodel / compbio / metadata / LimitExceededException.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0\r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.metadata;\r
20 \r
21 import java.util.List;\r
22 \r
23 import javax.xml.bind.annotation.XmlAccessType;\r
24 import javax.xml.bind.annotation.XmlAccessorType;\r
25 \r
26 import compbio.data.sequence.FastaSequence;\r
27 \r
28 /**\r
29  * Thrown if the task larger in size that the limit that applies to the\r
30  * calculation.\r
31  * \r
32  * @see Limit\r
33  * \r
34  * @author pvtroshin\r
35  * \r
36  *         Date February 2010\r
37  */\r
38 @XmlAccessorType(XmlAccessType.FIELD)\r
39 public class LimitExceededException extends JobSubmissionException {\r
40 \r
41     private static final long serialVersionUID = 15066952180013505L;\r
42 \r
43     int numberOfSequencesAllowed;\r
44     int actualNumberofSequences;\r
45     int aSequenceLenghtAllowed;\r
46     int aSequenceLenghtActual;\r
47 \r
48     public LimitExceededException(String message) {\r
49         super(message);\r
50     }\r
51 \r
52     public static LimitExceededException newLimitExceeded(Limit<?> limit,\r
53             List<FastaSequence> seqs) {\r
54         String message = "Job exceed size limits, maximum number of sequences must be less than "\r
55                 + limit.getSeqNumber() + "\n";\r
56         if (limit.getAvgSeqLength() != 0) {\r
57             message += "and an average sequence length must not exceed "\r
58                     + limit.getAvgSeqLength() + "\n";\r
59         }\r
60         message += " However, the task contained " + seqs.size()\r
61                 + " sequences " + "\n";\r
62         if (limit.getAvgSeqLength() != 0) {\r
63             message += "and an average sequence length was "\r
64                     + Limit.getAvgSequenceLength(seqs) + "\n";\r
65         }\r
66         return new LimitExceededException(message);\r
67     }\r
68 \r
69     public int getNumberOfSequencesAllowed() {\r
70         return numberOfSequencesAllowed;\r
71     }\r
72 \r
73     public int getActualNumberofSequences() {\r
74         return actualNumberofSequences;\r
75     }\r
76 \r
77     public int getSequenceLenghtAllowed() {\r
78         return aSequenceLenghtAllowed;\r
79     }\r
80 \r
81     public int getSequenceLenghtActual() {\r
82         return aSequenceLenghtActual;\r
83     }\r
84 }\r