1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  
17  package org.apache.commons.betwixt.schema;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  /***
24   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
25   * @version $Id: PhysicalSchema.java,v 1.7 2004/02/28 13:38:36 yoavs Exp $
26   */
27  public class PhysicalSchema
28  {
29      
30      private ArrayList dbmsCollection;
31      
32      
33      private boolean autoCreate = false;
34      
35      public PhysicalSchema()
36      {
37          dbmsCollection = new ArrayList();
38      }
39      public PhysicalSchema(String autoCreate)
40      {
41          this.autoCreate = autoCreate.equalsIgnoreCase("yes");
42      }
43      public void setAutocreate(String autoCreate)
44      {
45          this.autoCreate = (autoCreate.equalsIgnoreCase("yes"));
46      }
47      
48      public String getAutocreate() 
49      {
50          return this.autoCreate?"yes":"no";
51      }
52      
53      public void addDbms(Dbms dbms)
54      {
55          dbmsCollection.add(dbms);
56      }
57      
58      public List getDbmss()
59      {
60          return dbmsCollection;
61      }
62      
63      public boolean equals(Object object) 
64      {
65          if (object == null) { 
66              return false;
67          }
68          if (object instanceof PhysicalSchema) {
69              PhysicalSchema schema = (PhysicalSchema) object;
70              if (schema.getAutocreate().equals(this.getAutocreate())) {
71                  int count = 0;
72                  Iterator it = schema.getDbmss().iterator();
73                  while ( it.hasNext() ) {
74                      if (count >= dbmsCollection.size() ) {
75                          return false;
76                      }
77                      if (! it.next().equals( dbmsCollection.get(count++) ) ) {
78                          return false;
79                      }
80                  }
81                  
82                  return true;
83              }
84          }
85          return false;
86      }
87      
88      public String toString() {
89          return "[PhysicalSchema] autocreate=" + getAutocreate() + " dbmass=" + getDbmss();
90      }	
91  }
92