This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.metadata.repository.cassandra.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 org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
023
024import java.io.Serializable;
025
026
027/**
028 * @author Olivier Lamy
029 * @since 2.0.0
030 */
031public class Namespace
032    implements Serializable
033{
034
035    private String name;
036
037    private String repositoryName;
038
039    public Namespace()
040    {
041        // no op
042    }
043
044
045    public Namespace( String id, Repository repository )
046    {
047        this.name = id;
048        this.repositoryName = repository.getName();
049    }
050
051
052    public String getName()
053    {
054        return name;
055    }
056
057    public void setName( String name )
058    {
059        this.name = name;
060    }
061
062    public Repository getRepository()
063    {
064        return new Repository( this.repositoryName );
065    }
066
067    public void setRepository( Repository repository )
068    {
069        this.repositoryName = repository.getName();
070    }
071
072    @Override
073    public boolean equals( Object o )
074    {
075        if ( this == o )
076        {
077            return true;
078        }
079        if ( o == null || getClass() != o.getClass() )
080        {
081            return false;
082        }
083
084        Namespace namespace = (Namespace) o;
085
086        if ( !name.equals( namespace.name ) )
087        {
088            return false;
089        }
090        if ( !repositoryName.equals( namespace.repositoryName ) )
091        {
092            return false;
093        }
094
095        return true;
096    }
097
098    @Override
099    public int hashCode()
100    {
101        int result = name.hashCode();
102        result = 31 * result + repositoryName.hashCode();
103        return result;
104    }
105
106    @Override
107    public String toString()
108    {
109        final StringBuilder sb = new StringBuilder( "Namespace{" );
110        sb.append( ", name='" ).append( name ).append( '\'' );
111        sb.append( ", repository='" ).append( repositoryName ).append( '\'' );
112        sb.append( '}' );
113        return sb.toString();
114    }
115
116    public static class KeyBuilder
117    {
118
119        private String namespace;
120
121        private String repositoryId;
122
123        public KeyBuilder()
124        {
125
126        }
127
128        public KeyBuilder withNamespace( Namespace namespace )
129        {
130            this.namespace = namespace.getName();
131            this.repositoryId = namespace.getRepository().getName();
132            return this;
133        }
134
135        public KeyBuilder withNamespace( String namespace )
136        {
137            this.namespace = namespace;
138            return this;
139        }
140
141        public KeyBuilder withRepositoryId( String repositoryId )
142        {
143            this.repositoryId = repositoryId;
144            return this;
145        }
146
147        public String build()
148        {
149            // FIXME add some controls
150            return CassandraUtils.generateKey( this.repositoryId, this.namespace );
151        }
152    }
153}