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.xml.annotation; 018 019import org.apache.juneau.*; 020import org.apache.juneau.reflect.*; 021import org.apache.juneau.svl.*; 022import org.apache.juneau.xml.*; 023 024/** 025 * Utility classes and methods for the {@link XmlConfig @XmlConfig} annotation. 026 * 027 * <h5 class='section'>See Also:</h5><ul> 028 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/XmlBasics">XML Basics</a> 029 * </ul> 030 */ 031public class XmlConfigAnnotation { 032 033 /** 034 * Applies {@link XmlConfig} annotations to a {@link org.apache.juneau.xml.XmlSerializer.Builder}. 035 */ 036 public static class SerializerApply extends AnnotationApplier<XmlConfig,XmlSerializer.Builder> { 037 038 /** 039 * Constructor. 040 * 041 * @param vr The resolver for resolving values in annotations. 042 */ 043 public SerializerApply(VarResolverSession vr) { 044 super(XmlConfig.class, XmlSerializer.Builder.class, vr); 045 } 046 047 @Override 048 public void apply(AnnotationInfo<XmlConfig> ai, XmlSerializer.Builder b) { 049 XmlConfig a = ai.inner(); 050 051 bool(a.addBeanTypes()).ifPresent(x -> b.addBeanTypesXml(x)); 052 bool(a.addNamespaceUrisToRoot()).ifPresent(x -> b.addNamespaceUrisToRoot(x)); 053 bool(a.disableAutoDetectNamespaces()).ifPresent(x -> b.disableAutoDetectNamespaces(x)); 054 string(a.defaultNamespace()).map(Namespace::create).ifPresent(x -> b.defaultNamespace(x)); 055 bool(a.enableNamespaces()).ifPresent(x -> b.enableNamespaces(x)); 056 strings(a.namespaces()).map(Namespace::createArray).ifPresent(x -> b.namespaces(x)); 057 } 058 } 059 060 /** 061 * Applies {@link XmlConfig} annotations to a {@link org.apache.juneau.xml.XmlParser.Builder}. 062 */ 063 public static class ParserApply extends AnnotationApplier<XmlConfig,XmlParser.Builder> { 064 065 /** 066 * Constructor. 067 * 068 * @param vr The resolver for resolving values in annotations. 069 */ 070 public ParserApply(VarResolverSession vr) { 071 super(XmlConfig.class, XmlParser.Builder.class, vr); 072 } 073 074 @Override 075 public void apply(AnnotationInfo<XmlConfig> ai, XmlParser.Builder b) { 076 XmlConfig a = ai.inner(); 077 078 type(a.eventAllocator()).ifPresent(x -> b.eventAllocator(x)); 079 bool(a.preserveRootElement()).ifPresent(x -> b.preserveRootElement(x)); 080 type(a.reporter()).ifPresent(x -> b.reporter(x)); 081 type(a.resolver()).ifPresent(x -> b.resolver(x)); 082 bool(a.validating()).ifPresent(x -> b.validating(x)); 083 } 084 } 085}