<?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>涂0实验室 &#187; xml</title>
	<atom:link href="http://www.sulong.info/archives/tag/xml/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sulong.info</link>
	<description>一个程序员的成长之路</description>
	<lastBuildDate>Fri, 27 Aug 2010 01:54:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>让JAXB生成序列化的类</title>
		<link>http://www.sulong.info/archives/332</link>
		<comments>http://www.sulong.info/archives/332#comments</comments>
		<pubDate>Fri, 20 Nov 2009 13:36:30 +0000</pubDate>
		<dc:creator>sulong</dc:creator>
				<category><![CDATA[技巧]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.sulong.info/?p=332</guid>
		<description><![CDATA[默认jaxb生成的类是没有序列化的，但是我们经常需要他们序列化。jaxb ri有生成序列化的类的这样的功能，但由于这不属于标准的功能，所以需要手动的开启。开启的方法是在用来生成java类的xml schema文件头添加如下内容： &#60;annotation&#62; &#160; &#160; &#60;appinfo&#62; &#160; &#160; &#160; &#160; &#60;jaxb:globalBindings generateIsSetMethod=&#34;true&#34;&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;xjc:serializable uid=&#34;1&#34;/&#62; &#160; &#160; &#160; &#160; &#60;/jaxb:globalBindings&#62; &#160; &#160; &#60;/appinfo&#62; &#60;/annotation&#62; 另外，在使用jaxb的 xjc 编译器时，要加上 -extension 的参数。]]></description>
			<content:encoded><![CDATA[<p>默认jaxb生成的类是没有序列化的，但是我们经常需要他们序列化。jaxb ri有生成序列化的类的这样的功能，但由于这不属于标准的功能，所以需要手动的开启。开启的方法是在用来生成java类的xml schema文件头添加如下内容：</p>
<pre>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;annotation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appinfo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jaxb:globalBindings</span> <span style="color: #000066;">generateIsSetMethod</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xjc:serializable</span> <span style="color: #000066;">uid</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jaxb:globalBindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appinfo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/annotation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
</pre>
<p>另外，在使用jaxb的 xjc 编译器时，要加上 -extension 的参数。</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sulong.info/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sulong.info/archives/332/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>对使用annotation的一些反思</title>
		<link>http://www.sulong.info/archives/49</link>
		<comments>http://www.sulong.info/archives/49#comments</comments>
		<pubDate>Wed, 05 Dec 2007 14:50:26 +0000</pubDate>
		<dc:creator>sulong</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.sulong.info/archives/49</guid>
		<description><![CDATA[Annotation是java 5加入的新功能，可以加在java代码的类，域，方法和参数上，丰富程序语义。我一度认为引入annotation后，可以轻松地抛弃html，但是现在我发现annotation也有不好的地方： 侵入java代码，被标注代码会对标注产生依赖，比如，如果在类里加了javax.persistence.Entity标注，这意味着编译时得把javax.persistence.Entity所在包加入类路径，即使你并不实际使用这个标注。如果编译期不检测，到运行期才寻找Annotation定义的话，会好很多。xml则不会对代码有任何入侵。 需要重新编译才能升效。用XML时，只要更新一下XML重部署，现在是要把java代码也得重新编译。 要配置的信息很多时，多个annotation加在同一个目标上，格式很难排，不易读。 配置信息散在文档各个地方，不易于查找。 我觉得，使用Annotation时，最好要想清楚，你的代码是不是不会迁移到其它坏境，和annotation的耦合也是没问题可以接受的，否则，不要用annotation了。如果真的要用，最好只用annotation来做标注，但不要来做“配置”。比方说，如果你在用一个标注来配合做权限控制，在调用被标注的方法前，做一些权限的检测。那么，最好只在方法前的标注里说明这个方法需要被做权限检测，但不要说明需要被做怎么样的权限检测，例如下面的这个就很好， @NeedPermission&#40;methodName=&#34;writePost&#34;&#41; 但是下面这个就不好 @NeedPermission&#40;methodName=&#34;writePost&#34;, permission=&#34;read,write,admin&#34; condition=&#34;and&#34;&#41; 上面的写法，暴露了太多的细节（配置信息），而这些信息很可能会随着业务变化而变动。我觉得，把配置的细节统一存放到一个XML中，再用annotation来定义这些配置应该应用到哪里。]]></description>
			<content:encoded><![CDATA[<p>Annotation是java 5加入的新功能，可以加在java代码的类，域，方法和参数上，丰富程序语义。我一度认为引入annotation后，可以轻松地抛弃html，但是现在我发现annotation也有不好的地方：</p>
<ol>
<li>侵入java代码，被标注代码会对标注产生依赖，比如，如果在类里加了javax.persistence.Entity标注，这意味着编译时得把javax.persistence.Entity所在包加入类路径，即使你并不实际使用这个标注。如果编译期不检测，到运行期才寻找Annotation定义的话，会好很多。xml则不会对代码有任何入侵。</li>
<li>需要重新编译才能升效。用XML时，只要更新一下XML重部署，现在是要把java代码也得重新编译。</li>
<li>要配置的信息很多时，多个annotation加在同一个目标上，格式很难排，不易读。</li>
<li>配置信息散在文档各个地方，不易于查找。</li>
</ol>
<p>我觉得，使用Annotation时，最好要想清楚，你的代码是不是不会迁移到其它坏境，和annotation的耦合也是没问题可以接受的，否则，不要用annotation了。如果真的要用，最好只用annotation来做标注，但不要来做“配置”。比方说，如果你在用一个标注来配合做权限控制，在调用被标注的方法前，做一些权限的检测。那么，最好只在方法前的标注里说明这个方法需要被做权限检测，但不要说明需要被做怎么样的权限检测，例如下面的这个就很好，</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@NeedPermission<span style="color: #009900;">&#40;</span>methodName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;writePost&quot;</span><span style="color: #009900;">&#41;</span></div></div>
<p>但是下面这个就不好</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@NeedPermission<span style="color: #009900;">&#40;</span>methodName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;writePost&quot;</span>, permission<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;read,write,admin&quot;</span> condition<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;and&quot;</span><span style="color: #009900;">&#41;</span></div></div>
<p>上面的写法，暴露了太多的细节（配置信息），而这些信息很可能会随着业务变化而变动。我觉得，把配置的细节统一存放到一个XML中，再用annotation来定义这些配置应该应用到哪里。 </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.sulong.info/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.sulong.info/archives/49/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
