Logical problem using vectors

Hi and Happy New Year,
I have a vector in my java application which contains a number of elements that is not fix which means each time the number of elements might change.
I want to retrieve the elements of the vector 3 by 3 its like table records paging in jsp , asp or php
- lets say this time i've got 10 elements in my vector , I have to JButtons previous_3 and next_3
- The first time the program runs I want to get the first three elements of the vector (0 to 2)
- By clicking on the next_3 button I want to get the next 3 ( 3 to 5) and so on... providing that the exist
- By clicking on the privious_3 button I want to get the previous 3 ( 0 to 2) in this instance and so on... providing that the exist
Can anyone give me a hint as how to solve this problem at least give me some ideas cause i am lacking of ideas my brain is frozen, I know that is it more a logical problem that a programming one
I 've done this kind of thing in Asp and PHP but as I am new to Java
I just can not figure out how to tackle this issue

You may want to use the modulus function.
lets look at an example.
pseudo code
vector v = new vector()
v.size = 10; //lets say there are 10 elements in the vector
int n = 3; // you want to jump maximum 3 elements each time
// you can jump 3.3 times before running outide the scope
// of the vector, well after the third time you must check
// how many elements that is left in the vector, this is
// done by modulus n%10 = 1, this means that the last time
// you can not jump more than 1 element.
I have to go now so I cant give you any code to cope with the problem, Ill be back in 3 hours, maybe I can give a good axample, but this outline is the way to go.
TheLaw

