View Javadoc

1   /*
2    * Copyright 2007-2010 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.jaxb;
17  
18  import java.util.Map;
19  
20  import javax.xml.bind.annotation.adapters.XmlAdapter;
21  
22  import org.kuali.rice.kim.bo.types.dto.AttributeSet;
23  
24  /**
25   * 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
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public class AttributeSetAdapter extends XmlAdapter<StringMapEntry[], AttributeSet> {
31  
32  	/**
33  	 * @see org.kuali.rice.core.jaxb.MapStringStringAdapter#marshal(java.lang.Object)
34  	 */
35  	@Override
36  	public StringMapEntry[] marshal(AttributeSet attributeSet) throws Exception {
37  		if(null == attributeSet) return null;
38  		StringMapEntry[] entryArray = new StringMapEntry[attributeSet.size()];
39  		int i = 0;
40  		for (Map.Entry<String, String> e : attributeSet.entrySet()) {
41  			entryArray[i] = new StringMapEntry(e);
42  			i++;
43  		}
44  		return entryArray;
45  	}
46  
47  	/**
48  	 * @see org.kuali.rice.core.jaxb.MapStringStringAdapter#unmarshal(java.util.ArrayList)
49  	 */
50  	@Override
51  	public AttributeSet unmarshal(StringMapEntry[] entryArray) throws Exception {
52  		if (null == entryArray) return null;
53  		AttributeSet resultMap = new AttributeSet(entryArray.length);
54  		for (int i = 0; i < entryArray.length; i++) {
55  			StringMapEntry stringMapEntry = entryArray[i];
56  			resultMap.put(stringMapEntry.key, stringMapEntry.value);
57  		}
58  		return resultMap;
59  	}
60  
61  }