﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-积少成多</title><link>http://www.blogjava.net/ilovebabyfat/</link><description>垃圾堆</description><language>zh-cn</language><lastBuildDate>Tue, 05 May 2026 21:59:20 GMT</lastBuildDate><pubDate>Tue, 05 May 2026 21:59:20 GMT</pubDate><ttl>60</ttl><item><title>java web中的路径获取</title><link>http://www.blogjava.net/ilovebabyfat/archive/2013/10/18/405412.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Fri, 18 Oct 2013 13:29:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2013/10/18/405412.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/405412.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2013/10/18/405412.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/405412.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/405412.html</trackback:ping><description><![CDATA[<div><div><span style="color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; line-height: 25px;">如果是Servlet , Action , Controller, 或则Filter , Listener , 拦截器等相关类时， 我们只需要获得ServletContext， 然后通过ServletContext.getRealPath("/")来获取当前应用在服务器上的物理地址</span><br /><br /><span style="color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; line-height: 25px;">如果在类中取不到ServletContext时， 有两种方式可以做到</span><br /><div><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">1) 利用Java的类加载机制 调用 XXX.class.getClassLoader().getResource(""); 方法来获取到ClassPath , 然后处理获得WebRoot目录，这种方式只能是该class在WebRoot/WEB-INF/classes下才能生效， 如果该class被打包到一个<a href="http://www.chinabyte.com/keyword/JAR/" target="_blank" style="text-decoration: none; color: #555555; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d30010;">jar</a>文件中， 则该方法失效。这时就应该用下面一种方式<br /><br />2) spring框架的思路, 在WEB-INF/web.xml中 ， 创建一个webAppRootKey的param, 指定一个值(默认为webapp.root)作为键值， 然后通过Listener , 或者Filter , 或者Servlet 执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root 分别作为Key , Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径<br /><br /><br /></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">下面是一些得到classpath和当前类的绝对路径的一些方法。你可使用其中的一些方法来得到你需要的资源的绝对路径:</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;"></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　1.DebitNoteAction.class.getResource("")</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　得到的是当前类FileTest.class文件的URI目录。不包括自己!</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　如：<span style="background-color: yellow;">file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/atacarnet/src/com/evi/modules/atacarnet/action/</span></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　2.DebitNoteAction.class.getResource("/")</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　得到的是当前的classpath的绝对URI路径。</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　如：<span style="background-color: yellow;">file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/</span></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　3.Thread.currentThread().getContextClassLoader().getResource("")</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　得到的也是当前ClassPath的绝对URI路径</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　如：<span style="background-color: yellow;">file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/</span></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　4.DebitNoteAction.class.getClassLoader().getResource("") 或ClassLoader.getSystemResource("")</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　得到的也是当前ClassPath的绝对URI路径。</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　如：<span style="background-color: yellow;">file:/D:/eclipse/springTest/WebRoot/WEB-INF/classes/</span></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　5.取得服务器相对路径</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　System.getProperty("user.dir")</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　例如:<span style="background-color: yellow;">E:\apache-tomcat-5.5.16\apache-tomcat-5.5.16\bin</span></p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　我推荐使用Thread.currentThread().getContextClassLoader().getResource("")来得到当前的classpath的绝对路径的URI表示法</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　6.取得项目中的绝对路径</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　一般用request.getRealPath("/")或request.getRealPath("/config/")</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　但现在不提倡使用request.getRealPath("/")了，大家可试用ServletContext.getRealPath("/")方法得到Web应用程序的根目录的绝对路径</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　要取得src的文件非常容易，因为src是默认的相对目录，比如你说要取得src下com目录的test.java文件，你只需要这样就够了</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　File f = new File(com/test.java);</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　但如果我要取得不在src目录或者WebRoot目录下的文件呢，而是要从src或者WebRoot同级的目录中取呢，比如说doc吧</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　我的硬方法是这样实现的：</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　String path = this.getServletContext().getRealPath("/");</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　Properties p = new Properties();</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　p.load(new FileInputStream(new File(path.substring(0,(path.lastIndexOf("\\WebRoot") + 1)) + "doc/db.properties")));</p><p style="margin: 0pt 0pt 12px; padding: 0pt; border: 0px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif, 'microsoft yahei'; color: #555555;">　　System.out.println(p.getProperty("driverName"));</p></div></div></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/405412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2013-10-18 21:29 <a href="http://www.blogjava.net/ilovebabyfat/archive/2013/10/18/405412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache Commons Lang_User guide</title><link>http://www.blogjava.net/ilovebabyfat/archive/2012/04/18/375096.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Wed, 18 Apr 2012 05:47:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2012/04/18/375096.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/375096.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2012/04/18/375096.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/375096.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/375096.html</trackback:ping><description><![CDATA[<div><div align="center">       <h1>The Commons <em>Lang</em> Package</h1>       <div><h2>Users Guide<a name="Users_Guide"></a></h2>       <br />       <a href="http://commons.apache.org/lang/userguide.html#Description">[Description]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.">[lang3.*]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.builder.">[lang3.builder.*]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.math.">[lang3.math.*]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.mutable.">[lang3.mutable.*]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.text.">[lang3.text.*]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.time.">[lang3.time.*]</a>       <a href="http://commons.apache.org/lang/userguide.html#lang3.concurrent.">[lang3.concurrent.*]</a>       <br /><br />     </div>   </div>    <div><h2>Description<a name="Description"></a></h2>这个包增强了标准jdk的java.lang包，重用性很高。<p>顶层的包里面包含了一些工具类，同时一些子包里面，包含了math,concurrent和builder。使用这些工具类很方便。子包中可能包含一些需要实现的借口和类。他们更像了全局的功能实现。<br /></p>    <p>Lang 3.0 is JDK 1.5+; before that Lang was JDK 1.2+. In both cases  you can find features of later JDKs being maintained by us and likely  to be removed or modified in favour of the JDK in the next major  version. Note that Lang 3.0 uses a different package than its  predecessors, allowing it to be used at the same time as an earlier  version. <br /></p><p>Lang 3.0需要jdk 1.5+，之前的版本只需要1.2+。<br /></p>    <p>You will find deprecated methods as you stroll through the Lang documentation. These are removed in the next major version. </p>    <p>Before we begin, it's a good time to mention the Utils classes.  They all contain empty public constructors with warnings not to use.  This may seem an odd thing to do, but it allows tools like Velocity to  access the class as if it were a bean. In other words, yes we know about  private constructors and have chosen not to use them. </p>   </div>     <div><h2>lang3.*<a name="lang3."></a></h2>     <div><h3>String manipulation - StringUtils, StringEscapeUtils, RandomStringUtils, Tokenizer, WordUtils<a name="String_manipulation_-_StringUtils_StringEscapeUtils_RandomStringUtils_Tokenizer_WordUtils"></a></h3>      <p>Lang has a series of String utilities. The first is StringUtils,  oodles and oodles of functions which tweak, transform, squeeze and  cuddle java.lang.Strings. In addition to StringUtils, there are a series  of other String manipulating classes; RandomStringUtils,  StringEscapeUtils and Tokenizer. RandomStringUtils speaks for itself.  It's provides ways in which to generate pieces of text, such as might be  used for default passwords. StringEscapeUtils contains methods to  escape and unescape Java, JavaScript, HTML, XML and SQL. Tokenizer is an  improved alternative to java.util.StringTokenizer. </p>      <p>These are ideal classes to start using if you're looking to get  into Lang. StringUtils' capitalize, substringBetween/Before/After, split  and join are good methods to begin with. If you use java.sql.Statements  a lot, StringEscapeUtils.escapeSql might be of interest. </p>      <p>In addition to these classes, WordUtils is another String  manipulator. It works on Strings at the word level, for example  WordUtils.capitalize will capitalize every word in a piece of text.  WordUtils also contains methods to wrap text. </p>     </div>      <div><h3>Character handling - CharSetUtils, CharSet, CharRange, CharUtils<a name="Character_handling_-_CharSetUtils_CharSet_CharRange_CharUtils"></a></h3>      <p>In addition to dealing with Strings, it's also important to deal  with chars and Characters. CharUtils exists for this purpose, while  CharSetUtils exists for set-manipulation of Strings. Be careful,  although CharSetUtils takes an argument of type String, it is only as a  set of characters. For example, <tt>CharSetUtils.delete("testtest", "tr")</tt> will remove all t's and all r's from the String, not just the String "tr". </p>      <p>CharRange and CharSet are both used internally by CharSetUtils, and will probaby rarely be used. </p>     </div>      <div><h3>JVM interaction - SystemUtils, CharEncoding<a name="JVM_interaction_-_SystemUtils_CharEncoding"></a></h3>      <p>SystemUtils is a simple little class which makes it easy to find  out information about which platform you are on. For some, this is a  necessary evil. It was never something I expected to use myself until I  was trying to ensure that Commons Lang itself compiled under JDK 1.2.  Having pushed out a few JDK 1.3 bits that had slipped in (<tt>Collections.EMPTY_MAP</tt>  is a classic offender), I then found that one of the Unit Tests was  dying mysteriously under JDK 1.2, but ran fine under JDK 1.3. There was  no obvious solution and I needed to move onwards, so the simple solution  was to wrap that particular test in a <tt>if(SystemUtils.isJavaVersionAtLeast(1.3f)) {</tt>, make a note and move on. </p>      <p>The CharEncoding class is also used to interact with the Java  environment and may be used to see which character encodings are  supported in a particular environment. </p>     </div>      <div><h3>Serialization - SerializationUtils, SerializationException<a name="Serialization_-_SerializationUtils_SerializationException"></a></h3>      <p>Serialization doesn't have to be that hard! A simple util class  can take away the pain, plus it provides a method to clone an object by  unserializing and reserializing, an old Java trick.</p>     </div>      <div><h3>Assorted functions - ObjectUtils, ClassUtils, ArrayUtils, BooleanUtils<a name="Assorted_functions_-_ObjectUtils_ClassUtils_ArrayUtils_BooleanUtils"></a></h3>      <p>Would you believe it, ObjectUtils contains handy functions for  Objects, mainly null-safe implementations of the methods on  java.lang.Object. </p>      <p>ClassUtils is largely a set of helper methods for reflection. Of  special note are the comparators hidden away in ClassUtils, useful for  sorting Class and Package objects by name; however they merely sort  alphabetically and don't understand the common habit of sorting <tt>java</tt> and <tt>javax</tt> first. </p>      <p>Next up, ArrayUtils. This is a big one with many methods and  many overloads of these methods so it is probably worth an in depth look  here. Before we begin, assume that every method mentioned is overloaded  for all the primitives and for Object. Also, the short-hand 'xxx'  implies a generic primitive type, but usually also includes Object. </p>      <ul><li>ArrayUtils provides singleton empty arrays for all the basic  types. These will largely be of use in the Collections API with its  toArray methods, but also will be of use with methods which want to  return an empty array on error. </li><li><tt>add(xxx[], xxx)</tt> will add a primitive type to an array, resizing the array as you'd expect. Object is also supported. </li><li><tt>clone(xxx[])</tt> clones a primitive or Object array. </li><li><tt>contains(xxx[], xxx)</tt> searches for a primitive or Object in a primitive or Object array. </li><li><tt>getLength(Object)</tt> returns the length of any array or an IllegalArgumentException if the parameter is not an array. <tt>hashCode(Object)</tt>, <tt>equals(Object, Object)</tt>, <tt>toString(Object)</tt> </li><li><tt>indexOf(xxx[], xxx)</tt> and <tt>indexOf(xxx[], xxx, int)</tt>  are copies of the classic String methods, but this time for  primitive/Object arrays. In addition, a lastIndexOf set of methods  exists. </li><li><tt>isEmpty(xxx[])</tt> lets you know if an array is zero-sized or null. </li><li><tt>isSameLength(xxx[], xxx[])</tt> returns true if the arrays are the same length. </li><li>Along side the add methods, there are also remove methods of two types. The first type remove the value at an index, <tt>remove(xxx[], int)</tt>, while the second type remove the first value from the array, <tt>remove(xxx[], xxx)</tt>. </li><li>Nearing the end now. The <tt>reverse(xxx[])</tt> method turns an array around. </li><li>The <tt>subarray(xxx[], int, int)</tt> method splices an array out of a larger array. </li><li>Primitive to primitive wrapper conversion is handled by the <tt>toObject(xxx[])</tt> and <tt>toPrimitive(Xxx[])</tt> methods. </li></ul>      <p>Lastly, <tt>ArrayUtils.toMap(Object[])</tt> is worthy of special  note. It is not a heavily overloaded method for working with arrays,  but a simple way to create Maps from literals. </p>      <div><div><h5>Using toMap<a name="Using_toMap"></a></h5>      <div><pre> <br />&nbsp; &nbsp; &nbsp; &nbsp;Map colorMap = MapUtils.toMap(new String[][] {{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{"RED", "#FF0000"},<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{"GREEN", "#00FF00"},<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{"BLUE", "#0000FF"}<br />&nbsp; &nbsp; &nbsp; &nbsp;});<br />&nbsp; &nbsp; &nbsp;</pre></div>       <p>Our final util class is BooleanUtils. It contains various Boolean acting methods, probably of most interest is the <tt>BooleanUtils.toBoolean(String)</tt> method which turns various positive/negative Strings into a Boolean object, and not just true/false as with Boolean.valueOf. </p>     </div></div></div>      <div><h3>Flotsam - BitField, Validate<a name="Flotsam_-_BitField_Validate"></a></h3>      <p>On reaching the end of our package, we are left with a couple of classes that haven't fit any of the topics so far. </p>      <p>The BitField class provides a wrapper class around the classic  bitmask integer, whilst the Validate class may be used for assertions  (remember, we support Java 1.2). </p>     </div>    </div>     <div><h2>lang3.builder.*<a name="lang3.builder."></a></h2>         <p>When you write a hashcode, do you check Bloch's Effective Java?  No? You just hack in a quick number? Well HashCodeBuilder will save your  day. It, and its buddies (EqualsBuilder, CompareToBuilder,  ToStringBuilder), take care of the nasty bits while you focus on the  important bits, like which fields will go into making up the hashcode.</p>    </div>     <div><h2>lang3.math.*<a name="lang3.math."></a></h2>         <p>Although Commons-Math also exists, some basic mathematical  functions are contained within Lang. These include classes to a Fraction  class, various utilities for random numbers, and the flagship class,  NumberUtils which contains a handful of classic number functions. </p>     <p>There are two aspects of this package I would like to highlight. The first is <tt>NumberUtils.createNumber(String)</tt>,  a method which does its best to convert a String into a Number object.  You have no idea what type of Number it will return, so you should call  the relevant <tt>xxxValue</tt> method when you reach the point of needing a number. NumberUtils also has a related <tt>isNumber</tt> method. </p>    </div>     <div><h2>lang3.mutable.*<a name="lang3.mutable."></a></h2>         <p>New in 2.1, the mutable package provides mutable wrappers for  primitive values (such as int, long, etc.) and Object. These wrappers  are simiar to the wrappers provided by the Java API, but allow the  wrapped value to be changed without needing to create a separate wrapper  object.     </p>    </div>     <div><h2>lang3.text.*<a name="lang3.text."></a></h2>        <p>The text package was added in Lang 2.2. It provides, amongst other classes, a replacement for StringBuffer named <tt>StrBuilder</tt>, a class for substituting variables within a String named <tt>StrSubstitutor</tt> and a replacement for StringTokenizer named <tt>StrTokenizer</tt>. While somewhat ungainly, the <tt>Str</tt> prefix has been used to ensure we don't clash with any current or future standard Java classes. </p>    </div>     <div><h2>lang3.time.*<a name="lang3.time."></a></h2>         <p>Lang 2.0 saw the arrival of a time package. It contains some  basic utilities for manipulating time (a delorean, police box and  grandfather clock?). These include a StopWatch for simple performance  measurements and an optimised FastDateFormat class. </p>     <p>New in Lang 2.1 is the DurationFormatUtils class, which provides various methods for formatting durations. </p>    </div>     <div><h2>lang3.concurrent.*<a name="lang3.concurrent."></a></h2>    <p>      In Lang 3.0 a new <em>concurrent</em> package was introduced containing      interfaces and classes to support programming with multiple threads. Its      aim is to serve as an extension of the <em>java.util.concurrent</em>      package of the JDK.    </p>     <div><h3>Concurrent initializers<a name="Concurrent_initializers"></a></h3>    <p>      A group of classes deals with the correct creation and initialization of      objects that are accessed by multiple threads. All these classes implement      the <tt>ConcurrentInitializer</tt> interface which provides just a      single method:    </p>    <div><pre>public interface ConcurrentInitializer&lt;T&gt; {<br />&nbsp; &nbsp; T get() throws ConcurrentException;<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      A <tt>ConcurrentInitializer</tt> produces an object. By calling the      <tt>get()</tt> method the object managed by the initializer can be      obtained. There are different implementations of the interface available      addressing various use cases:    </p>    <p>      <tt>ConstantInitializer</tt> is a very straightforward implementation of      the <tt>ConcurrentInitializer</tt> interface: An instance is passed an      object when it is constructed. In its <tt>get()</tt> method it simply      returns this object. This is useful, for instance in unit tests or in cases      when you want to pass a specific object to a component which expects a      <tt>ConcurrentInitializer</tt>.    </p>    <p>      The <tt>LazyInitializer</tt> class can be used to defer the creation of      an object until it is actually used. This makes sense, for instance, if the      creation of the object is expensive and would slow down application startup      or if the object is needed only for special executions. <tt>LazyInitializer</tt>      implements the <em>double-check idiom for an instance field</em> as      discussed in Joshua Bloch's "Effective Java", 2nd edition, item 71. It      uses <strong>volatile</strong> fields to reduce the amount of      synchronization. Note that this idiom is appropriate for instance fields      only. For <strong>static</strong> fields there are superior alternatives.    </p>    <p>      We provide an example use case to demonstrate the usage of this class: A      server application uses multiple worker threads to process client requests.      If such a request causes a fatal error, an administrator is to be notified      using a special messaging service. We assume that the creation of the      messaging service is an expensive operation. So it should only be performed      if an error actually occurs. Here is where <tt>LazyInitializer</tt>      comes into play. We create a specialized subclass for creating and      initializing an instance of our messaging service. <tt>LazyInitializer</tt>      declares an abstract <tt>initialize()</tt> method which we have to      implement to create the messaging service object:    </p>    <div><pre>public class MessagingServiceInitializer<br />&nbsp; extends LazyInitializer&lt;MessagingService&gt; {<br />&nbsp; &nbsp; protected MessagingService initialize() throws ConcurrentException {<br />&nbsp; &nbsp; &nbsp; &nbsp; // Do all necessary steps to create and initialize the service object<br />&nbsp; &nbsp; &nbsp; &nbsp; MessagingService service = ...<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; return service;<br />&nbsp; &nbsp; }<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      Now each server thread is passed a reference to a shared instance of our      new <tt>MessagingServiceInitializer</tt> class. The threads run in a      loop processing client requests. If an error is detected, the messaging      service is obtained from the initializer, and the administrator is      notified:    </p>    <div><pre>public class ServerThread implements Runnable {<br />&nbsp; &nbsp; /** The initializer for obtaining the messaging service. */<br />&nbsp; &nbsp; private final ConcurrentInitializer&lt;MessagingService&gt; initializer;<br /><br />&nbsp; &nbsp; public ServerThread(ConcurrentInitializer&lt;MessagingService&gt; init) {<br />&nbsp; &nbsp; &nbsp; &nbsp; initializer = init;<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; public void run() {<br />&nbsp; &nbsp; &nbsp; &nbsp; while (true) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // wait for request<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // process request<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (FatalServerException ex) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // get messaging service<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessagingService svc = initializer.get();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; svc.notifyAdministrator(ex);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (ConcurrentException cex) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cex.printStackTrace();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      The <tt>AtomicInitializer</tt> class is very similar to      <tt>LazyInitializer</tt>. It serves the same purpose: to defer the      creation of an object until it is needed. The internal structure is also      very similar. Again there is an abstract <tt>initialize()</tt> method      which has to be implemented by concrete subclasses in order to create and      initialize the managed object. Actually, in our example above we can turn      the <tt>MessagingServiceInitializer</tt> into an atomic initializer by      simply changing the <strong>extends</strong> declaration to refer to      <tt>AtomicInitializer&lt;MessagingService&gt;</tt> as super class.    </p>    <p>      The difference between <tt>AtomicInitializer</tt> and      <tt>LazyInitializer</tt> is that the former uses classes from the      <tt>java.util.concurrent.atomic</tt> package for its implementation      (hence the name). This has the advantage that no synchronization is needed,      thus the implementation is usually more efficient than the one of the      <tt>LazyInitializer</tt> class. However, there is one drawback: Under      high load, if multiple threads access the initializer concurrently, it is      possible that the <tt>initialize()</tt> method is invoked multiple      times. The class guarantees that <tt>get()</tt> always returns the      same object though; so objects created accidently are immideately discarded.    </p>    <p>      With <tt>AtomicSafeInitializer</tt> there is yet another variant      implementing the lazy initializing pattern. Its implementation is close to      <tt>AtomicInitializer</tt>; it also uses atomic variables internally      and therefore does not need synchronization. The name "Safe" is      derived from the fact that it implements an additional check which guarantees      that the <tt>initialize()</tt> method is called only once. So it      behaves exactly in the same way as <tt>LazyInitializer</tt>.    </p>    <p>      Now, which one of the lazy initializer implementations should you use?      First of all we have to state that is is problematic to give general      recommendations regarding the performance of these classes. The initializers      make use of low-level functionality whose efficiency depends on multiple      factors including the target platform and the number of concurrent threads.      So developers should make their own benchmarks in scenarios close to their      specific use cases. The following statements are rules of thumb which have      to be verified in practice.    </p>    <p>      <tt>AtomicInitializer</tt> is probably the most efficient implementation      due to its lack of synchronization and further checks. Its main drawback is      that the <tt>initialize()</tt> method can be called multiple      times. In cases where this is not an issue <tt>AtomicInitializer</tt> is      a good choice. <tt>AtomicSafeInitializer</tt> and      <tt>LazyInitializer</tt> both guarantee that the initialization method      is called only once. Because <tt>AtomicSafeInitializer</tt> does not      use synchronization it is probably slightly more efficient than      <tt>LazyInitializer</tt>, but the concrete numbers might depend on the      level of concurrency.    </p>    <p>      Another implementation of the <tt>ConcurrentInitializer</tt> interface      is <tt>BackgroundInitializer</tt>. It is again an abstract base class      with an <tt>initialize()</tt> method that has to be defined by concrete      subclasses. The idea of <tt>BackgroundInitializer</tt> is that it calls      the <tt>initialize()</tt> method in a separate worker thread. An      application creates a background initializer and starts it. Then it can      continue with its work while the initializer runs in parallel. When the      application needs the results of the initializer it calls its      <tt>get()</tt> method. <tt>get()</tt> blocks until the initialization      is complete. This is useful for instance at application startup. Here      initialization steps (e.g. reading configuration files, opening a database      connection, etc.) can be run in background threads while the application      shows a splash screen and constructs its UI.    </p>    <p>      As a concrete example consider an application that has to read the content      of a URL - maybe a page with news - which is to be displayed to the user after      login. Because loading the data over the network can take some time a      specialized implementation of <tt>BackgroundInitializer</tt> can be      created for this purpose:    </p>    <div><pre>public class URLLoader extends BackgroundInitializer&lt;String&gt; {<br />&nbsp; &nbsp; /** The URL to be loaded. */<br />&nbsp; &nbsp; private final URL url;<br /><br />&nbsp; &nbsp; public URLLoader(URL u) {<br />&nbsp; &nbsp; &nbsp; &nbsp; url = u;<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; protected String initialize() throws ConcurrentException {<br />&nbsp; &nbsp; &nbsp; try {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputStream in = url.openStream();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // read content into string<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return content;<br />&nbsp; &nbsp; &nbsp; } catch (IOException ioex) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new ConcurrentException(ioex);<br />&nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      An application creates an instance of <tt>URLLoader</tt> and starts it.      Then it can do other things. When it needs the content of the URL it calls      the initializer's <tt>get()</tt> method:    </p>    <div><pre>URL url = new URL("http://www.application-home-page.com/");<br />URLLoader loader = new URLLoader(url);<br />loader.start();&nbsp;// this starts the background initialization<br /><br />// do other stuff<br />...<br />// now obtain the content of the URL<br />String content;<br />try {<br />&nbsp; &nbsp; content = loader.get();&nbsp;// this may block<br />} catch (ConcurrentException cex) {<br />&nbsp; &nbsp; content = "Error when loading URL " + url;<br />}<br />// display content<br />&nbsp; &nbsp;</pre></div>    <p>      Related to <tt>BackgroundInitializer</tt> is the      <tt>MultiBackgroundInitializer</tt> class. As the name implies, this      class can handle multiplie initializations in parallel. The basic usage      scenario is that a <tt>MultiBackgroundInitializer</tt> instance is      created. Then an arbitrary number of <tt>BackgroundInitializer</tt>      objects is added using the <tt>addInitializer()</tt> method. When adding      an initializer a string has to be provided which is later used to obtain      the result for this initializer. When all initializers have been added the      <tt>start()</tt> method is called. This starts processing of all      initializers. Later the <tt>get()</tt> method can be called. It waits      until all initializers have finished their initialization. <tt>get()</tt>      returns an object of type <tt>MultiBackgroundInitializer.MultiBackgroundInitializerResults</tt>.      This object provides information about all initializations that have been      performed. It can be checked whether a specific initializer was successful      or threw an exception. Of course, all initialization results can be queried.    </p>    <p>      With <tt>MultiBackgroundInitializer</tt> we can extend our example to      perform multiple initialization steps. Suppose that in addition to loading      a web site we also want to create a JPA entity manager factory and read a      configuration file. We assume that corresponding <tt>BackgroundInitializer</tt>      implementations exist. The following example fragment shows the usage of      <tt>MultiBackgroundInitializer</tt> for this purpose:    </p>    <div><pre>MultiBackgroundInitializer initializer = new MultiBackgroundInitializer();<br />initializer.addInitializer("url", new URLLoader(url));<br />initializer.addInitializer("jpa", new JPAEMFInitializer());<br />initializer.addInitializer("config", new ConfigurationInitializer());<br />initializer.start();&nbsp;// start background processing<br /><br />// do other interesting things in parallel<br />...<br />// evaluate the results of background initialization<br />MultiBackgroundInitializer.MultiBackgroundInitializerResults results =<br />&nbsp; &nbsp; initializer.get();<br />String urlContent = (String) results.getResultObject("url");<br />EntityManagerFactory emf =<br />&nbsp; &nbsp; (EntityManagerFactory) results.getResultObject("jpa");<br />...<br />&nbsp; &nbsp;</pre></div>    <p>      The child initializers are added to the multi initializer and are assigned      a unique name. The object returned by the <tt>get()</tt> method is then      queried for the single results using these unique names.    </p>    <p>      If background initializers - including <tt>MultiBackgroundInitializer</tt>      - are created using the standard constructor, they create their own      <tt>ExecutorService</tt> which is used behind the scenes to execute the      worker tasks. It is also possible to pass in an <tt>ExecutorService</tt>      when the initializer is constructed. That way client code can configure      the <tt>ExecutorService</tt> according to its specific needs; for      instance, the number of threads available could be limited.    </p>    </div>     <div><h3>Utility classes<a name="Utility_classes"></a></h3>    <p>      Another group of classes in the new <tt>concurrent</tt> package offers      some generic functionality related to concurrency. There is the      <tt>ConcurrentUtils</tt> class with a bunch of static utility methods.      One focus of this class is dealing with exceptions thrown by JDK classes.      Many JDK classes of the executor framework throw exceptions of type      <tt>ExecutionException</tt> if something goes wrong. The root cause of      these exceptions can also be a runtime exception or even an error. In      typical Java programming you often do not want to deal with runtime      exceptions directly; rather you let them fall through the hierarchy of      method invocations until they reach a central exception handler. Checked      exceptions in contrast are usually handled close to their occurrence. With      <tt>ExecutionException</tt> this principle is violated. Because it is a      checked exception, an application is forced to handle it even if the cause      is a runtime exception. So you typically have to inspect the cause of the      <tt>ExecutionException</tt> and test whether it is a checked exception      which has to be handled. If this is not the case, the causing exception can      be rethrown.    </p>    <p>      The <tt>extractCause()</tt> method of <tt>ConcurrentUtils</tt> does      this work for you. It is passed an <tt>ExecutionException</tt> and tests      its root cause. If this is an error or a runtime exception, it is directly      rethrown. Otherwise, an instance of <tt>ConcurrentException</tt> is      created and initialized with the root cause. (<tt>ConcurrentException</tt>      is a new exception class in the <tt>o.a.c.l.concurrent</tt> package.)      So if you get such a <tt>ConcurrentException</tt>, you can be sure that      the original cause for the <tt>ExecutionException</tt> was a checked      exception. For users who prefer runtime exceptions in general there is also      an <tt>extractCauseUnchecked()</tt> method which behaves like      <tt>extractCause()</tt>, but returns the unchecked exception      <tt>ConcurrentRuntimeException</tt> instead.    </p>    <p>      In addition to the <tt>extractCause()</tt> methods there are      corresponding <tt>handleCause()</tt> methods. These methods extract the      cause of the passed in <tt>ExecutionException</tt> and throw the      resulting <tt>ConcurrentException</tt> or <tt>ConcurrentRuntimeException</tt>.      This makes it easy to transform an <tt>ExecutionException</tt> into a      <tt>ConcurrentException</tt> ignoring unchecked exceptions:    </p>    <div><pre>Future&lt;Object&gt; future = ...;<br />try {<br />&nbsp; &nbsp; Object result = future.get();<br />&nbsp; &nbsp; ...<br />} catch (ExecutionException eex) {<br />&nbsp; &nbsp; ConcurrentUtils.handleCause(eex);<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      There is also some support for the concurrent initializers introduced in      the last sub section. The <tt>initialize()</tt> method is passed a      <tt>ConcurrentInitializer</tt> object and returns the object created by      this initializer. It is null-safe. The <tt>initializeUnchecked()</tt>      method works analogously, but a <tt>ConcurrentException</tt> throws by the      initializer is rethrown as a <tt>ConcurrentRuntimeException</tt>. This      is especially useful if the specific <tt>ConcurrentInitializer</tt>      does not throw checked exceptions. Using this method the code for requesting      the object of an initializer becomes less verbose. The direct invocation      looks as follows:    </p>    <div><pre>ConcurrentInitializer&lt;MyClass&gt; initializer = ...;<br />try {<br />&nbsp; &nbsp; MyClass obj = initializer.get();<br />&nbsp; &nbsp; // do something with obj<br />} catch (ConcurrentException cex) {<br />&nbsp; &nbsp; // exception handling<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      Using the <tt>initializeUnchecked()</tt> method, this becomes:    </p>    <div><pre>ConcurrentInitializer&lt;MyClass&gt; initializer = ...;<br />MyClass obj = ConcurrentUtils.initializeUnchecked(initializer);<br />// do something with obj<br />&nbsp; &nbsp;</pre></div>    <p>      Another utility class deals with the creation of threads. When using the      <em>Executor</em> framework new in JDK 1.5 the developer usually does not      have to care about creating threads; the executors create the threads they      need on demand. However, sometimes it is desired to set some properties of      the newly created worker threads. This is possible through the      <tt>ThreadFactory</tt> interface; an implementation of this interface      has to be created and pased to an executor on creation time. Currently, the      JDK does not provide an implementation of <tt>ThreadFactory</tt>, so      one has to start from scratch.    </p>    <p>      With <tt>BasicThreadFactory</tt> Commons Lang has an implementation of      <tt>ThreadFactory</tt> that works out of the box for many common use      cases. For instance, it is possible to set a naming pattern for the new      threads, set the daemon flag and a priority, or install a handler for      uncaught exceptions. Instances of <tt>BasicThreadFactory</tt> are      created and configured using the nested <tt>Builder</tt> class. The      following example shows a typical usage scenario:    </p>    <div><pre>BasicThreadFactory factory = new BasicThreadFactory.Builder()<br />&nbsp; &nbsp; .namingPattern("worker-thread-%d")<br />&nbsp; &nbsp; .daemon(true)<br />&nbsp; &nbsp; .uncaughtExceptionHandler(myHandler)<br />&nbsp; &nbsp; .build();<br />ExecutorService exec = Executors.newSingleThreadExecutor(factory);<br />&nbsp; &nbsp;</pre></div>    <p>      The nested <tt>Builder</tt> class defines some methods for configuring      the new <tt>BasicThreadFactory</tt> instance. Objects of this class are      immutable, so these attributes cannot be changed later. The naming pattern      is a string which can be passed to <tt>String.format()</tt>. The      placeholder <em>%d</em> is replaced by an increasing counter value. An      instance can wrap another <tt>ThreadFactory</tt> implementation; this      is achieved by calling the builder's <tt>wrappedFactory()</tt> method.      This factory is then used for creating new threads; after that the specific      attributes are applied to the new thread. If no wrapped factory is set, the      default factory provided by the JDK is used.    </p>    </div>     <div><h3>Synchronization objects<a name="Synchronization_objects"></a></h3>    <p>      The <tt>concurrent</tt> package also provides some support for specific      synchronization problems with threads.    </p>    <p>      <tt>TimedSemaphore</tt> allows restricted access to a resource in a      given time frame. Similar to a semaphore, a number of permits can be      acquired. What is new is the fact that the permits available are related to      a given time unit. For instance, the timed semaphore can be configured to      allow 10 permits in a second. Now multiple threads access the semaphore      and call its <tt>acquire()</tt> method. The semaphore keeps track about      the number of granted permits in the current time frame. Only 10 calls are      allowd; if there are further callers, they are blocked until the time      frame (one second in this example) is over. Then all blocking threads are      released, and the counter of available permits is reset to 0. So the game      can start anew.    </p>    <p>      What are use cases for <tt>TimedSemaphore</tt>? One example is to      artificially limit the load produced by multiple threads. Consider a batch      application accessing a database to extract statistical data. The      application runs multiple threads which issue database queries in parallel      and perform some calculation on the results. If the database to be processed      is huge and is also used by a production system, multiple factors have to be      balanced: On one hand, the time required for the statistical evaluation      should not take too long. Therefore you will probably use a larger number      of threads because most of its life time a thread will just wait for the      database to return query results. On the other hand, the load on the      database generated by all these threads should be limited so that the      responsiveness of the production system is not affected. With a      <tt>TimedSemaphore</tt> object this can be achieved. The semaphore can      be configured to allow e.g. 100 queries per second. After these queries      have been sent to the database the threads have to wait until the second is      over - then they can query again. By fine-tuning the limit enforced by the      semaphore a good balance between performance and database load can be      established. It is even possible to change the number of available permits      at runtime. So this number can be reduced during the typical working hours      and increased at night.    </p>    <p>      The following code examples demonstrate parts of the implementation of such      a scenario. First the batch application has to create an instance of      <tt>TimedSemaphore</tt> and to initialize its properties with default      values:    </p>    <div><pre>TimedSemaphore semaphore = new TimedSemaphore(1, TimeUnit.SECONDS, 100);<br />&nbsp; &nbsp;</pre></div>    <p>      Here we specify that the semaphore should allow 100 permits in one second.      This is effectively the limit of database queries per second in our      example use case. Next the server threads issuing database queries and      performing statistical operations can be initialized. They are passed a      reference to the semaphore at creation time. Before they execute a query      they have to acquire a permit.    </p>    <div><pre>public class StatisticsTask implements Runnable {<br />&nbsp; &nbsp; /** The semaphore for limiting database load. */<br />&nbsp; &nbsp; private final TimedSemaphore semaphore;<br /><br />&nbsp; &nbsp; public StatisticsTask(TimedSemaphore sem, Connection con) {<br />&nbsp; &nbsp; &nbsp; &nbsp; semaphore = sem;<br />&nbsp; &nbsp; &nbsp; &nbsp; ...<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; /**<br />&nbsp; &nbsp; &nbsp;* The main processing method. Executes queries and evaluates their results.<br />&nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; public void run() {<br />&nbsp; &nbsp; &nbsp; &nbsp; try {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (!isDone()) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; semaphore.acquire(); &nbsp; &nbsp;// enforce the load limit<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; executeAndEvaluateQuery();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; } catch (InterruptedException iex) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // fall through<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      The important line here is the call to <tt>semaphore.acquire()</tt>.      If the number of permits in the current time frame has not yet been reached,      the call returns immediately. Otherwise, it blocks until the end of the      time frame. The last piece missing is a scheduler service which adapts the      number of permits allowed by the semaphore according to the time of day. We      assume that this service is pretty simple and knows only two different time      slots: working shift and night shift. The service is triggered periodically.      It then determines the current time slot and configures the timed semaphore      accordingly.    </p>    <div><pre>public class SchedulerService {<br />&nbsp; &nbsp; /** The semaphore for limiting database load. */<br />&nbsp; &nbsp; private final TimedSemaphore semaphore;<br />&nbsp; &nbsp; ...<br /><br />&nbsp; &nbsp; /**<br />&nbsp; &nbsp; &nbsp;* Configures the timed semaphore based on the current time of day. This<br />&nbsp; &nbsp; &nbsp;* method is called periodically.<br />&nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; public void configureTimedSemaphore() {<br />&nbsp; &nbsp; &nbsp; &nbsp; int limit;<br />&nbsp; &nbsp; &nbsp; &nbsp; if (isWorkshift()) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; limit = 50; &nbsp; &nbsp;// low database load<br />&nbsp; &nbsp; &nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; limit = 250;&nbsp;// high database load<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; semaphore.setLimit(limit);<br />&nbsp; &nbsp; }<br />}<br />&nbsp; &nbsp;</pre></div>    <p>      With the <tt>setLimit()</tt> method the number of permits allowed for      a time frame can be changed. There are some other methods for querying the      internal state of a timed semaphore. Also some statistical data is available,      e.g. the average number of <tt>acquire()</tt> calls per time frame. When      a timed semaphore is no more needed, its <tt>shutdown()</tt> method has      to be called.    </p>    </div>    </div></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/375096.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2012-04-18 13:47 <a href="http://www.blogjava.net/ilovebabyfat/archive/2012/04/18/375096.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven(译自apache的资料)</title><link>http://www.blogjava.net/ilovebabyfat/archive/2012/04/16/374750.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Mon, 16 Apr 2012 09:05:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2012/04/16/374750.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/374750.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2012/04/16/374750.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/374750.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/374750.html</trackback:ping><description><![CDATA[Maven的功能<div><ul><li>遵循最佳实践，简单的建立项目-在分秒之间建立一个新的项目或者模块。<br /></li><li>在多个项目之间统一使用。<br /></li><li>依附环境的管理，包括自动的升级。<br /></li><li>方便地在同一时间参加多个项目。<br /></li><li>大且不断增长的库和元数据可供食用。<br /></li><li>可扩展，用java或脚本语言开发插件<br /></li><li>加入新的功能只需要很少或不需要额外的配置<br /></li><li>Ant任务支持依附环境管理，在Maven之外进行发布。</li><li>在大多数情况下，maven不需要脚本就可以编译多个项目，打包成jar, war或基于元数据进行项目发布<br /></li><li>清晰的项目信息：Maven能够建立一个站点或PDF文档，其中包括项目的一些基本信息和报表。<br /></li><li>版本管理和项目发布：不需要太多的额外配置，maven会和你的代码管理器整合，然后基于一定的tag,来帮助管理你的版本。它也可以为其他的项目发布到一个地方。maven也支持发布成jar或其他归档的文件或是源代码。<br /></li><li>依附管理：maven建议集中管理jar库。项目客户可以到集中的jar库中下载任何包。这允许maven用户可以在多个项目中公用jar，并鼓励项目之间的交流。</li></ul><p>&nbsp;</p><div><div><h3><a name="How_can_Maven_benefit_my_development_process">Maven如何帮助改进我们的开发过程？</a></h3>通过标准的约定和实践Maven对你的build流程提供帮助，加速你的开发周期并同时帮助你的项目成功。<p>下面我们提供一些例子让你来运行maven！<br /></p></div></div><div><div><h3><a name="How_do_I_setup_Maven">如何建立Maven?</a></h3><p>基本上，maven默认的配置已经足够面对大部分情况了，但是如果你需要修改缓存策略或者设置http代理，你就需要自己建立一个配置。详细请参考<a href="http://maven.apache.org/guides/mini/guide-configuring-maven.html">Guide to Configuring Maven</a>。</p><p>&nbsp;</p><div><div><h3><a name="How_do_I_make_my_first_Maven_project">如何建立我的第一个maven项目？</a></h3>我们会使用maven的archetype 机制来建立我们的第一个maven项目。maven中，archetype是项目模版，在加上一些用户的输入来建立一个maven的项目。我们会向你展示archetype机制如何工作。更多请参考<p>&nbsp;</p><div><a href="http://maven.apache.org/guides/introduction/introduction-to-archetypes.html">Introduction to Archetypes。</a></div><br /><p>创建最简单的maven项目，只需要执行下面的命令就可以了<br /></p><div><pre>mvn archetype:generate \   -DarchetypeGroupId=org.apache.maven.archetypes \   -DgroupId=com.mycompany.app \   -DartifactId=my-app </pre></div><p>执行命令后，首先，你会发现一个叫my-app的文件夹建立了，其中有pom.xml文件，内容如下：<br /></p><div><pre>&lt;project xmlns="http://maven.apache.org/POM/4.0.0"   <br />xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   <br />xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                       <br />http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;   <br />  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;   <br />  &lt;groupId&gt;com.mycompany.app&lt;/groupId&gt;   <br />  &lt;artifactId&gt;my-app&lt;/artifactId&gt;   <br />  &lt;packaging&gt;jar&lt;/packaging&gt;  <br />  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;   <br />  &lt;name&gt;Maven Quick Start Archetype&lt;/name&gt;   <br />  &lt;url&gt;http://maven.apache.org&lt;/url&gt;   <br />  &lt;dependencies&gt;     <br />    &lt;dependency&gt;       <br />      &lt;groupId&gt;junit&lt;/groupId&gt;       <br />      &lt;artifactId&gt;junit&lt;/artifactId&gt;       <br />      &lt;version&gt;3.8.1&lt;/version&gt;       <br />      &lt;scope&gt;test&lt;/scope&gt;     <br />    &lt;/dependency&gt;   <br />  &lt;/dependencies&gt; <br />&lt;/project&gt; </pre></div><p>pom.xml里有项目的project object model。pom是maven的基本工作单元。This is  important to remember because Maven is inherently  project-centric in  that everything revolves around the notion of a  project. 简单的说，pom包含了所有项目的重要信息。更多请参考<a href="http://maven.apache.org/guides/introduction/introduction-to-the-pom.html">Introduction to the POM</a>.<br /></p><p>This  is a very simple POM but still displays the key elements every POM  contains, so let's walk through each of them <br /></p><p><br /></p><p>to familiarize you with the  POM essentials:</p><ul><li><strong>project</strong> This is the top-level element in all Maven pom.xml files.</li><li><strong>modelVersion</strong>  This element indicates what version of the object model this POM is  using. The version of the model itself changes very infrequently but it  is mandatory in order to ensure stability of use if and when the Maven  developers deem it necessary to change the model.</li><li><strong>groupId</strong>  This element indicates the unique identifier of the organization or  group that created the project. The groupId is one of the key  identifiers of a project and is typically based on the fully qualified  domain name of your organization. For example <tt>org.apache.maven.plugins</tt> is the designated groupId for all Maven plug-ins.</li><li><strong>artifactId</strong>  This element indicates the unique base name of the primary artifact  being generated by this project. The primary artifact for a project is  typically a JAR file. Secondary artifacts like source bundles also use  the artifactId as part of their final name. A typical artifact produced  by Maven would have the form  &lt;artifactId&gt;-&lt;version&gt;.&lt;extension&gt; (for example, <tt>myapp-1.0.jar</tt>).</li><li><strong>packaging</strong>  This element indicates the package type to be used by this artifact  (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced  is JAR, WAR, or EAR but can also indicate a specific lifecycle to use  as part of the build process. (The lifecycle is a topic we will deal  with further on in the guide. For now, just keep in mind that the  indicated packaging of a project can play a part in customizing the  build lifecycle.) The default value for the <tt>packaging</tt> element is JAR so you do not have to specify this for most projects.</li><li><strong>version</strong>  This element indicates the version of the artifact generated by the  project. Maven goes a long way to help you with version management and  you will often see the <tt>SNAPSHOT</tt> designator in a version, which  indicates that a project is in a state of development. We will discuss  the use of snapshots and how they work further on in this guide.</li><li><strong>name</strong> This element indicates the display name used for the project. This is often used in Maven's generated documentation.</li><li><strong>url</strong> This element indicates where the project's site can be found. This is often used in Maven's generated documentation.</li><li><strong>description</strong> This element provides a basic description of your project. This is often used in Maven's generated documentation.</li></ul><p>For a complete reference of what elements are available for use in the POM please refer to our <a href="http://maven.apache.org/maven-model/maven.html">POM Reference</a>. Now let's get back to the project at hand.</p><p>After  the archetype generation of your first project you will also notice  that the following directory structure has been created:</p><div><pre>my-app |-- pom.xml `-- src     |-- main     |   `-- java     |       `-- com     |           `-- mycompany     |               `-- app     |                   `-- App.java     `-- test         `-- java             `-- com                 `-- mycompany                     `-- app                         `-- AppTest.java </pre></div><p>As you can see, the project created from the archetype  has a POM, a source tree for your application's sources and a source  tree for your test sources. This is the standard layout for Maven  projects (the application sources reside in <tt>${basedir}/src/main/java</tt> and test sources reside in <tt>${basedir}/src/test/java</tt>, where ${basedir} represents the directory containing <tt>pom.xml</tt>).</p><p>If  you were to create a Maven project by hand this is the directory  structure that we recommend using. This is a Maven convention and to  learn more about it you can read our <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">Introduction to the Standard Directory Layout</a>.</p><p>Now that we have a POM, some application sources, and some test sources you are probably asking ...</p></div></div><br /><p>&nbsp;</p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p></div><h3><div><h3><a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="How_do_I_make_my_first_Maven_project"></a></h3></div><div><h3><a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="How_do_I_setup_Maven"></a></h3></div><br /></h3></div><br /><p>&nbsp;</p></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/374750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2012-04-16 17:05 <a href="http://www.blogjava.net/ilovebabyfat/archive/2012/04/16/374750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JQGrid</title><link>http://www.blogjava.net/ilovebabyfat/archive/2012/04/06/373456.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Fri, 06 Apr 2012 04:57:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2012/04/06/373456.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/373456.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2012/04/06/373456.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/373456.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/373456.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: JQGrid是一个在jquery基础上做的一个表格控件，以ajax的方式和服务器端通信。JQGrid Demo 是一个在线的演示项目。在这里，可以知道jqgrid可以做什么事情。下面是转自其他人blog的一个学习资料，与其说是学习资料，说成查询帮助文档更加合适。  jqGrid学习之 ------------- 安装  jqGrid安装很简单，只需把相应的css、js文件加入到页面中即可。  按照...&nbsp;&nbsp;<a href='http://www.blogjava.net/ilovebabyfat/archive/2012/04/06/373456.html'>阅读全文</a><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/373456.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2012-04-06 12:57 <a href="http://www.blogjava.net/ilovebabyfat/archive/2012/04/06/373456.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse插件</title><link>http://www.blogjava.net/ilovebabyfat/archive/2012/02/20/370345.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Mon, 20 Feb 2012 06:25:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2012/02/20/370345.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/370345.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2012/02/20/370345.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/370345.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/370345.html</trackback:ping><description><![CDATA[<div>1. http://download.eclipse.org/windowbuilder/WB/integration/3.7/<br />1.http://code.google.com/p/visualswing4eclipse/<br />2个用于J2SE swing之类的桌面编程。<br /><br />2. doxygen&nbsp;&nbsp;&nbsp; http://www.stack.nl/~dimitri/doxygen/<br />能根据项目的源文件，自动生成比较完整的文档，包括类层次图<br />3. open explorer&nbsp;&nbsp; http://blog.samsonis.me/2009/02/open-explorer-plugin-for-eclipse/<br />可以在eclipse中比较方便的打开本地文件夹</div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/370345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2012-02-20 14:25 <a href="http://www.blogjava.net/ilovebabyfat/archive/2012/02/20/370345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SVN的使用</title><link>http://www.blogjava.net/ilovebabyfat/archive/2011/08/23/357075.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Mon, 22 Aug 2011 16:15:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2011/08/23/357075.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/357075.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2011/08/23/357075.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/357075.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/357075.html</trackback:ping><description><![CDATA[svn作为一个代码版本管理工具，适合团队使用。<br />1. 服务端架设<br />平台选windows. 软件下载：<a href="http://subversion.tigris.org/servlets/ProjectDocumentList?expandFolder=91&amp;folderID=91">http://subversion.tigris.org/servlets/ProjectDocumentList?expandFolder=91&amp;folderID=91</a><br />相关命令<br /><div><div><div>sc create svn binpath= "\"E:\SVN\svn-win32-1.4.3\bin\svnserve.exe\" --service -r E:\SVN\MyRePos" displayname= "Subversion Server" depend= Tcpip start= auto&nbsp;建立svn服务器</div><div>net stop svn 停止svn服务</div><div>net start svn 启动svn服务</div><div>sc delete svn 删除svn服务，可能需要重启</div><div>SVNADMIN CREATE E:\SVN\MyRePos 建立版本库<br /><div>svn import -m "MyProject" LoginDemo file:///E:\SVN\MyRePos\LoginDemo 导入项目LoginDemo在当前目录下<br /><br />2.客户端插件<br /><div><a href="http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA">http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA</a></div></div></div></div></div><div><p style="margin-bottom:0pt; margin-top:0pt; "><font class="Apple-style-span" face="'Courier New'">eclipse安装插件，在eclipse上打开资源库，就可以将资源库中的工程检出了。<br /><br />因为只有在自己的机器上进行操作，所以没有涉及到用户权限设置之类的问题.<br /><br />Issue:<br />使用svn:协议连接server出现无法连接，首先需要查看服务有没有启动。<br />遇到错误消息&#8216;object expected&#8217;,可能是配置文件的键值对有空格。<br /><br /><br /><br /></font></p></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/357075.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2011-08-23 00:15 <a href="http://www.blogjava.net/ilovebabyfat/archive/2011/08/23/357075.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IE长时间等待服务器响应，显示页面无法显示的问题</title><link>http://www.blogjava.net/ilovebabyfat/archive/2011/08/07/355967.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Sun, 07 Aug 2011 14:12:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2011/08/07/355967.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/355967.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2011/08/07/355967.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/355967.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/355967.html</trackback:ping><description><![CDATA[项目通过JASPER跑报表，有几个报表牵涉的数据量比较大，导致响应时间超过1个小时，此时页面会提示&#8220;页面无法显示&#8221;。<br />开始以为是session的超时，于是在页面中添加了ajax去定期发送请求给服务器的代码来维持session， 问题无法解决。<br />然后以为是页面缓存的问题，在请求中加了随机的数字，查看每次请求回来的响应头状态都是200的，问题仍旧无法解决。<br />继续百度，继续谷歌。<br />搜索到microsoft的一篇文章，如下<br /><div><a href="http://support.microsoft.com/kb/181050">http://support.microsoft.com/kb/181050</a>&nbsp;<div style="display: inline-block; "></div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: normal; background-color: #ffffff; "><h1 class="title" style="box-sizing: border-box; font-size: 19px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Internet Explorer error "connection timed out" when server does not respond<br /><span class="Apple-style-span" style="font-weight: normal; font-size: 12pt; ">问题得到解决。<br />其实可以说问题无法得到解决。我怎么可能让每个用户去修改他们的注册表么。<br /><br />看来只能采取异步的请求方式了。</span></h1></span></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/355967.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2011-08-07 22:12 <a href="http://www.blogjava.net/ilovebabyfat/archive/2011/08/07/355967.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA to JSON 避免循环引用造成死循环</title><link>http://www.blogjava.net/ilovebabyfat/archive/2011/07/20/354719.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Wed, 20 Jul 2011 08:14:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2011/07/20/354719.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/354719.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2011/07/20/354719.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/354719.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/354719.html</trackback:ping><description><![CDATA[<div> <div style="position: relative; padding: 0px 3px; clear: both;" id="Normalcontent"> <div style="margin-left: 12px;" id="imcontent"><span> <div style="direction: ltr; color: #000000; font-size: 9pt;"> <div>JsonConfig config = new JsonConfig();<br />&nbsp;&nbsp;config.setJsonPropertyFilter(new  PropertyFilter() {<br />&nbsp;&nbsp;&nbsp;public boolean apply(Object source, String name, Object  value) {<br />&nbsp;&nbsp;&nbsp;&nbsp;if (name.equals("form") || name.equals("formElm")&nbsp;&nbsp; )  {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;<br />&nbsp;&nbsp;&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return  false;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;});<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;JSONObject jsonObject =  JSONObject.fromObject( form, config );</div></div></span></div></div></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/354719.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2011-07-20 16:14 <a href="http://www.blogjava.net/ilovebabyfat/archive/2011/07/20/354719.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PL/SQL 分割字符串</title><link>http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353358.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Wed, 29 Jun 2011 06:43:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353358.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/353358.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353358.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/353358.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/353358.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff;"><br />下面的方法提供了比较好的数据库分割字符串的方法。不要在每次需要这种功能的地方各写一个，统一的工具类非常重要。更能排除以下低级的错误。<br />create</span><span style="color: #000000;">&nbsp;</span><span style="color: #808080;">or</span><span style="color: #000000;">&nbsp;</span><span style="color: #ff00ff;">replace</span><span style="color: #000000;"><br />PACKAGE&nbsp;pk_genutilitypkg<br /></span><span style="color: #0000ff;">AS</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;</span><span style="color: #008080;">/*</span><span style="color: #008080;"><br /><br />&nbsp;&nbsp;&nbsp;Generic&nbsp;String&nbsp;Parser:&nbsp;provide&nbsp;a&nbsp;delimiter&nbsp;and&nbsp;it&nbsp;returns&nbsp;an<br />&nbsp;&nbsp;&nbsp;index-by&nbsp;table&nbsp;of&nbsp;the&nbsp;individual&nbsp;elements&nbsp;of&nbsp;the&nbsp;string&nbsp;that&nbsp;are<br />&nbsp;&nbsp;&nbsp;separated&nbsp;by&nbsp;the&nbsp;specified&nbsp;delimiter.<br /><br />&nbsp;&nbsp;&nbsp;Author:&nbsp;"GAUTHAM&nbsp;CHANDRASEKARAN"&nbsp;&lt;gautha@hotmail.com&gt;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #008080;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;TYPE&nbsp;t_string&nbsp;</span><span style="color: #0000ff;">IS</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">TABLE</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">OF</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">(</span><span style="color: #800000; font-weight: bold;">2000</span><span style="color: #000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">INDEX</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">BY</span><span style="color: #000000;">&nbsp;BINARY_INTEGER;<br /><br />&nbsp;&nbsp;&nbsp;m_ctr&nbsp;</span><span style="color: #000000; font-weight: bold;">NUMBER</span><span style="color: #000000;">(</span><span style="color: #800000; font-weight: bold;">5</span><span style="color: #000000;">);<br />&nbsp;&nbsp;&nbsp;m_pos&nbsp;</span><span style="color: #000000; font-weight: bold;">NUMBER</span><span style="color: #000000;">(</span><span style="color: #800000; font-weight: bold;">5</span><span style="color: #000000;">);<br /><br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">PROCEDURE</span><span style="color: #000000;">&nbsp;sp_parsestring&nbsp;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_string&nbsp;</span><span style="color: #808080;">IN</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delimiter&nbsp;</span><span style="color: #808080;">IN</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;OUT&nbsp;t_string);<br /></span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;pk_genutilitypkg;<br />&nbsp;&nbsp;<br /></span><span style="color: #0000ff;">create</span><span style="color: #000000;">&nbsp;</span><span style="color: #808080;">or</span><span style="color: #000000;">&nbsp;</span><span style="color: #ff00ff;">replace</span><span style="color: #000000;"><br />PACKAGE&nbsp;BODY&nbsp;pk_genutilitypkg<br /></span><span style="color: #0000ff;">AS</span><span style="color: #000000;"><br /><br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">PROCEDURE</span><span style="color: #000000;">&nbsp;sp_parsestring&nbsp;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_string&nbsp;</span><span style="color: #808080;">IN</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delimiter&nbsp;</span><span style="color: #808080;">IN</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;OUT&nbsp;t_string)<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">IS</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_string&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">(</span><span style="color: #800000; font-weight: bold;">4000</span><span style="color: #000000;">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">BEGIN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008080;">/*</span><span style="color: #008080;">&nbsp;Raise&nbsp;a&nbsp;Error&nbsp;if&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;delimiter&nbsp;is&nbsp;not&nbsp;1&nbsp;</span><span style="color: #008080;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">&nbsp;LENGTH&nbsp;(delimiter)&nbsp;</span><span style="color: #808080;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error&nbsp;(</span><span style="color: #808080;">-</span><span style="color: #800000; font-weight: bold;">20001</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000;">'</span><span style="color: #ff0000;">Delimiter&nbsp;should&nbsp;be&nbsp;of&nbsp;only&nbsp;one&nbsp;character</span><span style="color: #ff0000;">'</span><span style="color: #000000;">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">RETURN</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_string&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;p_string;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_ctr&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOOP<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pos&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;INSTR&nbsp;(m_string,&nbsp;delimiter);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">&nbsp;m_pos&nbsp;</span><span style="color: #808080;">&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;(m_ctr)&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #ff00ff;">LTRIM</span><span style="color: #000000;">(</span><span style="color: #ff00ff;">RTRIM</span><span style="color: #000000;">(&nbsp;SUBSTR&nbsp;(m_string,&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">,&nbsp;m_pos&nbsp;</span><span style="color: #808080;">-</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">)&nbsp;));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">&nbsp;(m_pos&nbsp;</span><span style="color: #808080;">&lt;</span><span style="color: #000000;">&nbsp;LENGTH&nbsp;(m_string))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_string&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;SUBSTR&nbsp;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_string,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pos&nbsp;</span><span style="color: #808080;">+</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LENGTH&nbsp;(m_string)&nbsp;</span><span style="color: #808080;">-</span><span style="color: #000000;">&nbsp;m_pos<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSIF&nbsp;m_pos&nbsp;</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;LENGTH&nbsp;(m_string)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_ctr&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;m_ctr&nbsp;</span><span style="color: #808080;">+</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;(m_ctr)&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">NULL</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">EXIT</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSIF&nbsp;m_pos&nbsp;</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;(m_ctr)&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">NULL</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">&nbsp;m_pos&nbsp;</span><span style="color: #808080;">&lt;</span><span style="color: #000000;">&nbsp;LENGTH&nbsp;(m_string)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_string&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;SUBSTR&nbsp;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_string,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pos&nbsp;</span><span style="color: #808080;">+</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LENGTH&nbsp;(m_string)&nbsp;</span><span style="color: #808080;">-</span><span style="color: #000000;">&nbsp;m_pos<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSIF&nbsp;m_pos&nbsp;</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;LENGTH&nbsp;(m_string)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_ctr&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;m_ctr&nbsp;</span><span style="color: #808080;">+</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;(m_ctr)&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">NULL</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">EXIT</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSIF&nbsp;m_pos&nbsp;</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">0</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">THEN</span><span style="color: #000000;"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p_t_string&nbsp;(m_ctr)&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #ff00ff;">LTRIM</span><span style="color: #000000;">(</span><span style="color: #ff00ff;">RTRIM</span><span style="color: #000000;">(&nbsp;m_string&nbsp;));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">EXIT</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">IF</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_ctr&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;m_ctr&nbsp;</span><span style="color: #808080;">+</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;LOOP;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">;<br /></span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;pk_genutilitypkg;<br /><br />使用方法如下:<br /></span><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff;">PROCEDURE</span><span style="color: #000000;">&nbsp;UseStringParse(<br />&nbsp;&nbsp;&nbsp;&nbsp;user_list&nbsp;&nbsp;&nbsp;</span><span style="color: #808080;">IN</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;"><br />)</span><span style="color: #0000ff;">IS</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;userid_list&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">&nbsp;(</span><span style="color: #800000; font-weight: bold;">1000</span><span style="color: #000000;">)&nbsp;:</span><span style="color: #808080;">=</span><span style="color: #000000;">&nbsp;user_list;<br />&nbsp;&nbsp;&nbsp;&nbsp;userlistarray&nbsp;&nbsp;&nbsp;pk_genutilitypkg.t_string;<br />&nbsp;&nbsp;&nbsp;&nbsp;vuserid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">VARCHAR2</span><span style="color: #000000;">&nbsp;(</span><span style="color: #800000; font-weight: bold;">100</span><span style="color: #000000;">);<br /></span><span style="color: #0000ff;">BEGIN</span><span style="color: #000000;"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;pk_genutilitypkg.sp_parsestring(userid_list,&nbsp;</span><span style="color: #ff0000;">'</span><span style="color: #ff0000;">,</span><span style="color: #ff0000;">'</span><span style="color: #000000;">,&nbsp;userlistarray);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">FOR</span><span style="color: #000000;">&nbsp;userindex&nbsp;</span><span style="color: #808080;">IN</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000; font-weight: bold;">1</span><span style="color: #000000;">&nbsp;..&nbsp;userlistarray.</span><span style="color: #ff00ff;">COUNT</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vuserid:</span><span style="color: #808080;">=</span><span style="color: #000000;">userlistarray(userindex);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;LOOP;<br /><br /></span><span style="color: #0000ff;">END</span><span style="color: #000000;">&nbsp;UseStringParse;</span></div><br /><span style="color: #000000;"><br /></span></div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/353358.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2011-06-29 14:43 <a href="http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353358.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Actuate使用总结</title><link>http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353346.html</link><dc:creator>思无</dc:creator><author>思无</author><pubDate>Wed, 29 Jun 2011 05:28:00 GMT</pubDate><guid>http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353346.html</guid><wfw:comment>http://www.blogjava.net/ilovebabyfat/comments/353346.html</wfw:comment><comments>http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353346.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ilovebabyfat/comments/commentRss/353346.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ilovebabyfat/services/trackbacks/353346.html</trackback:ping><description><![CDATA[<div>  <p>Actuate <span style="font-family: SimSun;">简单报表的建立过程</span></p>  <p style="text-indent: -0.25in;"><span>1． </span><span style="font-family: SimSun;">1. 打开</span> e.report <span style="font-family: SimSun;">选择</span>new report</p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_1.JPG" alt="" width="294" border="0" height="114" /><br /></p>  <p style="text-indent: -0.25in;"><span>2． </span><span style="font-family: SimSun;">2.选择空白报表</span></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_2.JPG" alt="" width="295" border="0" height="114" /><br /></p>  <p style="text-indent: -0.25in;"><span>3． </span><span style="font-family: SimSun;">3. 建立数据库连接。</span>Tools<span style="font-family: Wingdings;">&#224;</span> Database Connection</p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_3.JPG" alt="" width="296" border="0" height="119" /><br /></p>  <p style="text-indent: -0.25in;"><span>4． </span><span style="font-family: SimSun;">4. 填写参数</span> </p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_4.JPG" alt="" width="296" border="0" height="119" /><br /></p>  <p style="text-indent: -0.25in;"><span>5． </span><span style="font-family: SimSun;">5. 双击</span>datasource , <span style="font-family: SimSun;">填写查询参数</span></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_5.JPG" alt="" width="296" border="0" height="136" /><br /></p>  <p style="text-indent: -0.25in;"><span>6． </span><span style="font-family: SimSun;">6. 选中</span>Content, Tool--〉<span style="font-family: Wingdings;"></span> Grouping, <span style="font-family: SimSun;">设置整个报表的</span>group<span style="font-family: SimSun;">，</span>1<span style="font-family: SimSun;">层</span>or n<span style="font-family: SimSun;">层。</span></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_6.JPG" alt="" width="280" border="0" height="166" /><br /></p>  <p style="text-indent: -0.25in;"><span>7． </span><span style="font-family: SimSun;">7. 单击</span>grouping option,<span style="font-family: SimSun;">设置</span>group<span style="font-family: SimSun;">的显示，是否需要</span>befer,after<span style="font-family: SimSun;">等，每个</span>group<span style="font-family: SimSun;">需要单独设置。</span></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_7.JPG" alt="" width="211" border="0" height="109" /><br /></p>  <p style="text-indent: -0.25in;"><span>8．&nbsp; </span><span style="font-family: SimSun;">8. 设置各种页面的控件</span></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/o_8.JPG" alt="" width="291" border="0" height="221" /><br /></p>  <p style="text-indent: -0.25in;"><span>9． </span><span style="font-family: SimSun;">9. 设置参数，这些参数可以用在报表控制上或是查询的参数</span>Tools <span style="font-family: Wingdings;">--</span> Parameters</p>  <p><img src="http://www.blogjava.net/images/blogjava_net/ilovebabyfat/48970/t_9.JPG" alt="" width="120" border="0" height="102" /><br /></p>  <p style="text-indent: -0.25in;"><span><span><span style="font: 7pt &quot;Times New Roman&quot;;"></span></span></span><span style="font-family: SimSun;">修改后的查询字段</span></p>  <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff;">select</span><span style="color: #000000;">&nbsp;fund_id,fund_name,fund_abbreviation,fund_mode,rule_id&nbsp;</span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;te_fund&nbsp;</span><span style="color: #0000ff;">where</span><span style="color: #000000;">&nbsp;fund_mode</span><span style="color: #808080;">=</span><span style="color: #000000;">:fundmode</span></div>  <p style="text-indent: -0.25in;"><span><span></span></span><span style="font-family: SimSun;">参数10. 用来控制页面显示</span></p>  <p><span style="font-family: SimSun;">已</span>label<span style="font-family: SimSun;">为例子，重写</span>OnRow<span style="font-family: SimSun;">方法</span></p>  <p style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; <br /></span></p><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff;">Sub</span><span style="color: #000000;">&nbsp;OnRow(&nbsp;row&nbsp;</span><span style="color: #0000ff;">As</span><span style="color: #000000;">&nbsp;AcDataRow&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;Super::OnRow(&nbsp;row&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;fundmode</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">M</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">then</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me.Text&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Manual&nbsp;Fund&nbsp;Name</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me.Text&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Auto&nbsp;Fund&nbsp;Name</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">end</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;"><br /></span><span style="color: #0000ff;">End&nbsp;Sub</span></div><p style="margin-bottom: 0.0001pt; line-height: normal;"></p><p style="text-indent: -0.25in;"><span><span>11. </span></span><span style="font-family: SimSun;">用</span>datasource<span style="font-family: SimSun;">中的数据控制页面</span></p><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff;">Sub</span><span style="color: #000000;">&nbsp;OnRow(&nbsp;row&nbsp;</span><span style="color: #0000ff;">As</span><span style="color: #000000;">&nbsp;AcDataRow&nbsp;)<br />&nbsp;Super::OnRow(&nbsp;row&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">If</span><span style="color: #000000;">&nbsp;row.GetValue(</span><span style="color: #000000;">"</span><span style="color: #000000;">DR_SHORT_FLAG</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">Then</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me.Text&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">BUY&nbsp;BACK</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">ElseIf</span><span style="color: #000000;">&nbsp;row.GetValue(</span><span style="color: #000000;">"</span><span style="color: #000000;">DR_SHORT_FLAG</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">Then</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me.Text&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;to&nbsp;Open</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">End</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;"><br /></span><span style="color: #0000ff;">End&nbsp;Sub</span></div><p>&nbsp;</p>  </div><img src ="http://www.blogjava.net/ilovebabyfat/aggbug/353346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ilovebabyfat/" target="_blank">思无</a> 2011-06-29 13:28 <a href="http://www.blogjava.net/ilovebabyfat/archive/2011/06/29/353346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>