The Space For App Developers

Beyond Plain Old HTML Objects

Archive for December, 2009

LogProcessor – custom metadata processor for Swiz 1.0.0

with 7 comments

Just recently Swiz 1.0.0 alpha was released. Essentially it is rewrite of Swiz itself but it also brings new cool features. One of the features that I really like the most is the ability to define Custom Metadata Processors. It allows you to define your own metadata and have it wired into your code with the same mechanism that [Autowire] and [Mediate] are implemented by Swiz. I decided to give it a try by building a very simple LogProcessor that injects preconfigured ILogger from Flex API based on [Log] metadata.

The usage of this custom metadata looks like this:

[Log]
public var log:ILogger;
 
private function someFunction():void
{
    log.debug("someFunction was called!");
}

Here is the code of my LogProcessor. The addMetadata function actually does the job:

package processors
{
  import mx.logging.Log;
  import mx.logging.LogEventLevel;
  import mx.logging.targets.TraceTarget;
 
  import org.swizframework.core.Bean;
  import org.swizframework.processors.MetadataProcessor;
  import org.swizframework.reflection.IMetadataTag;
 
  public class LogProcessor extends MetadataProcessor
  {
 
    private static var traceTarget:TraceTarget;
 
    public function LogProcessor(level:int = LogEventLevel.ALL, filters:Array = null, includeDate:Boolean = true, includeTime:Boolean = true, includeCategory:Boolean = true, includeLevel:Boolean = true)
    {
      super("Log");
 
      if (LogProcessor.traceTarget == null)
      {
        LogProcessor.traceTarget = new TraceTarget();
 
        LogProcessor.traceTarget.level = level;
        LogProcessor.traceTarget.filters=filters;
        LogProcessor.traceTarget.includeDate = includeDate;
        LogProcessor.traceTarget.includeTime = includeTime;
        LogProcessor.traceTarget.includeCategory = includeCategory;
        LogProcessor.traceTarget.includeLevel = includeLevel;
 
        Log.addTarget(LogProcessor.traceTarget);
      }      
 
    }
 
    /**
     * Assign ILogger instance
     */
    override public function addMetadata(bean:Bean, metadata:IMetadataTag):void
    {
      // bean.typeDescriptor.className returns class name in packages::ClassName notation
      // that is not accepted by Log.getLogger function, returning only ClassName string 
      var className:String = bean.typeDescriptor.className;
      className = className.substr(className.lastIndexOf(":") + 1);
 
      // Setting Logger
      bean.source[ metadata.host.name ] = Log.getLogger(className);
    }
 
    /**
     * Remove ILogger instance
     */
    override public function removeMetadata(bean:Bean, metadata:IMetadataTag):void
    {
      bean.source[ metadata.host.name ] = null;
    }
 
    public function set level(value:int):void
    {
      LogProcessor.traceTarget.level = value;
    }
 
    public function set filters(value:Array):void
    {
      LogProcessor.traceTarget.filters = value;
    }
 
    public function set includeDate(value:Boolean):void
    {
      LogProcessor.traceTarget.includeDate = value;
    }
 
    public function set includeTime(value:Boolean):void
    {
      LogProcessor.traceTarget.includeTime = value;
    }
 
    public function set includeCategory(value:Boolean):void
    {
      LogProcessor.traceTarget.includeCategory = value;
    }
 
    public function set includeLevel(value:Boolean):void
    {
      LogProcessor.traceTarget.includeLevel = value;
    }
 
  }
}

Written by Piotr Walczyszyn

December 16th, 2009 at 12:15 pm

Posted in Uncategorized

Configuring Eclipse PDT and Flash Builder 4 Plug-in for PHP/Flex development

with 6 comments

In this tutorial I will explain how to configure a development environment to work with PHP and Flex projects in one tool. In order to do that I will use Eclipse PDT 2.1 (PHP Eclipse plugin), Flash Builder 4 Plug-in Beta 2 and the latest Eclipse IDE for Java EE Developers package, which is eclipse-jee-galileo-SR1-macosx-carbon (of course if you are on Windows you should get the proper Windows version instead) at the moment. Additionally I will use MAMP (Mac, Apache, MySQL, PHP stack), of course there are other possible solutions like WampServer for Windows, multiplatform XAMPP, or Zend Server.

