All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adaptrex.core.ext.FieldDefinition Maven / Gradle / Ivy

There is a newer version: 1.0-Alpha3
Show newest version
/*
 * Copyright 2012 Adaptrex, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.adaptrex.core.ext;

import com.adaptrex.core.Adaptrex;
import com.fasterxml.jackson.annotation.JsonInclude;

public class FieldDefinition {

	private String name;
	private String type;
	private Boolean useNull;
	private String dateFormat;

	public FieldDefinition(String name, String type) {
		this.name = name;
		this.type = type;
	}
	
	public FieldDefinition(String name, String type, boolean useNull) {
		this.name = name;
		this.type = type;
		this.useNull = useNull;
	}

	public FieldDefinition(java.lang.reflect.Field field, ExtConfig extConfig) {
		/*
		 * Get the field name
		 */
		this.name = field.getName();
		this.type = extConfig.getORMPersistenceManager().getFieldType(field.getDeclaringClass(),
				field.getName());

		/*
		 * Ext always wants "null" for number fields otherwise it generates a 0
		 */
		if (this.type.equals("int") || this.type.equals("float")) {
			this.useNull = true;
		} else if (this.type.equals("date")) {
			this.dateFormat = "Y-m-d";
		} else if (this.type.equals("time")) {
			this.type = "date"; // Ext "time" field doesn't actually exist
			this.dateFormat = "H:i:s";
		}
	}

	@JsonInclude
	public String getName() {
		return this.name;
	}

	@JsonInclude
	public String getType() {
		return this.type;
	}

	@JsonInclude(JsonInclude.Include.NON_NULL)
	public Boolean getUseNull() {
		return this.useNull;
	}

	@JsonInclude(JsonInclude.Include.NON_NULL)
	public String getDateFormat() {
		return this.dateFormat;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy