KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > dtd > schema > Schema


1 /*******************************************************************************
2  * Copyright (c) 2002, 2005 Object Factory Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Object Factory Inc. - Initial implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.dtd.schema;
12
13 import java.util.HashMap JavaDoc;
14
15 import org.eclipse.ant.internal.ui.dtd.IElement;
16 import org.eclipse.ant.internal.ui.dtd.ISchema;
17
18 /**
19  * This is a very simple schema suitable for DTDs.
20  * Once constructed, a schema is immutable and could be
21  * used by multiple threads. However, since in general
22  * the schema will reflect the internal DTD subset,
23  * re-use for multiple documents is problematic.
24  * @author Bob Foster
25  */

26 public class Schema implements ISchema {
27     private HashMap JavaDoc fElementMap = new HashMap JavaDoc();
28     private Exception JavaDoc fErrorException;
29     /**
30      * @see org.eclipse.ant.internal.ui.dtd.ISchema#getElement(java.lang.String)
31      */

32     public IElement getElement(String JavaDoc qname) {
33         return (IElement) fElementMap.get(qname);
34     }
35
36     /**
37      * @see org.eclipse.ant.internal.ui.dtd.ISchema#getElements()
38      */

39     public IElement[] getElements() {
40         return (IElement[]) fElementMap.entrySet().toArray(new IElement[fElementMap.entrySet().size()]);
41     }
42     
43     /**
44      * Add a visible element to the schema.
45      * @param element Element to add.
46      */

47     public void addElement(IElement element) {
48         fElementMap.put(element.getName(), element);
49     }
50     
51     /**
52      * Sets the exception thrown by then parser when the schema was built.
53      * Note that the exception does not necessarily mean the schema is incomplete.
54      *
55      * @param e the Exception
56      */

57     public void setErrorException(Exception JavaDoc e) {
58         fErrorException = e;
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.ant.internal.ui.dtd.ISchema#getErrorException()
63      */

64     public Exception JavaDoc getErrorException() {
65         return fErrorException;
66     }
67 }
68
Popular Tags