Download links:

- Eclipse IDE for Java EE Developers – http://www.eclipse.org/downloads/

- Eclipse PDT 2.1 (pdt-Update-2.1.2.zip) – http://www.eclipse.org/pdt/downloads/

- Java SE Development Kit (JDK 6 Update 17 – at the moment) – http://java.sun.com/javase/downloads/index.jsp

- Flash Builder 4 Plug-in Beta 2 – https://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4 (you need to login with a free Adobe ID account)

- ZendDebugger (download latest version depending your operating system) – http://downloads.zend.com/pdt/server-debugger/

- MAMP, WAMP, XAMPP, or Zend Server
http://www.mamp.info/
http://www.wampserver.com/
http://www.apachefriends.org/en/xampp.html
http://www.zend.com/en/products/server-ce/

Installation steps:

Step 1) Start with Eclipse IDE for Java EE Developers installation, it is as simple as unpacking it to some folder on your drive. If you are on Windows make sure you have the JDK (Java Development Kit) installed on your system. Without that Eclipse will not run.

Step 2) Run Eclipse from the folder you installed it in. A clean installation will start with welcome screen; select Workbench option in the right upper corner to go directly to the development environment.

Step 3) Install PDT 2.1 as described in the following section of the PDT installation wiki: http://wiki.eclipse.org/PDT/Installation#Eclipse_3.5_.2F_Galileo_.2F_PDT_2.1

IMPORTANT DON’T INSTALL PDT 2.2 AT THE MOMENT as it has some bugs that are causing PHP scripts to crash. Go to the link  at the top and download one marked on a picture below (pdt-Update.2.1.2.zip):

pdt-download-link
As described in the wiki link above, in Eclipse go to Help > Install New Software… > Add… > Name: PDT, Location: jar:file:/path/to/pdt-Update-2.1.2.zip!/

pdt-Update.zip
Step 4) Install Flash Builder 4 Plug-in Beta 2 pointing to the Eclipse installation that was unpacked earlier, as shown below:eclipse-fb4

Step 5) Now you are ready to run your PHP/Flex development environment. Just remember NOT TO run it with the links provided by the Flash Builder 4 Plug-in installation. IMPORTANT: Directly start Eclipse from the folder you unpacked it into.

You can switch to the PHP or Flash perspective in upper right corner of your Eclipse Workbench by selecting it from the list in the Other option.

swith-perspective

Step 6) Install the Apache, MySQL, PHP stack. Unpack ZendDebugger downloaded from one of the links above. Follow the instructions in README file to install it on your system.

Alternatively you can use ZendExtensionManager and configure it this way in your php.ini file:

zend_extension_manager.debug_server=/Applications/MAMP/bin/php5/zend/lib/ZendDebugger-5.2.15
zend_debugger.allow_hosts=127.0.0.1
zend_debugger.expose_remotely=always

IMPORTANT: ZendDebugger-5.2.15 is the unzipped ZendDebugger package and its subfolders need to be renamed to follow this schema: php-5.2.x. For example: 5_2_x_comp => php-5.2.x

Just remember to drop dummy.php into your website public root folder on your dev environment.

Step 7) Create your PHP project and give it a Flex Project nature by right clicking on your PHP project and selecting option Add/Change Project Type > Add Flex Project Type. This way you can have all your code in one single project. Of course you can have two separate projects for PHP and Flex but this is your decision. Do what will be more convenient for you.

flex-nature

And now you can Rock & Roll with PHP and Flex!

Written by Piotr Walczyszyn

December 3rd, 2009 at 12:44 pm

Posted in Articles

Tagged with , ,

Wywiad ze mną na UMK

without comments

Zachęcam wszystkich do obejrzenia wywiadu ze mną poprowadzonego przez Macieja Pańkę z Uniwersytetu Mikołaja Kopernika! Dodatkowo na tej samej stronie dostępna jest transmisja wykładu w ramach Flex Challenge Academic Tour odbywającego się właśnie na UMK w Toruniu.

http://www.ucntn.umk.pl/inne,flexchallenge

Written by Piotr Walczyszyn

December 2nd, 2009 at 4:11 pm

Posted in Events

Tagged with