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.

ResourceGroup.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.util.Set;
  22. import org.apache.fop.afp.Streamable;
  23. /**
  24. * A Resource Group contains a set of overlays.
  25. */
  26. public class ResourceGroup extends AbstractNamedAFPObject {
  27. /** Set of resource uri */
  28. private final Set<AbstractNamedAFPObject> resourceSet = new java.util.HashSet<AbstractNamedAFPObject>();
  29. /**
  30. * Constructor for the ResourceGroup, this takes a
  31. * name parameter which must be 8 characters long.
  32. *
  33. * @param name the resource group name
  34. */
  35. public ResourceGroup(String name) {
  36. super(name);
  37. }
  38. /**
  39. * Add this named object to this resource group
  40. *
  41. * @param namedObject a named object
  42. * @throws IOException thrown if an I/O exception of some sort has occurred.
  43. */
  44. public void addObject(AbstractNamedAFPObject namedObject) throws IOException {
  45. resourceSet.add(namedObject);
  46. }
  47. /**
  48. * Returns the number of resources contained in this resource group
  49. *
  50. * @return the number of resources contained in this resource group
  51. */
  52. public int getResourceCount() {
  53. return resourceSet.size();
  54. }
  55. /** {@inheritDoc} */
  56. public void writeStart(OutputStream os) throws IOException {
  57. byte[] data = new byte[17];
  58. copySF(data, Type.BEGIN, Category.RESOURCE_GROUP);
  59. os.write(data);
  60. }
  61. /** {@inheritDoc} */
  62. public void writeContent(OutputStream os) throws IOException {
  63. for (Object object : resourceSet) {
  64. if (object instanceof Streamable) {
  65. Streamable streamableObject = (Streamable) object;
  66. streamableObject.writeToStream(os);
  67. }
  68. }
  69. }
  70. /** {@inheritDoc} */
  71. public void writeEnd(OutputStream os) throws IOException {
  72. byte[] data = new byte[17];
  73. copySF(data, Type.END, Category.RESOURCE_GROUP);
  74. os.write(data);
  75. }
  76. /** {@inheritDoc} */
  77. public String toString() {
  78. return this.name + " " + resourceSet/*getResourceMap()*/;
  79. }
  80. }