001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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 * http://www.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.common.util.xml.jaxb.adapter;
017
018import javax.xml.bind.annotation.adapters.XmlAdapter;
019
020public abstract class OmitBooleanAdapter extends XmlAdapter<String, Boolean> {
021
022        public OmitBooleanAdapter(boolean omitValue) {
023                this.omitValue = omitValue;
024        }
025
026        private final Boolean omitValue;
027
028        @Override
029        public final String marshal(Boolean value) {
030                if (omitValue.equals(value)) {
031                        return null;
032                } else {
033                        return value.toString();
034                }
035        }
036
037        @Override
038        public final Boolean unmarshal(String value) {
039                if (value == null) {
040                        return omitValue;
041                } else {
042                        return Boolean.parseBoolean(value);
043                }
044        }
045
046        public final boolean getOmitValue() {
047                return omitValue;
048        }
049
050}