
org.ow2.bonita.identity.impl.SerializedIdentityService Maven / Gradle / Ivy
/**
* Copyright (C) 2007 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.identity.impl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
import org.ow2.bonita.identity.GroupOp;
import org.ow2.bonita.identity.UserOp;
import org.ow2.bonita.util.Misc;
/**
* @author "Pierre Vigneras"
* @date Nov 27, 2007
*/
public class SerializedIdentityService extends PersistentIdentityService {
public SerializedIdentityService(final File file, boolean create) throws FileNotFoundException {
super(file, create);
}
public SerializedIdentityService(final String fileName, boolean create) throws FileNotFoundException {
this(new File(fileName), create);
}
protected void flush() {
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new BufferedOutputStream(
new FileOutputStream(file)));
oos.writeInt(next);
oos.writeObject(users);
oos.writeObject(groupOps);
oos.flush();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
Misc.close(oos);
}
}
@SuppressWarnings("unchecked")
protected void sync() {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(
file)));
next = ois.readInt();
users = (Map) ois.readObject();
groupOps = (Map) ois.readObject();
} catch (EOFException eofe) {
init();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
throw new Error("Ouch! Should never reach this statement!");
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
Misc.close(ois);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy