This project has retired. For details please refer to its Attic page.
Namespace xref
View Javadoc
1   package org.apache.archiva.metadata.repository.cassandra.model;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
23  
24  import java.io.Serializable;
25  
26  
27  /**
28   * @author Olivier Lamy
29   * @since 2.0.0
30   */
31  public class Namespace
32      implements Serializable
33  {
34  
35      private String name;
36  
37      private String repositoryName;
38  
39      public Namespace()
40      {
41          // no op
42      }
43  
44  
45      public Namespace( String id, Repository repository )
46      {
47          this.name = id;
48          this.repositoryName = repository.getName();
49      }
50  
51  
52      public String getName()
53      {
54          return name;
55      }
56  
57      public void setName( String name )
58      {
59          this.name = name;
60      }
61  
62      public Repository getRepository()
63      {
64          return new Repository( this.repositoryName );
65      }
66  
67      public void setRepository( Repository repository )
68      {
69          this.repositoryName = repository.getName();
70      }
71  
72      @Override
73      public boolean equals( Object o )
74      {
75          if ( this == o )
76          {
77              return true;
78          }
79          if ( o == null || getClass() != o.getClass() )
80          {
81              return false;
82          }
83  
84          Namespace../../../../../org/apache/archiva/metadata/repository/cassandra/model/Namespace.html#Namespace">Namespace namespace = (Namespace) o;
85  
86          if ( !name.equals( namespace.name ) )
87          {
88              return false;
89          }
90          if ( !repositoryName.equals( namespace.repositoryName ) )
91          {
92              return false;
93          }
94  
95          return true;
96      }
97  
98      @Override
99      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 }