| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.templategen; |
| 34 | | | |
| 35 | | | import java.util.regex.Pattern; |
| 36 | | | |
| 37 | | | |
| 38 | | | @author |
| 39 | | | |
| 40 | | | public class Parameter |
| 41 | | | { |
| 42 | | | private final String mName; |
| 43 | | | private final int mMinLength; |
| 44 | | | private final int mMaxLength; |
| 45 | | | private final boolean mMultiLine; |
| 46 | | | |
| 47 | | | private String mDescription; |
| 48 | | | private String mDefaultValue; |
| 49 | | | private String mRegexp; |
| 50 | | | |
| 51 | | (1) | public Parameter ( |
| 52 | | | String name, |
| 53 | | | int minLength, |
| 54 | | | int maxLength, |
| 55 | | | boolean multiLine) |
| 56 | 0 | | { |
| 57 | 0 | | mName = name; |
| 58 | 0 | | mMinLength = minLength; |
| 59 | 0 | | mMaxLength = maxLength; |
| 60 | 0 | | mMultiLine = multiLine; |
| 61 | 0 | | } |
| 62 | | | |
| 63 | | (2) | public int getMaxLength () |
| 64 | | | { |
| 65 | 0 | | return mMaxLength; |
| 66 | | | } |
| 67 | | | |
| 68 | | (3) | public int getMinLength () |
| 69 | | | { |
| 70 | 0 | | return mMinLength; |
| 71 | | | } |
| 72 | | | |
| 73 | | (4) | public boolean isMultiLine () |
| 74 | | | { |
| 75 | 0 | | return mMultiLine; |
| 76 | | | } |
| 77 | | | |
| 78 | | (5) | public String getName () |
| 79 | | | { |
| 80 | 0 | | return mName; |
| 81 | | | } |
| 82 | | | |
| 83 | | (6) | public String getDescription () |
| 84 | | | { |
| 85 | 0 | | return mDescription; |
| 86 | | | } |
| 87 | | | |
| 88 | | (7) | public void setDescription (String string) |
| 89 | | | { |
| 90 | 0 | | mDescription = string; |
| 91 | 0 | | } |
| 92 | | | |
| 93 | | (8) | public String getDefaultValue () |
| 94 | | | { |
| 95 | 0 | | return mDefaultValue; |
| 96 | | | } |
| 97 | | | |
| 98 | | (9) | public String getRegexp () |
| 99 | | | { |
| 100 | 0 | | return mRegexp; |
| 101 | | | } |
| 102 | | | |
| 103 | | (10) | public void setDefaultValue (String string) |
| 104 | | | { |
| 105 | 0 | | mDefaultValue = string; |
| 106 | 0 | | } |
| 107 | | | |
| 108 | | (11) | public void setRegexp (String string) |
| 109 | | | { |
| 110 | 0 | | mRegexp = string; |
| 111 | 0 | | } |
| 112 | | | |
| 113 | | (12) | public void checkValue (String value) throws TemplateGeneratorException |
| 114 | | | { |
| 115 | 0 | | if (value.length() < mMinLength |
| 116 | | | || value.length() > mMaxLength) |
| 117 | | | { |
| 118 | 0 | | throw new TemplateGeneratorException( |
| 119 | | | "Invalid value '" + value + "' for parameter " + mName |
| 120 | | | + ": length must be between " + mMinLength |
| 121 | | | + " and " + mMaxLength + " characters"); |
| 122 | | | } |
| 123 | 0 | | if (mRegexp != null) |
| 124 | | | { |
| 125 | 0 | | if (! Pattern.matches(mRegexp, value)) |
| 126 | | | { |
| 127 | 0 | | throw new TemplateGeneratorException( |
| 128 | | | "Invalid value '" + value + "' for parameter " + mName |
| 129 | | | + ": does not match regular expression " |
| 130 | | | + "'" + mRegexp + "'"); |
| 131 | | | } |
| 132 | | | } |
| 133 | 0 | | } |
| 134 | | | |
| 135 | | | {@inheritDoc} |
| 136 | | | public String toString () |
| 137 | | | { |
| 138 | 0 | | return "[Parameter name=" + mName |
| 139 | | | + ", minLength=" + mMinLength |
| 140 | | | + ", maxLength=" + mMaxLength |
| 141 | | | + ", multiLine=" + mMultiLine |
| 142 | | | + ", description=" + mDescription |
| 143 | | | + ", default=" + mDefaultValue |
| 144 | | | + ", regexp=" + mRegexp |
| 145 | | | + "]"; |
| 146 | | | } |
| 147 | | | } |