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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* $Id$ */
  18. package embedding.model;
  19. //Java
  20. import java.util.Iterator;
  21. import java.io.IOException;
  22. //SAX
  23. import org.xml.sax.InputSource;
  24. import org.xml.sax.SAXException;
  25. import embedding.tools.AbstractObjectReader;
  26. /**
  27. * XMLReader implementation for the ProjectTeam class. This class is used to
  28. * generate SAX events from the ProjectTeam class.
  29. */
  30. public class ProjectTeamXMLReader extends AbstractObjectReader {
  31. /**
  32. * @see org.xml.sax.XMLReader#parse(InputSource)
  33. */
  34. public void parse(InputSource input) throws IOException, SAXException {
  35. if (input instanceof ProjectTeamInputSource) {
  36. parse(((ProjectTeamInputSource)input).getProjectTeam());
  37. } else {
  38. throw new SAXException("Unsupported InputSource specified. "
  39. + "Must be a ProjectTeamInputSource");
  40. }
  41. }
  42. /**
  43. * Starts parsing the ProjectTeam object.
  44. * @param projectTeam The object to parse
  45. * @throws SAXException In case of a problem during SAX event generation
  46. */
  47. public void parse(ProjectTeam projectTeam) throws SAXException {
  48. if (projectTeam == null) {
  49. throw new NullPointerException("Parameter projectTeam must not be null");
  50. }
  51. if (handler == null) {
  52. throw new IllegalStateException("ContentHandler not set");
  53. }
  54. //Start the document
  55. handler.startDocument();
  56. //Generate SAX events for the ProjectTeam
  57. generateFor(projectTeam);
  58. //End the document
  59. handler.endDocument();
  60. }
  61. /**
  62. * Generates SAX events for a ProjectTeam object.
  63. * @param projectTeam ProjectTeam object to use
  64. * @throws SAXException In case of a problem during SAX event generation
  65. */
  66. protected void generateFor(ProjectTeam projectTeam) throws SAXException {
  67. if (projectTeam == null) {
  68. throw new NullPointerException("Parameter projectTeam must not be null");
  69. }
  70. if (handler == null) {
  71. throw new IllegalStateException("ContentHandler not set");
  72. }
  73. handler.startElement("projectteam");
  74. handler.element("projectname", projectTeam.getProjectName());
  75. Iterator i = projectTeam.getMembers().iterator();
  76. while (i.hasNext()) {
  77. ProjectMember member = (ProjectMember)i.next();
  78. generateFor(member);
  79. }
  80. handler.endElement("projectteam");
  81. }
  82. /**
  83. * Generates SAX events for a ProjectMember object.
  84. * @param projectMember ProjectMember object to use
  85. * @throws SAXException In case of a problem during SAX event generation
  86. */
  87. protected void generateFor(ProjectMember projectMember) throws SAXException {
  88. if (projectMember == null) {
  89. throw new NullPointerException("Parameter projectMember must not be null");
  90. }
  91. if (handler == null) {
  92. throw new IllegalStateException("ContentHandler not set");
  93. }
  94. handler.startElement("member");
  95. handler.element("name", projectMember.getName());
  96. handler.element("function", projectMember.getFunction());
  97. handler.element("email", projectMember.getEmail());
  98. handler.endElement("member");
  99. }
  100. }