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