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.

EventProducerModel.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 org.apache.fop.events.model;
  19. import java.io.Serializable;
  20. import java.util.Iterator;
  21. import java.util.Map;
  22. import org.xml.sax.ContentHandler;
  23. import org.xml.sax.SAXException;
  24. import org.xml.sax.helpers.AttributesImpl;
  25. import org.apache.xmlgraphics.util.XMLizable;
  26. /**
  27. * Represents the model of an event producer with multiple event methods.
  28. */
  29. public class EventProducerModel implements Serializable, XMLizable {
  30. private static final long serialVersionUID = 122267104123721902L;
  31. private String interfaceName;
  32. private Map methods = new java.util.LinkedHashMap();
  33. /**
  34. * Creates a new instance.
  35. * @param interfaceName the fully qualified interface name of the event producer
  36. */
  37. public EventProducerModel(String interfaceName) {
  38. this.interfaceName = interfaceName;
  39. }
  40. /**
  41. * Returns the fully qualified interface name of the event producer.
  42. * @return the fully qualified interface name
  43. */
  44. public String getInterfaceName() {
  45. return this.interfaceName;
  46. }
  47. /**
  48. * Sets the fully qualified interface name of the event producer.
  49. * @param name the fully qualified interface name
  50. */
  51. public void setInterfaceName(String name) {
  52. this.interfaceName = name;
  53. }
  54. /**
  55. * Adds a model instance of an event method.
  56. * @param method the event method model
  57. */
  58. public void addMethod(EventMethodModel method) {
  59. this.methods.put(method.getMethodName(), method);
  60. }
  61. /**
  62. * Returns the model instance of an event method for the given method name.
  63. * @param methodName the method name
  64. * @return the model instance (or null if no method with the given name exists)
  65. */
  66. public EventMethodModel getMethod(String methodName) {
  67. return (EventMethodModel)this.methods.get(methodName);
  68. }
  69. /**
  70. * Returns an iterator over the contained event producer methods.
  71. * @return an iterator (Iterator<EventMethodModel>)
  72. */
  73. public Iterator getMethods() {
  74. return this.methods.values().iterator();
  75. }
  76. /** {@inheritDoc} */
  77. public void toSAX(ContentHandler handler) throws SAXException {
  78. AttributesImpl atts = new AttributesImpl();
  79. atts.addAttribute(null, "name", "name", "CDATA", getInterfaceName());
  80. String elName = "producer";
  81. handler.startElement(null, elName, elName, atts);
  82. Iterator iter = getMethods();
  83. while (iter.hasNext()) {
  84. ((XMLizable)iter.next()).toSAX(handler);
  85. }
  86. handler.endElement(null, elName, elName);
  87. }
  88. }