01: package it.unimi.dsi.mg4j.util.parser;
02:
03: import it.unimi.dsi.fastutil.Hash;
04: import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
05: import it.unimi.dsi.mg4j.util.MutableString;
06:
07: /*
08: * MG4J: Managing Gigabytes for Java
09: *
10: * Copyright (C) 2005-2007 Sebastiano Vigna
11: *
12: * This library is free software; you can redistribute it and/or modify it
13: * under the terms of the GNU Lesser General Public License as published by the Free
14: * Software Foundation; either version 2.1 of the License, or (at your option)
15: * any later version.
16: *
17: * This library is distributed in the hope that it will be useful, but
18: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
20: * for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public License
23: * along with this program; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25: *
26: */
27:
28: /** A factory for well-formed XML documents.
29: *
30: * <p>This factory assumes that every new name of an element type or of an
31: * attribute is new valid name. For entities, instead, resolution is
32: * deferred to {@link it.unimi.dsi.mg4j.util.parser.HTMLFactory}.
33: *
34: * @author Sebastiano Vigna
35: * @since 1.0.2
36: * @deprecated Moved to <code>dsiutils</code>.
37: */
38:
39: @Deprecated
40: public class WellFormedXmlFactory implements ParsingFactory {
41: /** The load factor for all maps. */
42: private static final float ONE_HALF = .5f;
43:
44: /** A (quick) map from attribute names to attributes. */
45: final private Object2ObjectOpenHashMap<CharSequence, Attribute> name2Attribute = new Object2ObjectOpenHashMap<CharSequence, Attribute>(
46: Hash.DEFAULT_INITIAL_SIZE, ONE_HALF);
47:
48: /** A (quick) map from element-type names to element types. */
49: final private Object2ObjectOpenHashMap<CharSequence, Element> name2Element = new Object2ObjectOpenHashMap<CharSequence, Element>(
50: Hash.DEFAULT_INITIAL_SIZE, ONE_HALF);
51:
52: public WellFormedXmlFactory() {
53: }
54:
55: public Element getElement(final MutableString name) {
56: Element element = name2Element.get(name);
57: if (element == null) {
58: element = new Element(name);
59: name2Element.put(element.name, element);
60: }
61: return element;
62: }
63:
64: public Attribute getAttribute(final MutableString name) {
65: Attribute attribute = name2Attribute.get(name);
66: if (attribute == null) {
67: attribute = new Attribute(name);
68: name2Attribute.put(attribute.name, attribute);
69: }
70: return attribute;
71: }
72:
73: public Entity getEntity(final MutableString name) {
74: return HTMLFactory.INSTANCE.getEntity(name);
75: }
76: }
|