001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.jsonschema; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020 021import java.net.*; 022import java.text.*; 023 024import org.apache.juneau.*; 025 026/** 027 * Simple implementation of the {@link BeanDefMapper} interface. 028 * 029 * <p> 030 * IDs are created by calling {@link Class#getSimpleName()}. 031 * <p> 032 * URIs are constructed using the pattern <js>"#/definitions/{id}"</js>. 033 * 034 * <h5 class='section'>See Also:</h5><ul> 035 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JsonSchemaDetails">JSON-Schema Support</a> 036 * </ul> 037 */ 038public class BasicBeanDefMapper implements BeanDefMapper { 039 040 private final MessageFormat format; 041 042 /** 043 * Default constructor. 044 */ 045 public BasicBeanDefMapper() { 046 this("#/definitions/{0}"); 047 } 048 049 /** 050 * Constructor that allows you to override the URI pattern. 051 * 052 * @param uriPattern The URI pattern using {@link MessageFormat}-style arguments. 053 */ 054 protected BasicBeanDefMapper(String uriPattern) { 055 format = new MessageFormat(uriPattern); 056 } 057 058 @Override /* Overridden from BeanDefMapper */ 059 public String getId(ClassMeta<?> cm) { 060 return cm.getNameSimple(); 061 } 062 063 @Override /* Overridden from BeanDefMapper */ 064 public URI getURI(ClassMeta<?> cm) { 065 return getURI(getId(cm)); 066 } 067 068 @Override /* Overridden from BeanDefMapper */ 069 public URI getURI(String id) { 070 return URI.create(format.format(a(id))); 071 } 072}