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.

FacetedMetadata.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package org.apache.archiva.metadata.model;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.util.Collection;
  21. import java.util.Collections;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. /**
  25. * Base class for metadata that is contains facets for storing extensions by various plugins.
  26. */
  27. public abstract class FacetedMetadata
  28. {
  29. /**
  30. * The facets to store, keyed by the {@linkplain MetadataFacet#getFacetId() Facet ID} of the metadata.
  31. */
  32. private Map<String, MetadataFacet> facets = new HashMap<>();
  33. /**
  34. * Add a new facet to the metadata. If it already exists, it will be replaced.
  35. *
  36. * @param metadataFacet the facet to add
  37. */
  38. public void addFacet( MetadataFacet metadataFacet )
  39. {
  40. this.facets.put( metadataFacet.getFacetId(), metadataFacet );
  41. }
  42. /**
  43. * Get a particular facet of metadata.
  44. *
  45. * @param facetId the facet ID
  46. * @return the facet of the metadata.
  47. */
  48. public MetadataFacet getFacet( String facetId )
  49. {
  50. return this.facets.get( facetId );
  51. }
  52. public MetadataFacet removeFacet( String facetId )
  53. {
  54. return this.facets.remove( facetId );
  55. }
  56. /**
  57. * Get all the facets available on this metadata.
  58. *
  59. * @return the facets of the metadata
  60. */
  61. public Collection<MetadataFacet> getFacetList()
  62. {
  63. return this.facets.values();
  64. }
  65. /**
  66. * Get all the keys of the facets available on this metadata.
  67. *
  68. * @return the collection of facet IDs.
  69. */
  70. public Collection<String> getFacetIds()
  71. {
  72. return this.facets.keySet();
  73. }
  74. /**
  75. * Get all available facets as a Map (typically used by bean rendering, such as in Archiva's JSPs).
  76. *
  77. * @return the map of facets
  78. * @see #facets
  79. */
  80. public Map<String, MetadataFacet> getFacets()
  81. {
  82. return Collections.unmodifiableMap( facets );
  83. }
  84. }