KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > jmi > xmi > Consumer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.lib.jmi.xmi;
20
21 import org.netbeans.api.xmi.*;
22 import org.netbeans.api.xmi.sax.*;
23 import org.xml.sax.*;
24
25 import javax.jmi.reflect.*;
26
27
28 public class Consumer extends XMIConsumer {
29
30     private RefPackage extent = null;
31     private XMIInputConfig config;
32     private XmiSAXReader reader;
33
34     // init .....................................................................
35

36     public Consumer () {
37         this (null);
38     }
39
40     public Consumer (XMIInputConfig cfg) {
41         this.config = new InputConfig ();
42         if (cfg != null)
43             this.config.setReferenceResolver (cfg.getReferenceResolver ());
44     }
45     
46     // methods ..................................................................
47

48     public void setExtent(RefPackage extent) {
49         this.extent = extent;
50     }
51     
52     public RefPackage getExtent() {
53         return extent;
54     }
55         
56     public XMIInputConfig getConfiguration() {
57         return config;
58     }
59
60     // ContentHadler implementation .............................................
61

62     public void startDocument() throws SAXException {
63         if (reader != null)
64             throw new SAXException ("Consuming is in process, cannot start a new document.");
65         if (extent == null)
66             throw new SAXException ("No target extent is set.");
67         reader = new XmiSAXReader (config);
68         reader.initConsumer (extent);
69     }
70     
71     public void endDocument() throws SAXException {
72         check ();
73         reader.endDocument ();
74         reader = null;
75     }
76     
77     public void characters(char[] ch, int start, int length) throws SAXException {
78         check ();
79         reader.characters (ch, start, length);
80     }
81
82     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes atts) throws SAXException {
83         check ();
84         reader.startElement (namespaceURI, localName, qName, atts);
85     }
86     
87     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) throws SAXException {
88         check ();
89         reader.endElement (namespaceURI, localName, qName);
90     }
91     
92     public void endPrefixMapping(String JavaDoc prefix) throws SAXException {
93     }
94           
95     public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
96     }
97  
98     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException {
99     }
100     
101     public void setDocumentLocator(Locator locator) {
102     }
103     
104     public void skippedEntity(String JavaDoc name) throws SAXException {
105     }
106     
107     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) throws SAXException {
108     }
109
110     // helper methods ...........................................................
111

112     private void check () throws SAXException {
113         if (reader == null)
114             throw new SAXException ("Consumer not started.");
115     }
116     
117 }
118
Popular Tags