View Javadoc

1   package org.apache.maven.continuum.management.redback;
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.maven.continuum.management.DataManagementException;
23  import org.apache.maven.continuum.management.DataManagementTool;
24  import org.codehaus.plexus.redback.keys.KeyManager;
25  import org.codehaus.plexus.redback.rbac.RBACManager;
26  import org.codehaus.plexus.redback.rbac.RbacManagerException;
27  import org.codehaus.plexus.redback.users.UserManager;
28  
29  import javax.xml.stream.XMLStreamException;
30  import java.io.File;
31  import java.io.IOException;
32  
33  /**
34   * JDO implementation the database management tool API.
35   * @version $Id: JdoDataManagementTool.java 785095 2009-06-16 07:20:12Z ctan $
36   * @plexus.component role="org.apache.maven.continuum.management.DataManagementTool" role-hint="redback-jdo"
37   */
38  public class JdoDataManagementTool
39      implements DataManagementTool
40  {
41      /**
42       * @plexus.requirement role-hint="jdo"
43       */
44      private org.codehaus.plexus.redback.management.DataManagementTool toolDelegate;
45  
46      /**
47       * @plexus.requirement role-hint="jdo"
48       */
49      private RBACManager rbacManager;
50  
51      /**
52       * @plexus.requirement role-hint="jdo"
53       */
54      private UserManager userManager;
55  
56      /**
57       * @plexus.requirement role-hint="jdo"
58       */
59      private KeyManager keyManager;
60  
61      public void backupDatabase( File backupDirectory )
62          throws IOException
63      {
64          try
65          {
66              toolDelegate.backupKeyDatabase( keyManager, backupDirectory );
67              toolDelegate.backupRBACDatabase( rbacManager, backupDirectory );
68              toolDelegate.backupUserDatabase( userManager, backupDirectory );
69          }
70          catch ( XMLStreamException e )
71          {
72              throw new DataManagementException( e );
73          }
74          catch ( RbacManagerException e )
75          {
76              throw new DataManagementException( e );
77          }
78      }
79  
80      public void eraseDatabase()
81      {
82          toolDelegate.eraseKeysDatabase( keyManager );
83          toolDelegate.eraseRBACDatabase( rbacManager );
84          toolDelegate.eraseUsersDatabase( userManager );
85      }
86  
87      public void restoreDatabase( File backupDirectory, boolean strict )
88          throws IOException
89      {
90          try
91          {
92              toolDelegate.restoreKeysDatabase( keyManager, backupDirectory );
93              toolDelegate.restoreRBACDatabase( rbacManager, backupDirectory );
94              toolDelegate.restoreUsersDatabase( userManager, backupDirectory );
95          }
96          catch ( XMLStreamException e )
97          {
98              throw new DataManagementException( e );
99          }
100         catch ( RbacManagerException e )
101         {
102             throw new DataManagementException( e );
103         }
104     }
105 }