This project has retired. For details please refer to its Attic page.
ProjectMetadata 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.Properties;
23  
24  /**
25   * Metadata on project level.
26   * Namely the namespace and the project id. But different repository types may
27   * add additional metadata information.
28   *
29   */
30  public class ProjectMetadata
31  {
32      private Properties customProperties;
33  
34      private String namespace;
35  
36      private String id;
37  
38      /**
39       * Sets the project id.
40       * @param id
41       */
42      public void setId( String id )
43      {
44          this.id = id;        
45      }
46  
47      /**
48       * Returns the project id.
49       * @return
50       */
51      public String getId()
52      {
53          return id;
54      }
55  
56      /**
57       * Returns the namespace where the project resides.
58       * @return The namespace.
59       */
60      public String getNamespace()
61      {
62          return namespace;
63      }
64  
65      /**
66       * Sets the namespace. Namespaces are strings that may contain '.' characters to separate
67       * the hierarchy levels.
68       * @return
69       */
70      public void setNamespace( String namespace )
71      {
72          this.namespace = namespace;
73      }
74  
75      /**
76       * Adds a custom property. Repository storage implementations may add custom properties
77       * on the project level.
78       * @param key
79       * @param value
80       */
81      public void addProperty(String key, String value) {
82          Properties props = getProperties();
83          props.setProperty( key, value );
84      }
85  
86      /**
87       * Replaces all custom properties with the given properties object.
88       * The given object is stored by reference and not copied.
89       * @param properties
90       */
91      public void setProperties(Properties properties) {
92          this.customProperties = properties;
93      }
94  
95  
96      /**
97       * Returns the object with all custom properties.
98       * If there are no custom properties set, a empty object will be returned.
99       *
100      * @return The custom properties.
101      */
102     public Properties getProperties() {
103         if (customProperties==null)
104         {
105             Properties props = new Properties( );
106             this.customProperties = props;
107             return props;
108         } else {
109             return this.customProperties;
110         }
111     }
112 
113     /**
114      * Returns true, if there are custom properties set.
115      * @return True, if there exist custom properties.
116      */
117     public boolean hasProperties() {
118         return this.customProperties != null && this.customProperties.size()>0;
119     }
120 
121     @Override
122     public String toString()
123     {
124         final StringBuilder sb = new StringBuilder( "ProjectMetadata{" );
125         sb.append( "namespace='" ).append( namespace ).append( '\'' );
126         sb.append( ", id='" ).append( id ).append( '\'' );
127         if (customProperties!=null) {
128             sb.append(", custom: '").append(customProperties.toString()).append('\'');
129         }
130         sb.append( '}' );
131         return sb.toString();
132     }
133 
134 
135 }