The base for the Cairngorm code creation is defined in the @Cairngorm annotation.
Several default values are set, as knwon from the Cairngorm sample applications and its documentation.
To create a working CairngormConfig implementation, create a Java class and name it CairngormConfig.java within the root directory of your desired cairngorm java package.
Next, annotate CairngormConfig.java with the @Cairngorm annotation and set the required annotation values.
package de.aixcept.flex2.cairngorm;
import de.aixcept.flex2.annotations.*;
@Cairngorm(
projectName = "MyProject",
businessDelegates = @BusinessDelegates(
values = {
@BusinessDelegate(name = "Foo")
}
),
commands = @Commands(
commandWithoutDelegates = {
@CommandWithoutDelegate(name = "Bar")
},
commandWithDelegates = {
@CommandWithDelegate(name = "Foo", delegate = "Foo", event = "MyFoo")
}
),
events = @Events()
)
public class CairngormConfig {
}All Cairngorm ActionScript class are only created if not yet existant. You should be safe, to add your custom implementation into the generated ActionScript files.
Starting from the cairngorm root directory, the configured packages are being created.
Starting from de.aixcept.flex2.cairngorm, the business, command, control, event, model, vo and view
packages and its required directories get created.
Creating directory... de/aixcept/flex2/cairngorm/business
Creating directory... de/aixcept/flex2/cairngorm/command
Creating directory... de/aixcept/flex2/cairngorm/control
Creating directory... de/aixcept/flex2/cairngorm/event
Creating directory... de/aixcept/flex2/cairngorm/model
Creating directory... de/aixcept/flex2/cairngorm/vo
Creating directory... de/aixcept/flex2/cairngorm/viewThis file will be generated on every build. So you should not edit it in any case.
FooDelegate.as
/*
* File: FooDelegate.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.business
{
import de.aixcept.flex2.cairngorm.business.Services;
import com.adobe.cairngorm.business.ServiceLocator;
import mx.rpc.IResponder;
import mx.rpc.AsyncToken;
public class FooDelegate
{
private var responder : IResponder;
public function FooDelegate(responder : IResponder)
{
this.responder = responder;
}
}
}File: Services.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* File: Services.mxml
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
-->
<cairngorm:ServiceLocator xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:cairngorm="com.adobe.cairngorm.business.*" >
<mx:Script>
<![CDATA[
public static const SERVICE : String = "service";
]]>
</mx:Script>
</cairngorm:ServiceLocator>BarCommand.as
/*
* File: BarCommand.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.command
{
import com.adobe.cairngorm.commands.ICommand;
import com.adobe.cairngorm.control.CairngormEvent;
import de.aixcept.flex2.cairngorm.event.BarEvent;
public class BarCommand implements ICommand
{
public function BarCommand()
{
}
public function execute(event : CairngormEvent):void
{
var evt : BarEvent = event as BarEvent;
}
}
}File: FooDelegateCommand.as
/*
* File: FooDelegateCommand.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*
* Implementation Details
* ======================
* Why we use the mx.rpc.IRsponder interface instead of Cairngorm's Responder interface
*
* o IResponder ships with the Flex 2 framework
* o IResponder integrates well with other classes in the mx.rpc package, specifically AsyncToken
* o IResponder allows multiple responders to act on the return value of a remote service call
* o Cairngorm's Responder requires some "hard-wiring" and isn't as type-safe (which makes it more error prone)
*
* See http://www.darronschall.com/weblog/archives/000234.cfm for more details
*
*/
package de.aixcept.flex2.cairngorm.command
{
import com.adobe.cairngorm.commands.ICommand;
import com.adobe.cairngorm.control.CairngormEvent;
import de.aixcept.flex2.cairngorm.business.FooDelegate;
import de.aixcept.flex2.cairngorm.event.FooEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.AsyncToken;
import mx.rpc.IResponder;
public class FooDelegateCommand implements ICommand, IResponder
{
public function FooDelegateCommand()
{
}
public function execute(event : CairngormEvent):void
{
var evt : FooEvent = event as FooEvent;
var delegate : FooDelegate = new FooDelegate( this );
}
public function result(data : Object):void
{
var result : ResultEvent = data as ResultEvent;
}
public function fault(info : Object):void
{
var fault : FaultEvent = info as FaultEvent;
}
}
}File: MyProjectController.as
/*
* File: MyProjectController.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.control
{
import com.adobe.cairngorm.control.FrontController;
import de.aixcept.flex2.cairngorm.command.*;
import de.aixcept.flex2.cairngorm.event.*;
public class MyProjectController extends FrontController
{
public function MyProjectController()
{
this.initialize();
}
private function initialize() : void
{
this.addCommand(FetchDataEvent.FETCHDATA_EVENT, FetchDataCommand);
this.addCommand(StoreDataEvent.STOREDATA_EVENT, StoreDataCommand);
this.addCommand(FooEvent.FOO_EVENT, FooDelegateCommand);
this.addCommand(BarEvent.MYBAR_EVENT, BarDelegateCommand);
}
}
}File: FooEvent.as
/*
* File: FooEvent.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.event
{
import com.adobe.cairngorm.control.CairngormEvent;
public class FooEvent extends CairngormEvent
{
public static const FOO_EVENT : String = "<fooEvent>";
/**
* Constructor.
*/
public function FooEvent()
{
super( FOO_EVENT );
}
/**
* Override the inherited clone() method, but don't return any state.
*/
override public function clone() : Event
{
return new FooEvent();
}
}File: MyBarEvent.as
/*
* File: MyBarEvent.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.event
{
import com.adobe.cairngorm.control.CairngormEvent;
public class MyBarEvent extends CairngormEvent
{
public static const MYBAR_EVENT : String = "<myBarEvent>";
/**
* Constructor.
*/
public function MyBarEvent()
{
super( MYBAR_EVENT );
}
/**
* Override the inherited clone() method, but don't return any state.
*/
override public function clone() : Event
{
return new MyBarEvent();
}
}
}File: MyProjectModelLocator.as
/*
* File: MyProjectModelLocator.as
*
* Generated by aixcept Flex Annotations for Package: de.aixcept.flex2.cairngorm
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.model
{
import com.adobe.cairngorm.model.IModelLocator;
import com.adobe.cairngorm.CairngormError;
import com.adobe.cairngorm.CairngormMessageCodes;
[Bindable]
public class MyProjectModelLocator implements IModelLocator
{
/**
* Singleton instance of MyProjectModelLocator
*/
private static var instance : MyProjectModelLocator;
public function MyProjectModelLocator(access : Private)
{
if (access != null)
{
if (instance == null)
{
instance = this;
}
}
else
{
throw new CairngormError( CairngormMessageCodes.SINGLETON_EXCEPTION, "MyProjectModelLocator" );
}
}
/**
* Returns the Singleton instance of MyProjectModelLocator
*/
public static function getInstance() : MyProjectModelLocator
{
if (instance == null)
{
instance = new MyProjectModelLocator( new Private );
}
return instance;
}
}
}
/**
* Inner class which restricts contructor access to Private
*/
class Private {}The view package is only created as a directory, but no view releated files are created. You should place you view implementations here.
This package should contain your ValueObjects. Use the @ActionScript(valueObject = true) annotation on your Java Value Objects.
The following Java Value Object implementation is annotated with the correct annotation values as a sample
package de.aixcept.flex2.cairngorm.vo;
import de.aixcept.flex2.annotations.ActionScript;
import de.aixcept.flex2.annotations.ActionScriptProperty;
@ActionScript(valueObject = true)
public class TestVO {
private String name;
private Long id;
@ActionScriptProperty(read = true, write = true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ActionScriptProperty(bindable = true, read = true, write = true)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}The resulting ActionScript implementation looks like this:
File: TestVO.as
/*
* File: TestVO.as
*
* Generated by aixcept Flex Annotations from TestVO.java (Package: de.aixcept.flex2.cairngorm.vo).
*
* NOTE:
* This file is generated only if not existant.
* You may safely add your custom implementation code here.
*/
package de.aixcept.flex2.cairngorm.vo
{
/**
* <code>TestVO</code>
*/
[RemoteClass(alias="de.aixcept.flex2.cairngorm.vo.TestVO")]
public class TestVO extends TestVOBase
{
}
}File: TestVOBase.as
/*
* File: TestVOBase.as
*
* Generated by aixcept Flex Annotations from TestVO.java (Package: de.aixcept.flex2.cairngorm.vo).
*
* WARNING:
* DO NOT EDIT THIS FILE. EDIT THE INHERITED CLASS TestVO.as INSTEAD.
* THIS ACTIONSCRIPT FILE IS AUTOGENERATED AND WILL BE OVERRIDDEN ON EVERY BUILD!!!
*/
package de.aixcept.flex2.cairngorm.vo
{
import com.adobe.cairngorm.vo.IValueObject;
/**
* <code>TestVO</code>
*/
public class TestVOBase implements IValueObject
{
[Bindable]
private var _id : Number;
private var _name : String;
/**
* Default constructor for TestVOBase.
*/
public function TestVOBase()
{
}
/**
* Sets the id property.
*/
public function set id( value : Number ) : void
{
_id = value;
}
/**
* Returns the id property value.
*/
public function get id() : Number
{
return _id;
}
/**
* Sets the name property.
*/
public function set name( value : String ) : void
{
_name = value;
}
/**
* Returns the name property value.
*/
public function get name() : String
{
return _name;
}
}
}