001: /*
002: * XML 2 Java Binding (X2JB) - the excellent Java tool.
003: * Copyright 2007, by Richard Opalka.
004: *
005: * This is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as
007: * published by the Free Software Foundation; either version 2.1 of
008: * the License, or (at your option) any later version.
009: *
010: * This software is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this software; if not see the FSF site:
017: * http://www.fsf.org/ and search for the LGPL License document there.
018: */
019: package arrayssupport;
020:
021: import arrayssupport.ifaces.Data;
022: import org.x2jb.bind.XML2Java;
023: import org.w3c.dom.Document;
024: import javax.xml.parsers.DocumentBuilder;
025: import javax.xml.parsers.DocumentBuilderFactory;
026: import javax.xml.parsers.ParserConfigurationException;
027:
028: /**
029: * Arrays support sample
030: *
031: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
032: * @version 1.0
033: */
034: public final class Main {
035:
036: /**
037: * Lookups specified resource on the classpath and returns parsed document instance
038: * @param classpath resource to return
039: */
040: private static Document getDocument(String resource)
041: throws Exception {
042: Document retVal = null;
043: try {
044: DocumentBuilderFactory builderFactory = DocumentBuilderFactory
045: .newInstance();
046: builderFactory.setNamespaceAware(true);
047: builderFactory.setIgnoringComments(true);
048: DocumentBuilder builder = builderFactory
049: .newDocumentBuilder();
050: retVal = builder.parse(Main.class
051: .getResourceAsStream(resource));
052: } catch (ParserConfigurationException e) {
053: e.printStackTrace(System.err);
054: System.exit(1);
055: }
056: return retVal;
057: }
058:
059: public static void main(String[] args) throws Exception {
060: Document parsedDocument = getDocument("/arrayssupport.xml");
061: Data data = (Data) XML2Java.bind(parsedDocument, Data.class);
062: Data.Arrays arrays = data.getArrays();
063:
064: // display byte array values
065: byte[] byteValues = arrays.byteValues();
066: for (int i = 0; i < byteValues.length; i++) {
067: System.out.println("byte value on position " + i + " is "
068: + byteValues[i]);
069: }
070: System.out.println();
071:
072: // display char array values
073: char[] charValues = arrays.charValues();
074: for (int i = 0; i < charValues.length; i++) {
075: System.out.println("char value on position " + i + " is "
076: + charValues[i]);
077: }
078: System.out.println();
079:
080: // display short array values
081: short[] shortValues = arrays.shortValues();
082: for (int i = 0; i < shortValues.length; i++) {
083: System.out.println("short value on position " + i + " is "
084: + shortValues[i]);
085: }
086: System.out.println();
087:
088: // display int array values
089: int[] intValues = arrays.intValues();
090: for (int i = 0; i < intValues.length; i++) {
091: System.out.println("int value on position " + i + " is "
092: + intValues[i]);
093: }
094: System.out.println();
095:
096: // display long array values
097: long[] longValues = arrays.longValues();
098: for (int i = 0; i < longValues.length; i++) {
099: System.out.println("long value on position " + i + " is "
100: + longValues[i]);
101: }
102: System.out.println();
103:
104: // display float array values
105: float[] floatValues = arrays.floatValues();
106: for (int i = 0; i < floatValues.length; i++) {
107: System.out.println("float value on position " + i + " is "
108: + floatValues[i]);
109: }
110: System.out.println();
111:
112: // display double array values
113: double[] doubleValues = arrays.doubleValues();
114: for (int i = 0; i < doubleValues.length; i++) {
115: System.out.println("double value on position " + i + " is "
116: + doubleValues[i]);
117: }
118: System.out.println();
119:
120: // display BigInteger array values
121: java.math.BigInteger[] bigIntegerValues = arrays
122: .bigIntegerValues();
123: for (int i = 0; i < bigIntegerValues.length; i++) {
124: System.out.println("BigInteger value on position " + i
125: + " is " + bigIntegerValues[i]);
126: }
127: System.out.println();
128:
129: // display BigDecimal array values
130: java.math.BigDecimal[] bigDecimalValues = arrays
131: .bigDecimalValues();
132: for (int i = 0; i < bigDecimalValues.length; i++) {
133: System.out.println("BigDecimal value on position " + i
134: + " is " + bigDecimalValues[i]);
135: }
136: System.out.println();
137:
138: // display String array values
139: String[] stringValues = arrays.stringValues();
140: for (int i = 0; i < stringValues.length; i++) {
141: System.out.println("String value on position " + i + " is "
142: + stringValues[i]);
143: }
144: System.out.println();
145:
146: }
147:
148: }
|