Similar Messages

  • Problems using Vector in Flex Builder 3

    I've been using Vector with no problems in Flash Builder Beta, but when I try the same thing in Flex Builder 3, the compiler throws a fit when I use it. 
    public function PuzzleEvent(type:String, pieces:Vector.<Sprite>, bubbles:Boolean=false, cancelable:Boolean=false)
         //handle PuzzleEvent
    The other strange thing is, Flex automatically adds this line when I use vector:
    import __AS3__.vec.Vector;
    An import shouldn't be necessary should it?  Vector is in the top level package right?  With or without that import statement, I get compile errors.  Has anyone else had such problems with vector in Flex Builder?
    Dan

    The only way I was ever able to solve this problem was to use Flex builder Beta and now Flash Builder 4.  I did target flash player 10.0.0, but I still never could get it to work.  At least it works in Flash Builder 4.

  • Problem using vectors

    there is a warning message occuring when i try to add value
    Vector myVector = new Vector;
    String line = "check this out";code]myVector.add(line);

    Sorry for the late reply.......
    These are the error messages that i get.
    assignment.java:7: cannot find symbol
    symbol  : constructor <java.lang.String>Vector()
    location: class java.util.Vector
            Vector<String> myVector = new <String>Vector();
                                      ^
    assignment.java:123: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
                                    myVector.add(newLine);
                                                ^
    1 warning

  • Problem while creating logical port using soamanager

    Hi all,
    I have created a client proxy for web service from a 3rd party system.
    When i am creating a logical port for the same consumer proxy i get a error as follows:
    RABAX_STATE -e: UNCAUGHT_EXCEPTION
    and a dump saying
    "  The exception 'CX_SXMLP' was raised, but it was not caught anywhere along the call hierarchy.
         Since exceptions represent error situations and this error was not adequately responded to, the running ABAP program
          'CL_SXMLP_FRAGMENT=============CP' has to be terminated.                  
    Please suggest what can be done or what can be the problem.
    Thanks in advance.
    Komal

    Pls go to txn SM59 and check if the RFC destination for webservice is working in the test connection.
    Then go to txn LPCONFIG and create the logical port using the RFC dest.  Pls mention the path suffix appropriately.
    Next in your code while instantiating the client proxy pass the logical port name in the constructor (if the LP is not maintained as default).
    Pls reward points if the tips are helpful.

  • HELP!  logical question on VECTOR

    Hi all:
    anyone understand how this logical works?I had to use vector to store objects from data files andi make it works and sort perfect. but i do not understand why you have adding to element 0 for number 90
    then adding to elelemnt 0 for number 8
    assing to ellent 1 for 25 and so on. Where do u get that?
    i do not understand this logicial. this is demo output that i am supposed to follow. all i have left is add the code for adding to element number etc
    any idea?
    for ( int i = 0 ; i < v.size() ; i++ )
             System.out.println("Trying to add " +v.elementAt(i));
             //stem.out.println("adding to element "+v.??);
             System.out.println("Vector size = "+(i+1));
            }Enter file to read: input.txt
    Trying to add 90
    adding to element 0
    Vector size =1
    Trying to add 8
    adding to element 0
    Vector size =2
    Trying to add 25
    adding to element 1
    Vector size =3
    Trying to add 10
    adding to element 1
    Vector size =4
    Trying to add 27
    adding to element 3
    Vector size =5

    i don't know what you're trying to say us. as i can
    see the loop simply traverses the vector, outputting
    all its values and the momentary index.yeah, i am trying to figure out why it is adding to element 0
    ans 2nd number still adding to elemment 0
    adding to elment 1
    and number 27 is adding to element 3, i do dnot think i tis fixed that way. there must be some alogirthim in this.
    where do they come from, and how do i implmnet that into the code that's my problem
    do u mean by momentary index refers to adding element 0 1 etc? what is that
    thanks
    willy

  • Exception IndexOutOfBoundsException using Vector. Christmas homework!

    Hi everyone, I'm not a java expert (almost a newbie, I would say) and this is the first time I post anything in a Forum. I have the following piece of code:
    public class Test extends javax.swing.JFrame {
    private java.util.Vector list;
    public Test() {
         super("test");
         list = new java.util.Vector();
         javax.swing.JButton add = new javax.swing.JButton("Add");
         add.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent e) {
              String value = "new element";
              System.out.println("size: "+list.size());
              list.add(value);
              int i = list.size();
              System.out.println("size + 1: "+i);
              /**/System.out.println("elem i: "+ (String)list.get(i));
         getContentPane().add(add);
         pack();
         setVisible(true);
    public static void main(String[] args) {
         new Test();
    and when I run it I have the following printout:
    size: 0
    size + 1: 1
    java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
    at....
    (omissis)
    Does anyone have any idea of why? how can I solve the problem? Isn't Vector supposed to be "dynamic"?
    Elsewhere I use Vectors with no problems but I am not accessing it right after having added any element, rather I return it as the result of some elaboration and then access it.
    I know it's Christmas time and so I wish you all Merry Christmas and Happy new Year. I hope someone has time to answer me over this holydays.
    Thanks anyway,
    Rosario

    Does anyone have any idea of why? how can I solve the
    problem? Isn't Vector supposed to be "dynamic"?You try to access an element after the last element. When you set i = list.size(), i will be the index of the last element plus one. This is because indices count from 0.
    It is the list.get(i) that causes the problem.
    S&oslash;ren

  • Is there a way to "mix" colors using vectors?

    Here's my problem: I'm not a very technical and detailed artist, and I'm not trying to be. My works is pretty cartoonish actually, so I never dabble with the paintbrush and always use vectors. Anyhow, I was wondering, if I want to draw, using vectors, a guy with half of his legs in a pool, and half not, how would I go about coloring that? I mean, I'm intending to make the man pinkish, and the water light bluish, but how can I achieve the mixture, a combination of the two, for the half of the legs underwater? I'm not seeking color recommendations (for the legs) by the way. Is there a way to combine two colors to achieve an in-between ground?

    Put the legs on one layer and put the water on another layer above/in-front and adjust the opacity of the water-layer to let some of the leg-layer show through.  If you don't want to construct your cartoon using layers which is one of Photoshop's main benefits, you can figure out what color to make the wet leg with by creating a swatch of leg color in one layer and then make a water-colored layer in front/above it and adjust the opacity then use the eyedropper to sample the color of the combination.
    Of course in a real situation with the observer above the level of the water looking through it at an angle, the leg would become bluer the further into the water it went because there would be more water between the foot and the observer than say the knee and the observer and you'd want to make a gradient of color or gradient of transparency using a layer mask with a black-to-white gradient in the mask instead of just one opacity setting, and there would also be some size and offset of the leg due to refraction of the water, but as you said you're not a detailed artist.

  • N-Queens Problem Using Stacks Help

    I'm trying to solve the N-Queens problem using Stacks. Quite frankly, I'm completely lost.
    Here's the pseudocode from the book:
    "Push information onto the stack indicating the first choice is a queen in row 1, column 1.
    success = false;
    while(!success && !s.isEmpty())
    Check whether the most recent choice (on top of the stack) is in the same row, same column, or same diagonal as any other choices (below the top). If so, we say there is a conflict: otherwise, there is no conflict.
    if (there is a conflict)
    -Pop items off the stack until the stack becomes empty or the top of the stack is a choice that is not in column n. If the stack is now not empty, then increase the column number of the top choice by 1.
    else if (no conflict and the stack size is n)
    -Set success to true because we have found a solution to the n-queens problem.
    else
    -Push information onto the stack indicating tat the next choice is to place a queen at row number s.size()+1 and column number 1.
    And here is my excuse for code so far. I have no idea how to check the diagonals, or how to even really make this work
    {code}import java.util.Stack;
    public class NQueens {
    int row, column, n;
    public NQueens(int n) {
    row = 0;
    column = 0;
    n = n;
    public Stack Solve(){
    boolean success, conflict;
    Stack<NQueens> Qs = new Stack<NQueens>();
    if (Qs.size() == 0)
    Qs.push(new NQueens(1));
    success = false;
    while (!success && !Qs.isEmpty())
    if (Qs.peek().row == row)
    conflict = true;
    if (Qs.peek().column == column)
    conflict = true;
    if (conflict = true)
    Qs.pop();
    Qs.peek().column += 1;
    else
    if (!conflict && Qs.size() == n)
    success = true;
    else
    Qs.push(new NQueens(Qs.size()+1));
    return Qs;
    {code}

    First off I'll address this:
        int row, column, n;
        public NQueens(int n) {
            row = 0;
            column = 0;
            n = n; //here
        }Notice the last line of that. I get what you're trying to do, but think about what the compiler sees there. If you have two variables called 'n', one at the class level, and one at the method level, the compiler must have rules so it knows which one you're talking about. And if it follows those rules, then saying 'n' inside that method must always refer to the same n. Otherwise, how would it decide which one you're talking about? The rule here is that it uses the most local variable available to it, which in this case is your method parameter. So 'n = n' is setting the parameter equal to itself. To refer to the class variable n, use "this.n", like so:
    this.n = n;Now that that's settled, let's address some logic. You'll need to figure out whether two Queens share a diagonal. I can think of at least a couple options for that. First, every time you look at a Queen you could loop through the entire board and make sure that if a piece is in r3c4, that no piece is in r2c3,r4c5,r5c6, etc. Or you could create a new variable for your class similar to your 'row' and 'column' variables that tracks the diagonal a piece is in. But that requires some calculating. And remember, there's 2 directions for diagonals, so you'll need 2 diagonal variables.
    If these are your Row and Column values:
    Row          Column
    00000000     01234567
    11111111     01234567
    22222222     01234567
    33333333     01234567
    44444444     01234567
    55555555     01234567
    66666666     01234567
    77777777     01234567And these are your diagonal values:
    Diag 1                    Diag 2
    0  1  2  3  4  5  6  7          7  6  5  4  3  2  1  0
    1  2  3  4  5  6  7  8          8  7  6  5  4  3  2  1
    2  3  4  5  6  7  8  9          9  8  7  6  5  4  3  2
    3  4  5  6  7  8  9  10          10 9  8  7  6  5  4  3
    4  5  6  7  8  9  10 11          11 10 9  8  7  6  5  4
    5  6  7  8  9  10 11 12          12 11 10 9  8  7  6  5
    6  7  8  9  10 11 12 13          13 12 11 10 9  8  7  6
    7  8  9  10 11 12 13 14          14 13 12 11 10 9  8  7Then examine the relationship between Row(R), Column(C), and Diagonals 1 and 2 (D1/D2):
    RC   D1,D2
    00 = 0,7
    01 = 1,6
    02 = 2,5
    03 = 3,4
    04 = 4,3
    05 = 5,2
    06 = 6,1
    07 = 7,0
    10 = 1,8
    11 = 2,7
    12 = 3,6
    13 = 4,5
    14 = 5,4
    15 = 6,3
    16 = 7,2
    17 = 8,1You'll notice that D1 is always the same as R + C. And D2 is always the same as C subtracted from 7 plus R, giving:
    int d1 = row + column;
    int d2 = (7 + row) - column;But remember, that 7 in the formula above, is based on how big your grid is. So whatever your 'N' is, whether its a 10x10 square or a 574x574 square, that 7 should be changed to (N-1)
    So those could be your variables to track diagonals. What I'm noticing in your current code, is that you never change your row and column variables...so every Queen is always at r0c0. You should probably put values for those in your parameters for the constructor, in addition to n. Then the diagonals can be calculated from those.
    Edited by: newark on Apr 17, 2008 10:46 AM

  • Problem using SmartCard with 2 Certificates stored and SunPKCS11

    Hi,
    I'm trying to access one SmartCard token in Java 1.5 using SunPKCS11 provider for crypt, decrypt and digital signature operations.
    I have 2 certificates stored on Token:
    - CertA;
    - CertB.
    There are also 2 PIN:
    - PIN1;
    - PIN2.
    I use:
    - PIN1 for logging into the token;
    - PIN1 for operation involving CertA;
    - PIN2 for operation involving CertB;
    There is no problem to logging into the token using Java and, without any troubles, I can read certificates and key from the
    cryptographic card.
    There is no problem using CertA for all my operation, but every attempt of using Private Key of CertB (for the same operations) returns with an Exception:
    java.security.ProviderException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_DEVICE_ERROR
    Here there's an extract of my source code.
    public void loginToken() {
    Provider UserProvider = new sun.security.pkcs11.SunPKCS11(C:\\pkcs11.cfg);
    Security.addProvider(UserProvider);
    try {
    KeyStore ks = null;
    X509Certificate UserCert = null;
    PrivateKey UserCertPrivKey = null;
    PublicKey UserCertPubKey = null;
    //PIN
    char PIN1[] = "11111".toCharArray();
    char PIN2[] = "22222".toCharArray();
    //logging into token
    ks = KeyStore.getInstance("PKCS11", UserProvider);
    ks.load(null, PIN1);
    //enumeration alias
    String alias = "";
    Enumeration e = ks.aliases();
    while (e.hasMoreElements()) {
    alias = (String) e.nextElement();
    //Certificate
    UserCert = (X509Certificate) ks.getCertificate(alias);
    //PublicKey
    UserCertPubKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
    if (alias.compareToIgnoreCase("Cert1") == 0) {
         //PrivateKey reference     
    UserCertPrivKey = (PrivateKey) ks.getKey(alias, PIN1);
    } else if (alias.compareToIgnoreCase("Cert2") == 0) {
    //PrivateKey reference
    UserCertPrivKey = (PrivateKey) ks.getKey(alias, PIN2);
    } else {
    System.out.println("ALIAS UNKNOW");
    System.exit(1);
    //Signature Test
    if (!MakeSignature(UserCertPrivKey, UserProvider))
    System.out.println(" *** SIGNATURE OK *** ");
    else
    System.out.println(" *** SIGNATURE KO *** ");
    catch (Exception ex) {
    System.out.println("ERROR: " + ex);
    public boolean MakeSign(PrivateKey PrivKey, Provider p) {
    try {
    //File I/O
    FileInputStream txtfis = new FileInputStream("C:\\Test.txt");
    FileOutputStream sigfos = new FileOutputStream("C:\\Test_Signature.txt");
    //Signature Obj init
    Signature dsa = Signature.getInstance("SHA1withRSA", p.getName());
    dsa.initSign(PrivKey);
    //Update data
    BufferedInputStream bufin = new BufferedInputStream(txtfis);
    byte[] buffer = new byte[1024];
    int len;
    while (bufin.available() != 0) {
    len = bufin.read(buffer);
    dsa.update(buffer, 0, len);
    bufin.close();
    //Make signature
    byte[] realSig = dsa.sign();
    //save signature on file
    sigfos.write(realSig);
    sigfos.close();
    return true;
    catch (Exception ex) {
    System.out.println("ERROR: " + ex);
    return false;
    Any help would be grateful...
    Thanks in advance.
    P.S. Sorry for my English

    This is the same my initial problem.
    I resolved it using IAIK-PKCS#11Wrapper (it is FREE) insted of sun.security.pkcs11.SunPKCS11.
    You can find it here:
    http://jce.iaik.tugraz.at/sic/products/core_crypto_toolkits/pkcs_11_wrapper
    Here an exemple of code.
    The main class:
    import iaik.pkcs.pkcs11.Module;
    import iaik.pkcs.pkcs11.DefaultInitializeArgs;
    import java.util.Hashtable;
    import iaik.pkcs.pkcs11.Token;
    import iaik.pkcs.pkcs11.Slot;
    import iaik.pkcs.pkcs11.Session;
    import iaik.pkcs.pkcs11.objects.RSAPrivateKey;
    import java.util.Vector;
    import iaik.pkcs.pkcs11.objects.PrivateKey;
    import iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate;
    import java.util.Enumeration;
    import iaik.pkcs.pkcs11.objects.Key;
    import java.security.cert.CertificateFactory;
    import java.io.ByteArrayInputStream;
    import iaik.pkcs.pkcs11.Mechanism;
    import java.security.Security;
    import org.bouncycastle.jce.provider.BouncyCastleProvider;
    import java.io.File;
    import java.io.FileInputStream;
    import org.bouncycastle.cms.CMSSignedDataGenerator;
    import org.bouncycastle.cms.CMSProcessableByteArray;
    import java.util.ArrayList;
    import java.security.cert.CertStore;
    import java.security.cert.CollectionCertStoreParameters;
    import org.bouncycastle.cms.CMSSignedData;
    import java.io.FileOutputStream;
    import java.security.cert.X509Certificate;
    import iaik.pkcs.pkcs11.TokenInfo;
    import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
    public class MakeSignature {
      public static void main(String[] args) {
         String USER_PIN = "12345678";
         String DLL_NAME = "C:\\windows\\system32\\dll_P11_name.dll";
         String OBJ_LABEL1 = "CNS0"; //this is the label of my 1th cert
         String OBJ_LABEL2 = "CNS1"; //this is the label of my 2th cert
         String INPUT_FILE = "C:\\Temp\\test.txt";
         String OUTPUT_FILE = "C:\\Temp\\test.p7m";
        try {
           // ********** INITIALIZE PKCS#11 MODULE WITH DEFAULT PARAMETERS **********
          Module pkcs11Module = Module.getInstance(DLL_NAME);
          pkcs11Module.initialize(new DefaultInitializeArgs());
           // ********** SELECT TOKEN **********
          Slot[] slotsWithToken = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
          Token[] tokens = new Token[slotsWithToken.length];
          Hashtable tokenIDtoToken = new Hashtable(tokens.length);
          long tokenID = -1;
          Token tokenUsed = null;
          //enum readers
          for (int i = 0; i < slotsWithToken.length; i++) {
            tokens[i] = slotsWithToken.getToken();
    tokenID = tokens[i].getTokenID();
    tokenIDtoToken.put(new Long(tokenID), tokens[i]);
    System.out.println("Active tokens:");
    System.out.println("Token ID: " + tokenID);
    if (tokens.length == 0) { //No SC found
    System.out.println("No SC presents");
    else {
    System.out.println("Using token: " + tokens[0].getTokenID());
    tokenUsed = tokens[0];
         //Note: if you have more reader and more SC inserted, you have to write
         //here the code for select the right token
         // ********** OPEN SESSION VS THE TOKEN AND IF REQUIRED SUBMIT PIN **********
    TokenInfo tokenInfo = tokenUsed.getTokenInfo();
    Session session = tokenUsed.openSession(Token.SessionType.SERIAL_SESSION, false, null, null);
    if (tokenInfo.isLoginRequired()) {
    session.login(Session.UserType.USER, USER_PIN.toCharArray());
         // ********** SET SEARCH TEMPLATE FOR THE P11 OBJECT **********
    RSAPrivateKey privateSignatureKeyTemplate = new RSAPrivateKey();
    privateSignatureKeyTemplate.getSign().setBooleanValue(Boolean.TRUE);
    privateSignatureKeyTemplate.getLabel().setCharArrayValue(OBJ_LABEL2.toCharArray());
         // ********** SEARCH P11 OBJECT USING TEMPLATE **********
    Vector keyList = new Vector(4);
    session.findObjectsInit(privateSignatureKeyTemplate);
    Object[] matchingKeys;
    while ( (matchingKeys = session.findObjects(1)).length > 0) {
    keyList.addElement(matchingKeys[0]);
    session.findObjectsFinal();
         //Try to find the corresponding certificates for the signature keys
    Hashtable keyToCertificateTable = new Hashtable(4);
    Enumeration keyListEnumeration = keyList.elements();
    while (keyListEnumeration.hasMoreElements()) {
    PrivateKey signatureKey = (PrivateKey) keyListEnumeration.nextElement();
    byte[] keyID = signatureKey.getId().getByteArrayValue();
    X509PublicKeyCertificate certificateTemplate = new X509PublicKeyCertificate();
    certificateTemplate.getId().setByteArrayValue(keyID);
    session.findObjectsInit(certificateTemplate);
    Object[] correspondingCertificates = session.findObjects(1);
    if (correspondingCertificates.length > 0) {
    keyToCertificateTable.put(signatureKey, correspondingCertificates[0]);
    session.findObjectsFinal();
         //There are three cases now: 1 no obj found; 2 found only one obj, 3 found more obj
    Key selectedKey = null;
    X509PublicKeyCertificate correspondingCertificate = null;
    //no object found for template
    if (keyList.size() == 0) {
    System.out.println("No object found for template");
    throw new Exception("No object found for template");
    //Founf only one object
    else if (keyList.size() == 1) {
    selectedKey = (Key) keyList.elementAt(0);
    // create a IAIK JCE certificate from the PKCS11 certificate
              correspondingCertificate = (X509PublicKeyCertificate)keyToCertificateTable.get(selectedKey);
    System.out.println("One object Found");
    //Found more object ... user can select one
    else {
         System.out.println("Many obj found!!!");
    //write here the code for select the right object
         // ********** GET THE OBJECT **********
    RSAPrivateKey signerPriKey = (RSAPrivateKey) selectedKey;
    java.security.cert.CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    byte[] derEncodedCertificate = correspondingCertificate.getValue().getByteArrayValue();
    //Cast to java.security.cert.X509Certificate
    java.security.cert.X509Certificate signerCert = (java.security.cert.X509Certificate) certificateFactory.
    generateCertificate(new ByteArrayInputStream(derEncodedCertificate));
         // ********** SIGNATURE OPERATION **********
    //Add BouncyCastle as provider
    Security.addProvider(new BouncyCastleProvider());
    //initialize signature operation
    session.signInit(Mechanism.RSA_PKCS, (PrivateKey) signerPriKey);
    //get input data
    File src = new File(INPUT_FILE);
    int sizecontent = ( (int) src.length());
    byte[] contentData = new byte[sizecontent];
    FileInputStream freader = new FileInputStream(src);
    freader.read(contentData, 0, sizecontent);
    freader.close();
         //calculate digest of the input data
    byte[] toEncrypt = buildBits(contentData); //I've already posted the code for this function
    //make signature
    byte[] signature = session.sign(toEncrypt);
         // ********** MAKE P7 WELL FORMAT DOCUMENT **********
    //CMSSignedDataGenerator fact = new CMSSignedDataGenerator();
    Signature2CMSSignedData fact = new Signature2CMSSignedData();
    CMSProcessableByteArray content = new CMSProcessableByteArray(contentData);
    //Creation of BC CertStore
    ArrayList certList = new ArrayList();
    certList.add(signerCert);
    CertStore certs = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), "BC");
    //Signature Alg
    String algorithm = CMSSignedDataGenerator.DIGEST_SHA1;
    //add element to P7
    fact.addSignature(signature, signerCert, algorithm);
    fact.addCertificatesAndCRLs(certs);
    //generate enveloped using Bouncycastle provider
         CMSSignedData envdata = fact.generate(PKCSObjectIdentifiers.data.getId(), content, true);
    byte[] enveloped = envdata.getEncoded();
    //Write P7 file
    FileOutputStream efos = new FileOutputStream(OUTPUT_FILE);
    efos.write(enveloped);
    efos.close();
    // ********** END **********
    session.closeSession();
    pkcs11Module.finalize(null);
    catch (Exception ex) {
    ex.printStackTrace();
    }Main class uses buildBits function (already posted in this topic) and Signature2CMSSignedData class.import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.security.cert.CertStore;
    import java.security.cert.X509CRL;
    import java.security.cert.X509Certificate;
    import org.bouncycastle.asn1.ASN1EncodableVector;
    import org.bouncycastle.asn1.ASN1InputStream;
    import org.bouncycastle.asn1.ASN1OctetString;
    import org.bouncycastle.asn1.ASN1Sequence;
    import org.bouncycastle.asn1.ASN1Set;
    import org.bouncycastle.asn1.BERConstructedOctetString;
    import org.bouncycastle.asn1.DEREncodable;
    import org.bouncycastle.asn1.DERNull;
    import org.bouncycastle.asn1.DERObject;
    import org.bouncycastle.asn1.DERObjectIdentifier;
    import org.bouncycastle.asn1.DEROctetString;
    import org.bouncycastle.asn1.DERSet;
    import org.bouncycastle.asn1.cms.ContentInfo;
    import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
    import org.bouncycastle.asn1.cms.SignedData;
    import org.bouncycastle.asn1.cms.SignerIdentifier;
    import org.bouncycastle.asn1.cms.SignerInfo;
    import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
    import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
    import org.bouncycastle.asn1.x509.CertificateList;
    import org.bouncycastle.asn1.x509.TBSCertificateStructure;
    import org.bouncycastle.asn1.x509.X509CertificateStructure;
    import org.bouncycastle.cms.CMSProcessable;
    import org.bouncycastle.cms.CMSSignedData;
    * class for generating a RSA pkcs7-signature message.
    public class Signature2CMSSignedData2 {
    CertStore certStore;
    List certs = new ArrayList();
    List crls = new ArrayList();
    List signerInfs = new ArrayList();
    List signers = new ArrayList();
    public static final String DATA = PKCSObjectIdentifiers.data.getId();
    public static final String ENCRYPTION_RSA = "1.2.840.113549.1.1.1";
    private byte[] signatureData = null;
    private X509Certificate cert = null;
    private String digestOID = null;
    private String encOID = null;
    public Signature2CMSSignedData2() {
    public void addSignature(byte[] signatureData, X509Certificate cert, String digestOID) {
    this.signatureData = signatureData;
    this.cert = cert;
    this.digestOID = digestOID;
    this.encOID = ENCRYPTION_RSA;
    public void addCertificatesAndCRLs(CertStore certStore) throws Exception{
    try {
    Iterator it = certStore.getCertificates(null).iterator();
    while (it.hasNext()) {
    X509Certificate c = (X509Certificate) it.next();
    certs.add(new X509CertificateStructure((ASN1Sequence) makeObj(c.getEncoded())));
    Iterator it2 = certStore.getCRLs(null).iterator();
    while (it2.hasNext()) {
    X509CRL c = (X509CRL) it2.next();
    crls.add(new CertificateList((ASN1Sequence) makeObj(c.getEncoded())));
    catch (Exception e) {
    throw new Exception(e.getMessage());
    private DERObject makeObj(byte[] encoding) throws Exception {
    if (encoding == null) {
    return null;
    ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
    ASN1InputStream aIn = new ASN1InputStream(bIn);
    return aIn.readObject();
    public CMSSignedData generate(String signedContentType, CMSProcessable content, boolean encapsulate) throws Exception {
    try {
    ASN1EncodableVector digestAlgs = new ASN1EncodableVector();
    ASN1EncodableVector signerInfos = new ASN1EncodableVector();
    DERObjectIdentifier contentTypeOID = new DERObjectIdentifier(signedContentType);
    // add the SignerInfo objects
    Iterator it = signerInfs.iterator();
    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(digestOID), new DERNull());
    AlgorithmIdentifier encAlgId;
    encAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(encOID), new DERNull());
    digestAlgs.add(digAlgId);
    ASN1Set signedAttr = null;
    ASN1Set unsignedAttr = null;
    ASN1OctetString encDigest = new DEROctetString(signatureData);
    ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getTBSCertificate());
    ASN1InputStream aIn = new ASN1InputStream(bIn);
    TBSCertificateStructure tbs = TBSCertificateStructure.getInstance(aIn.readObject());
    IssuerAndSerialNumber encSid = new IssuerAndSerialNumber(tbs.getIssuer(), tbs.getSerialNumber().getValue());
    signerInfos.add(new SignerInfo(new SignerIdentifier(encSid), digAlgId, signedAttr, encAlgId, encDigest, unsignedAttr));
    ASN1Set certificates = null;
    if (certs.size() != 0) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    it = certs.iterator();
    while (it.hasNext()) {
    v.add( (DEREncodable) it.next());
    certificates = new DERSet(v);
    ASN1Set certrevlist = null;
    if (crls.size() != 0) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    it = crls.iterator();
    while (it.hasNext()) {
    v.add( (DEREncodable) it.next());
    certrevlist = new DERSet(v);
    ContentInfo encInfo;
    if (encapsulate) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    content.write(bOut);
    ASN1OctetString octs = new BERConstructedOctetString(bOut.toByteArray());
    encInfo = new ContentInfo(contentTypeOID, octs);
    else {
    encInfo = new ContentInfo(contentTypeOID, null);
    SignedData sd = new SignedData(new DERSet(digestAlgs), encInfo, certificates, certrevlist, new DERSet(signerInfos));
    ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, sd);
    return new CMSSignedData(content, contentInfo);
    catch (Exception e) {
    throw new Exception(e.getMessage());
    }Bye.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

  • Using Vectors in Entity Beans

    Hello,
    Can I use vectors in entity and store them in Tables directly as binary objects.I have tried making that bean but facing problem in retriving data from table using EJB-QL.Here are code snippets:
    -------public abstract class CartEntityBean implements EntityBean {
         private EntityContext ctx;
         public abstract String getCartId();
         public abstract Vector getItems();
         public abstract void setCartId(String CartId);
         public abstract void setItems(Vector items);
    public String ejbCreate(String cartId,Vector items) throws CreateException {
              setCartId(cartId);
              return cartId;
    rest other methods omitted
    public interface CartHomeInterface extends EJBHome{
    public CartRemoteInterface create (String cartId,Vector items )throws CreateException,RemoteException ;
    public CartRemoteInterface findByPrimaryKey(String pk) throws FinderException, RemoteException;
    public Collection findmyItems() throws FinderException, RemoteException;
    I am using Cloudscape as Database.
    Please help weather I can use Complex objects in Entity Beans or Not

    this is no good idea to store the cart-items as a java-vector. you should create a entity bean cart and a entity bean cartItem. then create a cmr between the two entity beans.

  • HELP-Problem with Vector type in Applet

    Hi,
    I am writing an Java applet which uses Vector. It won't run in IE browser, simply does not respond.
    However, when I tested the program using Appletviewer it runs prefectly.
    Is there a way to make Vector work in applet ?
    I have investigated the code and I'm pretty sure it's the Vector that causes problem in the applet.
    Pls your idea. Thanks.
    Hadi

    Hi,
    I use Applet, not JApplet. There are 3 deprecated things in this applet (mouseDown, keyDown, action) but I have used them all in my previous applet with no problem at all.
    I suspected the problem is Vector related by inserting several showDialogs as below:
    showDialog("1111");
    t.clear();     // to clear the vector
    showDialog("222222");
    I can see that the applet displays the 1111, but does not display 222222 at all. It seems like it simply ignores all commands after the first showDialog. Therefore, I suspect the t.clear() as the source of problem. But it does not display any error.
    't' is defined at the top as:
    static Vector t = new Vector();
    And t is manipulated by such: t.add(new Task()); and other regular Vector methods in jdk 1.3. I also checked that there is no deprecated methods for Vector from 1.2 to 1.3.
    I use MS Internet Explorer to run my applet.
    Any other things I should check ?
    Thanks.

  • How to define DefaultTableModel to use vector data?

    Hi ...
    I want to show files data in a jtable which consist of files (Name,size,path) I want to use vectors for remove and add methods. The problem is with data vector I tried to define it as
    Vector <Vector[][]>data;I get always an error when I tried to add data to data vector so where is my problem?
    Thanks.
    Feras

    Vector <Vector[][]>data;You are confusing 2Dimensional arrays with Vectors. When using Vectors you need to create a Vector of Vectors. The code should be something like this;
    Vector<Vector> data = new Vector<Vector>();
    Vector<Object> row1 = new Vector<Object>();
    row1.add(name);
    row1.add(size);
    row1.add(path);
    data.add(row);Presumably the code to add the rows would be in a loop.

  • Is it legal to use Vector in EJB?

    Chapter 24 of the EJB spec states:
    "An enterprise Bean must not use thread synchronization primitives to synchronize execution of multiple instances."
    As far as I know Vector ist thread save.
    Does this mean you must not use Vector in EJB? Or is it allowed to use Vector as only one bean instance accesses one Vector instance?

    I'd sure like to hear a clear answer to this question. I've been tasked with adding an EJB interface to an existing server application. Right now, we have 2 main methods of sending requests to the server, RMI and IP. We have clients that are requesting an EJB interface. What I'd like to do is create a Session bean( haven't decided on Stateless or Stateful yet ) that invokes the same underlying objects that the RMI and IP objects use. However, those classes were not written with EJB's in mind. They start threads. They access files. They have static data which is manipulated. All those things are forbidden( or at least, strongly discouraged ) in the EJB spec, as I understand it.
    Of course, I could create a Session bean that used the existing RMI or IP interface to talk to an instance of our application running in a different JVM, which would eliminate the problem. But that seems like a bit of a hack to me.
    Marc Robertson
    Staff Consultant
    DST Systems, Inc.

  • Logic is using 16.000.000 TerraByte physical Ram??? See picture:

    Hi, I got really massive problems with crashes of Logic. I have a absolute clean and new system with nothing more than Logic and OSX!
    Look at that:
    [img]http://www.xcellent-productions.de/downloads/activity.png[/img]
    The most crashes I got when I have loaded lots of stuff in the EXS and after that opening the Logic preferences (over the menu) or closing that song and opening a new one. It doesn't matter if I use the internal audio driver or an external (Fireface400)
    Any suggestions?
    Xcell

    Hi,
    first of all the terminal top is showing the same.
    The problem should everyone of you simply rebuild. I got some (expensive) new 2 GB (now 5 GB at all) but nothing changes because Logic is only able to adress 2 GB Ram. I thought that was a joke, but it's not. Everytime Logic is using more than 2GB the activity window is showing this 16mio stuff.
    So, what is that???
    I can put 16GB Ram into my Computer and am able to use just 2 of them??? The MacPro is fast enough to open 100 of EXS but can't load instruments? I am really frustrated.
    So, does anyone has any advice how I could make the physical Ram used by Logic smaller? I tried to use harddisc speed fast and recording activity less in the virtual memory, but than I can use about one instrument more (28 at all). What is with other samplers like Kontakt. Is it using the same Ram logic is using or does it use a new thread and it's own Ram? Does Redmaticas EXS Manager merge function is of any use against too much Ram using instruments?
    Any advice would be very very great!!!!
    Reagrds,
    Axel

  • Logic not using multiple cores?

    I have a project that seems to be burning out my CPU. The music starts distorting and crackling, and I've noticed that the little CPU indicator is hitting the top of the chart. But, I also have the iStat monitor installed, and the CPU never reads as going above 50%.
    I have a dual core intel, is it possible that Logic is using only one core?

    I have the same problem.
    On a i7 iMac with 16 gigs of ram. Logic is only using one core no matter what settings I use (auto, 8 or 4), and even using the bus rerouting trick the plugins still run on the same core. That core create glitch when it reaches 100%, but really only 25% of my iMac is used.
    Way to get us spending money, pay 3000$ for a computer that is 4 times faster than the previous one, but then your limited to 25% of what you paid for.

Maybe you are looking for