KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > embedding > model > ProjectTeamXMLReader


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: ProjectTeamXMLReader.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package embedding.model;
21
22 //Java
23
import java.util.Iterator JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 //SAX
27
import org.xml.sax.InputSource JavaDoc;
28 import org.xml.sax.SAXException JavaDoc;
29
30 import embedding.tools.AbstractObjectReader;
31
32 /**
33  * XMLReader implementation for the ProjectTeam class. This class is used to
34  * generate SAX events from the ProjectTeam class.
35  */

36 public class ProjectTeamXMLReader extends AbstractObjectReader {
37
38     /**
39      * @see org.xml.sax.XMLReader#parse(InputSource)
40      */

41     public void parse(InputSource JavaDoc input) throws IOException JavaDoc, SAXException JavaDoc {
42         if (input instanceof ProjectTeamInputSource) {
43             parse(((ProjectTeamInputSource)input).getProjectTeam());
44         } else {
45             throw new SAXException JavaDoc("Unsupported InputSource specified. "
46                     + "Must be a ProjectTeamInputSource");
47         }
48     }
49
50
51     /**
52      * Starts parsing the ProjectTeam object.
53      * @param projectTeam The object to parse
54      * @throws SAXException In case of a problem during SAX event generation
55      */

56     public void parse(ProjectTeam projectTeam) throws SAXException JavaDoc {
57         if (projectTeam == null) {
58             throw new NullPointerException JavaDoc("Parameter projectTeam must not be null");
59         }
60         if (handler == null) {
61             throw new IllegalStateException JavaDoc("ContentHandler not set");
62         }
63         
64         //Start the document
65
handler.startDocument();
66         
67         //Generate SAX events for the ProjectTeam
68
generateFor(projectTeam);
69         
70         //End the document
71
handler.endDocument();
72     }
73
74     
75     /**
76      * Generates SAX events for a ProjectTeam object.
77      * @param projectTeam ProjectTeam object to use
78      * @throws SAXException In case of a problem during SAX event generation
79      */

80     protected void generateFor(ProjectTeam projectTeam) throws SAXException JavaDoc {
81         if (projectTeam == null) {
82             throw new NullPointerException JavaDoc("Parameter projectTeam must not be null");
83         }
84         if (handler == null) {
85             throw new IllegalStateException JavaDoc("ContentHandler not set");
86         }
87         
88         handler.startElement("projectteam");
89         handler.element("projectname", projectTeam.getProjectName());
90         Iterator JavaDoc i = projectTeam.getMembers().iterator();
91         while (i.hasNext()) {
92             ProjectMember member = (ProjectMember)i.next();
93             generateFor(member);
94         }
95         handler.endElement("projectteam");
96     }
97
98     /**
99      * Generates SAX events for a ProjectMember object.
100      * @param projectMember ProjectMember object to use
101      * @throws SAXException In case of a problem during SAX event generation
102      */

103     protected void generateFor(ProjectMember projectMember) throws SAXException JavaDoc {
104         if (projectMember == null) {
105             throw new NullPointerException JavaDoc("Parameter projectMember must not be null");
106         }
107         if (handler == null) {
108             throw new IllegalStateException JavaDoc("ContentHandler not set");
109         }
110         
111         handler.startElement("member");
112         handler.element("name", projectMember.getName());
113         handler.element("function", projectMember.getFunction());
114         handler.element("email", projectMember.getEmail());
115         handler.endElement("member");
116     }
117
118 }
119
Popular Tags