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