001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: ProjectTeamXMLReader.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package embedding.model;
021:
022: //Java
023: import java.util.Iterator;
024: import java.io.IOException;
025:
026: //SAX
027: import org.xml.sax.InputSource;
028: import org.xml.sax.SAXException;
029:
030: import embedding.tools.AbstractObjectReader;
031:
032: /**
033: * XMLReader implementation for the ProjectTeam class. This class is used to
034: * generate SAX events from the ProjectTeam class.
035: */
036: public class ProjectTeamXMLReader extends AbstractObjectReader {
037:
038: /**
039: * @see org.xml.sax.XMLReader#parse(InputSource)
040: */
041: public void parse(InputSource input) throws IOException,
042: SAXException {
043: if (input instanceof ProjectTeamInputSource) {
044: parse(((ProjectTeamInputSource) input).getProjectTeam());
045: } else {
046: throw new SAXException(
047: "Unsupported InputSource specified. "
048: + "Must be a ProjectTeamInputSource");
049: }
050: }
051:
052: /**
053: * Starts parsing the ProjectTeam object.
054: * @param projectTeam The object to parse
055: * @throws SAXException In case of a problem during SAX event generation
056: */
057: public void parse(ProjectTeam projectTeam) throws SAXException {
058: if (projectTeam == null) {
059: throw new NullPointerException(
060: "Parameter projectTeam must not be null");
061: }
062: if (handler == null) {
063: throw new IllegalStateException("ContentHandler not set");
064: }
065:
066: //Start the document
067: handler.startDocument();
068:
069: //Generate SAX events for the ProjectTeam
070: generateFor(projectTeam);
071:
072: //End the document
073: handler.endDocument();
074: }
075:
076: /**
077: * Generates SAX events for a ProjectTeam object.
078: * @param projectTeam ProjectTeam object to use
079: * @throws SAXException In case of a problem during SAX event generation
080: */
081: protected void generateFor(ProjectTeam projectTeam)
082: throws SAXException {
083: if (projectTeam == null) {
084: throw new NullPointerException(
085: "Parameter projectTeam must not be null");
086: }
087: if (handler == null) {
088: throw new IllegalStateException("ContentHandler not set");
089: }
090:
091: handler.startElement("projectteam");
092: handler.element("projectname", projectTeam.getProjectName());
093: Iterator i = projectTeam.getMembers().iterator();
094: while (i.hasNext()) {
095: ProjectMember member = (ProjectMember) i.next();
096: generateFor(member);
097: }
098: handler.endElement("projectteam");
099: }
100:
101: /**
102: * Generates SAX events for a ProjectMember object.
103: * @param projectMember ProjectMember object to use
104: * @throws SAXException In case of a problem during SAX event generation
105: */
106: protected void generateFor(ProjectMember projectMember)
107: throws SAXException {
108: if (projectMember == null) {
109: throw new NullPointerException(
110: "Parameter projectMember must not be null");
111: }
112: if (handler == null) {
113: throw new IllegalStateException("ContentHandler not set");
114: }
115:
116: handler.startElement("member");
117: handler.element("name", projectMember.getName());
118: handler.element("function", projectMember.getFunction());
119: handler.element("email", projectMember.getEmail());
120: handler.endElement("member");
121: }
122:
123: }
|