001/* 002 * (C) Copyright 2018 Nuxeo (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * pierre 018 */ 019package org.nuxeo.runtime.avro; 020 021import java.util.Arrays; 022 023import org.apache.avro.Schema; 024 025/** 026 * The base class for any AvroSchemaFactory.<br> 027 * 028 * @since 10.2 029 */ 030public abstract class AvroSchemaFactory<T> { 031 032 protected static final Schema NULL_SCHEMA = Schema.create(Schema.Type.NULL); 033 034 protected final AvroSchemaFactoryContext context; 035 036 public AvroSchemaFactory(AvroSchemaFactoryContext context) { 037 this.context = context; 038 } 039 040 public abstract Schema createSchema(T input); 041 042 public abstract String getName(T input); 043 044 public String getQualifiedName(T input) { 045 return getName(input); 046 } 047 048 protected Schema nullable(Schema schema) { 049 return Schema.createUnion(Arrays.asList(NULL_SCHEMA, schema)); 050 } 051 052}