001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 * http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.basepom.mojo.propertyhelper.definitions;
015
016import java.io.File;
017import java.util.Arrays;
018
019public final class DefinitionHelper {
020
021    public static UuidDefinition uuidDefinition(String id) {
022        return new UuidDefinition(id);
023    }
024
025    public static NumberDefinition numberDefinition(String id) {
026        return new NumberDefinition(id);
027    }
028
029    public static DateDefinition dateDefinition(String id) {
030        return new DateDefinition(id);
031    }
032
033    public static StringDefinition stringDefinition(String id) {
034        return new StringDefinition(id);
035    }
036
037    public static PropertyGroupDefinition propertyGroupDefinition(String id) {
038        return new PropertyGroupDefinition(id);
039    }
040
041    public static PropertyDefinition propertyDefinition(String name, String value) {
042        return new PropertyDefinition(name, value);
043    }
044
045    public static void setOnMissingProperty(FieldDefinition<?> fieldDefinition, String value) {
046        fieldDefinition.setOnMissingProperty(value);
047    }
048
049    public static void setOnMissingFileProperty(FieldDefinition<?> fieldDefinition, String value) {
050        fieldDefinition.setOnMissingFileProperty(value);
051    }
052
053    public static void setOnMissingFile(FieldDefinition<?> fieldDefinition, String value) {
054        fieldDefinition.setOnMissingFile(value);
055    }
056
057    public static void setPropertyFile(FieldDefinition<?> fieldDefinition, File value) {
058        fieldDefinition.propertyFile = value;
059    }
060
061    public static void setInitialValue(FieldDefinition<?> fieldDefinition, String initialValue) {
062        fieldDefinition.initialValue = initialValue;
063    }
064
065    // uuid helpers
066    public static void setValue(UuidDefinition uuidDefinition, String value) {
067        uuidDefinition.value = value;
068    }
069
070    // date helpers
071    public static void setValue(DateDefinition dateDefinition, Long value) {
072        dateDefinition.value = value;
073    }
074
075    public static void setTimezone(DateDefinition dateDefinition, String timezone) {
076        dateDefinition.timezone = timezone;
077    }
078
079    public static void setFormat(DateDefinition dateDefinition, String format) {
080        dateDefinition.format = format;
081    }
082
083    // number helpers
084    public static void setFieldNumber(NumberDefinition numberDefinition, int fieldNumber) {
085        numberDefinition.fieldNumber = fieldNumber;
086    }
087
088    // string helpers
089
090    public static void setValues(StringDefinition stringDefinition, String ... values) {
091        stringDefinition.setValues(Arrays.asList(values));
092    }
093
094    public static void setBlankIsValid(StringDefinition stringDefinition, boolean blankIsValid) {
095        stringDefinition.blankIsValid = blankIsValid;
096    }
097
098    public static void setOnMissingValue(StringDefinition stringDefinition, String onMissingValue) {
099        stringDefinition.setOnMissingValue(onMissingValue);
100    }
101
102    // property group helpers
103    public static void setProperties(PropertyGroupDefinition propertyGroupDefinition, PropertyDefinition ... propertyDefinitions) {
104        propertyGroupDefinition.setProperties(propertyDefinitions);
105    }
106
107    public static void setOnMissingField(PropertyGroupDefinition propertyGroupDefinition, String value) {
108        propertyGroupDefinition.setOnMissingField(value);
109    }
110}