1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\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
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
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
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.metadata;
\r
21 import java.util.List;
\r
23 import javax.xml.bind.ValidationException;
\r
24 import javax.xml.bind.annotation.XmlAccessType;
\r
25 import javax.xml.bind.annotation.XmlAccessorType;
\r
26 import javax.xml.bind.annotation.XmlRootElement;
\r
28 import compbio.util.Util;
\r
31 * A collection of Limits
\r
36 * @version 1.0 January 2010
\r
40 @XmlRootElement(name = "limits")
\r
41 @XmlAccessorType(XmlAccessType.FIELD)
\r
42 public class LimitsManager<T> {
\r
44 String runnerClassName;
\r
45 List<Limit<T>> limit;
\r
49 * @return all limits defined for an executable T
\r
51 public List<Limit<T>> getLimits() {
\r
56 public String toString() {
\r
57 if (limit == null) {
\r
61 for (Limit<T> lim : limit) {
\r
62 value += lim.toString();
\r
70 * @return Limit defined for the executable T and presetName. If no limit is
\r
71 * defined for the presetName then default Limit is returned. If
\r
72 * presetName is empty or null than the default Limit will be
\r
73 * returned. If not limit defined for the type T than NULL will be
\r
76 public Limit<T> getLimitByName(String presetName) {
\r
77 if (limit == null) {
\r
80 if (Util.isEmpty(presetName)) {
\r
81 // return default limit
\r
82 return getDefaultLimit();
\r
84 for (Limit<T> lim : limit) {
\r
85 String preset = lim.getPreset();
\r
86 if (preset == null) {
\r
89 if (preset.equalsIgnoreCase(presetName)) {
\r
98 * @return the default Limit for an executable type T
\r
100 public Limit<T> getDefaultLimit() {
\r
101 for (Limit<T> lim : limit) {
\r
102 if (lim.isDefault) {
\r
115 * @throws ValidationException
\r
116 * if any of the Limit defined is found to be invalid. That is
\r
119 * 1) No default limit is defined
\r
121 * 2) More than 1 default limit is defined
\r
123 * 3) Limit's preset name does not match any presets for type T
\r
125 public void validate(PresetManager<T> presets) throws ValidationException {
\r
127 for (Limit<T> lim : limit) {
\r
128 if (lim.isDefault) {
\r
132 if (defaults == 0) {
\r
133 throw new ValidationException("Default limit is not set!");
\r
135 if (defaults > 1) {
\r
136 throw new ValidationException(
\r
137 "Default limit is set more than once!");
\r
139 if (presets != null) {
\r
140 for (Limit<T> lim : limit) {
\r
142 String presetName = lim.getPreset();
\r
143 // skip "special" preset
\r
144 if (presetName != null
\r
146 .equals(PresetManager.LOCAL_ENGINE_LIMIT_PRESET)) {
\r
147 Preset<T> preset = presets.getPresetByName(presetName);
\r
148 if (preset == null) {
\r
149 throw new ValidationException("Preset " + presetName
\r
150 + " is not found!");
\r