Friday, December 4, 2009

Enable Syntax Highlighter on JRoller

Howto to enable syntax Highlighter on jroller with alex gorbatchev code syntax Highlighter

1)Preferences->Templates->Weblog->Edit
Put at the end of the template, your preferred list of "brushes" like java, xml scala and others.

after import the gorbatchev css













Note:2.1.364 is latest version, feel free to change version

2)Go to Preferences->Formatting
Uncheck Convert Line Breaks and Emoticons

3)When create an entry (with simple text editor), go to plugin to apply at the end of the page
and unchecked Convert Line Breaks and Emoticons

That's all.
Happy coding.

Spring Aspect Oriented Programming Errata

Right Versions

Before Advice pag 146


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">















BankAccountAspect pag. 165
package org.springaop.chapter.five.concurrent;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springaop.utils.Constants;

@Aspect
public class BankAccountAspect {

@Pointcut("execution(* org.springaop.chapter.five.concurrent.BankAccount.getBalance())")
public void safeRead() {}

@Pointcut("execution(* org.springaop.chapter.five.concurrent.BankAccount.creditOperation(*,*)) ")
public void stateModificationCredit() {}

@Pointcut("execution(* org.springaop.chapter.five.concurrent.BankAccount.debitOperation(*,*)) ")
public void stateModificationDebit() {}

@Pointcut("execution(* org.springaop.chapter.five.concurrent.BankAccount.getId())")
public void getId() {}

@Pointcut("execution(* org.springaop.chapter.five.concurrent.BankAccount.getStartDate())")
public void getStartDate() {}

@Before("safeRead()")
public void beforeSafeRead() {
if (log.isInfoEnabled()) {
log.info("setReadLock");
}
rLock.lock();
}

@After("safeRead()")
public void afterSafeRead() {
rLock.unlock();
if (log.isInfoEnabled()) {
log.info("releaseReadLock");
}
}

@Before("stateModificationCredit() || stateModificationDebit()")
public void beforeSafeWrite() {
if (log.isInfoEnabled()) {
log.info("setWriteLock");
}
wLock.lock();
}

@After("stateModificationCredit() || stateModificationDebit()")
public void afterSafeWrite() {
wLock.unlock();
if (log.isInfoEnabled()) {
log.info("releaseWriteLock");
}
}

private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final Lock rLock = lock.readLock();
private final Lock wLock = lock.writeLock();
private Logger log = Logger.getLogger(Constants.LOG_NAME);
}


BankAccount pg. 167

package org.springaop.chapter.five.concurrent;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springaop.utils.Constants;

public class BankAccount {

public BankAccount(){
this.id = 0;
this.balance = new Float(0);
this.startDate = new Date();
}

public BankAccount(Integer id) {
this.id = id;
this.balance = new Float(0);
this.startDate = new Date();
}

public BankAccount(Integer id, Float balance) {
this.id = id;
this.balance = balance;
this.startDate = new Date();
}

public BankAccount(Integer id, Float balance, Date start) {
this.id = id;
this.balance = balance;
this.startDate = start;
}

public boolean debitOperation(Float debit, Float balance) {
if (balance < debit) {
return false;
} else {
setBalance(balance - debit);
return true;
}
}

public void creditOperation(Float credit, Float balance) {
setBalance(balance+ credit);
}


private void setBalance(Float balance) {
if (log.isInfoEnabled()) {
log.info("setBalance");
}
this.balance = balance;
}

public Float getBalance() {
if (log.isInfoEnabled()) {
log.info(balance);
}
return balance;
}

public Integer getId() {
return id;
}

public Date getStartDate() {
return (Date) startDate.clone();
}

private Float balance;
private final Integer id;
private final Date startDate;
private Logger log = Logger.getLogger(Constants.LOG_NAME);
}