001/**
002 * Copyright (C) 2006-2019 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.api.service.schema;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.List;
021
022import org.talend.sdk.component.api.meta.Partial;
023
024import lombok.AllArgsConstructor;
025import lombok.Data;
026import lombok.NoArgsConstructor;
027
028@Partial("This API should support nested schema but the Studio is not yet ready.\n\n"
029        + "The cloud platform also doesn't use it yet.\n\nAlso prefer to use "
030        + "`org.talend.sdk.component.api.record.Schema` over this partial default implementation.")
031@Data
032@NoArgsConstructor
033@AllArgsConstructor
034@Deprecated // use SchemaBuilder instead of this implementation
035public class Schema implements org.talend.sdk.component.api.record.Schema {
036
037    private List<org.talend.sdk.component.api.record.Schema.Entry> entries;
038
039    // 1.0 compat
040    public Schema(final Collection<org.talend.sdk.component.api.record.Schema.Entry> entries) {
041        this.entries = new ArrayList<>(entries);
042    }
043
044    // 1.0 compat
045    public void setEntries(final Collection<org.talend.sdk.component.api.record.Schema.Entry> entries) {
046        this.entries = new ArrayList<>(entries);
047    }
048
049    @Override
050    public Type getType() {
051        return Type.RECORD;
052    }
053
054    @Override
055    public org.talend.sdk.component.api.record.Schema getElementSchema() {
056        return null;
057    }
058
059    @Data
060    @AllArgsConstructor
061    @NoArgsConstructor
062    @Deprecated
063    public static class Entry implements org.talend.sdk.component.api.record.Schema.Entry {
064
065        private String name;
066
067        private Schema.Type type;
068
069        // 1.0 compat
070        public Entry(final String name, final org.talend.sdk.component.api.service.schema.Type type) {
071            this.name = name;
072            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
073        }
074
075        // 1.0 compat
076        public void setType(final org.talend.sdk.component.api.service.schema.Type type) {
077            this.type = org.talend.sdk.component.api.record.Schema.Type.valueOf(type.name());
078        }
079
080        @Override
081        public boolean isNullable() {
082            return true;
083        }
084
085        @Override
086        public <T> T getDefaultValue() {
087            return null;
088        }
089
090        @Override
091        public org.talend.sdk.component.api.record.Schema getElementSchema() {
092            return null;
093        }
094
095        @Override
096        public String getComment() {
097            return null;
098        }
099    }
100}