From e41fb8274a4b15de267f94a98165dcb40d14a435 Mon Sep 17 00:00:00 2001 From: Jared Gould Date: Sun, 19 Nov 2006 17:00:36 +0000 Subject: [PATCH] Inheritance is almost working.. not causing exceptions but not making another instance of rom. Scales are also not associating with tables yet. git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@357 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d --- .../definition/RomDefinitionHandler.java | 47 ++++++++++++++----- src/enginuity/newmaps/ecudata/Category.java | 35 +++++++++----- src/enginuity/newmaps/ecudata/Rom.java | 2 +- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/enginuity/newmaps/definition/RomDefinitionHandler.java b/src/enginuity/newmaps/definition/RomDefinitionHandler.java index cf41ce19..1134583c 100644 --- a/src/enginuity/newmaps/definition/RomDefinitionHandler.java +++ b/src/enginuity/newmaps/definition/RomDefinitionHandler.java @@ -11,11 +11,11 @@ import static java.lang.Integer.parseInt; import static enginuity.newmaps.definition.AttributeParser.*; import enginuity.newmaps.xml.SaxParserFactory; import enginuity.util.exception.NameableNotFoundException; +import enginuity.xml.ObjectCloner; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.util.Iterator; import java.util.Stack; public class RomDefinitionHandler extends DefaultHandler { @@ -27,6 +27,7 @@ public class RomDefinitionHandler extends DefaultHandler { private static final String TAG_TABLE2D = "table2d"; private static final String TAG_PARAMETER = "parameter"; private static final String TAG_SWITCH = "switch"; + private static final String TAG_DESCRIPTION = "description"; private static final String TAG_SCALES = "scales"; private static final String TAG_SCALE = "scale"; private static final String TAG_AXIS = "axis"; @@ -83,6 +84,7 @@ public class RomDefinitionHandler extends DefaultHandler { private NamedSet tables = new NamedSet(); private NamedSet scales = new NamedSet(); private NamedSet units = new NamedSet(); + private StringBuilder charBuffer; public RomDefinitionHandler(RomTreeBuilder roms) { @@ -95,7 +97,7 @@ public class RomDefinitionHandler extends DefaultHandler { } public void startElement(String uri, String localName, String qName, Attributes attr) { - + if (TAG_ROM.equalsIgnoreCase(qName)) { try { @@ -106,7 +108,9 @@ public class RomDefinitionHandler extends DefaultHandler { if (attr.getIndex(ATTR_BASE) > -1 && attr.getValue(ATTR_BASE).length() > 0) { - rom = (Rom)roms.get(attr.getValue(ATTR_NAME)); + rom = (Rom)ObjectCloner.deepCopy(roms.get(attr.getValue(ATTR_NAME))); + rom.setName(attr.getValue(name)); + } else { rom = new Rom(name); } @@ -131,7 +135,11 @@ public class RomDefinitionHandler extends DefaultHandler { rom.setAbstract(parseBoolean(attr.getValue(ATTR_ABSTRACT))); } catch (NameableNotFoundException ex) { - // uhh.. do something + // TODO: Deal with rom not found + + } catch (Exception ex) { + // TODO: Deal with clone and other exceptions + } @@ -167,9 +175,9 @@ public class RomDefinitionHandler extends DefaultHandler { // Store axis addresses if (attr.getIndex(ATTR_X_ADDRESS) > -1) - xAddress = parseInt(attr.getValue(ATTR_X_ADDRESS)); + xAddress = hexToInt(attr.getValue(ATTR_X_ADDRESS)); if (attr.getIndex(ATTR_Y_ADDRESS) > -1) - yAddress = parseInt(attr.getValue(ATTR_Y_ADDRESS)); + yAddress = hexToInt(attr.getValue(ATTR_Y_ADDRESS)); // Add scale try { @@ -201,7 +209,7 @@ public class RomDefinitionHandler extends DefaultHandler { // Store axis addresses if (attr.getIndex(ATTR_AXIS_ADDRESS) > -1) - yAddress = parseInt(attr.getValue(ATTR_AXIS_ADDRESS)); + yAddress = hexToInt(attr.getValue(ATTR_AXIS_ADDRESS)); // Add scale try { @@ -264,7 +272,7 @@ public class RomDefinitionHandler extends DefaultHandler { } catch (NameableNotFoundException ex) { // TODO: Handle exception } - + } else if (TAG_SCALE.equalsIgnoreCase(qName)) { @@ -367,6 +375,8 @@ public class RomDefinitionHandler extends DefaultHandler { } + charBuffer = new StringBuilder(); + } @@ -392,7 +402,7 @@ public class RomDefinitionHandler extends DefaultHandler { // Remove current category from stack categoryStack.pop(); - category = null; + //category = null; } else if (TAG_TABLE3D.equalsIgnoreCase(qName) || @@ -401,6 +411,7 @@ public class RomDefinitionHandler extends DefaultHandler { TAG_SWITCH.equalsIgnoreCase(qName)) { tables.add(table); + category.addTable(table); // Clear object for next element table = null; @@ -427,6 +438,11 @@ public class RomDefinitionHandler extends DefaultHandler { axis = null; + } else if (TAG_DESCRIPTION.equalsIgnoreCase(qName)) { + + table.setDescription(charBuffer.toString()); + + } else if (TAG_ROM.equalsIgnoreCase(qName)) { rom.setTables(tables); @@ -438,19 +454,26 @@ public class RomDefinitionHandler extends DefaultHandler { } } + + public void characters(char[] ch, int start, int length) { + charBuffer.append(ch, start, length); + } public static void main(String[] args) { try { - InputStream inputStream = new BufferedInputStream(new FileInputStream(new File("/ecu_defs/subaru/wrx/16BITBASE.xml"))); + InputStream inputStream1 = new BufferedInputStream(new FileInputStream(new File("/ecu_defs/subaru/wrx/16BITBASE.xml"))); + InputStream inputStream2 = new BufferedInputStream(new FileInputStream(new File("/ecu_defs/subaru/wrx/A4SG900C.xml"))); try { RomTreeBuilder builder = new RomTreeBuilder(); RomDefinitionHandler handler = new RomDefinitionHandler(builder); - SaxParserFactory.getSaxParser().parse(inputStream, handler); + SaxParserFactory.getSaxParser().parse(inputStream1, handler); + SaxParserFactory.getSaxParser().parse(inputStream2, handler); System.out.println(builder.get(0)); } finally { - inputStream.close(); + inputStream1.close(); + inputStream2.close(); } } catch (Exception e) { e.printStackTrace(); diff --git a/src/enginuity/newmaps/ecudata/Category.java b/src/enginuity/newmaps/ecudata/Category.java index 1cb3b0e0..037971ac 100644 --- a/src/enginuity/newmaps/ecudata/Category.java +++ b/src/enginuity/newmaps/ecudata/Category.java @@ -8,8 +8,7 @@ public class Category extends NamedSet implements Nameable { private String name; private String description; - private Category subcats; - private ECUData[] tables; + private NamedSet tables = new NamedSet(); private Category() { } @@ -32,25 +31,39 @@ public class Category extends NamedSet implements Nameable { public void setDescription(String description) { this.description = description; } - - public ECUData[] getEcuData() { - return tables; - } - - public void setEcuData(ECUData[] ecuData) { - this.tables = tables; - } public String toString() { StringBuffer output = new StringBuffer(); output.append(" - CATEGORY: " + name + " -\n"); - Iterator it = subcats.iterator(); + Iterator it = tables.iterator(); + while (it.hasNext()) { + output.append(it.next().toString() + "\n"); + } + + it = iterator(); while (it.hasNext()) { output.append(" " + it.next().toString() + "\n"); } return output + ""; } + + public void addTable(ECUData table) { + tables.add(table); + } + + public void removeTable(ECUData table) { + try { + tables.remove(table); + } catch (Exception ex) { + + } finally { + Iterator it = iterator(); + while (it.hasNext()) { + ((Category)it.next()).removeTable(table); + } + } + } } \ No newline at end of file diff --git a/src/enginuity/newmaps/ecudata/Rom.java b/src/enginuity/newmaps/ecudata/Rom.java index 61649ed4..d6e0e790 100644 --- a/src/enginuity/newmaps/ecudata/Rom.java +++ b/src/enginuity/newmaps/ecudata/Rom.java @@ -109,7 +109,7 @@ public class Rom implements Nameable { "\n - Obsolete: " + obsolete + "\n - Abstract: " + isAbstract + "\n --- SCALES ---\n" + scales + - "\n --- TABLES ---\n" + tables + + //"\n --- TABLES ---\n" + tables + "\n --- CATEGORIES ---\n" + categories; return output;