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