samples/messagedigest/src-new-spi/org/apidesign/impl/security/spi/DigestorAccessor.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/messagedigest/src-new-spi/org/apidesign/impl/security/spi/DigestorAccessor.java Sat Jun 14 09:52:23 2008 +0200
1.3 @@ -0,0 +1,35 @@
1.4 +/*
1.5 + * To change this template, choose Tools | Templates
1.6 + * and open the template in the editor.
1.7 + */
1.8 +
1.9 +package org.apidesign.impl.security.spi;
1.10 +
1.11 +import java.nio.ByteBuffer;
1.12 +import org.apidesign.spi.security.Digestor;
1.13 +
1.14 +/**
1.15 + *
1.16 + * @author jarda
1.17 + */
1.18 +public abstract class DigestorAccessor {
1.19 + private static DigestorAccessor INSTANCE;
1.20 +
1.21 + protected DigestorAccessor() {
1.22 + assert INSTANCE == null;
1.23 + INSTANCE = this;
1.24 + }
1.25 +
1.26 + public static DigestorAccessor getDefault() {
1.27 + try {
1.28 + Class.forName(Digestor.class.getName(), true, DigestorAccessor.class.getClassLoader());
1.29 + return INSTANCE;
1.30 + } catch (ClassNotFoundException ex) {
1.31 + throw new IllegalStateException(ex);
1.32 + }
1.33 + }
1.34 +
1.35 + protected abstract <Data> byte[] digest(Digestor<Data> dig, Data data);
1.36 + protected abstract <Data> Data create(Digestor<Data> dig, String algorithm);
1.37 + protected abstract <Data> void update(Digestor<Data> dig, Data data, ByteBuffer input);
1.38 +}