KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > backup > backupers > AbstractBackuper


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent Inc.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.continuent.sequoia.controller.backup.backupers;
20
21 import java.io.IOException JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24
25 import org.continuent.sequoia.common.exceptions.BackupException;
26 import org.continuent.sequoia.controller.backup.BackupManager;
27 import org.continuent.sequoia.controller.backup.Backuper;
28 import org.continuent.sequoia.controller.backup.DumpTransferInfo;
29
30 /**
31  * This class defines a AbstractBackuper, which can be used as a base class for
32  * most backupers. This class provides a default implementation for options
33  * parsing/setting and an implementation for dump serving/fetching that
34  * understands the dumpServer option.
35  */

36 public abstract class AbstractBackuper implements Backuper
37 {
38   protected HashMap JavaDoc optionsMap = new HashMap JavaDoc();
39   protected String JavaDoc optionsString = null;
40
41   /**
42    * @see Backuper#getOptions()
43    */

44   public String JavaDoc getOptions()
45   {
46     return optionsString;
47   }
48
49   /**
50    * @see Backuper#setOptions(java.lang.String)
51    */

52   public void setOptions(String JavaDoc options)
53   {
54     if (options != null)
55     {
56       StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(options, ",");
57       String JavaDoc option = null;
58       String JavaDoc name = null;
59       String JavaDoc value = null;
60
61       // Parse the string of options, add them to the HashMap
62
while (strTok.hasMoreTokens())
63       {
64         option = strTok.nextToken();
65         name = option.substring(0, option.indexOf("="));
66         value = option.substring(option.indexOf("=") + 1, option.length());
67         optionsMap.put(name, value);
68       }
69
70       optionsString = options;
71     }
72   }
73
74   /**
75    * Returns the value of 'ignoreStdErrOutput' option. This option tells whether
76    * command success should be altered by any output on stderr. Default is
77    * false.
78    *
79    * @return true if ignoreStdErrOutput option is set to true, false otherwise
80    */

81   public boolean getIgnoreStdErrOutput()
82   {
83     try
84     {
85       return Boolean.valueOf((String JavaDoc) optionsMap.get("ignoreStdErrOutput"))
86           .booleanValue();
87     }
88     catch (Exception JavaDoc e)
89     { // Invalid or non-existing value for ignoreStdErrOutput
90
return false;
91     }
92   }
93
94   /**
95    * {@inheritDoc}
96    *
97    * @see org.continuent.sequoia.controller.backup.Backuper#setupDumpServer()
98    */

99   public DumpTransferInfo setupDumpServer() throws IOException JavaDoc
100   {
101     if (optionsMap.containsKey("dumpServer"))
102       return BackupManager.setupDumpFileServer((String JavaDoc) optionsMap
103           .get("dumpServer"));
104
105     return BackupManager.setupDumpFileServer();
106   }
107
108   /**
109    * @see Backuper#fetchDump(org.continuent.sequoia.controller.backup.DumpTransferInfo,
110    * java.lang.String, java.lang.String)
111    */

112   public void fetchDump(DumpTransferInfo dumpTransferInfo, String JavaDoc path,
113       String JavaDoc dumpName) throws BackupException, IOException JavaDoc
114   {
115     BackupManager.fetchDumpFile(dumpTransferInfo, path, dumpName);
116   }
117
118 }
119
Popular Tags