1 32 33 package com.knowgate.hipergate; 34 35 import java.util.ArrayList ; 36 37 import java.io.IOException ; 38 import java.io.FileNotFoundException ; 39 import java.io.UnsupportedEncodingException ; 40 import java.io.FileInputStream ; 41 import java.io.BufferedInputStream ; 42 43 import org.jibx.runtime.IBindingFactory; 44 import org.jibx.runtime.IUnmarshallingContext; 45 import org.jibx.runtime.BindingDirectory; 46 import org.jibx.runtime.JiBXException; 47 48 import com.knowgate.debug.DebugFile; 49 50 61 public class Menu { 62 private ArrayList options; 63 64 66 69 public Menu() { 70 options = new ArrayList (); 71 } 72 73 75 79 public int countSubOptions() { 80 return options.size(); 81 } 82 83 85 91 public MenuOption getOption(int nIndex) 92 throws ArrayIndexOutOfBoundsException { 93 return (MenuOption) options.get(nIndex); 94 } 95 96 98 105 public MenuOption getOption(String sName) 106 throws ArrayIndexOutOfBoundsException { 107 final int nOptCount = countSubOptions(); 108 for (int o=0;o<nOptCount;o++) { 109 if (((MenuOption)options.get(o)).getName().equalsIgnoreCase(sName)) 110 return (MenuOption) options.get(o); 111 } throw new ArrayIndexOutOfBoundsException (sName + " menu option not found"); 113 } 115 117 127 public static Menu parse(String sXMLDocPath, String sEnc) 128 throws JiBXException, FileNotFoundException , UnsupportedEncodingException , 129 IOException { 130 131 if (DebugFile.trace) { 132 DebugFile.writeln("Begin Menu.parse("+sXMLDocPath+","+sEnc+")"); 133 DebugFile.incIdent(); 134 } 135 136 if (sEnc==null) sEnc="UTF-8"; 137 138 IBindingFactory bfact = BindingDirectory.getFactory(Menu.class); 139 IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); 140 141 final int BUFFER_SIZE = 28000; 142 FileInputStream oFileStream = new FileInputStream (sXMLDocPath); 143 BufferedInputStream oXMLStream = new BufferedInputStream (oFileStream, BUFFER_SIZE); 144 145 Object obj = uctx.unmarshalDocument (oXMLStream, sEnc); 146 147 oXMLStream.close(); 148 oFileStream.close(); 149 150 if (DebugFile.trace) { 151 DebugFile.decIdent(); 152 DebugFile.writeln("End Menu.parse()"); 153 } 154 155 return (Menu) obj; 156 } } 158 | Popular Tags |