"; */ ?>


09
Sep 10

Check If The Aspect Was Applied

Let’s say you have an aspect defined that will be applied to a class:

<bean id="someComponent"
      class="org.dotkam.SomeComponent" />
 
<aop:config>
	<aop:aspect ref="someAspect">
		<aop:around method="someMethod"
                            pointcut="execution(public * org.dotkam.SomeComponent.*(..))" />
	</aop:aspect>
</aop:config>

and you of course have “proxy-target-class” set to “true”:

<aop:aspectj-autoproxy proxy-target-class="true"/>

Here is how to check if the aspect was applied:

import static org.junit.Assert.assertTrue;
import net.sf.cglib.proxy.Enhancer;
 
  ... ...
@Resource(name="someComponent")
SomeComponent someComponent
 
  ... ...
assertTrue( Enhancer.isEnhanced( someComponent.getClass() ) );

Behind the scenes it is enhanced with CGLIB’s Enhancer that has a convenient isEnhanced method.

Useful when developing aspects.

NOTE: The above is true given, of course, that this is THE ONLY aspect applied to this component.


08
Sep 10

Convert String to Map in PHP

Let’s say I would like to have a PHP line:

image( "src => images/logo.png", "class => right", "alt => Company Logo" );

to generate a full blown HTML <img> tag:

<img src="http://www.dotkam.com/images/company-logo.png" class="right" alt="Company Logo">

For this I would need to translate these three function parameters:

"src => images/logo.png", "class => right", "alt => Company Logo"

into a MAP ( yes, PHP calls it an array, but it is in fact a MAP ):

imageTag (
    'src' => 'images/logo.png'
    'class' => 'right'
    'alt' => 'Company Logo'
)

Here is how it is done:

function image( ) {
 
    $validAttributes = array( 'src', 'class', 'alt' );
 
    foreach ( func_get_args() as $attr ) {
    	$attrMap = explode( ' => ', $attr ); 
    	if ( in_array( $attrMap[0], $validAttributes ) ) {
    		$imageAttrMap[ $attrMap[0] ] = $attrMap[1];
    	}
    	else {
    	    die( 'Configuration Problem: ['.$attrMap[0].'] is not a valid &lt;img&gt; attribute.' );
    	}
    }
 
    // .... validate 'src' is there, append imgTag string with all the attrs, echo it...
}

26
Aug 10

Cannot Start Microsoft Outlook. Cannot Open the Outlook Window

Sometimes I have to work on Windows boxes… Here is the fix:

C:\Program Files\Microsoft Office\Office12>outlook.exe /resetnavpane

26
Aug 10

Tomcat: Add Memory

sudo vi /usr/share/tomcat6/bin/catalina.sh

At the beginning of the file, after initial comment block add:

# setting JAVA_OPTS to perform
JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=384m -Xss128k"

Restart tomcat:

sudo service tomcat6 restart

26
Aug 10

Clean Hudson Workspace Before Build

In order to clean/delete the workspace before the build, “Add Build Step”, select “Execute Shell”, and use Hudson $WORKSPACE variable to delete the target directory:

rm -rf $WORKSPACE/target/*

Here is what it will look like:

clean hudson workspace before build

built-in support is on the way: HUDSON-3966