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