// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package xaal.parser; import java.util.HashMap; import java.util.Iterator; import java.util.Stack; import xaal.objects.Xaal; import xaal.parser.modules.XaalMainParserModule; public class ParserModule { public static final String CURRENT_PATH = "curr-path"; public static final String CURRENT_OBJECT = "curr-obj"; private static Stack curr = new Stack(); protected Stack s = new Stack(); private static HashMap ds = new HashMap(); public void push(Object item) { s.push(item); curr.push(item); setProperty(CURRENT_OBJECT, item); } public Object peek() { if (s.isEmpty()) return null; return s.peek(); } public Object pop() { if (s.isEmpty()) return null; Object o = s.pop(); curr.pop(); if (curr.isEmpty()) { setProperty(CURRENT_OBJECT, null); } else { setProperty(CURRENT_OBJECT, curr.peek()); } return o; } public static void setProperty(String name, Object value) { ds.put(name, value); } public static Object getProperty(String name) { return ds.get(name); } public static boolean hasProperty(String name) { return ds.containsKey(name); } public static Iterator getProperties() { return ds.keySet().iterator(); } public void characters(char[] ch, int start, int length) { } public static Object getCurrentObject() { return getProperty(CURRENT_OBJECT); } public static Xaal getXaalObject() { return (Xaal) ParserModule.getProperty(XaalMainParserModule.XAAL_ROOT_OBJECT); } }