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.swap; 014 015import java.net.*; 016import java.time.*; 017import java.time.temporal.*; 018import java.util.*; 019import java.util.concurrent.*; 020import java.util.regex.*; 021 022import javax.xml.datatype.*; 023 024import org.apache.juneau.reflect.*; 025import org.apache.juneau.swaps.*; 026 027/** 028 * Maintain the list of default swaps used by all serializers and parsers. 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * <li class='link'><a class="doclink" href="../../../../index.html#jm.Swaps">Swaps</a> 032 * </ul> 033 */ 034public class DefaultSwaps { 035 036 private static final Map<Class<?>,ObjectSwap<?,?>> SWAPS = new ConcurrentHashMap<>(); 037 static { 038 SWAPS.put(Enumeration.class, new EnumerationSwap()); 039 SWAPS.put(Iterator.class, new IteratorSwap()); 040 SWAPS.put(Locale.class, new LocaleSwap()); 041 SWAPS.put(Class.class, new ClassSwap()); 042 SWAPS.put(Calendar.class, new TemporalCalendarSwap.IsoOffsetDateTime()); 043 SWAPS.put(Date.class, new TemporalDateSwap.IsoLocalDateTime()); 044 SWAPS.put(Instant.class, new TemporalSwap.IsoInstant()); 045 SWAPS.put(ZonedDateTime.class, new TemporalSwap.IsoOffsetDateTime()); 046 SWAPS.put(LocalDate.class, new TemporalSwap.IsoLocalDate()); 047 SWAPS.put(LocalDateTime.class, new TemporalSwap.IsoLocalDateTime()); 048 SWAPS.put(LocalTime.class, new TemporalSwap.IsoLocalTime()); 049 SWAPS.put(OffsetDateTime.class, new TemporalSwap.IsoOffsetDateTime()); 050 SWAPS.put(OffsetTime.class, new TemporalSwap.IsoOffsetTime()); 051 SWAPS.put(StackTraceElement.class, new StackTraceElementSwap()); 052 SWAPS.put(Year.class, new TemporalSwap.IsoYear()); 053 SWAPS.put(YearMonth.class, new TemporalSwap.IsoYearMonth()); 054 SWAPS.put(Temporal.class, new TemporalSwap.IsoInstant()); 055 SWAPS.put(TimeZone.class, new TimeZoneSwap()); 056 SWAPS.put(XMLGregorianCalendar.class, new XMLGregorianCalendarSwap()); 057 SWAPS.put(ZoneId.class, new ZoneIdSwap()); 058 SWAPS.put(MatchResult.class, new MatchResultSwap()); 059 SWAPS.put(URL.class, new UrlSwap()); 060 } 061 062 /** 063 * Find the default ObjectSwap for the specified class. 064 * 065 * @param ci The class to find the swap for. 066 * @return The matched swap, or <jk>null</jk> if it couldn't be found. 067 */ 068 public static ObjectSwap<?,?> find(ClassInfo ci) { 069 ClassInfo ci2 = ci.getAnyParent(x -> SWAPS.get(x.inner()) != null); 070 return ci2 == null ? null : SWAPS.get(ci2.inner()); 071 } 072}