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.ManagedRepositoryContent;
23 import org.apache.archiva.repository.content.Namespace;
24 import org.apache.archiva.repository.content.Project;
25 import org.apache.archiva.repository.content.base.builder.ProjectOptBuilder;
26 import org.apache.archiva.repository.content.base.builder.ProjectWithIdBuilder;
27 import org.apache.archiva.repository.content.base.builder.WithAssetBuilder;
28 import org.apache.archiva.repository.content.base.builder.WithNamespaceBuilder;
29 import org.apache.archiva.repository.content.base.builder.WithNamespaceObjectBuilder;
30 import org.apache.archiva.repository.content.base.builder.WithProjectBuilder;
31 import org.apache.archiva.repository.storage.StorageAsset;
32 import org.apache.commons.lang3.StringUtils;
35 * Immutable class, that represents a project.
37 * The namespace and id are required attributes for each instance.
39 * Two project instances are equal if the id, and the namespace are equal and if the base attributes
40 * repository and asset match.
42 * @author Martin Stockhammer <martin_s@apache.org>
45 public class ArchivaProject extends BaseContentItem implements Project
47 private Namespace namespace;
50 // Setting all setters to private. Builder is the way to go.
51 private ArchivaProject( )
58 * Creates the builder for creating new archiva project instances.
59 * You have to set all required attributes before you can call the build() method.
61 * @param storageAsset the asset
62 * @return a builder instance
64 public static WithNamespaceObjectBuilder withAsset( StorageAsset storageAsset )
66 return new Builder( ).withAsset( storageAsset );
69 public static WithAssetBuilder<WithNamespaceObjectBuilder> withRepository( ManagedRepositoryContent repository )
71 return new ArchivaProject.Builder( ).withRepository( repository );
75 public Namespace getNamespace( )
77 return this.namespace;
81 public String getId( )
88 public boolean equals( Object o )
90 if ( this == o ) return true;
91 if ( o == null || getClass( ) != o.getClass( ) ) return false;
93 ArchivaProject that = (ArchivaProject) o;
95 if (!repository.equals( that.repository )) return false;
96 if ( !namespace.equals( that.namespace ) ) return false;
97 return id.equals( that.id );
101 public int hashCode( )
103 int result = super.hashCode( );
104 result = 31 * result + namespace.hashCode( );
105 result = 31 * result + id.hashCode( );
110 public String toString( )
112 return "ArchivaProject{ "+id + ", namespace="+namespace.toString()+"}";
118 public static final class Builder
119 extends ContentItemBuilder<ArchivaProject, ProjectOptBuilder, WithNamespaceObjectBuilder>
120 implements ProjectOptBuilder, ProjectWithIdBuilder, WithNamespaceObjectBuilder
124 super( new ArchivaProject( ) );
129 protected ProjectOptBuilder getOptBuilder( )
135 protected WithNamespaceObjectBuilder getNextBuilder( )
141 public ProjectOptBuilder withId( String id )
143 if ( StringUtils.isEmpty( id ) )
145 throw new IllegalArgumentException( "Null or empty value not allowed for id" );
152 public ProjectWithIdBuilder withNamespace( Namespace namespace )
154 if ( namespace == null )
156 throw new IllegalArgumentException( "Null value not allowed for namespace" );
158 item.namespace = namespace;
159 super.setRepository( namespace.getRepository( ) );
164 public ArchivaProject build( )
167 if ( item.namespace == null )
169 throw new IllegalArgumentException( "Namespace may not be null" );