<?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>Sparkle&#039;s Workshop &#187; annotation</title>
	<atom:link href="http://weavesky.com/tag/annotation/feed/" rel="self" type="application/rss+xml" />
	<link>http://weavesky.com</link>
	<description></description>
	<lastBuildDate>Tue, 24 Apr 2012 03:32:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>annotation for acegi</title>
		<link>http://weavesky.com/2005/04/19/annotation-for-acegi/</link>
		<comments>http://weavesky.com/2005/04/19/annotation-for-acegi/#comments</comments>
		<pubDate>Tue, 19 Apr 2005 01:04:46 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[annotation]]></category>

		<guid isPermaLink="false">http://69.197.153.196/?p=177</guid>
		<description><![CDATA[UPDATE: The new version of acegi has itself&#8217;s annotation implement. So you don&#8217;t need this any more. annotation is so good that i can&#8217;t wait to use it in acegi code sample import java.util.List; import org.gotblog.common.acegi.SecurityConfig; import org.springframework.transaction.annotation.Transactional; public interface BookManager &#123; @Transactional @SecurityConfig&#40; &#123; &#34;ROLE_USER&#34;, &#34;ROLE_ANONYMOUS&#34; &#125;&#41; public List listBook&#40;&#41;; &#125; here&#8217;s my implementation <a href='http://weavesky.com/2005/04/19/annotation-for-acegi/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: The new version of acegi has itself&#8217;s annotation implement. So you don&#8217;t need this any more.</strong></p>
<p>annotation is so good that i can&#8217;t wait to use it in acegi</p>
<p>code sample</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;">java.util.List</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.gotblog.common.acegi.SecurityConfig</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.transaction.annotation.Transactional</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> BookManager <span style="color: #009900;">&#123;</span>
	@Transactional
	@SecurityConfig<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;ROLE_USER&quot;</span>, <span style="color: #0000ff;">&quot;ROLE_ANONYMOUS&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> listBook<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>here&#8217;s my implementation for it</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.gotblog.common.acegi</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">annotation</span>.<span style="color: #006633;">ElementType</span>.<span style="color: #006633;">METHOD</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">annotation</span>.<span style="color: #006633;">ElementType</span>.<span style="color: #006633;">TYPE</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">annotation</span>.<span style="color: #006633;">RetentionPolicy</span>.<span style="color: #006633;">RUNTIME</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Retention</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Target</span><span style="color: #339933;">;</span>
&nbsp;
    @Target<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> TYPE, METHOD <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    @Retention<span style="color: #009900;">&#40;</span>RUNTIME<span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> SecurityConfig <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> value<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>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.gotblog.common.acegi</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Annotation</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Field</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Method</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collection</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashSet</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Set</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.metadata.Attributes</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AcegiAnnotationAttributes <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Attributes</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// TODO need to add cache</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Collection</span> getAttributes<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> targetClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Set<span style="color: #339933;">&lt;</span>net.<span style="color: #006633;">sf</span>.<span style="color: #006633;">acegisecurity</span>.<span style="color: #006633;">SecurityConfig</span><span style="color: #339933;">&gt;</span> configs <span style="color: #339933;">=</span>
			<span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;</span>net.<span style="color: #006633;">sf</span>.<span style="color: #006633;">acegisecurity</span>.<span style="color: #006633;">SecurityConfig</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Annotation</span> annotation <span style="color: #339933;">:</span> targetClass.<span style="color: #006633;">getAnnotations</span><span style="color: #009900;">&#40;</span><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;">if</span> <span style="color: #009900;">&#40;</span>annotation <span style="color: #000000; font-weight: bold;">instanceof</span> SecurityConfig<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				SecurityConfig config <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SecurityConfig<span style="color: #009900;">&#41;</span> annotation<span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> value <span style="color: #339933;">:</span> config.<span style="color: #006633;">value</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					configs.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> net.<span style="color: #006633;">sf</span>.<span style="color: #006633;">acegisecurity</span>.<span style="color: #006633;">SecurityConfig</span><span style="color: #009900;">&#40;</span>value<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: #000000; font-weight: bold;">break</span><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> configs<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Collection</span> getAttributes<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> targetClass, <span style="color: #000000; font-weight: bold;">Class</span> filter<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;Not support filter&quot;</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: #003399;">Collection</span> getAttributes<span style="color: #009900;">&#40;</span><span style="color: #003399;">Method</span> targetMethod<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Set<span style="color: #339933;">&lt;</span>net.<span style="color: #006633;">sf</span>.<span style="color: #006633;">acegisecurity</span>.<span style="color: #006633;">SecurityConfig</span><span style="color: #339933;">&gt;</span> configs <span style="color: #339933;">=</span>
			<span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;</span>net.<span style="color: #006633;">sf</span>.<span style="color: #006633;">acegisecurity</span>.<span style="color: #006633;">SecurityConfig</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Annotation</span> annotation <span style="color: #339933;">:</span> targetMethod.<span style="color: #006633;">getAnnotations</span><span style="color: #009900;">&#40;</span><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;">if</span> <span style="color: #009900;">&#40;</span>annotation <span style="color: #000000; font-weight: bold;">instanceof</span> SecurityConfig<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				SecurityConfig config <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SecurityConfig<span style="color: #009900;">&#41;</span> annotation<span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> value <span style="color: #339933;">:</span> config.<span style="color: #006633;">value</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					configs.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> net.<span style="color: #006633;">sf</span>.<span style="color: #006633;">acegisecurity</span>.<span style="color: #006633;">SecurityConfig</span><span style="color: #009900;">&#40;</span>value<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: #000000; font-weight: bold;">break</span><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> configs<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Collection</span> getAttributes<span style="color: #009900;">&#40;</span><span style="color: #003399;">Method</span> targetMethod, <span style="color: #000000; font-weight: bold;">Class</span> filter<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;Not support filter&quot;</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: #003399;">Collection</span> getAttributes<span style="color: #009900;">&#40;</span><span style="color: #003399;">Field</span> targetField<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;Not support field annotation&quot;</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: #003399;">Collection</span> getAttributes<span style="color: #009900;">&#40;</span><span style="color: #003399;">Field</span> targetField, <span style="color: #000000; font-weight: bold;">Class</span> filter<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;Not support field annotation&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></div></div>


<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;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;acegiAnnotationAttributes&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.gotblog.common.acegi.AcegiAnnotationAttributes&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> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;objectDefinitionSource&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;net.sf.acegisecurity.intercept.method.MethodDefinitionAttributes&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;attributes&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">local</span>=<span style="color: #ff0000;">&quot;acegiAnnotationAttributes&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 style="color: #000000; font-weight: bold;">&gt;</span></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></pre></div></div>

<p>it works fine and i haven&#8217;t optimized it for performance</p>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2005/04/19/annotation-for-acegi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

