001 /* 002 * Copyright 2007-2010 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 */ 016 package org.kuali.rice.core.jaxb; 017 018 import java.util.Map; 019 020 import javax.xml.bind.annotation.adapters.XmlAdapter; 021 022 import org.kuali.rice.kim.bo.types.dto.AttributeSet; 023 024 /** 025 * This class allows for a {@link org.kuali.rice.kim.bo.types.dto.AttributeSet} instance to be passed across the wire by jaxws enabled services 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 * 029 */ 030 public class AttributeSetAdapter extends XmlAdapter<StringMapEntry[], AttributeSet> { 031 032 /** 033 * @see org.kuali.rice.core.jaxb.MapStringStringAdapter#marshal(java.lang.Object) 034 */ 035 @Override 036 public StringMapEntry[] marshal(AttributeSet attributeSet) throws Exception { 037 if(null == attributeSet) return null; 038 StringMapEntry[] entryArray = new StringMapEntry[attributeSet.size()]; 039 int i = 0; 040 for (Map.Entry<String, String> e : attributeSet.entrySet()) { 041 entryArray[i] = new StringMapEntry(e); 042 i++; 043 } 044 return entryArray; 045 } 046 047 /** 048 * @see org.kuali.rice.core.jaxb.MapStringStringAdapter#unmarshal(java.util.ArrayList) 049 */ 050 @Override 051 public AttributeSet unmarshal(StringMapEntry[] entryArray) throws Exception { 052 if (null == entryArray) return null; 053 AttributeSet resultMap = new AttributeSet(entryArray.length); 054 for (int i = 0; i < entryArray.length; i++) { 055 StringMapEntry stringMapEntry = entryArray[i]; 056 resultMap.put(stringMapEntry.key, stringMapEntry.value); 057 } 058 return resultMap; 059 } 060 061 }