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.ManagedRepository;
23 import org.apache.archiva.repository.ManagedRepositoryContent;
24 import org.apache.archiva.repository.RepositoryContent;
25 import org.apache.archiva.repository.content.Project;
26 import org.apache.archiva.repository.storage.StorageAsset;
27 import org.apache.commons.lang3.StringUtils;
30 * Immutable class, that represents a project.
32 public class ArchivaProject extends ArchivaContentItem implements Project
34 private String namespace;
36 private RepositoryContent repositoryContent;
37 private StorageAsset asset;
39 // Setting all setters to private. Builder is the way to go.
40 private ArchivaProject() {
46 * Creates the builder that allows to create a new instance.
47 * @param id the project id, must not be <code>null</code>
48 * @return a builder instance
50 public static Builder withId( String id) {
51 return new Builder( ).withId( id );
56 public String getNamespace( )
58 return this.namespace;
62 public String getId( )
68 public RepositoryContent getRepository( )
70 return this.repositoryContent;
74 public StorageAsset getAsset( )
82 * Builder interface chaining is used to restrict mandatory attributes
83 * This interface is for the optional arguments.
85 public interface OptBuilder {
87 OptBuilder withAsset( StorageAsset asset );
89 OptBuilder withNamespace( String namespace);
91 OptBuilder withAttribute( String key, String value );
95 * Builder classes for instantiation
97 public static final class Builder implements OptBuilder
99 final private ArchivaProject project = new ArchivaProject();
106 private Builder withId(String id) {
107 if ( StringUtils.isEmpty( id ) ) {
108 throw new IllegalArgumentException( "Null or empty value not allowed for id" );
115 public OptBuilder withRepository( RepositoryContent repository ) {
116 project.repositoryContent = repository;
121 public OptBuilder withAsset( StorageAsset asset )
123 project.asset = asset;
127 public OptBuilder withNamespace( String namespace) {
128 if (namespace==null) {
129 throw new IllegalArgumentException( "Null value not allowed for namespace" );
131 project.namespace = namespace;
135 public OptBuilder withAttribute( String key, String value) {
136 project.putAttribute( key, value );
140 ArchivaProject build() {
141 if (project.namespace==null) {
142 project.namespace = "";
144 if (project.asset == null) {
145 if (project.getRepository() instanceof ManagedRepositoryContent) {
146 project.asset = (( ManagedRepositoryContent)project.getRepository( )).getRepository( ).getAsset( "" );