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 General Public License (GPL) Version 2.0.
8    * 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 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   * <script type="text/javascript">printFileStatus
25   *   ("$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/tags/el4j_1_5_1/el4j/framework/tests/remoting_jaxws/jar-wsgen/src/main/java/ch/elca/el4j/tests/remoting/jaxws/service/IntMatrixAdapter.java $",
26   *    "$Revision: 3038 $",
27   *    "$Date: 2008-06-09 12:08:34 +0200 (Mon, 09 Jun 2008) $",
28   *    "$Author: swismer $"
29   * );</script>
30   *
31   * @author Stefan Wismer (SWI)
32   */
33  public class IntMatrixAdapter extends XmlAdapter<String, int[][]> {
34  
35  	/** {@inheritDoc} */
36  	@Override
37  	public String marshal(int[][] v) throws Exception {
38  		StringBuilder b = new StringBuilder();
39  		for (int[] is : v) {
40  			for (int i : is) {
41  				b.append(i).append(",");
42  			}
43  			b.setLength(b.length() - 1);
44  			b.append(";");
45  		}
46  		b.setLength(b.length() - 1);
47  		return b.toString();
48  	}
49  	
50  	/** {@inheritDoc} */
51  	@Override
52  	public int[][] unmarshal(String v) throws Exception {
53  		String[] tmp = v.split(";");
54  		int[][] list1 = new int[tmp.length][];
55  		for (int i = 0; i < list1.length; i++) {
56  			String[] tmp2 = tmp[i].split(",");
57  			int[] list2 = new int[tmp2.length];
58  			for (int j = 0; j < list2.length; j++) {
59  				list2[j] = Integer.parseInt(tmp2[j]);
60  			}
61  			list1[i] = list2;
62  		}
63  		return list1;
64  	}
65  }