View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.tests.remoting.jaxws.service;
18  
19  import javax.xml.bind.annotation.adapters.XmlAdapter;
20  
21  /**
22   * This class is an adapter which converts int[][] to String and back.
23   *
24   * @svnLink $Revision: 3878 $;$Date: 2009-08-04 15:06:35 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/tests/remoting_jaxws/jar-wsgen/src/main/java/ch/elca/el4j/tests/remoting/jaxws/service/IntMatrixAdapter.java $
25   *
26   * @author Stefan Wismer (SWI)
27   */
28  public class IntMatrixAdapter extends XmlAdapter<String, int[][]> {
29  
30  	/** {@inheritDoc} */
31  	@Override
32  	public String marshal(int[][] v) throws Exception {
33  		StringBuilder b = new StringBuilder();
34  		for (int[] is : v) {
35  			for (int i : is) {
36  				b.append(i).append(",");
37  			}
38  			b.setLength(b.length() - 1);
39  			b.append(";");
40  		}
41  		b.setLength(b.length() - 1);
42  		return b.toString();
43  	}
44  	
45  	/** {@inheritDoc} */
46  	@Override
47  	public int[][] unmarshal(String v) throws Exception {
48  		String[] tmp = v.split(";");
49  		int[][] list1 = new int[tmp.length][];
50  		for (int i = 0; i < list1.length; i++) {
51  			String[] tmp2 = tmp[i].split(",");
52  			int[] list2 = new int[tmp2.length];
53  			for (int j = 0; j < list2.length; j++) {
54  				list2[j] = Integer.parseInt(tmp2[j]);
55  			}
56  			list1[i] = list2;
57  		}
58  		return list1;
59  	}
60  }