java class

search for more blogs here

 

"help debugging a dice game" posted by ~Ray
Posted on 2008-09-27 02:07:30

Hello. I am new to Java. I use BlueJ as my compiler. Currently i am working on a communicate that creates a game between 1 user and the computer you roll the cut and add points anyway almost all the rules are in the source below./* user plays a bet with the computer that has to do with rolling dice* first to 100 wins* rolling a 1 means you lose all points for that round* rolling two 1's means you lose all points for the game*/merchandise java util. Scanner;merchandise java util. Random;public class Pig{public static void main(String[] args){Scanner scan = new Scanner(System in);Random gen = new Random();int a = 0;int d = 0;int b = 1;int c = 0;int be1 = 0;int total2 = 0;PairOfDice user = new PairOfDice();PairOfDice computer = new PairOfDice();// introductionSystem out println(" Welcome to the dice game of PIG ");System out println(" Do you know the rules ? (1 for yes or 2 for no)");d = scan nextInt();if (d == 1)System out println(" ok then lets begin ");elseif (d == 2){System out println(" In this version you will play against the computer ");System out println(" to play you roll the cut and add up your total ");System out println(" If you roll a one during your roll you lose all points during that roll.(and forfeit dice to other user)");System out println(" If you roll two one's during a single turn you lose all your points for the entire game (and abandon dice to other user)");System out println(" After rolling you can roll again or turn the dice over to the other user (the computer in this inspect)");System out println(" If you keep the dice (be a pig) you risk losing points");System out println(" If you turn them over you risk allowing your opponent to gain points or win");System out println(" The choice is yours!");}while (b == 1){System out println(" ---------------------------------------------------------------------------------------------------------");System out println(" press 1 to roll the dice!");b = scan nextInt();// user turnsif ( b == 1 )c = user turn2();if (user facevalue1() != 1 && user facevalue2() != 1){System out println(" the first cut is a " + user facevalue1());System out println(" the second cut is a " + user facevalue2());System out println("your two dice combined rolled a " + c) ;total1 = be1 + c;System out println(" you get " + c + " points for this round ");System out println(" your total for the entire game is " + total1);System out println(" press 1 to keep the dice or press 2 to turn the dice over to the computer");System out println(" --------------------------------------------------------------------------");b = scan nextInt();}if (user facevalue1() == 1 || user facevalue2() == 1 ){System out println(" the first dice is a " + user facevalue1());System out println(" the second dice is a " + user facevalue2());System out println(" your two dice combined rolled a " + c) ;System out println(" you do not get any points for that roll becuase a 1 was present");System out println(" your total is still " + total1);System out println(" the dice are automatically turned over to the computer ");System out println(" -------------------------------------------------------------------------");b = 2;}if (user facevalue1() == 1 && user facevalue2() == 1){System out println(" the first cut is a " + user facevalue1());System out println(" the second dice is a " + user facevalue2());System out println(" your two cut combined rolled a " + c);System out println(" you do not get any points for that roll because a 1 was present");total1 = 0;System out println(" Uh Oh! you rolled two ones you lose all your points!");System out println(" Your total for the game is now " + total1 );System out println(" --------------------------------------------------------------------------");}}// computers turnswhile (b == 2){System out println(" the computer is now rolling..... ");a = computer roll2();if (computer facevalue1() != 1 && computer facevalue2() != 1){System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);total2 = be2 + a;System out println(" the computers total is " + total2);System out println(" the computer has turned the dice over to you!");System out println(" --------------------------------------------------------------------------");b = 1;}if (computer facevalue1() == 1 || computer facevalue2() == 1);{System out println(" the computers first cut is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);System out println(" the computer does not recieve any points for that roll because a 1 was present");System out println(" the computers total is still " + total2);System out println(" the dice are now yours. ");System out println(" --------------------------------------------------------------------------");b = 1;}if (computer facevalue1() == 1 && computer facevalue2() == 1);{System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);System out println(" the computer does not recieve any points for tht roll because a 1 was present");System out println(" Aren't you a lucky one the computer rolled two 1's the computer now has 0 points.");System out println(" the dice are now yours. ");System out println(" --------------------------------------------------------------------------");b = 1;}}// victory conditions// restartingif (total1 >= 100){System out println(" Congragtulations you win!");System out println(" press 5 to play again ");b = scan nextInt();}if (total2 >= 100){System out println(" Game Over! the computer wins");System out println(" press 5 to play again and get revenge " );b = examine nextInt();}if (b == 5){be1 = 0;total2 = 0;System out println(" touch 1 to begin ! ");b = scan nextInt();}}}--------------------------------------------------------------------------that is the main code this is the controller class that setups the PairOfDicepublic class PairOfDice{Die die1 = new Die();Die die2 = new Die();public int roll2(){die1 turn();die2 roll();return die1 getFaceValue() + die2 getFaceValue();}public int facevalue1(){go die1 getFaceValue();}public int facevalue2(){return die2 getFaceValue();}}-------------------------------------------------------------------------and this is the class that actually creates the die import java util. Random;public class Die{private final int MIN_FACES = 4;private static Random generator = new Random();private int numFaces; // number of sides on the diepublic int faceValue; // current determine showing on the die//-----------------------------------------------------------------// Defaults to a six-sided die. Initial face value is 1.//-----------------------------------------------------------------public Die (){numFaces = 6;faceValue = 1;}//-----------------------------------------------------------------// Explicitly sets the size of the die. Defaults to a size of// six if the parameter is invalid. Initial face value is 1.//-----------------------------------------------------------------public Die (int faces){if (faces < MIN_FACES)numFaces = 6;elsenumFaces = faces;faceValue = 1;}//-----------------------------------------------------------------// Rolls the die and returns the prove.//-----------------------------------------------------------------public int roll (){faceValue = generator nextInt(numFaces) + 1;return faceValue;}//-----------------------------------------------------------------// Returns the current die value.//-----------------------------------------------------------------public int getFaceValue (){return faceValue;}}------------------------------------------------------------------------Everything compiles fine but there is a glitch in the game that i can't seem to fix in the code. when i run the game the output is usually similar to this--------------------------------------------------------------Welcome to the cut game of PIGDo you know the rules ? (1 for yes or 2 for no)1ok then lets begin---------------------------------------------------------------------------------------------------------press 1 to roll the dice!1the first dice is a 1the back up dice is a 3your two dice combined rolled a 4you do not get any points for that roll becuase a 1 was presentyour total is still 0the dice are automatically turned over to the computer-------------------------------------------------------------------------the computer is now rolling.... the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computers total is 10the computer has turned the dice over to you!--------------------------------------------------------------------------the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computer does not recieve any points for that roll because a 1 was presentthe computers total is still 10the dice are now yours.--------------------------------------------------------------------------the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computer does not recieve any points for tht roll because a 1 was presentAren't you a lucky one the computer rolled two 1's the computer now has 0 points the dice are now yours.-----------------------------------------------------------------------------------------------------------------------------------------------------when the user rolls a 1 or two 1's the dice are automatically turned over to the computer (like they are suppose to) but when the computer rolls it prints it 3 times and automatically says it has two 1's everytime after the computers roll when the user hits one the computers rolls again.(but the user is suppose to) and when you hit 2 after the computer roll the user rolls (user is only suppose to roll if 1 is hit)so.... if anyone can back up me figure out the bug in the code it would be greatly appreciated.=)If you would like to contact me VIA Aol Instant Messanger you can at: berube52991 (i would prefer this method because it would be easier to relay messages).

Forex Groups - Tips on Trading

Related article:
http://www.java-forums.org/advanced-java/3880-help-debugging-dice-game.html

comments | Add comment | Report as Spam


"help debugging a dice game" posted by ~Ray
Posted on 2008-09-27 02:07:30

Hello. I am new to Java. I use BlueJ as my compiler. Currently i am working on a project that creates a game between 1 user and the computer you roll the dice and add points anyway almost all the rules are in the source below./* user plays a game with the computer that has to do with rolling dice* first to 100 wins* rolling a 1 means you lose all points for that round* rolling two 1's means you lose all points for the game*/import java util. Scanner;merchandise java util. Random;public class Pig{public static void main(String[] args){Scanner scan = new Scanner(System in);Random gen = new Random();int a = 0;int d = 0;int b = 1;int c = 0;int total1 = 0;int total2 = 0;PairOfDice user = new PairOfDice();PairOfDice computer = new PairOfDice();// introductionSystem out println(" Welcome to the dice game of PIG ");System out println(" Do you know the rules ? (1 for yes or 2 for no)");d = scan nextInt();if (d == 1)System out println(" ok then lets begin ");elseif (d == 2){System out println(" In this version you will play against the computer ");System out println(" to play you roll the dice and add up your total ");System out println(" If you roll a one during your roll you lose all points during that roll.(and forfeit dice to other user)");System out println(" If you roll two one's during a single roll you lose all your points for the entire game (and forfeit dice to other user)");System out println(" After rolling you can roll again or move the dice over to the other user (the computer in this case)");System out println(" If you keep the cut (be a pig) you risk losing points");System out println(" If you turn them over you risk allowing your opponent to gain points or win");System out println(" The choice is yours!");}while (b == 1){System out println(" ---------------------------------------------------------------------------------------------------------");System out println(" press 1 to roll the dice!");b = scan nextInt();// user turnsif ( b == 1 )c = user roll2();if (user facevalue1() != 1 && user facevalue2() != 1){System out println(" the first dice is a " + user facevalue1());System out println(" the second cut is a " + user facevalue2());System out println("your two cut combined rolled a " + c) ;total1 = be1 + c;System out println(" you get " + c + " points for this round ");System out println(" your total for the entire game is " + total1);System out println(" press 1 to keep the dice or press 2 to turn the dice over to the computer");System out println(" --------------------------------------------------------------------------");b = scan nextInt();}if (user facevalue1() == 1 || user facevalue2() == 1 ){System out println(" the first dice is a " + user facevalue1());System out println(" the second dice is a " + user facevalue2());System out println(" your two dice combined rolled a " + c) ;System out println(" you do not get any points for that roll becuase a 1 was show");System out println(" your total is still " + total1);System out println(" the dice are automatically turned over to the computer ");System out println(" -------------------------------------------------------------------------");b = 2;}if (user facevalue1() == 1 && user facevalue2() == 1){System out println(" the first dice is a " + user facevalue1());System out println(" the second dice is a " + user facevalue2());System out println(" your two dice combined rolled a " + c);System out println(" you do not get any points for that roll because a 1 was present");total1 = 0;System out println(" Uh Oh! you rolled two ones you lose all your points!");System out println(" Your total for the game is now " + total1 );System out println(" --------------------------------------------------------------------------");}}// computers turnswhile (b == 2){System out println(" the computer is now rolling..... ");a = computer roll2();if (computer facevalue1() != 1 && computer facevalue2() != 1){System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);total2 = total2 + a;System out println(" the computers total is " + total2);System out println(" the computer has turned the dice over to you!");System out println(" --------------------------------------------------------------------------");b = 1;}if (computer facevalue1() == 1 || computer facevalue2() == 1);{System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);System out println(" the computer does not recieve any points for that roll because a 1 was present");System out println(" the computers be is still " + total2);System out println(" the cut are now yours. ");System out println(" --------------------------------------------------------------------------");b = 1;}if (computer facevalue1() == 1 && computer facevalue2() == 1);{System out println(" the computers first cut is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);System out println(" the computer does not recieve any points for tht roll because a 1 was present");System out println(" Aren't you a lucky one the computer rolled two 1's the computer now has 0 points.");System out println(" the dice are now yours. ");System out println(" --------------------------------------------------------------------------");b = 1;}}// victory conditions// restartingif (total1 >= 100){System out println(" Congragtulations you win!");System out println(" press 5 to play again ");b = examine nextInt();}if (total2 >= 100){System out println(" Game Over! the computer wins");System out println(" press 5 to play again and get revenge " );b = scan nextInt();}if (b == 5){total1 = 0;total2 = 0;System out println(" press 1 to begin ! ");b = scan nextInt();}}}--------------------------------------------------------------------------that is the main code this is the controller class that setups the PairOfDicepublic class PairOfDice{Die die1 = new Die();Die die2 = new Die();public int roll2(){die1 roll();die2 roll();return die1 getFaceValue() + die2 getFaceValue();}public int facevalue1(){return die1 getFaceValue();}public int facevalue2(){return die2 getFaceValue();}}-------------------------------------------------------------------------and this is the class that actually creates the die import java util. Random;public class Die{private final int MIN_FACES = 4;private static Random generator = new Random();private int numFaces; // number of sides on the diepublic int faceValue; // current value showing on the die//-----------------------------------------------------------------// Defaults to a six-sided die. Initial face value is 1.//-----------------------------------------------------------------public Die (){numFaces = 6;faceValue = 1;}//-----------------------------------------------------------------// Explicitly sets the size of the die. Defaults to a size of// six if the parameter is invalid. Initial face value is 1.//-----------------------------------------------------------------public Die (int faces){if (faces < MIN_FACES)numFaces = 6;elsenumFaces = faces;faceValue = 1;}//-----------------------------------------------------------------// Rolls the die and returns the result.//-----------------------------------------------------------------public int roll (){faceValue = generator nextInt(numFaces) + 1;return faceValue;}//-----------------------------------------------------------------// Returns the current die value.//-----------------------------------------------------------------public int getFaceValue (){return faceValue;}}------------------------------------------------------------------------Everything compiles fine but there is a glitch in the game that i can't seem to fix in the code. when i run the game the output is usually similar to this--------------------------------------------------------------Welcome to the cut game of PIGDo you know the rules ? (1 for yes or 2 for no)1ok then lets begin---------------------------------------------------------------------------------------------------------press 1 to turn the dice!1the first dice is a 1the back up dice is a 3your two dice combined rolled a 4you do not get any points for that roll becuase a 1 was presentyour total is still 0the dice are automatically turned over to the computer-------------------------------------------------------------------------the computer is now rolling.... the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computers total is 10the computer has turned the dice over to you!--------------------------------------------------------------------------the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computer does not recieve any points for that roll because a 1 was presentthe computers total is still 10the dice are now yours.--------------------------------------------------------------------------the computers first dice is a 5the computers first cut is a 5the computers combined roll is a 10the computer does not recieve any points for tht roll because a 1 was presentAren't you a lucky one the computer rolled two 1's the computer now has 0 points the dice are now yours.-----------------------------------------------------------------------------------------------------------------------------------------------------when the user rolls a 1 or two 1's the dice are automatically turned over to the computer (like they are suppose to) but when the computer rolls it prints it 3 times and automatically says it has two 1's everytime after the computers roll when the user hits one the computers rolls again.(but the user is suppose to) and when you hit 2 after the computer turn the user rolls (user is only suppose to roll if 1 is hit)so.... if anyone can help me figure out the bug in the code it would be greatly appreciated.=)If you would like to contact me VIA Aol Instant Messanger you can at: berube52991 (i would prefer this method because it would be easier to relay messages).

Forex Groups - Tips on Trading

Related article:
http://www.java-forums.org/advanced-java/3880-help-debugging-dice-game.html

comments | Add comment | Report as Spam


"help debugging a dice game" posted by ~Ray
Posted on 2008-09-27 02:07:29

Hello. I am new to Java. I use BlueJ as my compiler. Currently i am working on a project that creates a game between 1 user and the computer you roll the dice and add points anyway almost all the rules are in the source below./* user plays a game with the computer that has to do with rolling dice* first to 100 wins* rolling a 1 means you suffer all points for that round* rolling two 1's means you lose all points for the game*/import java util. Scanner;import java util. Random;public class Pig{public static void main(String[] args){Scanner examine = new Scanner(System in);Random gen = new Random();int a = 0;int d = 0;int b = 1;int c = 0;int be1 = 0;int total2 = 0;PairOfDice user = new PairOfDice();PairOfDice computer = new PairOfDice();// introductionSystem out println(" Welcome to the dice game of PIG ");System out println(" Do you know the rules ? (1 for yes or 2 for no)");d = scan nextInt();if (d == 1)System out println(" ok then lets begin ");elseif (d == 2){System out println(" In this version you will play against the computer ");System out println(" to play you roll the dice and add up your total ");System out println(" If you roll a one during your roll you lose all points during that roll.(and forfeit dice to other user)");System out println(" If you roll two one's during a single roll you lose all your points for the entire game (and forfeit cut to other user)");System out println(" After rolling you can roll again or turn the dice over to the other user (the computer in this case)");System out println(" If you keep the dice (be a pig) you risk losing points");System out println(" If you turn them over you risk allowing your opponent to gain points or win");System out println(" The choice is yours!");}while (b == 1){System out println(" ---------------------------------------------------------------------------------------------------------");System out println(" press 1 to roll the dice!");b = scan nextInt();// user turnsif ( b == 1 )c = user roll2();if (user facevalue1() != 1 && user facevalue2() != 1){System out println(" the first dice is a " + user facevalue1());System out println(" the back up cut is a " + user facevalue2());System out println("your two dice combined rolled a " + c) ;total1 = total1 + c;System out println(" you get " + c + " points for this round ");System out println(" your total for the entire game is " + total1);System out println(" press 1 to keep the dice or touch 2 to turn the dice over to the computer");System out println(" --------------------------------------------------------------------------");b = scan nextInt();}if (user facevalue1() == 1 || user facevalue2() == 1 ){System out println(" the first dice is a " + user facevalue1());System out println(" the second dice is a " + user facevalue2());System out println(" your two dice combined rolled a " + c) ;System out println(" you do not get any points for that roll becuase a 1 was present");System out println(" your total is still " + total1);System out println(" the dice are automatically turned over to the computer ");System out println(" -------------------------------------------------------------------------");b = 2;}if (user facevalue1() == 1 && user facevalue2() == 1){System out println(" the first dice is a " + user facevalue1());System out println(" the second dice is a " + user facevalue2());System out println(" your two dice combined rolled a " + c);System out println(" you do not get any points for that roll because a 1 was show");total1 = 0;System out println(" Uh Oh! you rolled two ones you lose all your points!");System out println(" Your total for the game is now " + total1 );System out println(" --------------------------------------------------------------------------");}}// computers turnswhile (b == 2){System out println(" the computer is now rolling..... ");a = computer roll2();if (computer facevalue1() != 1 && computer facevalue2() != 1){System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);be2 = total2 + a;System out println(" the computers total is " + total2);System out println(" the computer has turned the dice over to you!");System out println(" --------------------------------------------------------------------------");b = 1;}if (computer facevalue1() == 1 || computer facevalue2() == 1);{System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);System out println(" the computer does not recieve any points for that roll because a 1 was present");System out println(" the computers total is still " + total2);System out println(" the dice are now yours. ");System out println(" --------------------------------------------------------------------------");b = 1;}if (computer facevalue1() == 1 && computer facevalue2() == 1);{System out println(" the computers first dice is a " + computer facevalue1());System out println(" the computers first dice is a " + computer facevalue2());System out println(" the computers combined roll is a " + a);System out println(" the computer does not recieve any points for tht turn because a 1 was present");System out println(" Aren't you a lucky one the computer rolled two 1's the computer now has 0 points.");System out println(" the dice are now yours. ");System out println(" --------------------------------------------------------------------------");b = 1;}}// victory conditions// restartingif (total1 >= 100){System out println(" Congragtulations you win!");System out println(" press 5 to compete again ");b = examine nextInt();}if (total2 >= 100){System out println(" Game Over! the computer wins");System out println(" press 5 to play again and get revenge " );b = scan nextInt();}if (b == 5){total1 = 0;total2 = 0;System out println(" press 1 to begin ! ");b = scan nextInt();}}}--------------------------------------------------------------------------that is the main code this is the controller class that setups the PairOfDicepublic class PairOfDice{Die die1 = new Die();Die die2 = new Die();public int roll2(){die1 roll();die2 roll();return die1 getFaceValue() + die2 getFaceValue();}public int facevalue1(){return die1 getFaceValue();}public int facevalue2(){return die2 getFaceValue();}}-------------------------------------------------------------------------and this is the class that actually creates the die import java util. Random;public class Die{private final int MIN_FACES = 4;private static Random generator = new Random();private int numFaces; // number of sides on the diepublic int faceValue; // current value showing on the die//-----------------------------------------------------------------// Defaults to a six-sided die. Initial face value is 1.//-----------------------------------------------------------------public Die (){numFaces = 6;faceValue = 1;}//-----------------------------------------------------------------// Explicitly sets the size of the die. Defaults to a size of// six if the parameter is invalid. Initial face value is 1.//-----------------------------------------------------------------public Die (int faces){if (faces < MIN_FACES)numFaces = 6;elsenumFaces = faces;faceValue = 1;}//-----------------------------------------------------------------// Rolls the die and returns the result.//-----------------------------------------------------------------public int roll (){faceValue = generator nextInt(numFaces) + 1;return faceValue;}//-----------------------------------------------------------------// Returns the current die value.//-----------------------------------------------------------------public int getFaceValue (){return faceValue;}}------------------------------------------------------------------------Everything compiles fine but there is a glitch in the game that i can't seem to fix in the code. when i run the game the output is usually similar to this--------------------------------------------------------------Welcome to the dice game of PIGDo you experience the rules ? (1 for yes or 2 for no)1ok then lets begin---------------------------------------------------------------------------------------------------------press 1 to roll the cut!1the first dice is a 1the second dice is a 3your two dice combined rolled a 4you do not get any points for that roll becuase a 1 was presentyour total is still 0the dice are automatically turned over to the computer-------------------------------------------------------------------------the computer is now rolling.... the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computers total is 10the computer has turned the dice over to you!--------------------------------------------------------------------------the computers first dice is a 5the computers first dice is a 5the computers combined roll is a 10the computer does not recieve any points for that roll because a 1 was presentthe computers total is still 10the dice are now yours.--------------------------------------------------------------------------the computers first cut is a 5the computers first dice is a 5the computers combined roll is a 10the computer does not recieve any points for tht roll because a 1 was presentAren't you a lucky one the computer rolled two 1's the computer now has 0 points the dice are now yours.-----------------------------------------------------------------------------------------------------------------------------------------------------when the user rolls a 1 or two 1's the cut are automatically turned over to the computer (like they are suppose to) but when the computer rolls it prints it 3 times and automatically says it has two 1's everytime after the computers roll when the user hits one the computers rolls again.(but the user is suppose to) and when you hit 2 after the computer roll the user rolls (user is only speculate to roll if 1 is hit)so.... if anyone can help me figure out the bug in the code it would be greatly appreciated.=)If you would like to contact me VIA Aol Instant Messanger you can at: berube52991 (i would prefer this method because it would be easier to relay messages).

Forex Groups - Tips on Trading

Related article:
http://www.java-forums.org/advanced-java/3880-help-debugging-dice-game.html

comments | Add comment | Report as Spam


"Howto extend LDAP in java with JLDAP" posted by ~Ray
Posted on 2008-06-13 06:04:20

is a protocol that is wonderfully extensible. You can augment existing messages by adding 'controls' and you can define end new messages. Extensions are identified by a universal so that even code that does not know about an extensions can comfort work properly. For this each extension has a criticality flag to indicate whether the receiver may ignore unknown extensions. As a bonus the circumscribe of controls and messages are all defined by a common syntax () and common encoding (which is with restrictions). Writing you own controls and messages is a kind of under documented thing. In addition not all LDAP libraries support all kinds of messages. In this small howto I show how to implement custom controls and messages based on my experiences with implementing a (synchronization) client. I used as it is the only java library I could find that supports IntermediateMessages a requirement for RFC4533. And before you ask: no sorry. I can not open obtain the results. In case you actually be to start with JLDAP you get a lot of knowledge from at the examples that are provided by Novel. You can find them through the JLDAP place. The javadoc is also useful at times. Decoding a controlLets take a be at the SyncDoneControl from RFC4533. The hold back's OID is 1.3.6.1.4.1.4203.1.9.1.3 and its content value is defined with ASN.1 as: syncDoneValue ::= SEQUENCE { cookie OCTET STRING OPTIONAL refreshDeletes BOOLEAN DEFAULT FALSE} public class SyncDoneControl extends LDAPControl { public static final String OID = "1.3.6.1.4.1.4203.1.9.1.3"; private byte[] cookie; private boolean refreshDeletes; // add getters for cookie and refresDeletes public SyncDoneControl(String oid boolean critical byte[] determine) { super(oid critical value); .. see below }} contains the BER encoded value of the hold back. The LDAP restriction put on the BER encoding convey that optional values and values that are equal to the default value must be omitted. With other words: when there is no cookie (allowed because it is declared OPTIONAL) and refreshDeletes is FALSE (which is the fail) constructor argument If it is not null/empty we'll use the decoder as provided by JLDAP to decode the bytes. As the ASN.1 value is defined to go away with a grade (one of the native ASN.1 types) the LBERDecoder ordain instantiate an disapprove of type The decoder can decode all native ASN.1 types. These native types are called "universal". Other important universal types are BOOLEAN. OCTET arrange. CHOICE and SET. Type information is available on every ASN1Object through the One small warning: when there is an exception in the control's constructor. JLDAP will silently ignore your class and do its default thing. Encoding a controlTo go away a sync operation one must add a SyncRequestControl to the search constraints. Here is the ASN.1 definition of the control determine: syncRequestValue ::= SEQUENCE { mode ENUMERATED { refreshOnly (1) refreshAndPersist (3) } cookie OCTET STRING OPTIONAL reloadHint BOOLEAN DEFAULT FALSE} In the last line we set the BER encoded value. Here is a complete implementation of the encode method. say how we go the ASN.1 definition but skip optional values and values that have the default value. private byte[] encodedValue() throws IOException { ASN1grade asn1 = new ASN1grade(); asn1 add(new ASN1Enumerated(mode == call back_ONLY ? 1 : 3)); if (cookie != null) { asn1 add(new ASN1OctetString(cookie)); } if (reloadHint) { asn1 add(new ASN1Boolean(reloadHint)); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); new LBEREncoder() encode(asn1 baos); return baos toByteArray();} More complex example decoding a messageThe JLDAP BER decoder can only rewrite ASN.1 universal types. As soon as you be your own types you must help the decoder. Lets look at the decoding of the SyncInfoMessage to see how this works. The value of SyncInfoMessage is defined with the following ASN.1: syncInfoValue ::= CHOICE { newcookie [0] OCTET arrange refreshDelete [1] grade { cookie OCTET STRING OPTIONAL refreshDone BOOLEAN fail TRUE } refreshPresent [2] SEQUENCE { cookie OCTET STRING OPTIONAL refreshDone BOOLEAN DEFAULT adjust } syncIdSet [3] grade { cookie OCTET arrange OPTIONAL refreshDeletes BOOLEAN DEFAULT FALSE syncUUIDs SET OF OCTET arrange (SIZE)16)) }} The ASN.1 defines that the value can undergo one or four values. We'll represent the chosen value with a Java enumeration. By defining the enum values in request we can do by that the ordinal value of the enum values corresponds to the tag (defined between brackets []) determine. public class SyncInfoMessage extends LDAPIntermediateResponse { public static final String OID = "1.3.6.1.4.1.4203.1.9.1.4"; private SyncInfoMessageChoiceType syncInfoMessageChoiceType; private byte[] cookie; private Boolean refreshDone; private Boolean refreshDeletes; private enumerate This is the most simple implementation and the user of this class must experience about the CHOICE write anyway. Intermediate messages must always undergo the same constructor so that JLDAP can construct it for us: Now comes the tricky part. As JLDAP has no clue about the ASN.1 definition it does not know about the choice and it can not decode any further. What we can do is get the contents of as an OCTET STRING get its byte array and decode that again with the JLDAP decoder. So for most choice types we be to decode the tag's contents to a grade. Here is a utility method we can add to the AsnUtil class: public static ASN1grade parseContentAsSequence(ASN1Tagged asn1Choice) throws IOException { ASN1OctetString taggedValue = (ASN1OctetString) asn1Choice taggedValue(); byte[] taggedContent = taggedValue byteValue(); go new ASN1Sequence(new LBERDecoder() new ByteArrayInputStream(taggedContent) taggedContent length);} With this drive we'll rewrite the choice refreshPresent. sight how we decode the contents of the tag and how refreshDone is set to its default determine when we did not see it in the sequence. ConclusionIn this article I showed how to get started with extending JLDAP. The example are functional but not always end. Nor are they always according to beat practices (for example. I would normally not say so many exceptions). I shared some of the pitfalls you will be when encoding and decoding messages and controls. It's a rare treat to construe an bind on JLDAP -- especially one about doing more than just "the basics". One of the main reasons I think the JLDAP library is under-utilized is because of the dearth of good articles and documentation. And the area in which this library particularly excels is in what we might call "advanced" LDAP work. But with so little information how is the deadline-driven programmer going to experience how to do this stuff? I evaluate you've made a good contribution to rectifying the situation. Thank you very much for this very insteresting bind. I would like to use your approach to apply a small synchronization client in order to detect when a change occures in an LDAP entry. In this context I would have two questions :* Is it possible with another LDAP than the Novel one like OpenLDAP. * how do you recieve the intermediate messages with an asynchronous search a persistant examine or something else ?Sorry if it is not the place for the questions and thanks again your article helped me anyway. Arnaud the only server implementation of RFC4533 I experience is done by Openldap. So that answers your first challenge. (Assuming you want to use RFC4533.)Regarding your second question within JLDAP you can receive messages in a number of ways. Novel (who donated JLDAP to Openldap) provides extensive example applications. Look up those on persistent examine. If you registered your communicate as outlined in the article the message you receive are instances of the registered write. In other words: you can simply do a type cast of the received communicate to your own message write. convey you for showing interest and please ask again. Erik first convey you for your say. With your explanations I evaluate I ordain be able to write my client. My error was that I expected the changes to be returned as adjust Info Messages. In fact as far as I undestand they are returned as search results with a adjust state control. When I go away a sync affect in a call back And continue mode a sequence of this messsages are send and then a sync info message is sent to indicate the end of the call back re-create. After that only changes are sent (still via a search prove)... For bunco I have to read a little bit more the RFC but your tutorial is a very good starting point for my job.

Forex Groups - Tips on Trading

Related article:
http://day-to-day-stuff.blogspot.com/2007/11/howto-extend-ldap-in-java-with-jldap.html

comments | Add comment | Report as Spam


"Howto extend LDAP in java with JLDAP" posted by ~Ray
Posted on 2008-06-13 06:04:20

is a protocol that is wonderfully extensible. You can increase existing messages by adding 'controls' and you can be complete new messages. Extensions are identified by a universal so that change surface code that does not experience about an extensions can comfort work properly. For this each extension has a criticality sign to indicate whether the receiver may ignore unknown extensions. As a bonus the content of controls and messages are all defined by a common syntax () and common encoding (which is with restrictions). Writing you own controls and messages is a kind of under documented thing. In addition not all LDAP libraries support all kinds of messages. In this small howto I show how to implement custom controls and messages based on my experiences with implementing a (synchronization) client. I used as it is the only java library I could sight that supports IntermediateMessages a requirement for RFC4533. And before you ask: no sorry. I can not change state source the results. In case you actually be to go away with JLDAP you get a lot of knowledge from at the examples that are provided by Novel. You can sight them through the JLDAP place. The javadoc is also useful at times. Decoding a controlLets take a look at the SyncDoneControl from RFC4533. The hold back's OID is 1.3.6.1.4.1.4203.1.9.1.3 and its content determine is defined with ASN.1 as: syncDoneValue ::= SEQUENCE { cookie OCTET arrange OPTIONAL refreshDeletes BOOLEAN DEFAULT FALSE} public class SyncDoneControl extends LDAPControl { public static final arrange OID = "1.3.6.1.4.1.4203.1.9.1.3"; private byte[] cookie; private boolean refreshDeletes; // add getters for cookie and refresDeletes public SyncDoneControl(String oid boolean critical byte[] determine) { super(oid critical determine); .. see below }} contains the BER encoded value of the hold back. The LDAP restriction put on the BER encoding mean that optional values and values that are compete to the fail determine must be omitted. With other words: when there is no cookie (allowed because it is declared OPTIONAL) and refreshDeletes is FALSE (which is the default) constructor argument If it is not null/alter we'll use the decoder as provided by JLDAP to decode the bytes. As the ASN.1 determine is defined to go away with a SEQUENCE (one of the native ASN.1 types) the LBERDecoder will instantiate an object of write The decoder can decode all native ASN.1 types. These native types are called "universal". Other important universal types are BOOLEAN. OCTET STRING. CHOICE and SET. Type information is available on every ASN1disapprove through the One small warning: when there is an exception in the control's constructor. JLDAP will silently do by your class and do its default thing. Encoding a controlTo start a sync operation one must add a SyncRequestControl to the search constraints. Here is the ASN.1 definition of the control value: syncRequestValue ::= SEQUENCE { mode ENUMERATED { refreshOnly (1) refreshAndPersist (3) } cookie OCTET arrange OPTIONAL reloadHint BOOLEAN DEFAULT FALSE} In the last lie we set the BER encoded value. Here is a end implementation of the convert method. say how we go the ASN.1 definition but skip optional values and values that have the default value. private byte[] encodedValue() throws IOException { ASN1grade asn1 = new ASN1Sequence(); asn1 add(new ASN1Enumerated(mode == call back_ONLY ? 1 : 3)); if (cookie != null) { asn1 add(new ASN1OctetString(cookie)); } if (reloadHint) { asn1 add(new ASN1Boolean(reloadHint)); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); new LBEREncoder() convert(asn1 baos); go baos toByteArray();} More complex example decoding a messageThe JLDAP BER decoder can only rewrite ASN.1 universal types. As soon as you define your own types you must back up the decoder. Lets look at the decoding of the SyncInfoMessage to see how this works. The value of SyncInfoMessage is defined with the following ASN.1: syncInfoValue ::= CHOICE { newcookie [0] OCTET arrange refreshDelete [1] SEQUENCE { cookie OCTET arrange OPTIONAL refreshDone BOOLEAN fail TRUE } refreshPresent [2] SEQUENCE { cookie OCTET STRING OPTIONAL refreshDone BOOLEAN fail adjust } syncIdSet [3] grade { cookie OCTET STRING OPTIONAL refreshDeletes BOOLEAN fail FALSE syncUUIDs SET OF OCTET STRING (coat)16)) }} The ASN.1 defines that the determine can undergo one or four values. We'll represent the chosen determine with a Java enumeration. By defining the enum values in request we can abuse that the ordinal determine of the enum values corresponds to the tag (defined between brackets []) determine. public class SyncInfoMessage extends LDAPIntermediateResponse { public static final arrange OID = "1.3.6.1.4.1.4203.1.9.1.4"; private SyncInfoMessageChoiceType syncInfoMessageChoiceType; private byte[] cookie; private Boolean refreshDone; private Boolean refreshDeletes; private enumerate This is the most simple implementation and the user of this class must experience about the CHOICE write anyway. Intermediate messages must always undergo the same constructor so that JLDAP can construct it for us: Now comes the tricky part. As JLDAP has no clue about the ASN.1 definition it does not know about the choice and it can not decode any advance. What we can do is get the contents of as an OCTET STRING get its byte array and decode that again with the JLDAP decoder. So for most choice types we be to rewrite the tag's contents to a SEQUENCE. Here is a utility method we can add to the AsnUtil class: public static ASN1Sequence parseContentAsSequence(ASN1Tagged asn1Choice) throws IOException { ASN1OctetString taggedValue = (ASN1OctetString) asn1Choice taggedValue(); byte[] taggedContent = taggedValue byteValue(); return new ASN1Sequence(new LBERDecoder() new ByteArrayInputStream(taggedContent) taggedContent length);} With this tool we'll decode the choice refreshPresent. Notice how we rewrite the contents of the tag and how refreshDone is set to its fail determine when we did not see it in the sequence. ConclusionIn this article I showed how to get started with extending JLDAP. The example are functional but not always complete. Nor are they always according to beat practices (for example. I would normally not declare so many exceptions). I shared some of the pitfalls you ordain encounter when encoding and decoding messages and controls. It's a rare interact to read an bind on JLDAP -- especially one about doing more than just "the basics". One of the main reasons I think the JLDAP library is under-utilized is because of the dearth of good articles and documentation. And the area in which this library particularly excels is in what we might call "advanced" LDAP bring home the bacon. But with so little information how is the deadline-driven programmer going to know how to do this stuff? I evaluate you've made a good contribution to rectifying the situation. convey you very much for this very insteresting article. I would like to use your approach to apply a small synchronization client in order to detect when a change occures in an LDAP entry. In this context I would have two questions :* Is it possible with another LDAP than the Novel one like OpenLDAP. * how do you recieve the negociate messages with an asynchronous search a persistant search or something else ?Sorry if it is not the place for the questions and thanks again your bind helped me anyway. Arnaud the only server implementation of RFC4533 I experience is done by Openldap. So that answers your first challenge. (Assuming you want to use RFC4533.)Regarding your back up challenge within JLDAP you can receive messages in a be of ways. Novel (who donated JLDAP to Openldap) provides extensive example applications. be up those on persistent examine. If you registered your message as outlined in the article the message you receive are instances of the registered type. In other words: you can simply do a write cast of the received communicate to your own communicate write. Thank you for showing interest and please ask again. Erik first convey you for your answer. With your explanations I think I will be able to create verbally my client. My error was that I expected the changes to be returned as Sync Info Messages. In fact as far as I undestand they are returned as examine results with a adjust express control. When I go away a adjust process in a Refresh And Persist mode a sequence of this messsages are send and then a adjust info communicate is sent to indicate the end of the refresh stage. After that only changes are sent (still via a search result)... For short I have to construe a little bit more the RFC but your tutorial is a very good starting point for my job.

Forex Groups - Tips on Trading

Related article:
http://day-to-day-stuff.blogspot.com/2007/11/howto-extend-ldap-in-java-with-jldap.html

comments | Add comment | Report as Spam


"Howto extend LDAP in java with JLDAP" posted by ~Ray
Posted on 2008-06-13 06:04:20

is a protocol that is wonderfully extensible. You can augment existing messages by adding 'controls' and you can define end new messages. Extensions are identified by a universal so that even code that does not know about an extensions can still work properly. For this each extension has a criticality flag to indicate whether the receiver may do by unknown extensions. As a bonus the content of controls and messages are all defined by a common syntax () and common encoding (which is with restrictions). Writing you own controls and messages is a kind of under documented thing. In addition not all LDAP libraries support all kinds of messages. In this small howto I show how to apply custom controls and messages based on my experiences with implementing a (synchronization) client. I used as it is the only java library I could sight that supports IntermediateMessages a requirement for RFC4533. And before you ask: no sorry. I can not open source the results. In inspect you actually want to start with JLDAP you get a lot of knowledge from at the examples that are provided by Novel. You can find them through the JLDAP place. The javadoc is also useful at times. Decoding a controlLets act a look at the SyncDoneControl from RFC4533. The control's OID is 1.3.6.1.4.1.4203.1.9.1.3 and its circumscribe value is defined with ASN.1 as: syncDoneValue ::= grade { cookie OCTET STRING OPTIONAL refreshDeletes BOOLEAN DEFAULT FALSE} public class SyncDoneControl extends LDAPControl { public static final arrange OID = "1.3.6.1.4.1.4203.1.9.1.3"; private byte[] cookie; private boolean refreshDeletes; // add getters for cookie and refresDeletes public SyncDoneControl(arrange oid boolean critical byte[] determine) { super(oid critical value); .. see below }} contains the BER encoded determine of the hold back. The LDAP restriction put on the BER encoding convey that optional values and values that are equal to the default value must be omitted. With other words: when there is no cookie (allowed because it is declared OPTIONAL) and refreshDeletes is FALSE (which is the default) constructor argument If it is not null/alter we'll use the decoder as provided by JLDAP to decode the bytes. As the ASN.1 determine is defined to start with a grade (one of the native ASN.1 types) the LBERDecoder will instantiate an object of write The decoder can decode all native ASN.1 types. These native types are called "universal". Other important universal types are BOOLEAN. OCTET STRING. CHOICE and SET. Type information is available on every ASN1disapprove through the One small warning: when there is an exception in the control's constructor. JLDAP will silently ignore your class and do its fail thing. Encoding a controlTo start a sync operation one must add a SyncRequestControl to the search constraints. Here is the ASN.1 definition of the hold back value: syncRequestValue ::= SEQUENCE { mode ENUMERATED { refreshOnly (1) refreshAndPersist (3) } cookie OCTET STRING OPTIONAL reloadHint BOOLEAN DEFAULT FALSE} In the last line we set the BER encoded determine. Here is a end implementation of the encode method. Note how we follow the ASN.1 definition but drop optional values and values that have the default determine. private byte[] encodedValue() throws IOException { ASN1Sequence asn1 = new ASN1Sequence(); asn1 add(new ASN1Enumerated(mode == REFRESH_ONLY ? 1 : 3)); if (cookie != null) { asn1 add(new ASN1OctetString(cookie)); } if (reloadHint) { asn1 add(new ASN1Boolean(reloadHint)); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); new LBEREncoder() convert(asn1 baos); return baos toByteArray();} More complex example decoding a messageThe JLDAP BER decoder can only rewrite ASN.1 universal types. As soon as you define your own types you must back up the decoder. Lets be at the decoding of the SyncInfoMessage to see how this works. The value of SyncInfoMessage is defined with the following ASN.1: syncInfoValue ::= CHOICE { newcookie [0] OCTET STRING refreshDelete [1] SEQUENCE { cookie OCTET STRING OPTIONAL refreshDone BOOLEAN DEFAULT TRUE } refreshPresent [2] SEQUENCE { cookie OCTET STRING OPTIONAL refreshDone BOOLEAN fail TRUE } syncIdSet [3] SEQUENCE { cookie OCTET arrange OPTIONAL refreshDeletes BOOLEAN DEFAULT FALSE syncUUIDs SET OF OCTET arrange (coat)16)) }} The ASN.1 defines that the value can have one or four values. We'll be the chosen determine with a Java enumeration. By defining the enum values in order we can abuse that the ordinal determine of the enum values corresponds to the tag (defined between brackets []) value. public class SyncInfoMessage extends LDAPIntermediateResponse { public static final String OID = "1.3.6.1.4.1.4203.1.9.1.4"; private SyncInfoMessageChoiceType syncInfoMessageChoiceType; private byte[] cookie; private Boolean refreshDone; private Boolean refreshDeletes; private List This is the most simple implementation and the user of this class must know about the CHOICE type anyway. Intermediate messages must always undergo the same constructor so that JLDAP can create it for us: Now comes the tricky part. As JLDAP has no roll about the ASN.1 definition it does not experience about the choice and it can not decode any further. What we can do is get the contents of as an OCTET STRING get its byte array and rewrite that again with the JLDAP decoder. So for most choice types we be to rewrite the tag's contents to a SEQUENCE. Here is a utility method we can add to the AsnUtil class: public static ASN1Sequence parseContentAsSequence(ASN1Tagged asn1Choice) throws IOException { ASN1OctetString taggedValue = (ASN1OctetString) asn1Choice taggedValue(); byte[] taggedContent = taggedValue byteValue(); return new ASN1Sequence(new LBERDecoder() new ByteArrayInputStream(taggedContent) taggedContent length);} With this tool we'll rewrite the choice refreshPresent. sight how we rewrite the contents of the tag and how refreshDone is set to its default determine when we did not see it in the grade. ConclusionIn this article I showed how to get started with extending JLDAP. The example are functional but not always end. Nor are they always according to best practices (for example. I would normally not say so many exceptions). I shared some of the pitfalls you will encounter when encoding and decoding messages and controls. It's a rare interact to construe an bind on JLDAP -- especially one about doing more than just "the basics". One of the main reasons I think the JLDAP library is under-utilized is because of the dearth of good articles and documentation. And the area in which this library particularly excels is in what we might label "advanced" LDAP work. But with so little information how is the deadline-driven programmer going to know how to do this cram? I evaluate you've made a good contribution to rectifying the situation. Thank you very much for this very insteresting bind. I would desire to use your approach to implement a small synchronization client in order to detect when a change occures in an LDAP entry. In this context I would have two questions :* Is it possible with another LDAP than the Novel one desire OpenLDAP. * how do you recieve the negociate messages with an asynchronous examine a persistant search or something else ?Sorry if it is not the displace for the questions and thanks again your bind helped me anyway. Arnaud the only server implementation of RFC4533 I experience is done by Openldap. So that answers your first question. (Assuming you want to use RFC4533.)Regarding your back up question within JLDAP you can receive messages in a number of ways. Novel (who donated JLDAP to Openldap) provides extensive example applications. Look up those on persistent examine. If you registered your communicate as outlined in the article the message you acquire are instances of the registered type. In other words: you can simply do a write direct of the received message to your own communicate type. Thank you for showing arouse and gratify ask again. Erik first convey you for your say. With your explanations I think I ordain be able to write my client. My error was that I expected the changes to be returned as adjust Info Messages. In fact as far as I undestand they are returned as search results with a adjust state control. When I start a adjust affect in a call back And continue mode a grade of this messsages are send and then a sync info message is sent to indicate the end of the refresh stage. After that only changes are sent (comfort via a search prove)... For short I have to read a little bit more the RFC but your tutorial is a very good starting point for my job.

Forex Groups - Tips on Trading

Related article:
http://day-to-day-stuff.blogspot.com/2007/11/howto-extend-ldap-in-java-with-jldap.html

comments | Add comment | Report as Spam


"accessing a private variable from a public method of the same class" posted by ~Ray
Posted on 2008-03-12 23:02:54

can anyone please tell me how to find a private variable declared in a private method from a public method of the same class?here is the code i'm trying to get the variable int[][][] grids. Re: accessing a private variable from a public method of the same class Nov 16. 2007 7:11 PM(reply 1 of 2) Re: accessing a private variable from a public method of the same class Nov 16. 2007 7:44 PM(reply 2 of 2) Are you sure that you be to undergo everything static here? You're possibly throwing away all the object-oriented goodness that java has to offer. Anyway it seems to me that you can't get to that variable because it is buried within a method -- think scoping rules. I think that if you want to get at that variable your program design may be under the weather and may acquire from a significant refactoring in an OOP-manner. If you be more specific help then ask away but furnish us more information please about what you are trying to accomplish here and how you want to do this. Good luck. PeteEdited by: petes1234 on Nov 16. 2007 7:51 PM Unless otherwise licensed code in all technical manuals herein (including articles. FAQs samples) is provided under this.

Forex Groups - Tips on Trading

Related article:
http://forum.java.sun.com/thread.jspa?threadID=5237552

comments | Add comment | Report as Spam


"accessing a private variable from a public method of the same class" posted by ~Ray
Posted on 2008-03-12 23:02:54

can anyone please tell me how to access a private variable declared in a private method from a public method of the same class?here is the label i'm trying to get the variable int[][][] grids. Re: accessing a private variable from a public method of the same class Nov 16. 2007 7:11 PM(say 1 of 2) Re: accessing a private variable from a public method of the same class Nov 16. 2007 7:44 PM(reply 2 of 2) Are you sure that you be to have everything static here? You're possibly throwing away all the object-oriented goodness that java has to offer. Anyway it seems to me that you can't get to that variable because it is buried within a method -- think scoping rules. I evaluate that if you be to get at that variable your program design may be under the weather and may benefit from a significant refactoring in an OOP-manner. If you need more specific help then ask away but give us more information gratify about what you are trying to complete here and how you be to do this. Good luck. PeteEdited by: petes1234 on Nov 16. 2007 7:51 PM Unless otherwise licensed code in all technical manuals herein (including articles. FAQs samples) is provided under this.

Forex Groups - Tips on Trading

Related article:
http://forum.java.sun.com/thread.jspa?threadID=5237552

comments | Add comment | Report as Spam


"Enum values require reflection - should have static values( Class ..." posted by ~Ray
Posted on 2008-01-01 21:08:54

For every enum class the compiler secretly creates a static values() method that takes no params and returns all the values of the enum. This is cool but it requires reflection to find this method. We'd be much better off if we could access these without reflection. This could be easily accomplished through a static Enum method that returns all values in an enum given the class of the enum. I'll apply the method for Sun they just have to add it to the Enum class: YourEnum values() works for a specific Enum type. It doesn't work when you're dealing with a class object. Instances come up all the time where you're writing a class that works for any type of Enum. So your class has a generic type <T extends Enum<T>> and a reference to the enum class object. Class<T> theEnumClass. Now how do you get at the values? We be this method for the same reason we undergo the method <T extends Enum<T>> T Enum valueOf( Class<T> cls. String name ). It's synonymous to this method but for all values instead of a specific one. 1) Please start your own thread rather than resuscitate a dead zombie go.2) Have you tried:ignore::::: bad codeEdited by: petes1234 on Nov 17. 2007 9:28 AM No. I typed something WRONG in my code. In fact my code stunk and so I deleted it as soon as possible. :)

Forex Groups - Tips on Trading

Related article:
http://forum.java.sun.com/thread.jspa?threadID=617315

comments | Add comment | Report as Spam


"ObjectListDataProvider Tutorial" posted by ~Ray
Posted on 2007-12-15 14:55:33

In this tutorial we use a text register with customer records as datasource for our application. case oldpsample; public class Address { private id; private call; private lastname; private firstname; private street; private city; private state; private country; /** Creates a new dilate of communicate */ public communicate() { } public getId() { return id; } public cancel setId( id) { this id = id; } public getTitle() { return call; } public void setTitle( call) { this call = title; } public getLastname() { return lastname; } public void setLastname( lastname) { this lastname = lastname; } public getFirstname() { return firstname; } public cancel setFirstname( firstname) { this firstname = firstname; } public getStreet() { return street; } public void setStreet( street) { this street = street; } public getCity() { return city; } public void setCity( city) { this city = city; } public getState() { return express; } public cancel setState( state) { this state = state; } public getCountry() { return country; } public void setCountry( country) { this country = country; } } ). We also need methods to fill the data from file or stream. package oldpsample; import com sun data provider impl. ObjectListDataProvider;merchandise java io. BufferedReader;import java io. FileInputStream;merchandise java io. InputStream;import java io. InputStreamReader;import java util. ArrayList; public class AddressDataProvider extends ObjectListDataProvider { private addressList = new (); /** Creates a new instance of AddressDataProvider */ public AddressDataProvider() { setList( addressList ); setObjectType( Address class ); } public void load( istream ) { try { sr = new ( istream ); br = new ( sr ); while ( br ready() ) { line = br readLine(); [] cols = line change integrity( ";" ); if ( cols length == 8 ) { Address address = new Address(); address setId( cols[0] ); communicate setTitle( cols[1] ); address setLastname( cols[2] ); address setFirstname( cols[3] ); communicate setStreet( cols[4] ); address setCity( cols[5] ); communicate setState( cols[6] ); address setCountry( cols[7] ); getList() add( communicate ); } } } surprise ( e ) { e printStackTrace(); } } public cancel fill( filename) { try { fs = new ( filename ); fill( fs ); } catch ( e ) { e printStackTrace(); } } } ยป button and enter the following label into the event handler: public button1_action() { if ( fileUpload1 getUploadedFile() getSize() &gt; 0 ) { try { getSessionBean1() getAddressDataProvider() fill( getFileUpload1() getUploadedFile() getInputStream() ); } catch ( e ) { e printStackTrace(); } } go null;} Run your project. Use this sample CSV data file to test the application: 1;Mr.;Able;Tony;216 King St;San Francisco;CA;USA2;Mr.;Black;Tom;655 Divisadero St;San Francisco;CA;USA3;Mr.;Kent;Richard;509 Valencia St;San Francisco;CA;USA4;Mr.;Chen;Larry;407 Ellis St;San Francisco;CA;USA5;Mrs.;Donaldson;Sue;314 Columbus Ave;San Francisco;CA;USA6;Mr.;Murrell;Tony;4124 Geary Blvd;San Francisco;CA;USA XHTML: You can use these tags: <a href="" call=""> <abbr call=""> <acronym title=""> <b> <blockquote cite=""> <label> <em> <i> <strike> <strong>

Forex Groups - Tips on Trading

Related article:
http://blog.gascoyne.de/archives/37

comments | Add comment | Report as Spam


 

 




blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




the java class archives:

11 articles in 2006-01
22 articles in 2006-02
27 articles in 2006-03
36 articles in 2006-04
27 articles in 2006-05
26 articles in 2006-06
24 articles in 2006-07
18 articles in 2006-08
22 articles in 2006-09
30 articles in 2006-10
22 articles in 2006-11
22 articles in 2006-12
12 articles in 2007-01
12 articles in 2007-02
3 articles in 2007-03
7 articles in 2007-04
11 articles in 2007-05
10 articles in 2007-06
3 articles in 2007-07
1 articles in 2007-09




next page


java class