001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: AdminImpl.java,v 1.2 2002/06/08 00:49:39 mediumnet Exp $
008:
009: package org.ozoneDB.core.admin;
010:
011: import java.io.*;
012:
013: import org.xml.sax.*;
014: import org.xml.sax.helpers.*;
015:
016: import org.apache.xml.serialize.*;
017:
018: import org.ozoneDB.*;
019: import org.ozoneDB.util.*;
020: import org.ozoneDB.core.*;
021: import org.ozoneDB.core.xml.*;
022: import org.ozoneDB.xml.util.*;
023: import org.ozoneDB.DxLib.*;
024:
025: /**
026: * <p>This is the server side implementation of the ozone admin system. Some of
027: * the admin functions are directly provided by this class. For other functions
028: * this class serves as a facade for the actual implementation classes.</p>
029: *
030: * @version $Revision: 1.2 $ $Date: 2002/06/08 00:49:39 $
031: * @author <a href="http://www.smb-tec.com">SMB</a>
032: * @see Admin
033: */
034: public class AdminImpl extends OzoneSupportObject implements Admin,
035: Externalizable {
036:
037: protected final static long serialVersionUID = 1;
038:
039: /**
040: * The object ID of the admin object in the database.
041: */
042: public final static long OBJECT_ID = 1;
043:
044: /**
045: * The name of the admin object in the database.
046: */
047: public final static String OBJECT_NAME = "ozonedb.admin";
048:
049: protected transient Env env;
050:
051: protected transient BackupRestore backupRestore;
052:
053: public AdminImpl() {
054: init();
055: }
056:
057: protected void init() {
058: env = Env.currentEnv();
059: backupRestore = new BackupRestore(env);
060: }
061:
062: public void writeExternal(ObjectOutput out) throws IOException {
063: }
064:
065: public void readExternal(ObjectInput in) throws IOException,
066: ClassNotFoundException {
067: init();
068: }
069:
070: public void newUser(String _name, int _id) throws Exception {
071: if (_id < 100) {
072: throw new UserManagerExc(
073: "IDs <100 are reserved by the system.");
074: }
075: env.userManager.newUser(_name, _id);
076: }
077:
078: public void removeUser(String _name) throws Exception {
079: env.userManager.removeUser(_name);
080: }
081:
082: public void newGroup(String _name, int _id) throws Exception {
083: if (_id < 100) {
084: throw new UserManagerExc(
085: "IDs <100 are reserved by the system.");
086: }
087: env.userManager.newGroup(_name, _id);
088: }
089:
090: public void removeGroup(String _name) throws Exception {
091: env.userManager.removeGroup(_name);
092: }
093:
094: public void addUser2Group(String _username, String _groupname)
095: throws Exception {
096: env.userManager.addUserToGroup(_username, _groupname);
097: }
098:
099: public void removeUserFromGroup(String _username, String _groupname)
100: throws Exception {
101: env.userManager.removeUserFromGroup(_username, _groupname);
102: }
103:
104: public DxCollection allUsers() throws Exception {
105: return env.userManager.allUsers();
106: }
107:
108: public DxCollection allGroups() throws Exception {
109: return env.userManager.allGroups();
110: }
111:
112: public User userForName(String _name) throws Exception {
113: return env.userManager.userForName(_name);
114: }
115:
116: public Group groupForName(String _name) throws Exception {
117: return env.userManager.groupForName(_name);
118: }
119:
120: public void shutdown() throws Exception {
121: Server.stop = true;
122: }
123:
124: public void beginRestore() throws Exception {
125: backupRestore.beginRestore();
126: }
127:
128: public void processRestoreChunk(byte[] chunk) throws Exception {
129: backupRestore.processRestoreChunk(chunk);
130: }
131:
132: public void beginBackup() throws Exception {
133: backupRestore.beginBackup();
134: }
135:
136: public byte[] nextBackupChunk() throws Exception {
137: return backupRestore.nextBackupChunk();
138: }
139:
140: public int numberOfTxs() throws Exception {
141: return Env.currentEnv().transactionManager.taTableCount();
142: }
143:
144: public void startGarbageCollection() {
145: env.getGarbageCollector().start();
146: }
147: }
|