001package org.apache.archiva.metadata.model; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Properties; 023 024/** 025 * Metadata on project level. 026 * Namely the namespace and the project id. But different repository types may 027 * add additional metadata information. 028 * 029 */ 030public class ProjectMetadata 031{ 032 private Properties customProperties; 033 034 private String namespace; 035 036 private String id; 037 038 /** 039 * Sets the project id. 040 * @param id 041 */ 042 public void setId( String id ) 043 { 044 this.id = id; 045 } 046 047 /** 048 * Returns the project id. 049 * @return 050 */ 051 public String getId() 052 { 053 return id; 054 } 055 056 /** 057 * Returns the namespace where the project resides. 058 * @return The namespace. 059 */ 060 public String getNamespace() 061 { 062 return namespace; 063 } 064 065 /** 066 * Sets the namespace. Namespaces are strings that may contain '.' characters to separate 067 * the hierarchy levels. 068 * @return 069 */ 070 public void setNamespace( String namespace ) 071 { 072 this.namespace = namespace; 073 } 074 075 /** 076 * Adds a custom property. Repository storage implementations may add custom properties 077 * on the project level. 078 * @param key 079 * @param value 080 */ 081 public void addProperty(String key, String value) { 082 Properties props = getProperties(); 083 props.setProperty( key, value ); 084 } 085 086 /** 087 * Replaces all custom properties with the given properties object. 088 * The given object is stored by reference and not copied. 089 * @param properties 090 */ 091 public void setProperties(Properties properties) { 092 this.customProperties = properties; 093 } 094 095 096 /** 097 * Returns the object with all custom properties. 098 * If there are no custom properties set, a empty object will be returned. 099 * 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}