glassfish jms, adding users

I was having issues when changing JMS queue factory username password (only admin and guest user worked, other clients couldn't connect, failing on invalid username password). I checked Sun forums but there was no help in there, so, last thing that I could do is read documentation where you can find how to add user / pass:

 glassfish/imq/bin:~$ ./imqusermgr add -u USER_NAME -p PASSWORD -g user
	

USER_NAME and PASSWORD of your choice, and I believe group part (-g user) is optional.

Password file is stored in:

 glassfish/domains/domain1/imq/instances/imqbroker/etc/passwd
	

It may be obvious, but I never had to deal with JMS before, so it may help someone.

stripes jquery validation example

See also Stripes validation reference

/**
 *
 * Jquery addapter class so we can use built in Jquery validator.
 * NOTE: this is only skeleton, implementing only small part of possible validation,
 * Usage:
 * <s:field-metadata var="metaData">
 *   $(function(){$.fn.stripesValidation('${metaData.formId}', ${metaData});});
 * </s:field-metadata>
 * dependancies:
 * jquery.1.3.1
 * jquery.form
 * jquery.validate
 * Licence:
 * Same as jquery, thus:
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 */
(function($){

    /**
     * Processess Stripes meta data and converting it so jquery
     * validation plugin is used for client side validation
     * @param formId id of a form to be processed
     * @param metaData metadata that is produced by stripes tag
     */
    $.fn.stripesValidation = function(formId, metaData){
        var form = $('#' + formId);
        var idCount = 0;
        for(var fieldName in metaData){
            var field = form.find('[name=' + fieldName + ']');
            addValidation(field, metaData[fieldName]);
            // run validation:
            form.validate();
        }
        function addValidation(field, obj){
            for(var prop in obj){
                var val = obj[prop];
                switch(prop){
                    case 'label':
                        break;
                    case 'required':
                        if(val){ // add only if true
                            field.addClass(prop);
                        }
                        break;
                    case 'minlength': // should  already be there
                    case 'maxlength': // should already be there
                        field.attr(prop, val);
                        break;
                    case 'minvalue':
                        field.attr('min', val);
                        break;
                    case 'maxvalue':
                        field.attr('max', val);
                        break;
                    case 'mask':
                        setMask(field, val);
                        break;
                    case 'typeConverter':
                        setConverter(field, val);
                        break;
                    default:
                        debug('missing this:' + prop + ':' + val);
                }
            }
        }

        /**
         * Adds regular expression validation
         * @param field field reference
         * @param mask regular expression mask
         */
        function setMask(field, mask){
            idCount++;
            var methodRef = 'maskMethod' + idCount;
            field.addClass(methodRef);
            $.validator.addClassRules({
                methodRef: {
                    methodRef: true
                }
            });
            $.validator.addMethod(methodRef, function (value){
                return mask.test(value);
            }, 'Value is invalid');
        }

        /**
         * Add converter mappings
         * @param field  field reference
         * @param converter converter used by stripes for given field
         */
        function setConverter(field, converter){
            if(converter == 'EmailTypeConverter'){
                field.addClass('email');
            }
            else if(converter =='DateTypeConverter'){                
                field.addClass('date');
                if($.fn.datepicker){field.datepicker();}
            }
            else{
                debug('missing converter mapping:' + converter);
            }
        }

        function debug(msg){
            if(window.console && window.console.log){
                window.console.log(msg);
            }
        }
    };
})(jQuery);

	
chess code samples

I am trying to learn ActionScript 3 / Flex 3 bit more, so I'll redo my old chess interface (actionscript 2 GUI) completely in AS3.

Because I am not building move engine (it is human vs human only, through XMPP protocol), I decided to skip bitboard stuff and go with 0x88 implementation, below are some code samples (can be useful for someone, soon I'll add more):

	/**
	* Is field on our chess board?
	* @param value integer value of field
	* @return  true if field is 'visible' field (on chessboard), false otherwise.
	*/
	public static function isOnBoard(value:int):Boolean{
		return (value & 0x88) == 0;
	}

	/**
	 * Given field value, returns row
	 * @param value integer value of an field
	 * @return
	 */
	private function valueToRow(value:int):int{
		return (value >> 4);
	}

	/**
	 * Given field value, returns column
	 * @param value integer value of an field
	 * @return
	 */
	private function valueToColumn(value:int):int{
		return (value & 7);
	}

I cleaned up this method a bit because it had some additional logic which is specific for my case, so hopefully I did it(cleanup) right ;-).

Note: this method calls processValidmoves(Array) method, which does additional checks (e.g. enpassant, check position etc.)

    /**
     * When a chess piece is clicked, hi-light 
     * all possible fields this piece can jump.
     * This also processes *repeatable* pieces (like Bishop for example [15, -15, 17, -17])
     */
    private function showPath():void{        
        var moves:Array = new Array();
        var repeatable_piece:Boolean = isRepeatable();
        outerLoop:
                for(var i:int = 0; i < validMoves.length; i++){
                    var move:int = validMoves[i];
                    var val:int = move + field.value;
                    if(isOnBoard(val)){
                        var f:Field = board.fields[Def.getFieldIndexForValue(val)];
                        if(f.hasPiece()){
                            // cannot jump unto own piece:
                            if(f.getPiece().white == this.white){
                                continue;
                            }
                        }
                        moves.push(val);
                        // check for repeatable and repeate till on board or while occupied field is hitted:
                        if(repeatable_piece){
                            var repeatable:int = val + move;
                            while(isOnBoard(repeatable)){
                                // check if field is free:
                                f = board.fields[Def.getFieldIndexForValue(repeatable)];
                                if(f.hasPiece()){
                                    if(f.getPiece().white == this.white){
                                        continue outerLoop;
                                    }
                                    // oposite color, we can jump to that one, but not further
                                    moves.push(repeatable);
                                    continue outerLoop;
                                }
                                moves.push(repeatable);
                                repetable += move;
                            }
                        }
                    }
                }
        // got our moves, now process it.
        processValidmoves(moves);

    }
    
    /** 
    * just checks if moves are repeatable. 
    * e.g. pawn, king or knight have none repeatable moves 
    */
    private function isRepeatable():Boolean{
        return this.type != Def.BISHOP || this.type == Def.ROOK || this.type == Def.QUEEN;
    }

 

©2009 m.milicevic