001/**
002 * Copyright (C) 2006-2026 Talend Inc. - www.talend.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.talend.sdk.component.server.front.model;
017
018import java.beans.ConstructorProperties;
019import java.math.BigDecimal;
020import java.time.temporal.Temporal;
021import java.util.Collection;
022import java.util.Date;
023import java.util.List;
024import java.util.Map;
025
026import lombok.Data;
027
028@Data
029public final class Schema {
030
031    private final Type type;
032
033    private final Schema elementSchema;
034
035    private final List<Entry> entries;
036
037    private final List<Entry> metadata;
038
039    private final Map<String, String> props;
040
041    @ConstructorProperties({ "type", "elementSchema", "entries", "metadata", "props" })
042    public Schema(
043            final Type type,
044            final Schema elementSchema,
045            final List<Entry> entries,
046            final List<Entry> metadata,
047            final Map<String, String> props) {
048        this.type = type;
049        this.elementSchema = elementSchema;
050        this.entries = entries;
051        this.metadata = metadata;
052        this.props = props;
053    }
054
055    public String getProp(final String key) {
056        return this.props.get(key);
057    }
058
059    public enum Type {
060
061        RECORD(new Class<?>[] { Record.class }),
062        ARRAY(new Class<?>[] { Collection.class }),
063        STRING(new Class<?>[] { String.class, Object.class }),
064        BYTES(new Class<?>[] { byte[].class, Byte[].class }),
065        INT(new Class<?>[] { Integer.class }),
066        LONG(new Class<?>[] { Long.class }),
067        FLOAT(new Class<?>[] { Float.class }),
068        DOUBLE(new Class<?>[] { Double.class }),
069        BOOLEAN(new Class<?>[] { Boolean.class }),
070        DATETIME(new Class<?>[] { Long.class, Date.class, Temporal.class }),
071        DECIMAL(new Class<?>[] { BigDecimal.class });
072
073        /**
074         * All compatibles Java classes
075         */
076        private final Class<?>[] classes;
077
078        Type(final Class<?>[] classes) {
079            this.classes = classes;
080        }
081
082    }
083}