Author: bobtarling Date: 2009-12-11 05:40:46-0800 New Revision: 17637 Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/PanelMetaCache.java Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/XMLPropPanelFactory.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java
Log: Move all XML knowledge into the xml package Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/XMLPropPanelFactory.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/XMLPropPanelFactory.java?view=diff&pathrev=17637&r1=17636&r2=17637 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/XMLPropPanelFactory.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/XMLPropPanelFactory.java 2009-12-11 05:40:46-0800 @@ -26,19 +26,18 @@ import java.io.InputStream; import java.util.Dictionary; +import java.util.HashMap; import java.util.Hashtable; +import java.util.Map; import javax.swing.JPanel; import org.apache.log4j.Logger; import org.argouml.core.propertypanels.xml.PanelMeta; -import org.argouml.core.propertypanels.xml.XmlSinglePanelHandler; +import org.argouml.core.propertypanels.xml.PanelMetaCache; import org.argouml.i18n.Translator; import org.argouml.model.Model; import org.argouml.uml.ui.PropPanelFactory; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; /** * @@ -49,7 +48,8 @@ private static final Logger LOG = Logger.getLogger(XMLPropPanelFactory.class); - private final Dictionary<String, PanelMeta> cache; + private final PanelMetaCache cache = + new PanelMetaCache(); private static XMLPropPanelFactory instance; @@ -62,8 +62,6 @@ } private XMLPropPanelFactory() throws Exception { - cache = new Hashtable<String, PanelMeta>(); - parseXML(); } /** @@ -101,20 +99,6 @@ } } - private void parseXML() throws Exception { - String file = "org/argouml/core/propertypanels/xml/panels.xml"; - XMLReader parser = XMLReaderFactory.createXMLReader(); - parser.setContentHandler(new XmlSinglePanelHandler(cache)); - InputStream stream = this.getClass().getClassLoader(). - getResourceAsStream(file); - if (stream != null) { - InputSource source = new InputSource(stream); - parser.parse(source); - } else { - LOG.error("Failed to find the panel XML"); - } - } - public PanelMeta getPropertyPanelsData (String forType) { return cache.get(forType); } Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/PanelMetaCache.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/PanelMetaCache.java?view=markup&pathrev=17637 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/PanelMetaCache.java 2009-12-11 05:40:46-0800 @@ -0,0 +1,67 @@ +// $Id: PanelCache.java 17635 2009-12-11 12:22:07Z bobtarling $ +// Copyright (c) 2008 The Regents of the University of California. All +// Rights Reserved. Permission to use, copy, modify, and distribute this +// software and its documentation without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph appear in all copies. This software program and +// documentation are copyrighted by The Regents of the University of +// California. The software program and documentation are supplied "AS +// IS", without any accompanying services from The Regents. The Regents +// does not warrant that the operation of the program will be +// uninterrupted or error-free. The end-user understands that the program +// was developed for research purposes and is advised not to rely +// exclusively on the program for any reason. IN NO EVENT SHALL THE +// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, +// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, +// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, +// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +package org.argouml.core.propertypanels.xml; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * The cache of property panel metadata + * + * @author Bob Tarling + */ +public class PanelMetaCache { + + private final Map<String, PanelMeta> cache = + new HashMap<String, PanelMeta>(); + + + public PanelMetaCache() throws Exception { + parseXML(); + } + + public PanelMeta get(String name) { + return cache.get(name); + } + + private void parseXML() throws Exception { + String file = "org/argouml/core/propertypanels/xml/panels.xml"; + XMLReader parser = XMLReaderFactory.createXMLReader(); + parser.setContentHandler(new XmlSinglePanelHandler(cache)); + InputStream stream = this.getClass().getClassLoader(). + getResourceAsStream(file); + if (stream != null) { + InputSource source = new InputSource(stream); + parser.parse(source); + } else { + throw new IllegalStateException("Failed to find the panel XML"); + } + } +} Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java?view=diff&pathrev=17637&r1=17636&r2=17637 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java 2009-12-11 05:40:46-0800 @@ -24,7 +24,7 @@ package org.argouml.core.propertypanels.xml; -import java.util.Dictionary; +import java.util.Map; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -35,12 +35,12 @@ * the property panels. * @author penyaskito */ -public class XmlSinglePanelHandler extends DefaultHandler { +class XmlSinglePanelHandler extends DefaultHandler { /** * The panel that will host the controls. */ - private final Dictionary<String, PanelMeta> data; + private final Map<String, PanelMeta> data; /** * the panel that we are traversing @@ -55,7 +55,7 @@ * host the info read. */ public XmlSinglePanelHandler( - Dictionary<String, PanelMeta> theData) { + Map<String, PanelMeta> theData) { this.data = theData; } ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2429778 To unsubscribe from this discussion, e-mail: [[email protected]].
