001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.oxm.xmlbeans; 018 019import java.util.Map; 020 021import org.apache.xmlbeans.XmlOptions; 022 023import org.springframework.beans.factory.FactoryBean; 024 025/** 026 * {@link FactoryBean} that configures an XMLBeans {@code XmlOptions} object 027 * and provides it as a bean reference. 028 * 029 * <p>Typical usage will be to set XMLBeans options on this bean, and refer to it 030 * in the {@link XmlBeansMarshaller}. 031 * 032 * @author Arjen Poutsma 033 * @author Juergen Hoeller 034 * @since 3.0 035 * @see XmlOptions 036 * @see #setOptions(java.util.Map) 037 * @see XmlBeansMarshaller#setXmlOptions(XmlOptions) 038 */ 039public class XmlOptionsFactoryBean implements FactoryBean<XmlOptions> { 040 041 private XmlOptions xmlOptions = new XmlOptions(); 042 043 044 /** 045 * Set options on the underlying {@code XmlOptions} object. 046 * <p>The keys of the supplied map should be one of the String constants 047 * defined in {@code XmlOptions}, the values vary per option. 048 * @see XmlOptions#put(Object, Object) 049 * @see XmlOptions#SAVE_PRETTY_PRINT 050 * @see XmlOptions#LOAD_STRIP_COMMENTS 051 */ 052 public void setOptions(Map<String, ?> optionsMap) { 053 this.xmlOptions = new XmlOptions(); 054 if (optionsMap != null) { 055 for (Map.Entry<String, ?> option : optionsMap.entrySet()) { 056 this.xmlOptions.put(option.getKey(), option.getValue()); 057 } 058 } 059 } 060 061 062 @Override 063 public XmlOptions getObject() { 064 return this.xmlOptions; 065 } 066 067 @Override 068 public Class<? extends XmlOptions> getObjectType() { 069 return XmlOptions.class; 070 } 071 072 @Override 073 public boolean isSingleton() { 074 return true; 075 } 076 077}