1 package org.apache.archiva.repository.content.base;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.repository.content.Namespace;
23 import org.apache.archiva.repository.content.Project;
24 import org.apache.archiva.repository.content.base.builder.ProjectOptBuilder;
25 import org.apache.archiva.repository.content.base.builder.ProjectWithIdBuilder;
26 import org.apache.archiva.repository.content.base.builder.WithNamespaceObjectBuilder;
27 import org.apache.archiva.repository.storage.StorageAsset;
28 import org.apache.commons.lang3.StringUtils;
31 * Immutable class, that represents a project.
33 * The namespace and id are required attributes for each instance.
35 * Two project instances are equal if the id, and the namespace are equal and if the base attributes
36 * repository and asset match.
38 * @author Martin Stockhammer <martin_s@apache.org>
41 public class ArchivaProject extends ArchivaContentItem implements Project
43 private Namespace namespace;
46 // Setting all setters to private. Builder is the way to go.
47 private ArchivaProject( )
54 * Creates the builder for creating new archiva project instances.
55 * You have to set all required attributes before you can call the build() method.
57 * @param storageAsset the asset
58 * @return a builder instance
60 public static WithNamespaceObjectBuilder withAsset( StorageAsset storageAsset )
62 return new Builder( ).withAsset( storageAsset );
66 public Namespace getNamespace( )
68 return this.namespace;
72 public String getId( )
79 public boolean equals( Object o )
81 if ( this == o ) return true;
82 if ( o == null || getClass( ) != o.getClass( ) ) return false;
83 if ( !super.equals( o ) ) return false;
85 ArchivaProject that = (ArchivaProject) o;
87 if ( !namespace.equals( that.namespace ) ) return false;
88 return id.equals( that.id );
92 public int hashCode( )
94 int result = super.hashCode( );
95 result = 31 * result + namespace.hashCode( );
96 result = 31 * result + id.hashCode( );
104 public static final class Builder
105 extends ContentItemBuilder<ArchivaProject, ProjectOptBuilder, WithNamespaceObjectBuilder>
106 implements ProjectOptBuilder, ProjectWithIdBuilder, WithNamespaceObjectBuilder
110 super( new ArchivaProject( ) );
115 protected ProjectOptBuilder getOptBuilder( )
121 protected WithNamespaceObjectBuilder getNextBuilder( )
127 public ProjectOptBuilder withId( String id )
129 if ( StringUtils.isEmpty( id ) )
131 throw new IllegalArgumentException( "Null or empty value not allowed for id" );
138 public ProjectWithIdBuilder withNamespace( Namespace namespace )
140 if ( namespace == null )
142 throw new IllegalArgumentException( "Null value not allowed for namespace" );
144 item.namespace = namespace;
145 super.setRepository( namespace.getRepository( ) );
150 public ArchivaProject build( )
153 if ( item.namespace == null )
155 throw new IllegalArgumentException( "Namespace may not be null" );