001/* 002 * SPDX-License-Identifier: Apache-2.0 003 * 004 * Copyright 2024-2026 The Enola <https://enola.dev> Authors 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package dev.enola.model.enola.meta; 019 020import dev.enola.thing.KIRI; 021import dev.enola.thing.java.TBF; 022 023import org.jspecify.annotations.Nullable; 024 025import java.net.URI; 026 027public interface Datatype extends Type { 028 029 String CLASS_IRI = "https://enola.dev/meta/Datatype"; 030 031 // Intentionally only singular instead of multiple 032 default Datatype parent() { 033 return getThing(KIRI.E.PARENT, Datatype.class).get(); 034 } 035 036 default @Nullable String java() { 037 return getString(KIRI.E.META.JAVA); 038 } 039 040 default @Nullable String proto() { 041 return getString(KIRI.E.META.PROTO); 042 } 043 044 default @Nullable URI xsd() { 045 return get(KIRI.E.META.XSD, URI.class); 046 } 047 048 // TODO Pattern regExp(); 049 050 interface Builder<B extends Datatype> extends Datatype, Type.Builder<B> { // skipcq: JAVA-E0169 051 052 @Override 053 default Datatype.Builder<B> schema(Schema schema) { 054 Type.Builder.super.schema(schema); 055 return this; 056 } 057 058 @Override 059 default Datatype.Builder<B> name(String name) { 060 Type.Builder.super.name(name); 061 return this; 062 } 063 064 default Datatype.Builder<B> parent(Datatype datatype) { 065 set(KIRI.E.PARENT, datatype); 066 return this; 067 } 068 069 default Datatype.Builder<B> java(String java) { 070 set(KIRI.E.META.JAVA, java); 071 return this; 072 } 073 074 default Datatype.Builder<B> proto(String proto) { 075 set(KIRI.E.META.PROTO, proto); 076 return this; 077 } 078 079 default Datatype.Builder<B> xsd(URI xsd) { 080 set(KIRI.E.META.XSD, xsd); 081 return this; 082 } 083 } 084 085 @SuppressWarnings("unchecked") 086 static Datatype.Builder<Datatype> builder(TBF tbf) { 087 return tbf.create(Datatype.Builder.class, Datatype.class); 088 } 089}