You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectTeamXMLReader.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package embedding.model;
  18. //Java
  19. import java.util.Iterator;
  20. import java.io.IOException;
  21. //SAX
  22. import org.xml.sax.InputSource;
  23. import org.xml.sax.SAXException;
  24. import embedding.tools.AbstractObjectReader;
  25. /**
  26. * XMLReader implementation for the ProjectTeam class. This class is used to
  27. * generate SAX events from the ProjectTeam class.
  28. */
  29. public class ProjectTeamXMLReader extends AbstractObjectReader {
  30. /**
  31. * @see org.xml.sax.XMLReader#parse(InputSource)
  32. */
  33. public void parse(InputSource input) throws IOException, SAXException {
  34. if (input instanceof ProjectTeamInputSource) {
  35. parse(((ProjectTeamInputSource)input).getProjectTeam());
  36. } else {
  37. throw new SAXException("Unsupported InputSource specified. "
  38. + "Must be a ProjectTeamInputSource");
  39. }
  40. }
  41. /**
  42. * Starts parsing the ProjectTeam object.
  43. * @param projectTeam The object to parse
  44. * @throws SAXException In case of a problem during SAX event generation
  45. */
  46. public void parse(ProjectTeam projectTeam) throws SAXException {
  47. if (projectTeam == null) {
  48. throw new NullPointerException("Parameter projectTeam must not be null");
  49. }
  50. if (handler == null) {
  51. throw new IllegalStateException("ContentHandler not set");
  52. }
  53. //Start the document
  54. handler.startDocument();
  55. //Generate SAX events for the ProjectTeam
  56. generateFor(projectTeam);
  57. //End the document
  58. handler.endDocument();
  59. }
  60. /**
  61. * Generates SAX events for a ProjectTeam object.
  62. * @param projectTeam ProjectTeam object to use
  63. * @throws SAXException In case of a problem during SAX event generation
  64. */
  65. protected void generateFor(ProjectTeam projectTeam) throws SAXException {
  66. if (projectTeam == null) {
  67. throw new NullPointerException("Parameter projectTeam must not be null");
  68. }
  69. if (handler == null) {
  70. throw new IllegalStateException("ContentHandler not set");
  71. }
  72. handler.startElement("projectteam");
  73. handler.element("projectname", projectTeam.getProjectName());
  74. Iterator i = projectTeam.getMembers().iterator();
  75. while (i.hasNext()) {
  76. ProjectMember member = (ProjectMember)i.next();
  77. generateFor(member);
  78. }
  79. handler.endElement("projectteam");
  80. }
  81. /**
  82. * Generates SAX events for a ProjectMember object.
  83. * @param projectMember ProjectMember object to use
  84. * @throws SAXException In case of a problem during SAX event generation
  85. */
  86. protected void generateFor(ProjectMember projectMember) throws SAXException {
  87. if (projectMember == null) {
  88. throw new NullPointerException("Parameter projectMember must not be null");
  89. }
  90. if (handler == null) {
  91. throw new IllegalStateException("ContentHandler not set");
  92. }
  93. handler.startElement("member");
  94. handler.element("name", projectMember.getName());
  95. handler.element("function", projectMember.getFunction());
  96. handler.element("email", projectMember.getEmail());
  97. handler.endElement("member");
  98. }
  99. }