<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex &#38; RIA</title>
	<atom:link href="http://www.flexria.com.br/home/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.flexria.com.br/home</link>
	<description>Tudo sobre Flex &#38; RIA</description>
	<lastBuildDate>Mon, 20 Jun 2011 19:53:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>PHP + BDD</title>
		<link>http://www.flexria.com.br/home/?p=815</link>
		<comments>http://www.flexria.com.br/home/?p=815#comments</comments>
		<pubDate>Mon, 20 Jun 2011 19:53:35 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[BDD/TDD]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testes]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=815</guid>
		<description><![CDATA[Olá, Nesse Post vou mostrar um pouco de desenvolvimento PHP usando BDD (Behaviour-Driven Development). O BDD é uma prática ágil que tem como objetivo facilitar o desenvolvimento orientado a testes, onde o software é direcionados por comportamentos, trazendo para o contexto de destes os casos de uso ou historias da aplicação. Enquanto em TDD (Test [...]]]></description>
			<content:encoded><![CDATA[<p>Olá,</p>
<p>Nesse Post vou mostrar um pouco de desenvolvimento PHP usando BDD (Behaviour-Driven Development).<br />
O BDD é uma prática ágil que tem como objetivo facilitar o desenvolvimento orientado a testes,<br />
onde o software é direcionados por comportamentos, trazendo para o contexto  de destes os casos de uso ou historias da aplicação.</p>
<p>Enquanto em TDD (Test Driven Development) testamos a aplicação de forma granular em um ambiente micro<br />
no BDD os testes são globais voltados para a Funcionalidade, Casos de uso, Comportamentos, etc..</p>
<p>Como se em TDD testamos a aplicação de dentro para fora e já em BDD a aplicação é testada de fora para dentro.<br />
Existe muito material sobre esse assunto p\ ai e muita gente mais preparada que eu para abordar esse assunto de forma teorica,<br />
Então nesse Post vou mostrar na pratica um pouco de desenvolvimento PHP usando o <a href="http://behat.org">Behat</a></p>
<p><img src="http://www.flexria.com.br/home/wp-content/uploads/2011/06/behat.png" alt="Behat" title="behat"/></p>
<p>Behat é um framework BDD <strong>em PHP 5.3</strong> construindo sobre de componentes do Symfony2.<br />
Behat foi inspirado no <a href="http://cukes.info">Cucumber</a> do Rails e especialmente a parte da sintaxe das features.</p>
<p>A instalação do Behat pode ser feita baixando diretalente pelo git diretamente pelo do git: <a href="http://github.com/Behat/Behat">http://github.com/Behat/Behat</a><br />
Ou instalando através do pear :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
$ pear channel-discover pear.behat.org
$ pear <span style="color: #c20cb9; font-weight: bold;">install</span> behat<span style="color: #000000; font-weight: bold;">/</span>behat</pre></div></div>

<p>Se tudo der certo o Behat esta instalado<br />
A versão atualmente disponível no pear é a 1.1.9<br />
Para verificar se esta correto e ver a versão instalada execute :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ behat <span style="color: #660033;">-V</span>
Behat version 1.1.9</pre></div></div>

<p>Depois de concluir a instalação o Behat esta pronto para ser usado.<br />
para isso vamos inicializar o projeto de testes com o Behat</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> path-to-my-app
$ behat <span style="color: #660033;">--init</span></pre></div></div>

<p>O comando behat &#8211;init vai criara a estruturar de diretórios usada p\ organizar os teste do Behat</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">|</span>-- features
   <span style="color: #000000; font-weight: bold;">|</span>-- steps            <span style="color: #666666; font-style: italic;">##Diretório dos arquivos que contem os cenários de testes</span>
       <span style="color: #000000; font-weight: bold;">|</span>-- steps.php
   <span style="color: #000000; font-weight: bold;">|</span>-- support          <span style="color: #666666; font-style: italic;">##Configurações, requires e configs de ambiente</span>
       <span style="color: #000000; font-weight: bold;">|</span>-- bootstrap.php  
       <span style="color: #000000; font-weight: bold;">|</span>-- env.php</pre></div></div>

<p>A definição de um historias e cenários de teste é bem simples.<br />
Utilizando algumas palavras chaves : <b>Feature, Scenario, Given, When, Then, But or And</b><br />
Os cenários são escritos em arquivos .feature que serão interpretados pelo Behat</p>
<p><b>features/contacts.feature</b></p>
<pre>
<b>Feature</b>: Contacts Registration
    In order to demonstrate the framework
    As a SouDev using BDD
    I want to register contacts

  <b>Scenario</b>: Add new contact
    <b>Given</b> a contact named "Fabio B. Silva" using the email "fabio.bat.silva@gmail.com"
      <b>And</b> the phone "xx xxxx-xxxx"
     <b>When</b> press save
     <b>Then</b> everything will be saved
</pre>
<p>Com a historia escrita podemos executar o Behat dentro da aplicação<br />
O Behat vai interpretar os arquivos .feature<br />
e mostrar quais funções vc tem que implementar para poder rodas o teste</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
$ <span style="color: #7a0874; font-weight: bold;">cd</span> path-to-my-app
$ behat
<span style="color: #000000;">1</span> scenario <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">4</span> steps <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
0m0.03s
&nbsp;
You can implement step definitions <span style="color: #000000; font-weight: bold;">for</span> undefined steps with these snippets:
&nbsp;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>Given<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^a contact named &quot;([^&quot;]*)&quot; using the email &quot;([^&quot;]*)&quot;$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span>, <span style="color: #007800;">$arg1</span>, <span style="color: #007800;">$arg2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>And<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^the phone &quot;([^&quot;]*)&quot;$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span>, <span style="color: #007800;">$arg1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>When<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^press save$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>Then<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^everything will be saved$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;</pre></div></div>

<p>Essa definição dos steps que o Behat lançou pode ser copiada para um arquivo de steps.php o que facilita bastante a implementação dos teste..<br />
Porem escrever historias em inglês pode ser meio confuso, mais o tem suporte a i18n oq nos permite escrever as historias em português.<br />
para isso basta adicionar # language: pt_BR no inicio do arquivo .feature<br />
com isso ganhamos as palavras chaves em português : <b>Funcionalidade,Cenario, Scenario, Quando, Então, Entao, Dado, Mas, E</b></p>
<p><b>features/contacts.feature</b></p>
<pre>
# language: pt_BR
<b>Funcionalidade</b>: Cadastro de contatos
    Para demostrar o funcionamento do framework
    Como SouDev que usa BDD
    Desejo cadastrar contatos

  <b>Cenario</b>: Adicionar um novo contato
    <b>Dado</b> um usuário chamado "Fabio B. Silva" usando o email "fabio.bat.silva@gmail.com"
      <b>E</b> com o telefone "xx xxxx-xxxx"
     <b>Quando</b> pressionar salvar
     <b>Entao</b> os dados serão salvos
</pre>
<p>E ao executar novamente o Behat a implementação dos teste agora também vem em português :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
$ <span style="color: #7a0874; font-weight: bold;">cd</span> path-to-my-app
$ behat
<span style="color: #000000;">1</span> scenario <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">4</span> steps <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
0m0.03s
&nbsp;
You can implement step definitions <span style="color: #000000; font-weight: bold;">for</span> undefined steps with these snippets:
&nbsp;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>Dado<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^um usuário chamado &quot;([^&quot;]*)&quot; usando o email &quot;([^&quot;]*)&quot;$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span>, <span style="color: #007800;">$arg1</span>, <span style="color: #007800;">$arg2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>E<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^com o telefone &quot;([^&quot;]*)&quot;$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span>, <span style="color: #007800;">$arg1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>Quando<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^pressionar salvar$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #007800;">$steps</span>-<span style="color: #000000; font-weight: bold;">&gt;</span>Entao<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'/^todos os dados serão salvos$/'</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$world</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    throw new \Behat\Behat\Exception\Pending<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;</pre></div></div>

<p>Com essa definição a implementação dos testes para essa feature pode ser feita<br />
<b>features/contacts_steps.php</b></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> App\Entities\Contact<span style="color: #339933;">,</span> App\Entities\Phone<span style="color: #339933;">,</span> App\Services\ContactService<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$steps</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Dado</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^um usuário chamado &quot;([^&quot;]*)&quot; usando o email &quot;([^&quot;]*)&quot;$/'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$world</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arg1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arg2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$contact</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Contact<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$contact</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$contact</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEmail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$world</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contact</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contact</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$steps</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">E</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^com o telefone &quot;([^&quot;]*)&quot;$/'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$world</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arg1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$world</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contact</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addPhone</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Phone<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$steps</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Quando</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^pressionar salvar$/'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$world</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$world</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveReturn</span> <span style="color: #339933;">=</span> ContactService<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$world</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contact</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$steps</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Entao</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^todos os dados serão salvos$/'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$world</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     assertTrue<span style="color: #009900;">&#40;</span><span style="color: #000088;">$world</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveReturn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<blockquote>
<p>O BDD e TDD são ferramentas essenciais para um software bem feito,<br />
Infeliz mente muitos &#8220;desenvolvedores&#8221; ainda tem resistência a aderir ao teste e por achar perda de tempo, tedioso, etc..<br />
O fato é que uma suite de testes bem feita vai tornar sua aplicação muito mais estável e vai lhe economizar tempo e cabelos ao longo do projeto. rsrs</p>
<p>Gostei bastante do Behat é um projeto muito bem estruturado e em constante evolução a versão 2.0 esta prestes a sair<br />
Vale apena dar uma conferida na <a href="http://docs.behat.org/en/quick_intro.html">Documentação do Behat</a></p>
<p>E Para quem tiver o interesse deixei a app no git<br />
<a href="https://github.com/FabioBatSilva/bdd-php-behat" target="_blank">https://github.com/FabioBatSilva/bdd-php-behat</a></p>
<p>Abraço e até a próxima…. </p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=815</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Repositórios Dinâmicos Com Spring JPA</title>
		<link>http://www.flexria.com.br/home/?p=771</link>
		<comments>http://www.flexria.com.br/home/?p=771#comments</comments>
		<pubDate>Mon, 06 Jun 2011 14:26:20 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Sem categoria]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring data]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=771</guid>
		<description><![CDATA[Olá. Escrevendo o post Java + MongoDB + Spring Data descobri o Spring Data JPA e fiquei surpreso em descobrir algumas features como a criação de repositórios e consultas dinâmicas. Neste Post vou falar um pouco sobre o Spring Data JPA e como ele pode lhe proporcionar uma maneira rápida e elegante de implementar seus [...]]]></description>
			<content:encoded><![CDATA[<p>Olá.</p>
<p>Escrevendo o post <a href="http://www.flexria.com.br/home/?p=728">Java + MongoDB + Spring Data</a> descobri o <a href="http://www.springsource.org/spring-data/jpa">Spring Data JPA</a><br />
e fiquei surpreso em descobrir algumas features como a criação de repositórios e consultas dinâmicas.<br />
Neste Post vou falar um pouco sobre o Spring Data JPA e como ele pode lhe proporcionar uma maneira rápida e elegante de implementar seus repositórios.</p>
<div>
<img src="http://www.flexria.com.br/home/wp-content/uploads/2011/05/spring.png" style="display:inline;"></img>
</div>
<p>O Spring Data JPA tem como principal objetivo facilitar a implementação das camadas de acesso a dados.<br />
O Spring fica responsável pela implementação dos repositórios e oferece algumas funcionalidades sofisticadas e comuns na maioria dos CRUDs baseado na entidade que esta sendo gerenciada.</p>
<p>Nessa aplicação vou usar as entidades Contact, Phone, e o repositório ContactRepository.</p>
<p>As entidades são bem simples, é anotadas com o mapeamento de seus atributos e relacionamentos.<br />
<strong>Contact.java</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;phones&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Phone <span style="color: #009900;">&#123;</span>
  @Id
  @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
&nbsp;
  @ManyToOne
  @JoinColumn<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;id_contact&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">private</span> Contact contact<span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//getter and setter methods </span>
  ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Phone.java</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Contact <span style="color: #009900;">&#123;</span>
&nbsp;
   @Id
   @Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;id_contact&quot;</span><span style="color: #009900;">&#41;</span>
   @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
&nbsp;
   @Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
   @Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span>,unique<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> email<span style="color: #339933;">;</span>
&nbsp;
   @OneToMany<span style="color: #009900;">&#40;</span>mappedBy<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contact&quot;</span>,cascade<span style="color: #339933;">=</span>CascadeType.<span style="color: #006633;">ALL</span>, fetch<span style="color: #339933;">=</span>FetchType.<span style="color: #006633;">LAZY</span><span style="color: #009900;">&#41;</span>
   @Fetch<span style="color: #009900;">&#40;</span>FetchMode.<span style="color: #006633;">JOIN</span><span style="color: #009900;">&#41;</span>
   @<span style="color: #000000; font-weight: bold;">private</span> Set<span style="color: #339933;">&lt;</span>Phone<span style="color: #339933;">&gt;</span> phones <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;</span>Phone<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//getter and setter methods </span>
  ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>ContactRepository.java</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ContactRepository <span style="color: #000000; font-weight: bold;">extends</span> JpaRepository<span style="color: #339933;">&lt;</span>Contact, Long<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Contact findByEmail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> email<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Até aqui nada de novo, porem agora como a &#8220;mágica&#8221; do Spring JPA ..rsrs</p>
<p>A interface do repositório estende <strong>JpaRepository</strong>, essa interface  tem alguns métodos comuns como  findAll, findOne, save, delete, etc&#8230;<br />
Normalmente teríamos que implementar essa interface criando uma classe ContactRepositoryImpl e registra-la como um bean do spring<br />
para que então possamos utilizar o repositório.</p>
<p>Com o Spring JPA não é necessário escrever essa implementação <img src='http://www.flexria.com.br/home/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ..<br />
Não é magia meus amigos, é tecnologia !!!&#8230;rsrs</p>
<p>O Spring JPA vai procurar por interfaces de repositórios que estendam a interface JpaRepository,<br />
e então criar uma implementação para a interface e registra-la como um bean.</p>
<p>Para isso so é necessário apenas adicionar a tag <strong>jpa:repositories</strong> no contexto do spring,<br />
com isso o Spring sabe onde procurar os repositórios que ele teve implementar.</p>
<p><strong>applicationContext.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
// Declaração dos Beans, TransactionManager, DataSource, etc...
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jpa:repositories</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;br.com.flexria.springjpa.repository&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Com isso a implementação do repositório já esta pronta para ser injetada é utilizada na aplicação.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
@Autowired
ContactRepository repository<span style="color: #339933;">;</span>
&nbsp;
repository.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
repository.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> list <span style="color: #339933;">=</span> contactRepository.<span style="color: #006633;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Isso por si so ja é algo incrível so que o Spring Data JPA vai alem.</p>
<p>Algo que ja é comum no Rails, são os Dynamic attribute-based finders que é a possibilidade de realizar buscas dinâmica baseadas nos atributos do objeto<br />
Em rails temos :</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">//</span><span style="color:#996600;">&quot;SQL : SELECT * FROM contacts WHERE email = 'fabio.bat.silva@gmail.com'&quot;</span>
&nbsp;
Contact.<span style="color:#9900CC;">where</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;fabio.bat.silva@gmail.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">//</span>Usando Dynamic attribute<span style="color:#006600; font-weight:bold;">-</span>based finders
Contact.<span style="color:#9900CC;">find_by_email</span> <span style="color:#996600;">&quot;fabio.bat.silva@gmail.com&quot;</span></pre></div></div>

<p>É exatamente isso que o Spring Data JPA faz,<br />
além de implementar do repositório com ele é possível utilizar buscas dinâmica baseadas nos atributos do objeto.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">   <span style="color: #666666; font-style: italic;">// HQL : select c from Contact c where c.email = ?1</span>
    <span style="color: #000000; font-weight: bold;">public</span> Contact findByEmail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> email<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// HQL : select c from Contact c where c.name like ?1</span>
    <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> findByNameLike<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Com base em algumas palavras chaves varias consultas podem ser feitas :</p>
<table border="1">
<thead>
<tr>
<th>Keyword</th>
<th>Sample</th>
<th>JPQL snippet</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="code">And</code>
			</td>
<td><code class="code">findByLastnameAndFirstname</code>
			</td>
<td><code class="code">… where x.lastname = ?1 and<br />
					x.firstname = ?2</code>
			</td>
</tr>
<tr>
<td><code class="code">Or</code>
			</td>
<td><code class="code">findByLastnameOrFirstname</code>
			</td>
<td><code class="code">… where x.lastname = ?1 or<br />
					x.firstname = ?2</code>
			</td>
</tr>
<tr>
<td><code class="code">Between</code>
			</td>
<td><code class="code">findByStartDateBetween</code>
			</td>
<td><code class="code">… where x.startDate between 1? and<br />
					?2</code>
			</td>
</tr>
<tr>
<td><code class="code">LessThan</code>
			</td>
<td><code class="code">findByAgeLessThan</code>
			</td>
<td><code class="code">… where x.age &lt; ?1</code>
			</td>
</tr>
<tr>
<td><code class="code">GreaterThan</code>
			</td>
<td><code class="code">findByAgeGreaterThan</code>
			</td>
<td><code class="code">… where x.age &gt; ?1</code>
			</td>
</tr>
<tr>
<td><code class="code">IsNull</code>
			</td>
<td><code class="code">findByAgeIsNull</code>
			</td>
<td><code class="code">… where x.age is null</code>
			</td>
</tr>
<tr>
<td><code class="code">IsNotNull,NotNull</code>
			</td>
<td><code class="code">findByAge(Is)NotNull</code>
			</td>
<td><code class="code">… where x.age not null</code>
			</td>
</tr>
<tr>
<td><code class="code">Like</code>
			</td>
<td><code class="code">findByFirstnameLike</code>
			</td>
<td><code class="code">… where x.firstname like ?1</code>
			</td>
</tr>
<tr>
<td><code class="code">NotLike</code>
			</td>
<td><code class="code">findByFirstnameNotLike</code>
			</td>
<td><code class="code">… where x.firstname not like ?1</code>
			</td>
</tr>
<tr>
<td><code class="code">OrderBy</code>
			</td>
<td><code class="code">findByAgeOrderByLastnameDesc</code>
			</td>
<td><code class="code">… where x.age = ?1 order by<br />
					x.lastname desc</code>
			</td>
</tr>
<tr>
<td><code class="code">Not</code>
			</td>
<td><code class="code">findByLastnameNot</code>
			</td>
<td><code class="code">… where x.lastname &lt;&gt; ?1</code>
			</td>
</tr>
</tbody>
</table>
<blockquote>
<p>Repositórios dinâmicos, consultas dinâmicas, Buscas baseadas em NamedQuery ou anotações, etc..<br />
com certeza tem muita coisa a ser explorada no Spring Data JPA, me surpreendi com a facilidade e agilidade.</p>
<p>Vale apena dar uma conferida na <a href="http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/">documentação do Spring Data JPA</a></p>
<p>E Para quem tiver o interesse deixei a app no git<br />
<a href="https://github.com/FabioBatSilva/spring-data-jpa" target="_blank">https://github.com/FabioBatSilva/spring-data-jpa</a></p>
<p>Abraço e até a próxima…. </p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=771</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java + MongoDB + Spring Data</title>
		<link>http://www.flexria.com.br/home/?p=728</link>
		<comments>http://www.flexria.com.br/home/?p=728#comments</comments>
		<pubDate>Tue, 31 May 2011 16:13:29 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring data]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=728</guid>
		<description><![CDATA[Olá. A alguns dias escrevi um post sobre PHP + MongoDB e recebi um feedback muito positivo então resolvi repetir a dose e mostrar um pouco da integração entre Java e MongoDB. Na minha opinião essa é uma das principais vantagens do MongoDB em relação a outros bancos de dados NoSQL, O MongoDB e extremamente [...]]]></description>
			<content:encoded><![CDATA[<p>Olá.</p>
<p>A alguns dias escrevi um post sobre <a href="http://www.flexria.com.br/home/?p=556">PHP + MongoDB</a> e recebi um feedback muito positivo<br />
então resolvi repetir a dose e mostrar um pouco da integração entre Java e MongoDB.</p>
<p>Na minha opinião essa é uma das principais vantagens do  MongoDB em relação a outros bancos de dados NoSQL,<br />
O MongoDB e extremamente fácil de se integrar com a maioria das linguagens. </p>
<div>
<img src="http://www.flexria.com.br/home/wp-content/uploads/2011/04/logo-mongoDB.png" style="display:inline;"><img src="http://www.flexria.com.br/home/wp-content/uploads/2011/05/spring.png" style="display:inline;"></img>
</div>
<p>Neste Post vou falar um pouco sobre o MongoDB e a integração com o java utilizando o Spring Data.<br />
O MongoDB fornece o mongo-java-driver que atualmente esta na versão 2.6.X é uma API completa para acessar o MongoDB.<br />
O Spring Data é um projeto recente, lançado em 2010, ele oferecer suporte a novas tecnologias não relacionais, suporte a extensões específicas a bancos de dados relacionais. Spring Data trabalha como uma camada intermediária entre seus POJOs e o MongoDB.</p>
<p>Nesse exemplo estou usando o maven para gerencias as dependências do projeto<br />
Então alem das dependências habituais do projeto: Spring, JUnit e etc.. vamos precisar adiciona ao pow.xml as dependências do MongoDB e Spring Data</p>
<p><b>pow.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- Spring dependencies --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>spring-core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${spring.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclusions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclusion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-logging<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-logging<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclusion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclusions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>spring-context<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${spring.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>spring-aop<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${spring.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework.data<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>spring-data-mongodb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${spring.data.mongo.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- Querydsl --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.mysema.querydsl<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>querydsl-mongodb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${querydsl.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;optional<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/optional<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclusions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclusion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.google.code.morphia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>morphia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclusion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclusions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.mysema.querydsl<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>querydsl-apt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${querydsl.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provided<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Feito isso as dependências do projeto estão configuradas e podemos partir para a configuração do spring.<br />
A configuração é bem simples, nesse exemplo existem apenas 2 beans que configuram o MongoDB e Spring Data <b>mongoTemplate</b> e <b>mongo</b></p>
<p><b>applicationContext.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:context</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/context&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:mongo</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/data/mongo&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</span>
<span style="color: #009900;">        http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd</span>
<span style="color: #009900;">        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:annotation-config</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;br.com.flexria.contacts&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mongoTemplate&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.data.document.mongodb.MongoTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mongo&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;mongo&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;databaseName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultCollectionName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;contacts&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mongo&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.data.document.mongodb.MongoFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;host&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;localhost&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>O Spring Data oferece uma serie de anotações que permitem mapear o POJO de forma bem similar ao Hibernate/JPA<br />
<b>Contact.java</b></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
@<span style="color: #003399;">Document</span><span style="color: #009900;">&#40;</span>collection<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Contact <span style="color: #009900;">&#123;</span>
    @Id
    <span style="color: #000000; font-weight: bold;">private</span> ObjectId id<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> email<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//getter and setter methods </span>
  ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>E é através do <b>mongoTemplate</b> que vamos interagir com o MongoDB por exemplo :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
@Autowired
MongoTemplate template<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// insere um novo registro		</span>
template.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacts&quot;</span>, contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// insere/altera um registro</span>
template.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacts&quot;</span>, contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// remove um registro</span>
template.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// lista todos os registros</span>
List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> list <span style="color: #339933;">=</span> template.<span style="color: #006633;">getCollection</span><span style="color: #009900;">&#40;</span>collectionName, Contact.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Apesar do Spring Data suportar o JPA repository fiz uma implementação genérica para um repositório usando o Spring Data.</p>
<p><strong>GenericRepositoryWithMongo.java</strong> &#8211; Repositório genérico</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> GenericRepositoryWithMongo<span style="color: #339933;">&lt;</span>T, ID <span style="color: #000000; font-weight: bold;">extends</span> Serializable<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  @Autowired
  <span style="color: #000000; font-weight: bold;">protected</span> MongoTemplate template<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">protected</span> Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> targetClass<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> collectionName<span style="color: #339933;">;</span>
&nbsp;
  @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> GenericRepositoryWithMongo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">targetClass</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ParameterizedType<span style="color: #009900;">&#41;</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getGenericSuperclass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getActualTypeArguments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @PostConstruct
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> initCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">targetClass</span>.<span style="color: #006633;">isAnnotationPresent</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Document</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">Document</span> document   <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">targetClass</span>.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Document</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">collectionName</span> <span style="color: #339933;">=</span> document.<span style="color: #006633;">collection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">collectionName</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">targetClass</span>.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> getCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> template.<span style="color: #006633;">getCollection</span><span style="color: #009900;">&#40;</span>collectionName, targetClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> persist<span style="color: #009900;">&#40;</span>T entity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    template.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span>collectionName, entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> merge<span style="color: #009900;">&#40;</span>T entity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    template.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>collectionName, entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> remove<span style="color: #009900;">&#40;</span>T entity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    template.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> findAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> getCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> getCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>E então a interface do repositório e sua implementação</p>
<p><strong>ContactRepository.java</strong> &#8211; Repositório de contatos</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ContactRepository <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Contact findByEmail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> email<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> persist<span style="color: #009900;">&#40;</span>Contact entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> merge<span style="color: #009900;">&#40;</span>Contact entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> remove<span style="color: #009900;">&#40;</span>Contact entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> findAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>ContactRepositoryImpl.java</strong> &#8211; Implementação do repositório de contatos</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Service<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contactRepository&quot;</span><span style="color: #009900;">&#41;</span>
@<span style="color: #003399;">Repository</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContactRepositoryImpl <span style="color: #000000; font-weight: bold;">extends</span> GenericRepositoryWithMongo<span style="color: #339933;">&lt;</span>Contact, ObjectId<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">implements</span> ContactRepository<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Contact findByEmail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> email<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	   Criteria criteria	 <span style="color: #339933;">=</span> Criteria.<span style="color: #006633;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">is</span><span style="color: #009900;">&#40;</span>email<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   Query query 	         <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Query<span style="color: #009900;">&#40;</span>criteria<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #000000; font-weight: bold;">return</span> template.<span style="color: #006633;">findOne</span><span style="color: #009900;">&#40;</span>query, targetClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote>
<p>Realmente me surpreendi com a facilidade da integração usando o Spring Data<br />
é um exemplo bem simples da integração porem mais da o caminho das pedras para quem esta se aventurando no mundo NoSQL.<br />
Espero que seja util..</p>
<p>Para quem tiver o interesse deixei app no git<br />
<a href="https://github.com/FabioBatSilva/spring-mongodb" target="_blank">https://github.com/FabioBatSilva/spring-mongodb</a></p>
<p>Abraço e até a próxima…. </p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=728</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JavaScriptMVC</title>
		<link>http://www.flexria.com.br/home/?p=635</link>
		<comments>http://www.flexria.com.br/home/?p=635#comments</comments>
		<pubDate>Fri, 13 May 2011 14:34:27 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dispatchEvent]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[JavaScriptMVC]]></category>
		<category><![CDATA[Padrão de projeto]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=635</guid>
		<description><![CDATA[Olá, Com a chegada eminente do HTML5 e outras tecnologias baseadas em javascript como MongoDB e node.js tenho deixado o Flex o meio de lado e me dedicado um pouco mais ao javascript. Porem fica a questão, Como ter um front-end com a mesma performance, escalabilidade e desacoplamento que o flex permite ? Realmente nesses [...]]]></description>
			<content:encoded><![CDATA[<p>Olá,</p>
<p>Com a chegada eminente do HTML5 e outras tecnologias baseadas em javascript como <a href="http://www.mongodb.org/" target="_blank">MongoDB</a> e <a href="http://www.nodejs.org" target="_blank">node.js</a><br />
tenho deixado o Flex o meio de lado e me dedicado um pouco mais ao javascript.<br />
Porem fica a questão, Como ter um front-end com a mesma performance, escalabilidade e desacoplamento que o flex permite ?<br />
Realmente nesses termos ainda não encontrei nada que me proporcione o que o Flex proporciona.</p>
<p>Nesse Post vou falar um pouco sobre Framework <a href="http://javascriptmvc.com" target="_blank">JavaScriptMVC</a><br />
Me perece uma das melhores alternativas para manter um frond-end JavaScript/HTML</p>
<p><img src="http://www.flexria.com.br/home/wp-content/uploads/2011/05/javascriptmvc.png" /></p>
<p>JavaScriptMVC é formado por uma seria de ferramentas para construção de aplicativos JavaScript e consiste nos seguintes componentes:</p>
<ul>
<li><a href="http://github.com/jupiterjs/steal" target="_blank">StealJS</a> -Gestão de Dependência</li>
<li><a href="http://github.com/jupiterjs/funcunit" target="_blank">FuncUnit</a> &#8211; Testes Unitários </li>
<li><a href="http://github.com/jupiterjs/jquerymx" target="_blank">jQueryMX</a> &#8211; Biblioteca de Componentes </li>
<li><a href="http://github.com/jupiterjs/documentjs" target="_blank">DocumentJS</a> &#8211; Geração de JSDoc</li>
</ul>
<p>O JavaScriptMVC pode ser utilizado com qualquer back-end , java,php,rails, etc&#8230;<br />
Ele pode ser instalado <a href="http://javascriptmvc.com/docs.html#&#038;who=download" target="_blank">baixando diretamente aqui</a> ou instalando cada componente individualmente atreves do github.</p>
<p>Os componentes devem ficar nas raiz do diretório web da sua aplicação, nesse caso a pasta public.<br />
Então as estrutura da aplicação fica assim.</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;">public
  <span style="color: #000000;">/</span>documentjs
  <span style="color: #000000;">/</span>funcunit
  <span style="color: #000000;">/</span>jquery
  <span style="color: #000000;">/</span>steal
  <span style="color: #000000;">/</span><span style="color: #668080;">js</span></pre></div></div>

<p>O JavaScriptMVC tem ferramentas de geração de código para auxiliar na criação da aplicação.<br />
Vamos começar criando a aplicação pelo terminal, então o JavaScriptMVC vai gerar toda a estrutura do projeto.</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;">    <span style="color: #668080;">cd</span> path<span style="color: #000000;">-</span>to<span style="color: #000000;">-</span>application<span style="color: #000000;">/</span>public<span style="color: #000000;">/</span>
   <span style="color: #000000;">./</span><span style="color: #668080;">js</span> jquery<span style="color: #000000;">/</span>generate<span style="color: #000000;">/</span>app contacts</pre></div></div>

<p>Assim como o rails o JavaScriptMVC  possui scaffolds que podem gerar seu CRUD.<br />
Para isso basta executar o comando scaffold passando como parâmetro o nome do modelo.<br />
Os nomes das classes seguem o seguinte padrão : &lt;Nome da Aplicação&gt;.&lt;Pacote&gt;.&lt;Nome da Classe&gt;<br />
então temos o model &#8220;Contacts.Models.Contact&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;">     <span style="color: #000000;">./</span><span style="color: #668080;">js</span> jquery<span style="color: #000000;">/</span>generate<span style="color: #000000;">/</span>scaffold Contacts<span style="color: #000000;">.</span>Models<span style="color: #000000;">.</span>Contact</pre></div></div>

<p>O JavaScriptMVC vai gerar o controlador, modelos, views e testes unitários da aplicação.<br />
Porem o único arquivo que sera incluído na aplicação é o steal.js ele é responsável por gerenciar as dependências da aplicação.<br />
No ambiente de desenvolvimento ele vai incluir individualmente todos os controladores, modelos, etc..</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">'text/javascript'</span>  <span style="color: #000066;">src</span>=<span style="color: #ff0000;">'../steal/steal.js?contacts,development'</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>O parâmetro &#8220;?contacts&#8221; na tag de inclusão indica o nome do arquivo de configuração que tem o mesmo nome da aplicação nesse caso contacts.js<br />
nele ficam mapeados todas dependências do projeto que serão gerenciadas pelo StealJS<br />
<strong>contacts/contacts.js</strong> &#8211; Arquivo de configuração</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">steal.<span style="color: #660066;">plugins</span><span style="color: #009900;">&#40;</span>	
    <span style="color: #3366CC;">'jquery/controller'</span><span style="color: #339933;">,</span>	
    <span style="color: #3366CC;">'jquery/controller/subscribe'</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">'jquery/view/ejs'</span><span style="color: #339933;">,</span>		
    <span style="color: #3366CC;">'jquery/controller/view'</span><span style="color: #339933;">,</span>	
    <span style="color: #3366CC;">'jquery/model'</span><span style="color: #339933;">,</span>		
    <span style="color: #3366CC;">'jquery/lang/json'</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">'jquery/dom/form_params'</span><span style="color: #009900;">&#41;</span>
&nbsp;
.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contacts'</span><span style="color: #009900;">&#41;</span>
&nbsp;
.<span style="color: #660066;">resources</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">models</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contact'</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">controllers</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contact'</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">views</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Depois de fazer uma refatoração a aplicação ficou assim :</p>
<p><strong>contacts/view/contact/contacts.html</strong> &#8211; Tela inicial da aplicação</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>JS - MVC<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">'text/javascript'</span>  <span style="color: #000066;">src</span>=<span style="color: #ff0000;">'../steal/steal.production.js?contacts'</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'contacts'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Contacts<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'contact'</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>contacts/view/contact/list_view.ejs</strong> &#8211; Template para a listagem de contatos</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;javascript://&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">'text_button create'</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>Create<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hr</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;table&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;thead<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>E-Mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/thead<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tbody<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;">&lt;%for<span style="color: #66cc66;">&#40;</span>var i = 0; i &lt; contacts.length ; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr</span> &lt;%= contacts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>&gt;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span>&lt;%= contacts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.name%<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span>&lt;%= contacts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.email%<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;last&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">'javascript://'</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">'edit'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>edit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>|<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">'javascript://'</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">'destroy'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>destroy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;">&lt;%<span style="color: #66cc66;">&#125;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tbody<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>contacts/view/contact/list_view.ejs</strong> &#8211; Template para o formulario de contatos</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> &lt;%= contact%<span style="color: #000000; font-weight: bold;">&gt;</span></span> &gt;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;form&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;text_field&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&lt;%= contact.name%&gt;</span></span>&quot; /&gt;          
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>E-Mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;text_field&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&lt;%= contact.email%&gt;</span></span>&quot; /&gt;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;javascript://&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;text_button save&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Save<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;javascript://&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;text_button cancel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Cancel<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>contacts/models/contact.js</strong> &#8211; Classe &#8216;Contacts.Models.Contact&#8217;  Reponsavel pela abstração do acesso aos serviços</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">Model</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Application.Models.Contact'</span><span style="color: #339933;">,</span>
<span style="color: #009966; font-style: italic;">/* @Static */</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">/**
     * Service url.
     */</span>
    url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://localhost/patho-to-app/contacts/'</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Recupera os dados dos contacts do serviço no backend.
     * @param {Object} params
     * @param {Function} success
     * @param {Function} error
     */</span>
    findAll<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> params<span style="color: #339933;">,</span> success<span style="color: #339933;">,</span> error <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            url     <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">url</span><span style="color: #339933;">,</span>
            type    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
            dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
            data    <span style="color: #339933;">:</span> params<span style="color: #339933;">,</span>
            success <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">callback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'wrapMany'</span><span style="color: #339933;">,</span>success<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            error   <span style="color: #339933;">:</span> error
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #006600; font-style: italic;">/**
     * Cria um novo contacto
     * @param {Object} attrs
     * @param {Function} success
     * @param {Function} error
     */</span>
    create<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> attrs<span style="color: #339933;">,</span> success<span style="color: #339933;">,</span> error <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            url     <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">url</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'save'</span><span style="color: #339933;">,</span>
            type    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
            dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
            error   <span style="color: #339933;">:</span> error<span style="color: #339933;">,</span>
            success <span style="color: #339933;">:</span> success<span style="color: #339933;">,</span>
            data    <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>contact<span style="color: #339933;">:</span>attrs<span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">/**
     * Altera os dados de um contacto
     * @param {String} id
     * @param {Object} attrs
     * @param {Function} success
     * @param {Function} error
    */</span>
    update<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> id<span style="color: #339933;">,</span> attrs<span style="color: #339933;">,</span> success<span style="color: #339933;">,</span> error <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            url     <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">url</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'save'</span><span style="color: #339933;">,</span>
            type    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
            dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
            data    <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>contact<span style="color: #339933;">:</span>attrs<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            success <span style="color: #339933;">:</span> success<span style="color: #339933;">,</span>
            error   <span style="color: #339933;">:</span> error
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #006600; font-style: italic;">/**
     * Remove um contacto
     * @param {String} id
     * @param {Function} success
     * @param {Function} error
     */</span>
    destroy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> id<span style="color: #339933;">,</span> success<span style="color: #339933;">,</span> error <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            url     <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">url</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'destroy/id/'</span><span style="color: #339933;">+</span>id<span style="color: #339933;">,</span>
            type    <span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
            dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
            error   <span style="color: #339933;">:</span> error<span style="color: #339933;">,</span>
            success <span style="color: #339933;">:</span> success
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>contacts/controllers/contact_controller.js</strong> &#8211; Classe &#8216;Contacts.Controllers.Contact&#8217;  Responde a eventos da view e do modelo</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Contacts.Controllers.Contact'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>onDocument<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span>      
     <span style="color: #006600; font-style: italic;">/**
     * Função chamada quando a página é carregada
     */</span>
     load<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">/**
     * Função que renderiza a listagem de contatos apartir do template /contacts/views/list_view.ejs
     * @param {Array} contacts
     */</span>
     listView<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> contacts <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#contact'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">view</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'list_view'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>contacts<span style="color: #339933;">:</span>contacts<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">/**
     * Função que renderiza o formulario de contatos apartir do template /contacts/views/form_view.ejs
     * @param {Contacts.Models.Contact} contact
     */</span>
     formView<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#contact'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">view</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form_view'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>contact<span style="color: #339933;">:</span>contact<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">/**
     * Função que lista os contatos atraves do model e renderiza a tela quando obtem resultado
     */</span>
     findAll<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
        Contacts.<span style="color: #660066;">Models</span>.<span style="color: #660066;">Contact</span>.<span style="color: #660066;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">callback</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'listView'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'click' no link create
     */</span>
    <span style="color: #3366CC;">'.create click'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// cria um novo contato e monta o formulario</span>
        <span style="color: #003366; font-weight: bold;">var</span> contact <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Contacts.<span style="color: #660066;">Models</span>.<span style="color: #660066;">Contact</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">formView</span><span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'click' no link edit
     * @param {jQuery} el
     */</span>
    <span style="color: #3366CC;">'.edit click'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> el <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Recupera o contato selecionado e monta o formulario</span>
        <span style="color: #003366; font-weight: bold;">var</span> contact <span style="color: #339933;">=</span> el.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.contact'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">formView</span><span style="color: #009900;">&#40;</span>contact<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'click' no link destroy
     * @param {jQuery} el
     */</span>
    <span style="color: #3366CC;">'.destroy click'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> el <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Are you sure you want to destroy?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// Recupera o contato selecionado e o remove</span>
            <span style="color: #003366; font-weight: bold;">var</span> contact <span style="color: #339933;">=</span> el.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.contact'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            contact.<span style="color: #660066;">destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'click' no link save
     * @param {jQuery} el
     */</span>
    <span style="color: #3366CC;">'.save click'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Recupera o contato selecionado</span>
        <span style="color: #003366; font-weight: bold;">var</span> contact <span style="color: #339933;">=</span> el.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.contact'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// Recupera os dados do formulario</span>
        <span style="color: #003366; font-weight: bold;">var</span> attrs   <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">formParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// Atualiza os dados no &quot;objeto&quot;</span>
        contact.<span style="color: #660066;">attrs</span><span style="color: #009900;">&#40;</span>attrs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
        <span style="color: #006600; font-style: italic;">// Salva</span>
        contact.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      	<span style="color: #006600; font-style: italic;">// a função save é erdada do objeto Model</span>
                               <span style="color: #006600; font-style: italic;">// ela verifica se o objeto ja existe e chama o metodo create ou update</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'click' no link cancel
     */</span>
    <span style="color: #3366CC;">'.cancel click'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'created' disparado pelo &quot;objeto&quot; Contacts.Models.Contact
     * @param {String} called
     * @param {Event} contact
     */</span>
    <span style="color: #3366CC;">'contact.created subscribe'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> called<span style="color: #339933;">,</span> contact <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'updated' disparado pelo &quot;objeto&quot; Contacts.Models.Contact
     * @param {String} called
     * @param {Event} contact
     */</span>
    <span style="color: #3366CC;">'contact.updated subscribe'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> called<span style="color: #339933;">,</span> contact <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">/**
     * Listener para o evento 'destroyed' disparado pelo &quot;objeto&quot; Contacts.Models.Contact
     * @param {String} called
     * @param {Event} contact
     */</span>
    <span style="color: #3366CC;">&quot;contact.destroyed subscribe&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>called<span style="color: #339933;">,</span> contact<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Agora antes de colocar a aplicação em ambiente de produção podemos compactar todos os arquivos .js e .css gerando uma versão final.</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"> <span style="color: #000000;">./</span><span style="color: #668080;">js</span> contacts<span style="color: #000000;">/</span>scripts<span style="color: #000000;">/</span>build<span style="color: #000000;">.</span><span style="color: #668080;">js</span></pre></div></div>

<p>O StealJS utiliza o <a href="http://code.google.com/intl/pt-BR/closure/compiler/" target="_blank">Google Closure</a> para compactar todos os arquivos<br />
e gerar arquivos compactados/concatenados que serão usados em produção contacts/production.js e contacts/production.css .</p>
<p>Com isso reduzimos todos os arquivos da aplicação, estilos, plugins, etc.. são reduzidos a apenas um arquivo .js e um arquivo .css.<br />
E para mudar as configuração do ambiente temos apelas que mudar o tag de inclusão do StealJS</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span>  src<span style="color: #339933;">=</span><span style="color: #3366CC;">'../steal/steal.production.js?contacts'</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<blockquote><p>
Esse foi apenas uma pequena amostra do JavaScriptMVC.<br />
Com essa estrutura ele nos permite construir grandes aplicações de forma modular<br />
com um bom ambiente de teste, velocidade no desenvolvimento e performance no ambiente de produção.</p>
<p>Essa aplicação esta rodando aqui : <a href="http://flexria.com.br/labs/js-mvc/" target="_blank">http://flexria.com.br/labs/js-mvc/</a><br />
E os fontes estão disponíveis  no github : <a href="https://github.com/FabioBatSilva/js-mvc" target="_blank">https://github.com/FabioBatSilva/js-mvc</a></p>
<p>Abraço e até a próxima…. <img src='http://www.flexria.com.br/home/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=635</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP + MongoDB</title>
		<link>http://www.flexria.com.br/home/?p=556</link>
		<comments>http://www.flexria.com.br/home/?p=556#comments</comments>
		<pubDate>Fri, 29 Apr 2011 18:37:08 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=556</guid>
		<description><![CDATA[Olá. Ultimamente me tenho dedicado bastante a melhora da performance das aplicações que desenvolvo. Resolvi compartilhar aqui um pouco do que aprendi sobre NoSql. Esses bancos de dados seguem uma abordagem diferente para o armazenamento de dados em comparação com o modelo relacional tradicional. E estão rapidamente se popularizando entre os desenvolvedores da Web, devido [...]]]></description>
			<content:encoded><![CDATA[<p>Olá.</p>
<p>Ultimamente me tenho dedicado bastante a melhora da performance das aplicações que desenvolvo.<br />
Resolvi compartilhar aqui um pouco do que aprendi sobre NoSql.<br />
Esses bancos de dados seguem uma abordagem diferente para o armazenamento de dados em comparação com o modelo relacional tradicional.<br />
E estão rapidamente se popularizando entre os desenvolvedores da Web, devido à sua flexibilidade, simplicidade e fácil integração.</p>
<p><img src="http://www.flexria.com.br/home/wp-content/uploads/2011/04/logo-mongoDB.png"></img></p>
<p>Neste Post vou falar um pouco sobre o MongoDB e a integração com o php.<br />
MongoDB é um banco de dados orientado a documentos uma solução escalável, de alto desempenho e código aberto.</p>
<p>Você vai encontrar nesse link instruções sobre como instalar o MongoDB no seu ambiente : <a href="http://www.mongodb.org/display/DOCS/Quickstart">http://www.mongodb.org/display/DOCS/Quickstart</a></p>
<p>Se você assim como eu estiver usando o Ubuntu, você pode instalar MongoDB usando apt-get.<br />
Para fazer isso, adicione a seguinte linha ao seu arquivo /etc/apt/sources.list:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>downloads-distro.mongodb.org<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>debian-sysvinit dist 10gen</pre></div></div>

<p>Em seguida, instale o pacote com apt-get executando os seguintes comandos:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update 
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mongodb-10gen</pre></div></div>

<p>Se tudo der certo depois de concluir a instalação você pode acessar o MongoDB via linha de comando, como abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mongo
<span style="color: #000000; font-weight: bold;">&gt;</span> show dbs
admin	<span style="color: #7a0874; font-weight: bold;">&#40;</span>empty<span style="color: #7a0874; font-weight: bold;">&#41;</span>
my_db	0.0625GB</pre></div></div>

<p>Agora pode enviar comandos para o servidor, assim como faria em cliente mysql, porem utilizando a sintaxe do javascript.<br />
A documentação do mongo é bem completa, la você pode encontrar mais detalhes sobre sua utilização : <a href="http://www.mongodb.org/display/DOCS/Home">http://www.mongodb.org/display/DOCS/Home</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// Exibe a versão banco de dados</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">version</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
1.8.1
&nbsp;
<span style="color: #006600; font-style: italic;">// Cria uma nava coleção</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">createCollection</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Lista todas as coleções</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">getCollectionNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">&quot;contacts&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;system.indexes&quot;</span> <span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Insere um novo item na coleção</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">contacts</span>.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;name&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Fabio B. Silva&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;email&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;fabio.bat.silva@gmail.com&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Lista todos os itens da coleção</span>
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">contacts</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> ObjectId<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;4db82c83a6510c5c77d67ebe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;name&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Fabio B. Silva&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;email&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;fabio.bat.silva@gmail.com&quot;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Observe que quando você adiciona um novo registro a coleção o MongoDB anexa automaticamente um identificador único ( _id ).<br />
Esse identificador pode ser usado para recuperar ou modificar um documento específico, similar a um id auto-increment em um banco de dados relacional.</p>
<p>Agora vamos partir para o código php.<br />
existe uma extensão/drive para o php que fornece uma API completa para acessar o MongoDB, Ela está disponível gratuitamente a partir do PECL.<br />
A extensão é estável e permite que você execute a maioria das tarefas comuns relacionadas ao acesso e utilização de um banco de dados MongoDB partir de uma aplicação PHP.</p>
<p>Para instalar <b>você precisa ter o pear/pecl previamente instalados</b> e executar o comando</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pecl <span style="color: #c20cb9; font-weight: bold;">install</span> mongo</pre></div></div>

<p>E então adicionar a extensão no seu php.ini e reiniciar o seu apache</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">extension</span>=mongo.so</pre></div></div>

<p>Se tudo der certo na instalação você terá as classes do mongo disponíveis no php, as principais são:<br />
* Mongo<br />
* MongoDB<br />
* MongoCollection<br />
* MongoCursor</p>
<p><strong>Mongo</strong> &#8211; Usado para interagir com o MongoDB</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Conexão com o banco de dados</span>
 <span style="color: #000088;">$mongo</span>  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Mongo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Conecta ao MongoDB</span>
<span style="color: #000088;">$mongo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Remove um esquema</span>
<span style="color: #000088;">$mongo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dropDB</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my_db_copy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Seleciona um esquema</span>
<span style="color: #000088;">$mongo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectDB</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my_db&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Lista esquemas  </span>
<span style="color: #000088;">$list</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$mongo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">listDBs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fecha conexão</span>
<span style="color: #000088;">$mongo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>MongoDB</strong> &#8211; Usado para interagir com um esquema</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// Seleciona um esquema</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mongo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectDB</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my_db&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Cria uma nova coleção</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createCollection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Seleciona uma coleção</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">selectCollection</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Remove uma coleção</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dropCollection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Lista todas as coleções</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">listCollections</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>MongoCollection</strong> &#8211; Representa uma coleção</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Novo registro</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'name'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Fabio B. Silva'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fabio.bat.silva@gmail.com'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$contacts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Insere um novo registro na coleção</span>
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>        <span style="color: #666666; font-style: italic;">// O índice '_id' é anexado automaticamente pelo MongoDB</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Fábio Silva'</span><span style="color: #339933;">;</span>         <span style="color: #666666; font-style: italic;">// Alterar o atributo</span>
<span style="color: #000088;">$criteria</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Critério do update|</span>
<span style="color: #000088;">$contacts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Altera registro na coleção</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$criteria</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_id'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Critério para remoção</span>
<span style="color: #000088;">$contacts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// remove registro da coleção</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000088;">$contacts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Lista todos os registros da coleção</span></pre></div></div>

<p><strong>MongoCursor</strong> &#8211; Resultado de uma consulta a uma coleção</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// Lista todos os registros da coleção</span>
<span style="color: #000088;">$cursor</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contacts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Numero de registros encontrados</span>
<span style="color: #000088;">$cursor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cursor</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p>
Existem varias outras funcionalidades e classes que podem ser exploradas no MongoDB,<br />
Essa é apenas uma pequena demostração do que ele pode fazer por você. <img src='http://www.flexria.com.br/home/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
Para quem tiver o interesse deixei uma pequena app no git que demonstra algumas outras funcionalidades do MongoDB<br />
<a href="https://github.com/FabioBatSilva/mongo-demo" target="_blank">https://github.com/FabioBatSilva/mongo-demo</a></p>
<p>Abraço e até a próxima…. </p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=556</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Reflecting Generics</title>
		<link>http://www.flexria.com.br/home/?p=535</link>
		<comments>http://www.flexria.com.br/home/?p=535#comments</comments>
		<pubDate>Thu, 03 Mar 2011 18:49:52 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=535</guid>
		<description><![CDATA[Olá. Uma Dica rápida nesse post. já via varias implementações de daos genéricos onde a classe abstrata é parametrizada usando o &#60;T&#62; Porem no momento de estender o dao genérico sempre tem um parâmetro que é a classe persistente, algo do tipo : &#160; public abstract class GenericDao&#60;T&#62; &#123; public GenericDao&#40;Class&#60;T&#62; clazz&#41; &#123; Class&#60;T&#62; persistentClass [...]]]></description>
			<content:encoded><![CDATA[<p>Olá.</p>
<p>Uma Dica rápida nesse post.</p>
<p>já via varias implementações de daos genéricos onde a classe abstrata é parametrizada usando o &lt;T&gt;<br />
Porem no momento de estender o dao genérico sempre tem um parâmetro que é a classe persistente, algo do tipo :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> GenericDao<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> GenericDao<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> clazz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> persistentClass <span style="color: #339933;">=</span> clazz<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyEntityDao <span style="color: #000000; font-weight: bold;">extends</span> GenericDao<span style="color: #339933;">&lt;</span>MyEntity<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> MyEntityDao<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>MyEntity.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Oque é algo meio redundante já que o &lt;T&gt; parametriza a classe persistente.<br />
Uma maneira mas elegante de se fazer isso é usando reflection. Segue o exemplo :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> GenericDao<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> GenericDao<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		ParameterizedType parameterized <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ParameterizedType<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getGenericSuperclass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Type<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arguments 		<span style="color: #339933;">=</span> parameterized.<span style="color: #006633;">getActualTypeArguments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> persistentClass 	<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> arguments<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p>
Bem simples porem muito útil. <img src='http://www.flexria.com.br/home/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Abraço e até a próxima
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=535</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ContentProvider</title>
		<link>http://www.flexria.com.br/home/?p=423</link>
		<comments>http://www.flexria.com.br/home/?p=423#comments</comments>
		<pubDate>Fri, 11 Feb 2011 17:02:47 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ContentcProvider]]></category>
		<category><![CDATA[provider]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=423</guid>
		<description><![CDATA[Olá, Esse sera o primeiro post que escrevo sobre android, estou começando a &#8220;brincar&#8221; com ele e resolvi compartilhar um pouco do pouco que descobri. Nesse post vou dar uma ideia de como implementar o seu próprio ContentProvider. SQLite : Uma das grandes facilidades do android e o suporte ao SQLite. As aplicações poderiam acessar [...]]]></description>
			<content:encoded><![CDATA[<p>Olá,</p>
<p>Esse sera o primeiro post que escrevo sobre android, estou começando a &#8220;brincar&#8221; com ele e resolvi compartilhar um pouco do pouco que descobri. <img src='http://www.flexria.com.br/home/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Nesse post vou dar uma ideia de como implementar o seu próprio ContentProvider. </p>
<pre>
</pre>
<blockquote><p><strong>SQLite :</strong></p></blockquote>
<p>Uma das grandes facilidades do android e o suporte ao SQLite.<br />
As aplicações poderiam acessar diretamente o banco porem é uma boa pratica encapsular isso em um ContentProviders<br />
 de forma que isso fique acessível para sua aplicação ou qualquer outra que precise acessar esses dados. </p>
<blockquote><p><strong> ContentProviders :</strong></p></blockquote>
<p>O ContentProviders é uma parte muito importante da arquitetura de um sistema android.<br />
São eles quem provem os dados para a aplicação.</p>
<blockquote><p><strong> Uri :</strong></p></blockquote>
<p>No Android a comunicação entre aplicações e providers é feita através de Uri.<br />
Cada ContentProviders expõe URIs públicas que identificam o seu conjunto de dados<br />
e controla uma ou mais tabelas e expondo uma URI diferente para cada uma delas. </p>
<p>Uma Uri segue o formato: &#8220;content://{authority}/{table}/parametroN&#8221;<br />
{authority} é o &#8220;nome&#8221; do ContentProviders<br />
{table} é a tabela que esta acessando<br />
{parametroN} são os parâmetros esperados pelo provider.</p>
<p>EX :<br />
Todos os registros da tabela (Diretório):   content://br.com.flexria.jobsdroid.jobsdroidprovider/jobs<br />
Um único registro com id 1 (Item) :   content://br.com.flexria.jobsdroid.jobsdroidprovider/jobs/1</p>
<blockquote><p><strong>Escrevendo seu ContentProvider :</strong></p></blockquote>
<p>Bom, vajamos na pratica com isso funciona.<br />
Para escrever seu ContentProviders vc precisa basicamente de quatro coisas.</p>
<ul>
<li>BaseColumns</li>
<li>ContentProviders</li>
<li>SQLiteOpenHelper</li>
<li>Registrar o provider no AndroidManifest.xml :</li>
</ul>
<blockquote><p><strong>ContentProvider :</strong></p></blockquote>
<p>E a classe que provera os dados a nossa aplicação,<br />
A classe abstrata ContentProvider exige a implementação dos métodos :</p>
<p>    * query(Uri, String[], String, String[], String)- Recuperar dados.<br />
    * insert(Uri, ContentValues) – Insere um novo registro.<br />
    * update(Uri, ContentValues, String, String[]) – Atualiza um registro existente.<br />
    * delete(Uri, String, String[]) – Deleta um registro.<br />
    * getType(Uri) – Obter o MIME type do dado.</p>
<p>Dentro desses métodos iremos implementar a logica que encapsula esses comportamentos.<br />
Isso é valido para cada uma das tabelas que o provider esteja acessando,<br />
Como aqui só tenho uma tabela e esse é apenas um exemplo didático esta tudo na mesma classe,<br />
porem isso pode ficar meio confuso com quando temos varias tabelas e comportamentos diferentes.<br />
Uma solução para isso seria implementar o <a href="http://en.wikipedia.org/wiki/Strategy_pattern">Pattern Strategy</a> para encapsular cada comportamento.</p>
<p>O exemplo é bem básico porem gostaria de salientar três pontos<br />
    * Método getType –  Informa que tipo de dado esta sendo requisitado, se é um item ou o diretório.<br />
    * Variável mMatcher &#8211; Usado para verificar qual Uri esta sendo acessada, se é um item ou o diretório.<br />
    * Constante AUTHORITY –  Mesma identificação do provider utilizado no AndroidManifest.xml</p>
<p>Bom, como uma Imagem diz mais que mil palavras ai vai o código:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JobsDroidProvider <span style="color: #000000; font-weight: bold;">extends</span> ContentProvider <span style="color: #009900;">&#123;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * Provider Authority
  */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> AUTHORITY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;br.com.flexria.jobsdroid.jobsdroidprovider&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * DataBase Name
  */</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span>  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> DATABASE_NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jobsdroid.db&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * DataBase Version
  */</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span>  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span>  DATABASE_VERSION <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * match for directory of jobs.
  */</span>
  <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MATCH_JOBS 		<span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * match for sub-directory of a single jobs.
  */</span>
  <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MATCH_JOBS_ID 	<span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * Log Tag  
  */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> TAG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;JobsDroidProvider&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * DBHelper instance
  */</span>
  <span style="color: #000000; font-weight: bold;">private</span> DBHelper mHelper<span style="color: #339933;">;</span>
  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * UriMatcher instance
  */</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> UriMatcher mMatcher<span style="color: #339933;">;</span>
   <span style="color: #008000; font-style: italic; font-weight: bold;">/**
   * Projection Map instance
   */</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> mProjection<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
	mProjection <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mProjection.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>Jobs._ID, 	Jobs._ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mProjection.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">NAME</span>, 	Jobs.<span style="color: #006633;">NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  	
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
    	mMatcher <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UriMatcher<span style="color: #009900;">&#40;</span>UriMatcher.<span style="color: #006633;">NO_MATCH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mMatcher.<span style="color: #006633;">addURI</span><span style="color: #009900;">&#40;</span>AUTHORITY, Jobs.<span style="color: #006633;">TABLE</span>, 		MATCH_JOBS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mMatcher.<span style="color: #006633;">addURI</span><span style="color: #009900;">&#40;</span>AUTHORITY, Jobs.<span style="color: #006633;">TABLE</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;/#&quot;</span>, 	MATCH_JOBS_ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getType<span style="color: #009900;">&#40;</span>Uri uri<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>mMatcher.<span style="color: #006633;">match</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">case</span> MATCH_JOBS<span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">return</span> Jobs.<span style="color: #006633;">CONTENT_TYPE</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">case</span> MATCH_JOBS_ID<span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">return</span> Jobs.<span style="color: #006633;">CONTENT_ITEM</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unsupported URI: &quot;</span> <span style="color: #339933;">+</span> uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> onCreate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	mHelper <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DBHelper<span style="color: #009900;">&#40;</span>getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>mHelper <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Cursor</span> query<span style="color: #009900;">&#40;</span>Uri uri, <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> projection, <span style="color: #003399;">String</span> selection,<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> selectionArgs, <span style="color: #003399;">String</span> sortOrder<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> type <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Log.<span style="color: #006633;">i</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;query &quot;</span> <span style="color: #339933;">+</span> uri.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003399;">Cursor</span> cursor<span style="color: #339933;">;</span>
	SQLiteQueryBuilder builder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SQLiteQueryBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SQLiteDatabase database <span style="color: #339933;">=</span> mHelper.<span style="color: #006633;">getReadableDatabase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	builder.<span style="color: #006633;">setTables</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">TABLE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	builder.<span style="color: #006633;">setProjectionMap</span><span style="color: #009900;">&#40;</span>mProjection<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>type.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">CONTENT_ITEM</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		builder.<span style="color: #006633;">appendWhere</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">whereItem</span><span style="color: #009900;">&#40;</span>uri, selection<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sortOrder <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> sortOrder.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		sortOrder <span style="color: #339933;">=</span> Jobs.<span style="color: #006633;">NAME</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	cursor <span style="color: #339933;">=</span> builder.<span style="color: #006633;">query</span><span style="color: #009900;">&#40;</span>database, projection, selection, selectionArgs,<span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span>, sortOrder<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	cursor.<span style="color: #006633;">setNotificationUri</span><span style="color: #009900;">&#40;</span>getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContentResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> cursor<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> Uri insert<span style="color: #009900;">&#40;</span>Uri uri, ContentValues values<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Log.<span style="color: #006633;">i</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;insert &quot;</span> <span style="color: #339933;">+</span> uri.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	SQLiteDatabase db <span style="color: #339933;">=</span> mHelper.<span style="color: #006633;">getWritableDatabase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">long</span> rowId <span style="color: #339933;">=</span> db.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">TABLE</span>, Jobs.<span style="color: #006633;">NAME</span>, values<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rowId <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    Uri itemUri <span style="color: #339933;">=</span> ContentUris.<span style="color: #006633;">withAppendedId</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">CONTENT_URI</span>, rowId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContentResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notifyChange</span><span style="color: #009900;">&#40;</span>itemUri, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #000000; font-weight: bold;">return</span> itemUri<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to insert row into : &quot;</span> <span style="color: #339933;">+</span> uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> update<span style="color: #009900;">&#40;</span>Uri uri, ContentValues values, <span style="color: #003399;">String</span> selection, <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> selectionArgs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> type 		<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SQLiteDatabase db 	<span style="color: #339933;">=</span> mHelper.<span style="color: #006633;">getWritableDatabase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Log.<span style="color: #006633;">i</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;update &quot;</span> <span style="color: #339933;">+</span> uri.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>type.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">CONTENT_ITEM</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		selection <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">whereItem</span><span style="color: #009900;">&#40;</span>uri, selection<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
      	<span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> db.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">TABLE</span>, values, selection, selectionArgs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContentResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notifyChange</span><span style="color: #009900;">&#40;</span>uri, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> count<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> delete<span style="color: #009900;">&#40;</span>Uri uri, <span style="color: #003399;">String</span> selection, <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> selectionArgs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> type 		<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SQLiteDatabase db 	<span style="color: #339933;">=</span> mHelper.<span style="color: #006633;">getWritableDatabase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Log.<span style="color: #006633;">i</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;delete &quot;</span> <span style="color: #339933;">+</span> uri.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>type.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">CONTENT_ITEM</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		selection <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">whereItem</span><span style="color: #009900;">&#40;</span>uri, selection<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> db.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">TABLE</span>, selection, selectionArgs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContentResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">notifyChange</span><span style="color: #009900;">&#40;</span>uri, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> count<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> whereItem<span style="color: #009900;">&#40;</span>Uri uri, <span style="color: #003399;">String</span> selection<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>Jobs.<span style="color: #006633;">CONTENT_ITEM</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> where  <span style="color: #339933;">=</span>  Jobs._ID <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; = &quot;</span> <span style="color: #339933;">+</span> uri.<span style="color: #006633;">getPathSegments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>TextUtils.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span>selection<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> where <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; AND (&quot;</span> <span style="color: #339933;">+</span> selection <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;)&quot;</span> <span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> where<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">return</span> selection<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
    * Inner class Jobs
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> Jobs <span style="color: #000000; font-weight: bold;">implements</span>  BaseColumns <span style="color: #009900;">&#123;</span>
    	    ....
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
    * Inner class DBHelper
    */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> DBHelper <span style="color: #000000; font-weight: bold;">extends</span> SQLiteOpenHelper <span style="color: #009900;">&#123;</span>
       	....
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p><strong>BaseColumns :</strong></p></blockquote>
<p>Inner class que representa a tabela do banco de dados,<br />
estende a interface BaseColumns que possue as constantes _ID e  _COUNT.<br />
A classe Jobs possuí as constantes que representam as colunas da tabela e a Uri que a identifica</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Inner class Jobs
*/</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> Jobs <span style="color: #000000; font-weight: bold;">implements</span>  BaseColumns <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Uri CONTENT_URI <span style="color: #339933;">=</span> Uri.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content://&quot;</span><span style="color: #339933;">+</span> JobsDroidProvider.<span style="color: #006633;">AUTHORITY</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #339933;">+</span> Jobs.<span style="color: #006633;">TABLE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
    * The MIME type of a directory.
    */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> CONTENT_TYPE <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;vnd.android.cursor.dir/vnd.flexria.&quot;</span> <span style="color: #339933;">+</span> Jobs.<span style="color: #006633;">TABLE</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
    * The MIME type of a single Jobs.
    */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> CONTENT_ITEM <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;vnd.android.cursor.item/vnd.flexria.&quot;</span> <span style="color: #339933;">+</span> Jobs.<span style="color: #006633;">TABLE</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Table name
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> TABLE 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jobs&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Column name
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> 	NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p><strong>SQLiteOpenHelper :</strong></p></blockquote>
<p>Inner class que é responsável pela criação e alteração do banco de dados,<br />
A classe abstrata SQLiteOpenHelper exige a implementação dos métodos :</p>
<p>    * onCreate() – Chamado quando o banco de dados for aberto pela primeira vez. Aqui que criaremos o banco de dados.<br />
    * onUpdate() – Chamado quando a versão do banco de dados muda. Quando uma nova versão da app for instalada.</p>
<p>Como nesse caso temos a primeira versão não tenho nada no método onUpdate.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Inner class DBHelper
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> DBHelper <span style="color: #000000; font-weight: bold;">extends</span> SQLiteOpenHelper <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SQL_CREATE_TASKS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CREATE TABLE &quot;</span> <span style="color: #339933;">+</span> Jobs.<span style="color: #006633;">TABLE</span> <span style="color: #339933;">+</span> 
                     <span style="color: #0000ff;">&quot; (&quot;</span> <span style="color: #339933;">+</span> 
                           Jobs._ID 	<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; INTEGER PRIMARY KEY AUTOINCREMENT,&quot;</span> <span style="color: #339933;">+</span> 
                           Jobs.<span style="color: #006633;">NAME</span> 	<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; TEXT&quot;</span> <span style="color: #339933;">+</span>
                       <span style="color: #0000ff;">&quot; );&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    DBHelper<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>context, DATABASE_NAME, <span style="color: #000066; font-weight: bold;">null</span>, DATABASE_VERSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>SQLiteDatabase db<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        db.<span style="color: #006633;">execSQL</span><span style="color: #009900;">&#40;</span>SQL_CREATE_TASKS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onUpgrade<span style="color: #009900;">&#40;</span>SQLiteDatabase db, <span style="color: #000066; font-weight: bold;">int</span> oldVersion, <span style="color: #000066; font-weight: bold;">int</span> newVersion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p><strong>AndroidManifest :</strong></p></blockquote>
<p>Depois disso podemos registrar o provider no AndroidManifest.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provider</span> <span style="color: #000066;">android:authorities</span>=<span style="color: #ff0000;">&quot;br.com.flexria.jobsdroid.jobsdroidprovider&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;.JobsDroidProvider&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<blockquote><p><strong>Utilizando o Provider :</strong></p></blockquote>
<p>Feito isso ja podemos utilizar o provider na Activity,<br />
quando utilizamos o método getContentResolver da Activity e passamos como parâmetro a Uri do conteúdo<br />
o nosso provider é chamado e os métodos que implementamos podem ser utilizados.</p>
<p>EX :<br />
   * getContentResolver().query(JobsDroidProvider.Jobs.CONTENT_URI, null, null, null, null);</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ContentValues values 	<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ContentValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
values.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>JobsDroidProvider.<span style="color: #006633;">Jobs</span>.<span style="color: #006633;">NAME</span>, <span style="color: #0000ff;">&quot;Fabio B. Silva&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
getContentResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">query</span><span style="color: #009900;">&#40;</span>JobsDroidProvider.<span style="color: #006633;">Jobs</span>.<span style="color: #006633;">CONTENT_URI</span>, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
getContentResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span>JobsDroidProvider.<span style="color: #006633;">Jobs</span>.<span style="color: #006633;">CONTENT_URI</span>, values<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
Uri uri <span style="color: #339933;">=</span> ContentUris.<span style="color: #006633;">withAppendedId</span><span style="color: #009900;">&#40;</span>JobsDroidProvider.<span style="color: #006633;">Jobs</span>.<span style="color: #006633;">CONTENT_URI</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// uri = content://br.com.flexria.jobsdroid.jobsdroidprovider/jobs/1</span>
getContentResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>uri, values,<span style="color: #000066; font-weight: bold;">null</span>,<span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
getContentResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span>uri, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<blockquote><p>
Em um próximo momento volto a falar sobre isso, mais por hora é só.</p>
<p>Espero que essa dicas possam ajudar aos que como eu estão começando com o android</p>
<p>Abraço e até a próxima&#8230;.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=423</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eventos no PHP</title>
		<link>http://www.flexria.com.br/home/?p=368</link>
		<comments>http://www.flexria.com.br/home/?p=368#comments</comments>
		<pubDate>Fri, 11 Feb 2011 11:10:38 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[Closure]]></category>
		<category><![CDATA[dispatchEvent]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[EventListener]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[Function]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=368</guid>
		<description><![CDATA[Olá, Depois de seculos sem aparecer resolvi fazer um post para divulgar um pequeno projeto que disponibilizei no github. Trata se de uma pequena lib que implementa o Pattern Observer bem conhecido no flex através dos events. O link para o projeto no github é : https://github.com/FabioBatSilva/events O php 5.3 é requisito para o funcionamento [...]]]></description>
			<content:encoded><![CDATA[<p>Olá,</p>
<p>Depois de seculos sem aparecer resolvi fazer um post para divulgar um pequeno projeto que disponibilizei no github.</p>
<p>Trata se de uma pequena lib que implementa o <a href="http://en.wikipedia.org/wiki/Observer_pattern">Pattern Observer</a> bem conhecido no flex através dos events.</p>
<p></p>
<p>O link para o projeto no github é : <a href="https://github.com/FabioBatSilva/events" target="_blank">https://github.com/FabioBatSilva/events</a> <strong>O php 5.3 é requisito para o funcionamento</strong></p>
<p></p>
<p>La existe um pequeno <a href="https://github.com/FabioBatSilva/events/wiki" target="_blank">wiki</a> sobre o projeto com as funcionalidades básicas.<br />
<strong><em>Desde já peço desculpa pelo inglês&#8230;rsrs</em></strong></p>
<p>Depois de realizar o <a href="https://github.com/FabioBatSilva/events/archives/master" target="_blank">download</a> dos arquivos<br />
podemos utilizar a lib carregando atravez de algum  autoloader como Zend_AutoLoad ou carregando manualmente:</p>
<p></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/my/library'</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Events/Event.php'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Events\Event<span style="color: #339933;">;</span></pre></div></div>

<blockquote><p><strong>Disparando Eventos :</strong></p></blockquote>
<p>Para disparar eventos a partir da sua classe vc terá que estender EventDispatcher e utilizar o método dispatchEvent($event)</p>
<p>    * Esse metodo tem como parâmetro um objeto do tipo Event que sera disparado</p>
<p></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Events\Event<span style="color: #339933;">,</span> Events\EventDispatcher<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyObject <span style="color: #000000; font-weight: bold;">extends</span> EventDispatcher
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>            
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatchEvent</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #009900;">&#40;</span>Event<span style="color: #339933;">::</span><span style="color: #004000;">CHANGE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
<blockquote><p><strong>Escutando Eventos :</strong></p></blockquote>
<p>Para escutar os evento vc deve utilizar o método addEventListener($type,$listener) do objeto que estende a classe EventDispatcher.</p>
<p>    * O primeiro parâmetro é uma string que identifica o tipo do evento<br />
    * O segundo  parâmetro a Closure/Function que será chamada  quando o evento disparar</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> MyObject<span style="color: #339933;">;</span>
<span style="color: #000088;">$object</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addEventListener</span><span style="color: #009900;">&#40;</span>Event<span style="color: #339933;">::</span><span style="color: #004000;">CHANGE</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'My Object Has Changed'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'New Name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Então quando o nome é alterado o evento do tipo Event::CHANGE é disparado e todos que estiverem ouvindo por esse tipo de evento serão chamados.</p>
<p></p>
<blockquote><p><strong>Customizando Eventos :</strong> </p></blockquote>
<p>Vc pode criar eventos personalizados, Eles poder servir para adicionar funcionalidades ao evento ou transportar dados.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Events\Event<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyEvent <span style="color: #000000; font-weight: bold;">extends</span> Event
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CHANGE_NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">'changeName'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$oldName</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$newName</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$oldName</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">oldName</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$oldName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newName</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$newName</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
<p>Então para dispara o evento:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$event</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #009900;">&#40;</span>MyEvent<span style="color: #339933;">::</span><span style="color: #004000;">CHANGE_NAME</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatchEvent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
<p>E capturar os dados na função que esta ouvindo o evento MyEvent::CHANGE_NAME : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addEventListener</span><span style="color: #009900;">&#40;</span>MyEvent<span style="color: #339933;">::</span><span style="color: #004000;">CHANGE_NAME</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;My Object Has Changed&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;OLD : &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">oldName</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;NEW : &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newName</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<blockquote><p>É bem simples porem pode ser útil.</p>
<p></p>
<p>Abraço e até a próxima</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=368</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lumine + ZendAmf + Flex</title>
		<link>http://www.flexria.com.br/home/?p=320</link>
		<comments>http://www.flexria.com.br/home/?p=320#comments</comments>
		<pubDate>Mon, 22 Feb 2010 09:00:56 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>
		<category><![CDATA[Lumine]]></category>
		<category><![CDATA[Swiz]]></category>
		<category><![CDATA[ZendAmf]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=320</guid>
		<description><![CDATA[Olá pessoal !!! Uma das metas que me dei p\ esse ano de 2010 e colocar esse blog p\ funcionar de fato. nos últimos dias postei aqui uma dica sobre Swiz Prototype e tive um otimo feedback oq me incentivou a escrever esse tutorial, uma serie de 5 posts que irão mostrar a integração entre [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal !!!<br />
Uma das metas que me dei p\ esse ano de 2010 e colocar esse blog p\ funcionar de fato.<br />
nos últimos dias postei aqui uma dica sobre Swiz Prototype e tive um otimo feedback oq me incentivou a escrever esse tutorial, uma serie de 5 posts que irão mostrar a integração entre Lumine, ZendAmf e Flex.<br />
Desde já peço desculpas p\ qualquer erro e espero que possa ser util aos desenvolvedores.</p>
<p><a href="http://www.flexria.com.br/home/?p=174">Tutorial : Lumine + ZendAmf + Flex 1/5</a><br />
<a href="http://www.flexria.com.br/home/?p=210">Tutorial : Lumine + ZendAmf + Flex 2/5</a><br />
<a href="http://www.flexria.com.br/home/?p=251">Tutorial : Lumine + ZendAmf + Flex 3/5</a><br />
<a href="http://www.flexria.com.br/home/?p=252">Tutorial : Lumine + ZendAmf + Flex 4/5</a><br />
<a href="http://www.flexria.com.br/home/?p=276">Tutorial : Lumine + ZendAmf + Flex 5/5</a></p>
<p><a href="wp-content/uploads/lumine-zend-flex/lumine-zend-flex.zip">O código fonte da aplicação pode ser baixado aqui</a></p>
<p>Valew pessoal, abraço e até a próxima !!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=320</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Lumine + ZendAmf + Flex 5/5</title>
		<link>http://www.flexria.com.br/home/?p=276</link>
		<comments>http://www.flexria.com.br/home/?p=276#comments</comments>
		<pubDate>Mon, 22 Feb 2010 08:00:02 +0000</pubDate>
		<dc:creator>Fabio B. Silva</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>
		<category><![CDATA[Lumine]]></category>
		<category><![CDATA[Swiz]]></category>
		<category><![CDATA[ZendAmf]]></category>

		<guid isPermaLink="false">http://www.flexria.com.br/home/?p=276</guid>
		<description><![CDATA[Lumine + ZendAmf + Flex 5/5 Olá pessoal !!! Agora que temos nosso backend e regra de negocio pronta podemos implementar nossas views e actions. Application Iniciando pelo nosso application que terá apenas as configurações do Swiz e uma instância de nossa view : &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;mx:Application xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34; xmlns:swiz=&#34;http://swiz.swizframework.org&#34; xmlns:views=&#34;br.com.flexria.views.*&#34; layout=&#34;absolute&#34; xmlns:local=&#34;*&#34; height=&#34;100%&#34; width=&#34;100%&#34;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Lumine + ZendAmf + Flex 5/5</strong></p>
<p>Olá pessoal !!!</p>
<p>Agora que temos nosso backend e regra de negocio pronta podemos implementar nossas views e actions.</p>
<p style="text-align: center;margin-top:60px;">
   <strong>Application</strong>
</p>
<p>Iniciando pelo nosso application que terá apenas as configurações do Swiz e uma instância de nossa view :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:swiz</span>=<span style="color: #ff0000;">&quot;http://swiz.swizframework.org&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:views</span>=<span style="color: #ff0000;">&quot;br.com.flexria.views.*&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;*&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:ApplicationSwizConfig</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;views:ContactView</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">horizontalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">verticalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;600&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;20&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: center;margin-top:60px;">
   <strong>Views</strong>
</p>
<p>A aplicação possui 2 view extremamente simples ContactView e PhoneView, sendo que a segunda será utilizado como filha da primeira:</p>
<p><strong>ContactView.mxml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Panel</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:views</span>=<span style="color: #ff0000;">&quot;br.com.flexria.views.*&quot;</span> </span>
<span style="color: #009900;"> 	<span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;{init()}&quot;</span></span>
<span style="color: #009900;"> 	<span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Contatos&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;actions/ContactAction.as&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:ViewStack</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_vs&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Canvas</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_canvasList&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox</span> <span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Nome&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_txFind&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;80%&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Buscar&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;find()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>	
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGrid</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_dataGrid&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;40&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;60&quot;</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">doubleClick</span>=<span style="color: #ff0000;">&quot;update()&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">doubleClickEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">dataProvider</span>=<span style="color: #ff0000;">&quot;{contactController.dataProvider}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Nome&quot;</span> 	<span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Email&quot;</span> 	<span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:DataGrid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:ControlBar</span> <span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;95%&quot;</span> <span style="color: #000066;">horizontalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">horizontalAlign</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">verticalAlign</span>=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Novo&quot;</span> 	<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnCreate&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{create()}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Editar&quot;</span> 	<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnUpdate&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{update()}&quot;</span>		<span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;{_dataGrid.selectedItem!=null}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Remover&quot;</span> 	<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnRemove&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{remove()}&quot;</span>		<span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;{_dataGrid.selectedItem!=null}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:ControlBar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Canvas</span>  <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_canvasForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TabNavigator</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Form</span> </span>
<span style="color: #009900;">					<span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">					<span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">					<span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">					<span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;10&quot;</span> </span>
<span style="color: #009900;">					<span style="color: #000066;">borderStyle</span>=<span style="color: #ff0000;">&quot;solid&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Contato&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormHeading</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;{contact.id&gt;</span></span>0?'Editando':'Incluindo'} contato&quot;/&gt;
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormItem</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Nome:&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> </span>
<span style="color: #009900;">							<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;339&quot;</span> </span>
<span style="color: #009900;">							<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_txtName&quot;</span> </span>
<span style="color: #009900;">							<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{contact.name}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:FormItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormItem</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Email:&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> </span>
<span style="color: #009900;">							<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;339&quot;</span> </span>
<span style="color: #009900;">							<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_txtEmail&quot;</span> </span>
<span style="color: #009900;">							<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{contact.email}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:FormItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormItem</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">direction</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Cancelar&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnCancel&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{cancel()}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Confirmar&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnConfirm&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{save()}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>		
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:FormItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #808080; font-style: italic;">&lt;!--Instancia de PhoneView--&gt;</span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;views:PhoneView</span> </span>
<span style="color: #009900;">					<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_phoneView&quot;</span> </span>
<span style="color: #009900;">					<span style="color: #000066;">contact</span>=<span style="color: #ff0000;">&quot;{contact}&quot;</span> </span>
<span style="color: #009900;">					<span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Telefones&quot;</span> </span>
<span style="color: #009900;">					<span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;{contact.id&gt;</span></span>0}&quot;/&gt;
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:TabNavigator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:ViewStack<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>PhoneView.mxml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Canvas</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #009900;"> 	<span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;{init()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;actions/PhoneAction.as&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:ViewStack</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_vs&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Canvas</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_canvasList&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGrid</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_dataGrid&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;60&quot;</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">doubleClick</span>=<span style="color: #ff0000;">&quot;update()&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">doubleClickEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">dataProvider</span>=<span style="color: #ff0000;">&quot;{phoneController.dataProvider}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:DataGridColumn</span> <span style="color: #000066;">headerText</span>=<span style="color: #ff0000;">&quot;Número&quot;</span> 	<span style="color: #000066;">dataField</span>=<span style="color: #ff0000;">&quot;number&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:DataGrid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:ControlBar</span> <span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;95%&quot;</span> <span style="color: #000066;">horizontalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">horizontalAlign</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">verticalAlign</span>=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Novo&quot;</span> 	<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnCreate&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{create()}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Editar&quot;</span> 	<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnUpdate&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{update()}&quot;</span>		<span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;{_dataGrid.selectedItem!=null}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Remover&quot;</span> 	<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnRemove&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{remove()}&quot;</span>		<span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;{_dataGrid.selectedItem!=null}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:ControlBar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Canvas</span>  <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_canvasForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Form</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">				<span style="color: #000066;">bottom</span>=<span style="color: #ff0000;">&quot;10&quot;</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">borderStyle</span>=<span style="color: #ff0000;">&quot;solid&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormHeading</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;{phone.id&gt;</span></span>0?'Editando':'Incluindo'} telefone&quot;/&gt;
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormItem</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Número:&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> </span>
<span style="color: #009900;">						<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;339&quot;</span> </span>
<span style="color: #009900;">						<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_txtNumber&quot;</span> </span>
<span style="color: #009900;">						<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{phone.number}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:FormItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:FormItem</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">direction</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Cancelar&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnCancel&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{cancel()}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Confirmar&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_btnConfirm&quot;</span> 	<span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;{save()}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>		
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:FormItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:ViewStack<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p style="text-align: center;margin-top:60px;">
   <strong>Actions</strong>
</p>
<p>E para finalizar as respectivas Actions para ContactView e PhoneView.<br />
Essas action possuem os métodos que disparam os eventos de chamada ao servidor e métodos handler que serão chamados quando a requisição for completada.<br />
Além disso temos a  meta tag [Autowire] que faz a injeção do respectivo controller.<br />
<strong>ContactAction.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.controllers.ContactController</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.events.ContactEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.vo.ContactVO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.swizframework.Swiz</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.events.CloseEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.controls.Alert</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#91;</span>Bindable<span style="color: #009900;">&#93;</span>
<span style="color: #000000; font-weight: bold;">private</span> var contact<span style="color: #339933;">:</span>ContactVO<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>Bindable<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#91;</span>Autowire<span style="color: #009900;">&#93;</span>
<span style="color: #000000; font-weight: bold;">public</span> var contactController<span style="color: #339933;">:</span>ContactController<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * init()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	find<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Swiz.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span>ContactEvent.<span style="color: #006633;">SAVE_COMPLETE</span>, saveCompleteHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Swiz.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span>ContactEvent.<span style="color: #006633;">REMOVE_COMPLETE</span>, removeCompleteHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * create()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	contact<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasForm<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * update()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	contact<span style="color: #339933;">=</span>_dataGrid.<span style="color: #006633;">selectedItem</span> as ContactVO<span style="color: #339933;">;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasForm<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * cancel()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function cancel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	contact<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * find()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function find<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
	var event<span style="color: #339933;">:</span>ContactEvent<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactEvent<span style="color: #009900;">&#40;</span>ContactEvent.<span style="color: #006633;">FIND</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	event.<span style="color: #006633;">contact</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	event.<span style="color: #006633;">contact</span>.<span style="color: #006633;">name</span><span style="color: #339933;">=</span>_txFind.<span style="color: #006633;">text</span><span style="color: #339933;">;</span>
	Swiz.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * save()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function save<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	contact.<span style="color: #006633;">name</span><span style="color: #339933;">=</span>_txtName.<span style="color: #006633;">text</span><span style="color: #339933;">;</span>
	contact.<span style="color: #006633;">email</span><span style="color: #339933;">=</span>_txtEmail.<span style="color: #006633;">text</span><span style="color: #339933;">;</span>
	var event<span style="color: #339933;">:</span>ContactEvent<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactEvent<span style="color: #009900;">&#40;</span>ContactEvent.<span style="color: #006633;">SAVE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	event.<span style="color: #006633;">contact</span><span style="color: #339933;">=</span>contact<span style="color: #339933;">;</span>
	Swiz.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * remove()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	Alert.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Deseja realmente excluir o registro selecionado?&quot;</span>, <span style="color: #0000ff;">&quot;Excluir&quot;</span>, Alert.<span style="color: #006633;">NO</span> <span style="color: #339933;">|</span> Alert.<span style="color: #006633;">YES</span> <span style="color: #339933;">|</span> Alert.<span style="color: #006633;">NONMODAL</span>, <span style="color: #000066; font-weight: bold;">null</span>, function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span>CloseEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">detail</span> <span style="color: #339933;">==</span> Alert.<span style="color: #006633;">YES</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			contact<span style="color: #339933;">=</span>_dataGrid.<span style="color: #006633;">selectedItem</span> as ContactVO<span style="color: #339933;">;</span>
			var event<span style="color: #339933;">:</span>ContactEvent<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> ContactEvent<span style="color: #009900;">&#40;</span>ContactEvent.<span style="color: #006633;">REMOVE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			event.<span style="color: #006633;">contact</span><span style="color: #339933;">=</span>contact<span style="color: #339933;">;</span>
			Swiz.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * saveCompleteHandler()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function saveCompleteHandler<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
	find<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * removeCompleteHandler()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function removeCompleteHandler<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
	find<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>PhoneAction.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.controllers.ContactController</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.controllers.PhoneController</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.events.ContactEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.events.PhoneEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.vo.ContactVO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.flexria.vo.PhoneVO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.swizframework.Swiz</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.events.CloseEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.controls.Alert</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>Bindable<span style="color: #009900;">&#93;</span>
<span style="color: #000000; font-weight: bold;">private</span> var _contact<span style="color: #339933;">:</span>ContactVO<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>Bindable<span style="color: #009900;">&#93;</span>
<span style="color: #000000; font-weight: bold;">private</span> var phone<span style="color: #339933;">:</span>PhoneVO<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PhoneVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>Bindable<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#91;</span>Autowire<span style="color: #009900;">&#93;</span>
<span style="color: #000000; font-weight: bold;">public</span> var phoneController<span style="color: #339933;">:</span>PhoneController<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> function set contact<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">:</span>ContactVO<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_contact<span style="color: #339933;">=</span>value<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_contact <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> _contact.<span style="color: #006633;">id</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * init()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	Swiz.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span>PhoneEvent.<span style="color: #006633;">SAVE_COMPLETE</span>, saveCompleteHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Swiz.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span>PhoneEvent.<span style="color: #006633;">REMOVE_COMPLETE</span>, removeCompleteHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * load()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
	var event<span style="color: #339933;">:</span>PhoneEvent<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PhoneEvent<span style="color: #009900;">&#40;</span>PhoneEvent.<span style="color: #006633;">LOAD</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	event.<span style="color: #006633;">contact</span><span style="color: #339933;">=</span>_contact<span style="color: #339933;">;</span>
	Swiz.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * create()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	phone<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PhoneVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasForm<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * update()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	phone<span style="color: #339933;">=</span>_dataGrid.<span style="color: #006633;">selectedItem</span> as PhoneVO<span style="color: #339933;">;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasForm<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * cancel()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function cancel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	phone<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PhoneVO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * save()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function save<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	phone.<span style="color: #006633;">contactId</span><span style="color: #339933;">=</span>_contact.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
	phone.<span style="color: #006633;">number</span><span style="color: #339933;">=</span>_txtNumber.<span style="color: #006633;">text</span><span style="color: #339933;">;</span>
	var event<span style="color: #339933;">:</span>PhoneEvent<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PhoneEvent<span style="color: #009900;">&#40;</span>PhoneEvent.<span style="color: #006633;">SAVE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	event.<span style="color: #006633;">phone</span><span style="color: #339933;">=</span>phone<span style="color: #339933;">;</span>
	Swiz.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * remove()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	Alert.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Deseja realmente excluir o registro selecionado?&quot;</span>, <span style="color: #0000ff;">&quot;Excluir&quot;</span>, Alert.<span style="color: #006633;">NO</span> <span style="color: #339933;">|</span> Alert.<span style="color: #006633;">YES</span> <span style="color: #339933;">|</span> Alert.<span style="color: #006633;">NONMODAL</span>, <span style="color: #000066; font-weight: bold;">null</span>, function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span>CloseEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">detail</span> <span style="color: #339933;">==</span> Alert.<span style="color: #006633;">YES</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			phone<span style="color: #339933;">=</span>_dataGrid.<span style="color: #006633;">selectedItem</span> as PhoneVO<span style="color: #339933;">;</span>
			var event<span style="color: #339933;">:</span>PhoneEvent<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PhoneEvent<span style="color: #009900;">&#40;</span>PhoneEvent.<span style="color: #006633;">REMOVE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			event.<span style="color: #006633;">phone</span><span style="color: #339933;">=</span>phone<span style="color: #339933;">;</span>
			Swiz.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * saveCompleteHandler()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function saveCompleteHandler<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
	load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * removeCompleteHandler()
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> function removeCompleteHandler<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
<span style="color: #009900;">&#123;</span>
	_vs.<span style="color: #006633;">selectedChild</span><span style="color: #339933;">=</span>_canvasList<span style="color: #339933;">;</span>
	load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Assim finalizamos nossa aplicação !!!</p>
<p><a href="wp-content/uploads/lumine-zend-flex/lumine-zend-flex.zip">O código fonte da aplicação pode ser baixado aqui</a> </p>
<p>Espero que esse tutorial possa ser utíl aos desenvolvedores PHP que pretendem utilizar essa arquitetura em seus projetos e peço desculpas por algum erro ou se deixei de explicar algo durante o post.<br />
Se houver alguma duvida podem podem perguntar via comentário no post ou email Q respondo na medida do possível..</p>
<p>Abraço a todos e até a próxima !!!!</p>
<p><a href="http://www.flexria.com.br/home/?p=174">Tutorial : Lumine + ZendAmf + Flex 1/5</a><br />
<a href="http://www.flexria.com.br/home/?p=210">Tutorial : Lumine + ZendAmf + Flex 2/5</a><br />
<a href="http://www.flexria.com.br/home/?p=251">Tutorial : Lumine + ZendAmf + Flex 3/5</a><br />
<a href="http://www.flexria.com.br/home/?p=252">Tutorial : Lumine + ZendAmf + Flex 4/5</a><br />
<a href="http://www.flexria.com.br/home/?p=276">Tutorial : Lumine + ZendAmf + Flex 5/5</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexria.com.br/home/?feed=rss2&#038;p=276</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

