samples/messagedigest/src-new-spi/org/apidesign/impl/security/spi/DigestorAccessor.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:23 +0200
changeset 44 716af5f2ebd1
permissions -rw-r--r--
Switching to freeform project
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 
     6 package org.apidesign.impl.security.spi;
     7 
     8 import java.nio.ByteBuffer;
     9 import org.apidesign.spi.security.Digestor;
    10 
    11 /**
    12  *
    13  * @author jarda
    14  */
    15 public abstract class DigestorAccessor {
    16     private static DigestorAccessor INSTANCE;
    17     
    18     protected DigestorAccessor() {
    19         assert INSTANCE == null;
    20         INSTANCE = this;
    21     }
    22     
    23     public static DigestorAccessor getDefault() {
    24         try {
    25             Class.forName(Digestor.class.getName(), true, DigestorAccessor.class.getClassLoader());
    26             return INSTANCE;
    27         } catch (ClassNotFoundException ex) {
    28             throw new IllegalStateException(ex);
    29         }
    30     }
    31     
    32     protected abstract <Data> byte[] digest(Digestor<Data> dig, Data data);
    33     protected abstract <Data> Data create(Digestor<Data> dig, String algorithm); 
    34     protected abstract <Data> void update(Digestor<Data> dig, Data data, ByteBuffer input);
    35 }