cp-hacking.texinfo 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename cp-hacking.info
  4. @settitle GNU Classpath Hacker's Guide
  5. @c %**end of header
  6. @setchapternewpage off
  7. @ifinfo
  8. This file contains important information you will need to know if you
  9. are going to hack on the GNU Classpath project code.
  10. Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2007,2009 Free Software Foundation, Inc.
  11. @ifnotplaintext
  12. @dircategory GNU Libraries
  13. @direntry
  14. * Classpath Hacking: (cp-hacking). GNU Classpath Hacker's Guide
  15. @end direntry
  16. @end ifnotplaintext
  17. @end ifinfo
  18. @titlepage
  19. @title GNU Classpath Hacker's Guide
  20. @author Aaron M. Renn
  21. @author Paul N. Fisher
  22. @author John Keiser
  23. @author C. Brian Jones
  24. @author Mark J. Wielaard
  25. @page
  26. @vskip 0pt plus 1filll
  27. Copyright @copyright{} 1998,1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  28. @sp 2
  29. Permission is granted to make and distribute verbatim copies of
  30. this document provided the copyright notice and this permission notice
  31. are preserved on all copies.
  32. Permission is granted to copy and distribute modified versions of this
  33. document under the conditions for verbatim copying, provided that the
  34. entire resulting derived work is distributed under the terms of a
  35. permission notice identical to this one.
  36. Permission is granted to copy and distribute translations of this manual
  37. into another language, under the above conditions for modified versions,
  38. except that this permission notice may be stated in a translation
  39. approved by the Free Software Foundation.
  40. @end titlepage
  41. @ifinfo
  42. @node Top, Introduction, (dir), (dir)
  43. @top GNU Classpath Hacker's Guide
  44. This document contains important information you'll want to know if
  45. you want to hack on GNU Classpath, Essential Libraries for Java, to
  46. help create free core class libraries for use with virtual machines
  47. and compilers for the java programming language.
  48. @end ifinfo
  49. @menu
  50. * Introduction:: An introduction to the GNU Classpath project
  51. * Requirements:: Very important rules that must be followed
  52. * Volunteering:: So you want to help out
  53. * Project Goals:: Goals of the GNU Classpath project
  54. * Needed Tools and Libraries:: A list of programs and libraries you will need
  55. * Installation:: Installation instructions
  56. * Building and running with the X AWT peers:: Building and running with the X AWT peers
  57. * Misc. Notes:: Miscellaneous notes
  58. * Programming Standards:: Standards to use when writing code
  59. * Hacking Code:: Working on code, Working with others
  60. * Programming Goals:: What to consider when writing code
  61. * API Compatibility:: How to handle serialization and deprecated methods
  62. * Specification Sources:: Where to find class library specs
  63. * Naming Conventions:: How files and directories are named
  64. * Character Conversions:: Working on Character conversions
  65. * Localization:: How to handle localization/internationalization
  66. @detailmenu
  67. --- The Detailed Node Listing ---
  68. Programming Standards
  69. * Source Code Style Guide::
  70. Working on the code, Working with others
  71. * Branches::
  72. * Writing ChangeLogs::
  73. Working with branches
  74. * Writing ChangeLogs::
  75. Programming Goals
  76. * Portability:: Writing Portable Software
  77. * Utility Classes:: Reusing Software
  78. * Robustness:: Writing Robust Software
  79. * Java Efficiency:: Writing Efficient Java
  80. * Native Efficiency:: Writing Efficient JNI
  81. * Security:: Writing Secure Software
  82. API Compatibility
  83. * Serialization:: Serialization
  84. * Deprecated Methods:: Deprecated methods
  85. Localization
  86. * String Collation:: Sorting strings in different locales
  87. * Break Iteration:: Breaking up text into words, sentences, and lines
  88. * Date Formatting and Parsing:: Locale specific date handling
  89. * Decimal/Currency Formatting and Parsing:: Local specific number handling
  90. @end detailmenu
  91. @end menu
  92. @node Introduction, Requirements, Top, Top
  93. @comment node-name, next, previous, up
  94. @chapter Introduction
  95. The GNU Classpath Project is dedicated to providing a 100% free,
  96. clean room implementation of the standard core class libraries for
  97. compilers and runtime environments for the java programming language.
  98. It offers free software developers an alternative core library
  99. implementation upon which larger java-like programming environments
  100. can be built. The GNU Classpath Project was started in the Spring of
  101. 1998 as an official Free Software Foundation project. Most of the
  102. volunteers working on GNU Classpath do so in their spare time, but a
  103. couple of projects based on GNU Classpath have paid programmers to
  104. improve the core libraries. We appreciate everyone's efforts in the
  105. past to improve and help the project and look forward to future
  106. contributions by old and new members alike.
  107. @node Requirements, Volunteering, Introduction, Top
  108. @comment node-name, next, previous, up
  109. @chapter Requirements
  110. Although GNU Classpath is following an open development model where input
  111. from developers is welcome, there are certain base requirements that
  112. need to be met by anyone who wants to contribute code to this project.
  113. They are mostly dictated by legal requirements and are not arbitrary
  114. restrictions chosen by the GNU Classpath team.
  115. You will need to adhere to the following things if you want to donate
  116. code to the GNU Classpath project:
  117. @itemize @bullet
  118. @item
  119. @strong{Never under any circumstances refer to proprietary code while
  120. working on GNU Classpath.} It is best if you have never looked at
  121. alternative proprietary core library code at all. To reduce
  122. temptation, it would be best if you deleted the @file{src.zip} file
  123. from your proprietary JDK distribution (note that recent versions of
  124. GNU Classpath and the compilers and environments build on it are
  125. mature enough to not need any proprietary implementation at all when
  126. working on GNU Classpath, except in exceptional cases where you need
  127. to test compatibility issues pointed out by users). If you have
  128. signed Sun's non-disclosure statement, then you unfortunately cannot
  129. work on Classpath code at all. If you have any reason to believe that
  130. your code might be ``tainted'', please say something on the mailing
  131. list before writing anything. If it turns out that your code was not
  132. developed in a clean room environment, we could be very embarrassed
  133. someday in court. Please don't let that happen.
  134. @item
  135. @strong{Never decompile proprietary class library implementations.} While
  136. the wording of the license in Sun's Java 2 releases has changed, it is
  137. not acceptable, under any circumstances, for a person working on
  138. GNU Classpath to decompile Sun's class libraries. Allowing the use of
  139. decompilation in the GNU Classpath project would open up a giant can of
  140. legal worms, which we wish to avoid.
  141. @item
  142. Classpath is licensed under the terms of the
  143. @uref{http://www.fsf.org/copyleft/gpl.html,GNU General Public
  144. License}, with a special exception included to allow linking with
  145. non-GPL licensed works as long as no other license would restrict such
  146. linking. To preserve freedom for all users and to maintain uniform
  147. licensing of Classpath, we will not accept code into the main
  148. distribution that is not licensed under these terms. The exact
  149. wording of the license of the current version of GNU Classpath can be
  150. found online from the
  151. @uref{http://www.gnu.org/software/classpath/license.html, GNU
  152. Classpath license page} and is of course distributed with current
  153. snapshot release from @uref{ftp://ftp.gnu.org/gnu/classpath/} or by
  154. obtaining a copy of the current CVS tree.
  155. @item
  156. GNU Classpath is GNU software and this project is being officially sponsored
  157. by the @uref{http://www.fsf.org/,Free Software Foundation}. Because of
  158. this, the FSF will hold copyright to all code developed as part of
  159. GNU Classpath. This will allow them to pursue copyright violators in court,
  160. something an individual developer may neither have the time nor
  161. resources to do. Everyone contributing code to GNU Classpath will need to
  162. sign a copyright assignment statement. Additionally, if you are
  163. employed as a programmer, your employer may need to sign a copyright
  164. waiver disclaiming all interest in the software. This may sound harsh,
  165. but unfortunately, it is the only way to ensure that the code you write
  166. is legally yours to distribute.
  167. @end itemize
  168. @node Volunteering, Project Goals, Requirements, Top
  169. @comment node-name, next, previous, up
  170. @chapter Volunteering to Help
  171. The GNU Classpath project needs volunteers to help us out. People are
  172. needed to write unimplemented core packages, to test GNU Classpath on
  173. free software programs written in the java programming language, to
  174. test it on various platforms, and to port it to platforms that are
  175. currently unsupported.
  176. While pretty much all contributions are welcome (but see
  177. @pxref{Requirements}) it is always preferable that volunteers do the
  178. whole job when volunteering for a task. So when you volunteer to write
  179. a Java package, please be willing to do the following:
  180. @itemize @bullet
  181. @item
  182. Implement a complete drop-in replacement for the particular package.
  183. That means implementing any ``internal'' classes. For example, in the
  184. java.net package, there are non-public classes for implementing sockets.
  185. Without those classes, the public socket interface is useless. But do
  186. not feel obligated to completely implement all of the functionality at
  187. once. For example, in the java.net package, there are different types
  188. of protocol handlers for different types of URLs. Not all of these
  189. need to be written at once.
  190. @item
  191. Please write complete and thorough API documentation comments for
  192. every public and protected method and variable. These should be
  193. superior to Sun's and cover everything about the item being
  194. documented.
  195. @item
  196. Please write a regression test package that can be used to run tests
  197. of your package's functionality. GNU Classpath uses the
  198. @uref{http://sources.redhat.com/mauve/,Mauve project} for testing the
  199. functionality of the core class libraries. The Classpath Project is
  200. fast approaching the point in time where all modifications to the
  201. source code repository will require appropriate test cases in Mauve to
  202. ensure correctness and prevent regressions.
  203. @end itemize
  204. Writing good documentation, tests and fixing bugs should be every
  205. developer's top priority in order to reach the elusive release of
  206. version 1.0.
  207. @node Project Goals, Needed Tools and Libraries, Volunteering, Top
  208. @comment node-name, next, previous, up
  209. @chapter Project Goals
  210. The goal of the Classpath project is to produce a
  211. @uref{http://www.fsf.org/philosophy/free-sw.html,free} implementation of
  212. the standard class library for Java. However, there are other more
  213. specific goals as to which platforms should be supported.
  214. Classpath is targeted to support the following operating systems:
  215. @enumerate
  216. @item
  217. Free operating systems. This includes GNU/Linux, GNU/Hurd, and the free
  218. BSDs.
  219. @item
  220. Other Unix-like operating systems.
  221. @item
  222. Platforms which currently have no Java support at all.
  223. @item
  224. Other platforms such as MS-Windows.
  225. @end enumerate
  226. While free operating systems are the top priority, the other priorities
  227. can shift depending on whether or not there is a volunteer to port
  228. Classpath to those platforms and to test releases.
  229. Eventually we hope the Classpath will support all JVMs that provide
  230. JNI or CNI support. However, the top priority is free JVMs. A small
  231. list of Compiler/VM environments that are currently actively
  232. incorporating GNU Classpath is below. A more complete overview of
  233. projects based on GNU classpath can be found online at
  234. @uref{http://www.gnu.org/software/classpath/stories.html,the GNU
  235. Classpath stories page}.
  236. @enumerate
  237. @item
  238. @uref{http://gcc.gnu.org/java/,GCJ}
  239. @item
  240. @uref{http://jamvm.sourceforge.net/,jamvm}
  241. @item
  242. @uref{http://www.cacaojvm.org/,cacao}
  243. @item
  244. @uref{http://jikesrvm.org,Jikes RVM}
  245. @item
  246. @uref{http://www.kaffe.org/,Kaffe}
  247. @item
  248. @uref{http://www.ikvm.net/,IKVM}
  249. @end enumerate
  250. As with OS platform support, this priority list could change if a
  251. volunteer comes forward to port, maintain, and test releases for a
  252. particular JVM@. Since gcj is part of the GNU Compiler Collective it
  253. is one of the most important targets. But since it doesn't currently
  254. work out of the box with GNU Classpath it is not the easiest
  255. target. When hacking on GNU Classpath the easiest solution is to use
  256. compilers and runtime environments that work out of the box with
  257. it, such as the Eclipse compiler, ecj, and the runtime environments jamvm and
  258. cacao. Both Jikes RVM and Kaffe use an included version of GNU Classpath by
  259. default, but Kaffe can now use a pre-installed version and Jikes RVM supports
  260. using a CVS snapshot as well as the latest release. Working directly with
  261. targets such as Jikes RVM, gcj and IKVM is possible but can be a little more
  262. difficult as changes have to be merged back into GNU Classpath proper,
  263. which requires additional work. Due to a recent switch to the use of 1.5 language
  264. features within GNU Classpath, a compiler compatible with these features is required.
  265. At present, this includes the Eclipse compiler, ecj, and the OpenJDK compiler.
  266. GNU Classpath currently implements the majority of the 1.4 and 1.5 APIs
  267. (binary compatibility is above 95% for both, but does not take into account
  268. internal implementations of features such as graphic and sound support). There
  269. is support for some 1.6 APIs but this is still nascent. Please do not create classes
  270. that depend on features in other packages unless GNU Classpath already
  271. contains those features. GNU Classpath has been free of any
  272. proprietary dependencies for a long time now and we like to keep it
  273. that way. Finishing, polishing up, documenting, testing and
  274. debugging current functionality is of higher priority then adding new
  275. functionality.
  276. @node Needed Tools and Libraries, Installation, Project Goals, Top
  277. @comment node-name, next, previous, up
  278. @chapter Needed Tools and Libraries
  279. If you want to hack on Classpath, you should at least download and
  280. install the following tools and try to familiarize yourself with
  281. them. In most cases having these tools installed will be all
  282. you really need to know about them. Also note that when working on
  283. (snapshot) releases only a 1.5 compiler (plus a free VM from the list above
  284. and the libraries listed below) is required. The other tools are only
  285. needed when working directly on the CVS version.
  286. @itemize @bullet
  287. @item
  288. GNU make 3.80+
  289. @item
  290. GCC 2.95+
  291. @item
  292. Eclipse Compiler for Java 3.1+
  293. @item
  294. CVS 1.11+
  295. @item
  296. automake 1.11+
  297. @item
  298. autoconf 2.64+
  299. @item
  300. libtool 1.5+
  301. @item
  302. GNU m4 1.4.6
  303. @item
  304. texinfo 4.2+
  305. @end itemize
  306. All of these tools are available from
  307. @uref{ftp://gnudist.gnu.org/pub/gnu/,gnudist.gnu.org} via anonymous
  308. ftp, except CVS which is available from
  309. @uref{http://www.cvshome.org/,www.cvshome.org} and the Eclipse
  310. Compiler for Java, which is available from
  311. @uref{http://www.eclipse.org/jdt/core,www.eclipse.org/jdt/core}.
  312. Except for the Eclipse Compiler for Java, they are fully documented
  313. with texinfo manuals. Texinfo can be browsed with the Emacs editor,
  314. or with the text editor of your choice, or transformed into nicely
  315. printable Postscript.
  316. Here is a brief description of the purpose of those tools.
  317. @table @b
  318. @item make
  319. GNU make ("gmake") is required for building Classpath.
  320. @item GCC
  321. The GNU Compiler Collection. This contains a C compiler (gcc) for
  322. compiling the native C code and a compiler for the java programming
  323. language (gcj). You will need at least gcc version 2.95 or higher
  324. in order to compile the native code. There is currently no
  325. released version of gcj that can compile the Java 1.5 programming
  326. language used by GNU Classpath.
  327. @item ecj
  328. The Eclipse Compiler for Java. This is a compiler for the Java 1.5
  329. programming language. It translates source code to bytecode. The
  330. Eclipse Foundation makes ``ecj.jar'' available as the JDT Core Batch
  331. Compiler download.
  332. @item CVS
  333. A version control system that maintains a centralized Internet
  334. repository of all code in the Classpath system.
  335. @item automake
  336. This tool automatically creates @file{Makefile.in} files from
  337. @file{Makefile.am} files. The @file{Makefile.in} is turned into a
  338. @file{Makefile} by @command{autoconf}.
  339. Why use this? Because it automatically generates every makefile
  340. target you would ever want (@option{clean}, @option{install},
  341. @option{dist}, etc) in full compliance with the GNU coding standards.
  342. It also simplifies Makefile creation in a number of ways that cannot
  343. be described here. Read the docs for more info.
  344. @item autoconf
  345. Automatically configures a package for the platform on which it is
  346. being built and generates the Makefile for that platform.
  347. @item libtool
  348. Handles all of the zillions of hairy platform specific options needed
  349. to build shared libraries.
  350. @item m4
  351. The free GNU replacement for the standard Unix macro processor.
  352. Proprietary m4 programs are broken and so GNU m4 is required for
  353. autoconf to work though knowing a lot about GNU m4 is not required to
  354. work with autoconf.
  355. @item perl
  356. Larry Wall's scripting language. It is used internally by automake.
  357. @item texinfo
  358. Manuals and documentation (like this guide) are written in texinfo.
  359. Texinfo is the official documentation format of the GNU project.
  360. Texinfo uses a single source file to produce output in a number of formats,
  361. both online and printed (dvi, info, html, xml, etc.). This means that
  362. instead of writing different documents for online information and another
  363. for a printed manual, you need write only one document. And when the work
  364. is revised, you need revise only that one document.
  365. @end table
  366. For any build environment involving native libraries, recent
  367. versions of @command{autoconf}, @command{automake}, and @command{libtool}
  368. are required if changes are made that require rebuilding @file{configure},
  369. @file{Makefile.in}, @file{aclocal.m4}, or @file{config.h.in}.
  370. When working from CVS you can run those tools by executing
  371. @command{autogen.sh} in the source directory.
  372. For building the Java bytecode (.class files), you can select
  373. which compiler should be employed using @option{--with-javac} or
  374. @option{--with-ecj} as an argument to @command{configure};
  375. the present default is @command{ecj} if found.
  376. Instead of @command{ecj}, you can also use @command{javac}, which is
  377. available at
  378. @uref{https://openjdk.dev.java.net/compiler, openjdk.dev.java.net/compiler}.
  379. For compiling the native AWT libraries you need to have the following
  380. libraries installed (unless @option{--disable-gtk-peer} is used as an argument
  381. to @command{configure}):
  382. @table @b
  383. @item GTK+ 2.8.x
  384. @uref{http://www.gtk.org/,GTK+} is a multi-platform toolkit for
  385. creating graphical user interfaces. It is used as the basis of the
  386. GNU desktop project GNOME.
  387. @item gdk-pixbuf
  388. @uref{http://www.gnome.org/start/,gdk-pixbuf} is a GNOME library for
  389. representing images.
  390. @item XTest
  391. @uref{http://www.x.org,www.x.org} hosts the XTest Extension (libXtst).
  392. It is necessary for GdkRobot support in java.awt.
  393. @end table
  394. There is a bug in earlier versions of at-spi, atk, and gail, which are
  395. used for GNOME accessibility. Prior to version 1.18.0 of these packages,
  396. gtk graphical applications should be run without accessibility (clear the
  397. GTK_MODULES environment variable).
  398. For building the Qt AWT peer JNI native libraries you have to
  399. specify @option{--enable-qt-peer} and need the following library:
  400. @table @b
  401. @item Qt
  402. @uref{http://www.trolltech.com/products/qt,Qt} version 4.0.1 or higher.
  403. The Qt library is a cross-platform graphics toolkit.
  404. @end table
  405. Please note that at the moment most operating systems do not
  406. ship Qt version 4.0.1 by default. We recommend using GNU Classpath' Qt
  407. support only for its developers and bug reporters. See
  408. @uref{http://developer.classpath.org/mediation/ClasspathShowcase, the wiki}
  409. for details on how to get it to work.
  410. For building the X AWT peers you have to specify where to find the
  411. Escher library on your system using the @option{--with-escher=ABS.PATH} option.
  412. You will need the following library:
  413. @table @b
  414. @item Escher
  415. @uref{http://escher.sourceforge.net,Escher} version 0.2.3 or higher.
  416. The Escher library is an implementation of X protocol and associated
  417. libraries written in the Java programming language.
  418. @end table
  419. For building the ALSA midi provider code you will need
  420. the following library:
  421. @table @b
  422. @item ALSA
  423. @uref{http://www.alsa-project.org,ALSA} libraries.
  424. The ALSA project provides sound device drivers and associated
  425. libraries for the Linux kernel.
  426. @end table
  427. Building the ALSA midi provider code can be disabled by passing
  428. @option{--disable-alsa} to @command{configure}.
  429. For building the DSSI midi synthesizer provider code you will
  430. need the following libraries:
  431. @table @b
  432. @item DSSI
  433. @uref{http://dssi.sourceforge.net,DSSI} library for audio
  434. processing plugins.
  435. @item liblo
  436. @uref{http://plugin.org.uk/liblo/,liblo}, the Lightweight OSC
  437. implementation.
  438. @item LADSPA
  439. @uref{http://www.ladspa.org,LADSPA}, the Linux Audio Developer's
  440. Simple Plugin API.
  441. @item JACK
  442. @uref{http://jackit.sourceforge.net,JACK}, a low latency audio
  443. server.
  444. @item libsndfile
  445. @uref{http://www.mega-nerd.com/libsndfile/,libsndfile}, an audio
  446. file I/O library.
  447. @item fluidsynth
  448. @uref{http://www.fluidsynth.org/,fluidsynth}, a real-time SoundFont
  449. 2 based soft-synth.
  450. @end table
  451. The GConf-based backend for java.util.prefs needs the following
  452. library headers:
  453. @table @b
  454. @item GConf
  455. @uref{http://www.gnome.org/projects/gconf/,GConf} version 2.11.2
  456. (or higher). GConf is used for storing desktop and application
  457. configuration settings in GNOME.
  458. @end table
  459. The GStreamer backend for javax.sound.sampled (The Java Sound API, not
  460. including the MIDI portion) needs the following library headers:
  461. @table @b
  462. @item GStreamer
  463. @uref{http://gstreamer.freedesktop.org/,GStreamer} version 0.10.10
  464. (or higher). You will also need at least gstreamer-base and
  465. gstreamer-plugins-base. More plugins can be used to allow streaming of
  466. different sound types but are not a compile time requirement. See
  467. README.gstreamer in the source distribution for more informations.
  468. @end table
  469. For building @command{gcjwebplugin} you'll need the Mozilla plugin
  470. support headers and libraries, which are available at
  471. @uref{http://www.mozilla.org,www.mozilla.org}.
  472. For enabling the com.sun.tools.javac support in tools.zip you
  473. will need a jar file containing the Eclipse Java Compiler.
  474. Otherwise com.sun.tools.javac will not be included in @file{tools.zip}.
  475. For building the xmlj JAXP implementation (disabled by default,
  476. use @command{configure --enable-xmlj}) you need the following libraries:
  477. @table @b
  478. @item libxml2
  479. @uref{http://www.xmlsoft.org/,libxml2} version 2.6.8 or higher.
  480. The libxml2 library is the XML C library for the Gnome desktop.
  481. @item libxslt
  482. @uref{http://www.xmlsoft.org/XSLT/,libxslt} version 1.1.11 or higher.
  483. The libxslt library if the XSLT C library for the Gnome desktop.
  484. @end table
  485. GNU Classpath comes with a couple of libraries included in the source
  486. that are not part of GNU Classpath proper, but that have been included
  487. to provide certain needed functionality. All these external libraries
  488. should be clearly marked as such. In general we try to use as much as
  489. possible the clean upstream versions of these sources. That way
  490. merging in new versions will be easier. You should always try to get
  491. bug fixes to these files accepted upstream first. Currently we
  492. include the following 'external' libraries. Most of these sources are
  493. included in the @file{external} directory. That directory also
  494. contains a @file{README} file explaining how to import newer versions.
  495. @table @b
  496. @item JSR166 concurrency support
  497. Can be found in @file{external/jsr166}. Provides java.util.concurrent
  498. and its subpackages. Upstream is
  499. @uref{http://g.oswego.edu/dl/concurrency-interest/,Doug Lea's Concurrency Interest Site}.
  500. @item RelaxNG Datatype Interfaces
  501. Can be found in @file{external/relaxngDatatype}. Provides org.relaxng.datatype
  502. and its subpackages. Upstream is
  503. @uref{http://www.oasis-open.org/committees/relax-ng/}.
  504. @item Simple API for XML (SAX)
  505. Can be found in @file{external/sax}. Provides org.xml.sax and its subpackages.
  506. Upstream is
  507. @uref{http://www.saxproject.org}.
  508. @item Document Object Model (DOM) bindings
  509. Can be found in @file{external/w3c_dom}. Provides org.w3c.dom and its subpackages.
  510. Upstream locations are listed in @file{external/w3c_dom/README}.
  511. @item fdlibm
  512. Can be found in @file{native/fdlibm}. Provides native implementations
  513. of some of the Float and Double operations. Upstream is
  514. @uref{http://gcc.gnu.org/java/,libgcj}, they sync again with the
  515. 'real' upstream @uref{http://www.netlib.org/fdlibm/readme}. See also
  516. java.lang.StrictMath.
  517. @end table
  518. @node Installation, Building and running with the X AWT peers, Needed Tools and Libraries, Top
  519. @comment node-name, next, previous, up
  520. @chapter Installation instructions
  521. This package was designed to use the GNU standard for configuration
  522. and makefiles. To build and install do the following:
  523. @enumerate
  524. @item Configuration
  525. Run the @command{configure} script to configure the package. There are
  526. various options you might want to pass to @command{configure} to control how the
  527. package is built. Consider the following options, @command{configure --help}
  528. gives a complete list.
  529. @table @option
  530. @item --enable-java
  531. compile Java source (default=@option{yes}).
  532. @item --enable-jni
  533. compile JNI source (default=@option{yes}).
  534. @item --enable-gtk-peer
  535. compile GTK native peers (default=@option{yes}).
  536. @item --enable-qt-peer
  537. compile Qt4 native peers (default=@option{no}).
  538. @item --enable-default-toolkit
  539. fully qualified class name of default AWT toolkit (default=@option{no}).
  540. @item --enable-xmlj
  541. compile native libxml/xslt library (default=@option{no}).
  542. @item --enable-load-library
  543. enable to use JNI native methods (default=@option{yes}).
  544. @item --enable-local-sockets
  545. enable build of local Unix sockets.
  546. @item --with-glibj
  547. define what to install @option{(zip|flat|both|none)} (default=@option{zip}).
  548. @item --with-escher=/path/to/escher
  549. enable build of the X/Escher peers, with
  550. the escher library at @file{/path/to/escher}, either
  551. in the form of a JAR file, or a directory
  552. containing the .class files of Escher.
  553. @item --enable-Werror
  554. whether to compile C code with @option{-Werror} which turns
  555. any compiler warning into a compilation failure
  556. (default=@option{no}).
  557. @item --with-gjdoc
  558. generate documentation using @command{gjdoc} (default=@option{no}).
  559. @item --with-jay
  560. Regenerate the parsers with @command{jay}, must be given the
  561. path to the @command{jay} executable
  562. @item --with-glibj-zip=ABS.PATH
  563. use prebuilt glibj.zip class library
  564. @item --with-ecj-jar=ABS.PATH
  565. specify jar file containing the Eclipse Java Compiler
  566. @item --with-gstreamer-peer
  567. build the experimental GStreamer peer (see @file{README.gstreamer})
  568. @end table
  569. For more flags run @command{configure --help}.
  570. @item Building
  571. Type @command{gmake} to build the package. There is no longer a
  572. dependency problem and we aim to keep it that way.
  573. @item Installation
  574. Type @command{gmake install} to install everything. This may require
  575. being the superuser. The default install path is /usr/local/classpath
  576. you may change it by giving @command{configure} the
  577. @option{--prefix=<path>} option.
  578. @end enumerate
  579. Report bugs to @email{classpath@@gnu.org} or much better to the
  580. GNU Classpath bug tracker at
  581. @uref{http://savannah.gnu.org/support/?func=addsupport&group=classpath,Savannah}.
  582. Happy Hacking!
  583. Once installed, GNU Classpath is ready to be used by any VM that supports
  584. using the official version of GNU Classpath. Simply ensure that
  585. @file{/usr/local/classpath/share/classpath} is in your @env{CLASSPATH} environment
  586. variable. You'll also have to set your @env{LD_LIBRARY_PATH}
  587. variable (or similar system configuration) to include the Classpath
  588. native libraries in @file{/usr/local/classpath/lib/classpath}.
  589. *NOTE* All example paths assume the default prefix is used with @command{configure}.
  590. If you don't know what this means then the examples are correct.
  591. @example
  592. LD_LIBRARY_PATH=/usr/local/classpath/lib/classpath
  593. CLASSPATH=/usr/local/classpath/share/classpath/glibj.zip:.
  594. export LD_LIBRARY_PATH CLASSPATH
  595. @end example
  596. More information about the VMs that use GNU Classpath can be found in the
  597. @file{README} file.
  598. @node Building and running with the X AWT peers, Misc. Notes, Installation, Top
  599. @comment node-name, next, previous, up
  600. @chapter Building and running with the X AWT peers
  601. In order build the X peers you need the Escher library version 0.2.3
  602. from @uref{http://escher.sourceforge.net,escher.sourceforge.net}.
  603. Unpack (and optionally build) the
  604. Escher library following the instructions in the downloaded
  605. package. Enable the build of the X peers by passing
  606. @option{--with-escher=/path/to/escher} to @command{configure} where @file{/path/to/escher}
  607. either points to a directory structure or JAR file containing the
  608. Escher classes. For Unix systems it is preferable to also build local
  609. socket support by passing @option{--enable-local-sockets}, which accelerates
  610. the network communication to the X server significantly.
  611. In this release you have to enable the X peers at runtime by
  612. setting the system property awt.toolkit=gnu.java.awt.peer.x.XToolkit
  613. by passing @option{-Dawt.toolkit=gnu.java.awt.peer.x.XToolkit} to the @command{java}
  614. command when running an application.
  615. @node Misc. Notes, Programming Standards, Building and running with the X AWT peers, Top
  616. @comment node-name, next, previous, up
  617. @chapter Misc. Notes
  618. Compilation is accomplished using a compiler's @@file syntax. For our
  619. part, we avoid placing make style dependencies as rules upon the
  620. compilation of a particular class file and leave this up to the Java
  621. compiler instead.
  622. The @option{--enable-maintainer-mode} option to @command{configure} currently does very
  623. little and shouldn't be used by ordinary developers or users anyway.
  624. On Windows machines, the native libraries do not currently build, but
  625. the Java bytecode library will. GCJ trunk is beginning to work under
  626. Cygwin.
  627. @node Programming Standards, Hacking Code, Misc. Notes, Top
  628. @comment node-name, next, previous, up
  629. @chapter Programming Standards
  630. For C source code, follow the
  631. @uref{http://www.gnu.org/prep/standards/,GNU Coding Standards}.
  632. The standards also specify various things like the install directory
  633. structure. These should be followed if possible.
  634. For Java source code, please follow the
  635. @uref{http://www.gnu.org/prep/standards/,GNU Coding
  636. Standards}, as much as possible. There are a number of exceptions to
  637. the GNU Coding Standards that we make for GNU Classpath as documented
  638. in this guide. We will hopefully be providing developers with a code
  639. formatting tool that closely matches those rules soon.
  640. For API documentation comments, please follow
  641. @uref{http://java.sun.com/products/jdk/javadoc/writingdoccomments.html,How
  642. to Write Doc Comments for Javadoc}. We would like to have a set of
  643. guidelines more tailored to GNU Classpath as part of this document.
  644. @menu
  645. * Source Code Style Guide::
  646. @end menu
  647. @node Source Code Style Guide, , Programming Standards, Programming Standards
  648. @comment node-name, next, previous, up
  649. @section Java source coding style
  650. Here is a list of some specific rules used when hacking on GNU
  651. Classpath java source code. We try to follow the standard
  652. @uref{http://www.gnu.org/prep/standards/,GNU Coding Standards}
  653. for that. There are lots of tools that can automatically generate it
  654. (although most tools assume C source, not java source code) and it
  655. seems as good a standard as any. There are a couple of exceptions and
  656. specific rules when hacking on GNU Classpath java source code however.
  657. The following lists how code is formatted (and some other code
  658. conventions):
  659. @itemize @bullet
  660. @item
  661. Java source files in GNU Classpath are encoded using UTF-8. However,
  662. ordinarily it is considered best practice to use the ASCII subset of
  663. UTF-8 and write non-ASCII characters using \u escapes.
  664. @item
  665. If possible, generate specific imports (expand) over java.io.* type
  666. imports. Order by gnu, java, javax, org. There must be one blank line
  667. between each group. The imports themselves are ordered alphabetically by
  668. package name. Classes and interfaces occur before sub-packages. The
  669. classes/interfaces are then also sorted alphabetical. Note that uppercase
  670. characters occur before lowercase characters.
  671. @example
  672. import gnu.java.awt.EmbeddedWindow;
  673. import java.io.IOException;
  674. import java.io.InputStream;
  675. import javax.swing.JFrame;
  676. @end example
  677. @item
  678. Blank line after package statement, last import statement, classes,
  679. interfaces, methods.
  680. @item
  681. Opening/closing brace for class and method is at the same level of
  682. indent as the declaration. All other braces are indented and content
  683. between braces indented again.
  684. @item
  685. Since method definitions don't start in column zero anyway (since they
  686. are always inside a class definition), the rational for easy grepping
  687. for ``^method_def'' is mostly gone already. Since it is customary for
  688. almost everybody who writes java source code to put modifiers, return
  689. value and method name on the same line, we do too.
  690. @c fixme Another rational for always indenting the method definition is that it makes it a bit easier to distinguish methods in inner and anonymous classes from code in their enclosing context. NEED EXAMPLE.
  691. @item
  692. Implements and extends on separate lines, throws too. Indent extends,
  693. implements, throws. Apply deep indentation for method arguments.
  694. @c fixme Needs example.
  695. @item
  696. Don't add a space between a method or constructor call/definition and
  697. the open-bracket. This is because often the return value is an object on
  698. which you want to apply another method or from which you want to access
  699. a field.
  700. Don't write:
  701. @example
  702. getToolkit ().createWindow (this);
  703. @end example
  704. But write:
  705. @example
  706. getToolkit().createWindow(this);
  707. @end example
  708. @item
  709. The GNU Coding Standard it gives examples for almost every construct
  710. (if, switch, do, while, etc.). One missing is the try-catch construct
  711. which should be formatted as:
  712. @example
  713. try
  714. @{
  715. //
  716. @}
  717. catch (...)
  718. @{
  719. //
  720. @}
  721. @end example
  722. @item
  723. Wrap lines at 80 characters after assignments and before operators.
  724. Wrap always before extends, implements, throws, and labels.
  725. @item
  726. Don't put multiple class definitions in the same file, except for
  727. inner classes. File names (plus .java) and class names should be the
  728. same.
  729. @item
  730. Don't catch a @code{NullPointerException} as an alternative to simply
  731. checking for @code{null}. It is clearer and usually more efficient
  732. to simply write an explicit check.
  733. For instance, don't write:
  734. @example
  735. try
  736. @{
  737. return foo.doit();
  738. @}
  739. catch (NullPointerException _)
  740. @{
  741. return 7;
  742. @}
  743. @end example
  744. If your intent above is to check whether @samp{foo} is @code{null},
  745. instead write:
  746. @example
  747. if (foo == null)
  748. return 7;
  749. else
  750. return foo.doit();
  751. @end example
  752. @item
  753. Don't use redundant modifiers or other redundant constructs. Here is
  754. some sample code that shows various redundant items in comments:
  755. @example
  756. /*import java.lang.Integer;*/
  757. /*abstract*/ interface I @{
  758. /*public abstract*/ void m();
  759. /*public static final*/ int i = 1;
  760. /*public static*/ class Inner @{@}
  761. @}
  762. final class C /*extends Object*/ @{
  763. /*final*/ void m() @{@}
  764. @}
  765. @end example
  766. Note that Jikes will generate warnings for redundant modifiers if you
  767. use @code{+Predundant-modifiers} on the command line.
  768. @item
  769. Modifiers should be listed in the standard order recommended by the
  770. JLS@. Jikes will warn for this when given @code{+Pmodifier-order}.
  771. @item
  772. Because the output of different compilers differs, we have
  773. standardized on explicitly specifying @code{serialVersionUID} in
  774. @code{Serializable} classes in Classpath. This field should be
  775. declared as @code{private static final}. Note that a class may be
  776. @code{Serializable} without being explicitly marked as such, due to
  777. inheritance. For instance, all subclasses of @code{Throwable} need to
  778. have @code{serialVersionUID} declared.
  779. @c fixme index
  780. @c fixme link to the discussion
  781. @item
  782. Don't declare unchecked exceptions in the @code{throws} clause of a
  783. method. However, if throwing an unchecked exception is part of the
  784. method's API, you should mention it in the Javadoc. There is one
  785. important exception to this rule, which is that a stub method should
  786. be marked as throwing @code{gnu.classpath.NotImplementedException}.
  787. This will let our API comparison tools note that the method is not
  788. fully implemented.
  789. @item
  790. When overriding @code{Object.equals}, remember that @code{instanceof}
  791. filters out @code{null}, so an explicit check is not needed.
  792. @item
  793. When catching an exception and rethrowing a new exception you should
  794. ``chain'' the Throwables. Don't just add the String representation of
  795. the caught exception.
  796. @example
  797. try
  798. @{
  799. // Some code that can throw
  800. @}
  801. catch (IOException ioe)
  802. @{
  803. throw (SQLException) new SQLException("Database corrupt").setCause(ioe);
  804. @}
  805. @end example
  806. @item
  807. Avoid the use of reserved words for identifiers. This is obvious with those
  808. such as @code{if} and @code{while} which have always been part of the Java
  809. programming language, but you should be careful about accidentally using
  810. words which have been added in later versions. Notable examples are
  811. @code{assert} (added in 1.4) and @code{enum} (added in 1.5). Jikes will warn
  812. of the use of the word @code{enum}, but, as it doesn't yet support the 1.5
  813. version of the language, it will still allow this usage through. A
  814. compiler which supports 1.5 (e.g.@: the Eclipse compiler, ecj) will simply
  815. fail to compile the offending source code.
  816. @c fixme Describe Anonymous classes (example).
  817. @c fixme Descibe Naming conventions when different from GNU Coding Standards.
  818. @c fixme Describee API doc javadoc tags used.
  819. @end itemize
  820. Some things are the same as in the normal GNU Coding Standards:
  821. @itemize @bullet
  822. @item
  823. Unnecessary braces can be removed, one line after an if, for, while as
  824. examples.
  825. @item
  826. Space around operators (assignment, logical, relational, bitwise,
  827. mathematical, shift).
  828. @item
  829. Blank line before single-line comments, multi-line comments, javadoc
  830. comments.
  831. @item
  832. If more than 2 blank lines, trim to 2.
  833. @item
  834. Don't keep commented out code. Just remove it or add a real comment
  835. describing what it used to do and why it is changed to the current
  836. implementation.
  837. @end itemize
  838. @node Hacking Code, Programming Goals, Programming Standards, Top
  839. @comment node-name, next, previous, up
  840. @chapter Working on the code, Working with others
  841. There are a lot of people helping out with GNU Classpath. Here are a
  842. couple of practical guidelines to make working together on the code
  843. smoother.
  844. The main thing is to always discuss what you are up to on the
  845. mailinglist. Making sure that everybody knows who is working on what
  846. is the most important thing to make sure we cooperate most
  847. effectively.
  848. We maintain a
  849. @uref{http://www.gnu.org/software/classpath/tasks.html,Task List}
  850. which contains items that you might want to work on.
  851. Before starting to work on something please make sure you read this
  852. complete guide. And discuss it on list to make sure your work does
  853. not duplicate or interferes with work someone else is already doing.
  854. Always make sure that you submit things that are your own work. And
  855. that you have paperwork on file (as stated in the requirements
  856. section) with the FSF authorizing the use of your additions.
  857. Technically the GNU Classpath project is hosted on
  858. @uref{http://savannah.gnu.org/,Savannah} a central point for
  859. development, distribution and maintenance of GNU Software. Here you
  860. will find the
  861. @uref{https://savannah.gnu.org/projects/classpath/,project page}, bug
  862. reports, pending patches, links to mailing lists, news items and CVS.
  863. You can find instructions on getting a CVS checkout for classpath at
  864. @uref{https://savannah.gnu.org/cvs/?group=classpath}.
  865. You don't have to get CVS commit write access to contribute, but it is
  866. sometimes more convenient to be able to add your changes directly to
  867. the project CVS@. Please contact the GNU Classpath savannah admins to
  868. arrange CVS access if you would like to have it.
  869. Make sure to be subscribed to the commit-classpath mailinglist while
  870. you are actively hacking on Classpath. You have to send patches (cvs
  871. diff -uN) to this list before committing.
  872. We really want to have a pretty open check-in policy. But this means
  873. that you should be extra careful if you check something in. If at all
  874. in doubt or if you think that something might need extra explaining
  875. since it is not completely obvious please make a little announcement
  876. about the change on the mailinglist. And if you do commit something
  877. without discussing it first and another GNU Classpath hackers asks for
  878. extra explanation or suggests to revert a certain commit then please
  879. reply to the request by explaining why something should be so or if
  880. you agree to revert it. (Just reverting immediately is OK without
  881. discussion, but then please don't mix it with other changes and please
  882. say so on list.)
  883. Patches that are already approved for libgcj or also OK for Classpath.
  884. (But you still have to send a patch/diff to the list.) All other
  885. patches require you to think whether or not they are really OK and
  886. non-controversial, or if you would like some feedback first on them
  887. before committing. We might get real commit rules in the future, for
  888. now use your own judgement, but be a bit conservative.
  889. Always contact the GNU Classpath maintainer before adding anything
  890. non-trivial that you didn't write yourself and that does not come from
  891. libgcj or from another known GNU Classpath or libgcj hacker. If you
  892. have been assigned to commit changes on behalf of another project or
  893. a company always make sure they come from people who have signed the
  894. papers for the FSF and/or fall under the arrangement your company made
  895. with the FSF for contributions. Mention in the ChangeLog who actually
  896. wrote the patch.
  897. Commits for completely unrelated changes they should be committed
  898. separately (especially when doing a formatting change and a logical
  899. change, do them in two separate commits). But do try to do a commit of
  900. as much things/files that are done at the same time which can
  901. logically be seen as part of the same change/cleanup etc.
  902. When the change fixes an important bug or adds nice new functionality
  903. please write a short entry for inclusion in the @file{NEWS} file. If it
  904. changes the VM interface you must mention that in both the @file{NEWS} file
  905. and the VM Integration Guide.
  906. All the ``rules'' are really meant to make sure that GNU Classpath
  907. will be maintainable in the long run and to give all the projects that
  908. are now using GNU Classpath an accurate view of the changes we make to
  909. the code and to see what changed when. If you think the requirements
  910. are ``unworkable'' please try it first for a couple of weeks. If you
  911. still feel the same after having some more experience with the project
  912. please feel free to bring up suggestions for improvements on the list.
  913. But don't just ignore the rules! Other hackers depend on them being
  914. followed to be the most productive they can be (given the above
  915. constraints).
  916. @menu
  917. * Branches::
  918. * Writing ChangeLogs::
  919. @end menu
  920. @node Branches, Writing ChangeLogs, Hacking Code, Hacking Code
  921. @comment node-name, next, previous, up
  922. @section Working with branches
  923. Sometimes it is necessary to create branch of the source for doing new
  924. work that is disruptive to the other hackers, or that needs new
  925. language or libraries not yet (easily) available.
  926. After discussing the need for a branch on the main mailinglist with
  927. the other hackers explaining the need of a branch and suggestion of
  928. the particular branch rules (what will be done on the branch, who will
  929. work on it, will there be different commit guidelines then for the
  930. mainline trunk and when is the branch estimated to be finished and
  931. merged back into the trunk) every GNU Classpath hacker with commit
  932. access should feel free to create a branch. There are however a couple
  933. of rules that every branch should follow:
  934. @itemize @bullet
  935. @item All branches ought to be documented in the developer wiki at
  936. @uref{http://developer.classpath.org/mediation/ClasspathBranches}, so
  937. we can know which are live, who owns them, and when they die.
  938. @item Some rules can be changed on a branch. In particular the branch
  939. maintainer can change the review requirements, and the requirement of
  940. keeping things building, testing, etc, can also be lifted. (These
  941. should be documented along with the branch name and owner if they
  942. differ from the trunk.)
  943. @item Requirements for patch email to classpath-patches and for paperwork
  944. @strong{cannot} be lifted. See @ref{Requirements}.
  945. @item A branch should not be seen as ``private'' or
  946. ``may be completely broken''. It should be as much as possible
  947. something that you work on with a team (and if there is no team - yet
  948. - then there is nothing as bad as having a completely broken build to
  949. get others to help out). There can of course be occasional breakage, but
  950. it should be planned and explained. And you can certainly have a rule
  951. like ``please ask me before committing to this branch''.
  952. @item Merges from the trunk to a branch are at the discretion of the
  953. branch maintainer.
  954. @item A merge from a branch to the trunk is treated like any other patch.
  955. In particular, it has to go through review, it must satisfy all the
  956. trunk requirements (build, regression test, documentation).
  957. @item There may be additional timing requirements on merging a branch to
  958. the trunk depending on the release schedule, etc. For instance we may
  959. not want to do a branch merge just before a release.
  960. @end itemize
  961. If any of these rules are unclear please discuss on the list first.
  962. @menu
  963. * Writing ChangeLogs::
  964. @end menu
  965. @node Writing ChangeLogs, , Branches, Hacking Code
  966. @comment node-name, next, previous, up
  967. @section Documenting what changed when with ChangeLog entries
  968. To keep track of who did what when we keep an explicit ChangeLog entry
  969. together with the code. This mirrors the CVS commit messages and in
  970. general the ChangeLog entry is the same as the CVS commit message.
  971. This provides an easy way for people getting a (snapshot) release or
  972. without access to the CVS server to see what happened when. We do not
  973. generate the ChangeLog file automatically from the CVS server since
  974. that is not reliable.
  975. A good ChangeLog entry guideline can be found in the Guile Manual at
  976. @uref{http://www.gnu.org/software/guile/changelogs/guile-changelogs_3.html}.
  977. Here are some example to explain what should or shouldn't be in a
  978. ChangeLog entry (and the corresponding commit message):
  979. @itemize @bullet
  980. @item
  981. The first line of a ChangeLog entry should be:
  982. @example
  983. [date] <two spaces> [full name] <two spaces> [email-contact]
  984. @end example
  985. The second line should be blank. All other lines should be indented
  986. with one tab.
  987. @item
  988. Just state what was changed. Why something is done as it is done in
  989. the current code should be either stated in the code itself or be
  990. added to one of the documentation files (like this Hacking Guide).
  991. So don't write:
  992. @example
  993. * java/awt/font/OpenType.java: Remove 'public static final'
  994. from OpenType tags, reverting the change of 2003-08-11. See
  995. Classpath discussion list of 2003-08-11.
  996. @end example
  997. Just state:
  998. @example
  999. * java/awt/font/OpenType.java: Remove 'public static final' from
  1000. all member fields.
  1001. @end example
  1002. In this case the reason for the change was added to this guide.
  1003. @item
  1004. Just as with the normal code style guide, don't make lines longer then
  1005. 80 characters.
  1006. @item
  1007. Just as with comments in the code. The ChangeLog entry should be a
  1008. full sentence, starting with a capital and ending with a period.
  1009. @item
  1010. Be precise in what changed, not the effect of the change (which should
  1011. be clear from the code/patch). So don't write:
  1012. @example
  1013. * java/io/ObjectOutputStream.java : Allow putFields be called more
  1014. than once.
  1015. @end example
  1016. But explain what changed and in which methods it was changed:
  1017. @example
  1018. * java/io/ObjectOutputStream.java (putFields): Don't call
  1019. markFieldsWritten(). Only create new PutField when
  1020. currentPutField is null.
  1021. (writeFields): Call markFieldsWritten().
  1022. @end example
  1023. @end itemize
  1024. The above are all just guidelines. We all appreciate the fact that writing
  1025. ChangeLog entries, using a coding style that is not ``your own'' and the
  1026. CVS, patch and diff tools do take some time to getting used to. So don't
  1027. feel like you have to do it perfect right away or that contributions
  1028. aren't welcome if they aren't ``perfect''. We all learn by doing and
  1029. interacting with each other.
  1030. @node Programming Goals, API Compatibility, Hacking Code, Top
  1031. @comment node-name, next, previous, up
  1032. @chapter Programming Goals
  1033. When you write code for Classpath, write with three things in mind, and
  1034. in the following order: portability, robustness, and efficiency.
  1035. If efficiency breaks portability or robustness, then don't do it the
  1036. efficient way. If robustness breaks portability, then bye-bye robust
  1037. code. Of course, as a programmer you would probably like to find sneaky
  1038. ways to get around the issue so that your code can be all three ... the
  1039. following chapters will give some hints on how to do this.
  1040. @menu
  1041. * Portability:: Writing Portable Software
  1042. * Utility Classes:: Reusing Software
  1043. * Robustness:: Writing Robust Software
  1044. * Java Efficiency:: Writing Efficient Java
  1045. * Native Efficiency:: Writing Efficient JNI
  1046. * Security:: Writing Secure Software
  1047. @end menu
  1048. @node Portability, Utility Classes, Programming Goals, Programming Goals
  1049. @comment node-name, next, previous, up
  1050. @section Portability
  1051. The portability goal for Classpath is the following:
  1052. @enumerate
  1053. @item
  1054. native functions for each platform that work across all VMs on that
  1055. platform
  1056. @item
  1057. a single classfile set that work across all VMs on all platforms that
  1058. support the native functions.
  1059. @end enumerate
  1060. For almost all of Classpath, this is a very feasible goal, using a
  1061. combination of JNI and native interfaces. This is what you should shoot
  1062. for. For those few places that require knowledge of the Virtual Machine
  1063. beyond that provided by the Java standards, the VM Interface was designed.
  1064. Read the Virtual Machine Integration Guide for more information.
  1065. Right now the only supported platform is Linux. This will change as that
  1066. version stabilizes and we begin the effort to port to many other
  1067. platforms. Jikes RVM runs Classpath on AIX, and generally the Jikes
  1068. RVM team fixes Classpath to work on that platform.
  1069. @node Utility Classes, Robustness, Portability, Programming Goals
  1070. @comment node-name, next, previous, up
  1071. @section Utility Classes
  1072. At the moment, we are not very good at reuse of the JNI code. There
  1073. have been some attempts, called @dfn{libclasspath}, to
  1074. create generally useful utility classes. The utility classes are in
  1075. the directory @file{native/jni/classpath} and they are mostly declared
  1076. in @file{native/jni/classpath/jcl.h}. These utility classes are
  1077. currently only discussed in @ref{Robustness} and in @ref{Native
  1078. Efficiency}.
  1079. There are more utility classes available that could be factored out if
  1080. a volunteer wants something nice to hack on. The error reporting and
  1081. exception throwing functions and macros in
  1082. @file{native/jni/gtk-peer/gthread-jni.c} might be good
  1083. candidates for reuse. There are also some generally useful utility
  1084. functions in @file{gnu_java_awt_peer_gtk_GtkMainThread.c} that could
  1085. be split out and put into libclasspath.
  1086. @node Robustness, Java Efficiency, Utility Classes, Programming Goals
  1087. @comment node-name, next, previous, up
  1088. @section Robustness
  1089. Native code is very easy to make non-robust. (That's one reason Java is
  1090. so much better!) Here are a few hints to make your native code more
  1091. robust.
  1092. Always check return values for standard functions. It's sometimes easy
  1093. to forget to check that malloc() return for an error. Don't make that
  1094. mistake. (In fact, use JCL_malloc() in the jcl library instead--it will
  1095. check the return value and throw an exception if necessary.)
  1096. Always check the return values of JNI functions, or call
  1097. @code{ExceptionOccurred} to check whether an error occurred. You must
  1098. do this after @emph{every} JNI call. JNI does not work well when an
  1099. exception has been raised, and can have unpredictable behavior.
  1100. Throw exceptions using @code{JCL_ThrowException}. This guarantees that if
  1101. something is seriously wrong, the exception text will at least get out
  1102. somewhere (even if it is stderr).
  1103. Check for null values of @code{jclass}es before you send them to JNI functions.
  1104. JNI does not behave nicely when you pass a null class to it: it
  1105. terminates Java with a "JNI Panic."
  1106. In general, try to use functions in @file{native/jni/classpath/jcl.h}. They
  1107. check exceptions and return values and throw appropriate exceptions.
  1108. @node Java Efficiency, Native Efficiency, Robustness, Programming Goals
  1109. @comment node-name, next, previous, up
  1110. @section Java Efficiency
  1111. For methods which explicitly throw a @code{NullPointerException} when an
  1112. argument is passed which is null, per a Sun specification, do not write
  1113. code like:
  1114. @example
  1115. int
  1116. strlen (String foo) throws NullPointerException
  1117. @{
  1118. if (foo == null)
  1119. throw new NullPointerException ("foo is null");
  1120. return foo.length ();
  1121. @}
  1122. @end example
  1123. Instead, the code should be written as:
  1124. @example
  1125. int
  1126. strlen (String foo) throws NullPointerException
  1127. @{
  1128. return foo.length ();
  1129. @}
  1130. @end example
  1131. Explicitly comparing foo to null is unnecessary, as the virtual machine
  1132. will throw a NullPointerException when length() is invoked. Classpath
  1133. is designed to be as fast as possible -- every optimization, no matter
  1134. how small, is important.
  1135. @node Native Efficiency, Security, Java Efficiency, Programming Goals
  1136. @comment node-name, next, previous, up
  1137. @section Native Efficiency
  1138. You might think that using native methods all over the place would give
  1139. our implementation of Java speed, speed, blinding speed. You'd be
  1140. thinking wrong. Would you believe me if I told you that an empty
  1141. @emph{interpreted} Java method is typically about three and a half times
  1142. @emph{faster} than the equivalent native method?
  1143. Bottom line: JNI is overhead incarnate. In Sun's implementation, even
  1144. the JNI functions you use once you get into Java are slow.
  1145. A final problem is efficiency of native code when it comes to things
  1146. like method calls, fields, finding classes, etc. Generally you should
  1147. cache things like that in static C variables if you're going to use them
  1148. over and over again. GetMethodID(), GetFieldID(), and FindClass() are
  1149. @emph{slow}. Classpath provides utility libraries for caching methodIDs
  1150. and fieldIDs in @file{native/jni/classpath/jnilink.h}. Other native data can
  1151. be cached between method calls using functions found in
  1152. @file{native/jni/classpath/native_state.h}.
  1153. Here are a few tips on writing native code efficiently:
  1154. Make as few native method calls as possible. Note that this is not the
  1155. same thing as doing less in native method calls; it just means that, if
  1156. given the choice between calling two native methods and writing a single
  1157. native method that does the job of both, it will usually be better to
  1158. write the single native method. You can even call the other two native
  1159. methods directly from your native code and not incur the overhead of a
  1160. method call from Java to C.
  1161. Cache @code{jmethodID}s and @code{jfieldID}s wherever you can. String
  1162. lookups are
  1163. expensive. The best way to do this is to use the
  1164. @file{native/jni/classpath/jnilink.h}
  1165. library. It will ensure that @code{jmethodID}s are always valid, even if the
  1166. class is unloaded at some point. In 1.1, jnilink simply caches a
  1167. @code{NewGlobalRef()} to the method's underlying class; however, when 1.2 comes
  1168. along, it will use a weak reference to allow the class to be unloaded
  1169. and then re-resolve the @code{jmethodID} the next time it is used.
  1170. Cache classes that you need to access often. jnilink will help with
  1171. this as well. The issue here is the same as the methodID and fieldID
  1172. issue--how to make certain the class reference remains valid.
  1173. If you need to associate native C data with your class, use Paul
  1174. Fisher's native_state library (NSA). It will allow you to get and set
  1175. state fairly efficiently. Japhar now supports this library, making
  1176. native state get and set calls as fast as accessing a C variable
  1177. directly.
  1178. If you are using native libraries defined outside of Classpath, then
  1179. these should be wrapped by a Classpath function instead and defined
  1180. within a library of their own. This makes porting Classpath's native
  1181. libraries to new platforms easier in the long run. It would be nice
  1182. to be able to use Mozilla's NSPR or Apache's APR, as these libraries
  1183. are already ported to numerous systems and provide all the necessary
  1184. system functions as well.
  1185. @node Security, , Native Efficiency, Programming Goals
  1186. @comment node-name, next, previous, up
  1187. @section Security
  1188. Security is such a huge topic it probably deserves its own chapter.
  1189. Most of the current code needs to be audited for security to ensure
  1190. all of the proper security checks are in place within the Java
  1191. platform, but also to verify that native code is reasonably secure and
  1192. avoids common pitfalls, buffer overflows, etc. A good source for
  1193. information on secure programming is the excellent HOWTO by David
  1194. Wheeler,
  1195. @uref{http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/index.html,Secure
  1196. Programming for Linux and Unix HOWTO}.
  1197. @node API Compatibility, Specification Sources, Programming Goals, Top
  1198. @comment node-name, next, previous, up
  1199. @chapter API Compatibility
  1200. @menu
  1201. * Serialization:: Serialization
  1202. * Deprecated Methods:: Deprecated methods
  1203. @end menu
  1204. @node Serialization, Deprecated Methods, API Compatibility, API Compatibility
  1205. @comment node-name, next, previous, up
  1206. @section Serialization
  1207. Sun has produced documentation concerning much of the information
  1208. needed to make Classpath serializable compatible with Sun
  1209. implementations. Part of doing this is to make sure that every class
  1210. that is Serializable actually defines a field named serialVersionUID
  1211. with a value that matches the output of serialver on Sun's
  1212. implementation. The reason for doing this is below.
  1213. If a class has a field (of any accessibility) named serialVersionUID
  1214. of type long, that is what serialver uses. Otherwise it computes a
  1215. value using some sort of hash function on the names of all method
  1216. signatures in the .class file. The fact that different compilers
  1217. create different synthetic method signatures, such as access$0() if an
  1218. inner class needs access to a private member of an enclosing class,
  1219. make it impossible for two distinct compilers to reliably generate the
  1220. same serial #, because their .class files differ. However, once you
  1221. have a .class file, its serial # is unique, and the computation will
  1222. give the same result no matter what platform you execute on.
  1223. Serialization compatibility can be tested using tools provided with
  1224. @uref{http://www.kaffe.org/~stuart/japi/,Japitools}. These
  1225. tools can test binary serialization compatibility and also provide
  1226. information about unknown serialized formats by writing these in XML
  1227. instead. Japitools is also the primary means of checking API
  1228. compatibility for GNU Classpath with Sun's Java Platform.
  1229. @node Deprecated Methods, , Serialization, API Compatibility
  1230. @comment node-name, next, previous, up
  1231. @section Deprecated Methods
  1232. Sun has a practice of creating ``alias'' methods, where a public or
  1233. protected method is deprecated in favor of a new one that has the same
  1234. function but a different name. Sun's reasons for doing this vary; as
  1235. an example, the original name may contain a spelling error or it may
  1236. not follow Java naming conventions.
  1237. Unfortunately, this practice complicates class library code that calls
  1238. these aliased methods. Library code must still call the deprecated
  1239. method so that old client code that overrides it continues to work.
  1240. But library code must also call the new version, because new code is
  1241. expected to override the new method.
  1242. The correct way to handle this (and the way Sun does it) may seem
  1243. counterintuitive because it means that new code is less efficient than
  1244. old code: the new method must call the deprecated method, and throughout
  1245. the library code calls to the old method must be replaced with calls to
  1246. the new one.
  1247. Take the example of a newly-written container laying out a component and
  1248. wanting to know its preferred size. The Component class has a
  1249. deprecated preferredSize method and a new method, getPreferredSize.
  1250. Assume that the container is laying out an old component that overrides
  1251. preferredSize and a new component that overrides getPreferredSize. If
  1252. the container calls getPreferredSize and the default implementation of
  1253. getPreferredSize calls preferredSize, then the old component will have
  1254. its preferredSize method called and new code will have its
  1255. getPreferredSize method called.
  1256. Even using this calling scheme, an old component may still be laid out
  1257. improperly if it implements a method, getPreferredSize, that has the
  1258. same signature as the new Component.getPreferredSize. But that is a
  1259. general problem -- adding new public or protected methods to a
  1260. widely-used class that calls those methods internally is risky, because
  1261. existing client code may have already declared methods with the same
  1262. signature.
  1263. The solution may still seem counterintuitive -- why not have the
  1264. deprecated method call the new method, then have the library always call
  1265. the old method? One problem with that, using the preferred size example
  1266. again, is that new containers, which will use the non-deprecated
  1267. getPreferredSize, will not get the preferred size of old components.
  1268. @node Specification Sources, Naming Conventions, API Compatibility, Top
  1269. @comment node-name, next, previous, up
  1270. @chapter Specification Sources
  1271. There are a number of specification sources to use when working on
  1272. Classpath. In general, the only place you'll find your classes
  1273. specified is in the JavaDoc documentation or possibly in the
  1274. corresponding white paper. In the case of java.lang, java.io and
  1275. java.util, you should look at the Java Language Specification.
  1276. Here, however, is a list of specs, in order of canonicality:
  1277. @enumerate
  1278. @item
  1279. @uref{http://java.sun.com/docs/books/jls/clarify.html,Clarifications and Amendments to the JLS - 1.1}
  1280. @item
  1281. @uref{http://java.sun.com/docs/books/jls/html/1.1Update.html,JLS Updates
  1282. - 1.1}
  1283. @item
  1284. @uref{http://java.sun.com/docs/books/jls/html/index.html,The 1.0 JLS}
  1285. @item
  1286. @uref{http://java.sun.com/docs/books/vmspec/index.html,JVM spec - 1.1}
  1287. @item
  1288. @uref{http://java.sun.com/products/jdk/1.1/docs/guide/jni/spec/jniTOC.doc.html,JNI spec - 1.1}
  1289. @item
  1290. @uref{http://java.sun.com/products/jdk/1.1/docs/api/packages.html,Sun's javadoc - 1.1}
  1291. (since Sun's is the reference implementation, the javadoc is
  1292. documentation for the Java platform itself.)
  1293. @item
  1294. @uref{http://java.sun.com/products/jdk/1.2/docs/guide/jvmdi/jvmdi.html,JVMDI spec - 1.2},
  1295. @uref{http://java.sun.com/products/jdk/1.2/docs/guide/jni/jni-12.html,JNI spec - 1.2}
  1296. (sometimes gives clues about unspecified things in 1.1; if
  1297. it was not specified accurately in 1.1, then use the spec
  1298. for 1.2; also, we are using JVMDI in this project.)
  1299. @item
  1300. @uref{http://java.sun.com/products/jdk/1.2/docs/api/frame.html,Sun's javadoc - 1.2}
  1301. (sometimes gives clues about unspecified things in 1.1; if
  1302. it was not specified accurately in 1.1, then use the spec
  1303. for 1.2)
  1304. @item
  1305. @uref{http://developer.java.sun.com/developer/bugParade/index.html,The
  1306. Bug Parade}: I have obtained a ton of useful information about how
  1307. things do work and how they *should* work from the Bug Parade just by
  1308. searching for related bugs. The submitters are very careful about their
  1309. use of the spec. And if something is unspecified, usually you can find
  1310. a request for specification or a response indicating how Sun thinks it
  1311. should be specified here.
  1312. @end enumerate
  1313. You'll notice that in this document, white papers and specification
  1314. papers are more canonical than the JavaDoc documentation. This is true
  1315. in general.
  1316. @node Naming Conventions, Character Conversions, Specification Sources, Top
  1317. @comment node-name, next, previous, up
  1318. @chapter Directory and File Naming Conventions
  1319. The Classpath directory structure is laid out in the following manner:
  1320. @example
  1321. classpath
  1322. |
  1323. |---->java
  1324. | |
  1325. | |-->awt
  1326. | |-->io
  1327. | |-->lang
  1328. | |-->util
  1329. | | |
  1330. | | |--->zip
  1331. | | |--->jar
  1332. | |-->net
  1333. | |-->etc
  1334. |
  1335. |---->gnu
  1336. | |
  1337. | |-->java
  1338. | |
  1339. | |-->awt
  1340. | |-->lang
  1341. | |-->util
  1342. | | |
  1343. | | |-->zip
  1344. | |-->etc
  1345. |
  1346. |---->native
  1347. |
  1348. |-->jni
  1349. | |-->classpath
  1350. | |-->gtk-peer
  1351. | |-->java-io
  1352. | |-->java-lang
  1353. | |-->java-net
  1354. | |-->java-util
  1355. | |-->etc
  1356. |-->cni
  1357. @end example
  1358. Here is a brief description of the toplevel directories and their contents.
  1359. @table @b
  1360. @item java
  1361. Contains the source code to the Java packages that make up the core
  1362. class library. Because this is the public interface to Java, it is
  1363. important that the public classes, interfaces, methods, and variables
  1364. are exactly the same as specified in Sun's documentation. The directory
  1365. structure is laid out just like the java package names. For example,
  1366. the class java.util.zip would be in the directory java-util.
  1367. @item gnu/java
  1368. Internal classes (roughly analogous to Sun's sun.* classes) should go
  1369. under the @file{gnu/java} directory. Classes related to a particular public
  1370. Java package should go in a directory named like that package. For
  1371. example, classes related to java.util.zip should go under a directory
  1372. @file{gnu/java/util/zip}. Sub-packages under the main package name are
  1373. allowed. For classes spanning multiple public Java packages, pick an
  1374. appropriate name and see what everybody else thinks.
  1375. @item native
  1376. This directory holds native code needed by the public Java packages.
  1377. Each package has its own subdirectory, which is the ``flattened'' name
  1378. of the package. For example, native method implementations for
  1379. java.util.zip should go in @file{native/classpath/java-util}. Classpath
  1380. actually includes an all Java version of the zip classes, so no native
  1381. code is required.
  1382. @end table
  1383. Each person working on a package get's his or her own ``directory
  1384. space'' underneath each of the toplevel directories. In addition to the
  1385. general guidelines above, the following standards should be followed:
  1386. @itemize @bullet
  1387. @item
  1388. Classes that need to load native code should load a library with the
  1389. same name as the flattened package name, with all hyphens removed. For
  1390. example, the native library name specified in LoadLibrary for
  1391. java-util would be ``javautil''.
  1392. @item
  1393. Each package has its own shared library for native code (if any).
  1394. @item
  1395. The main native method implementation for a given method in class should
  1396. go in a file with the same name as the class with a ``.c'' extension.
  1397. For example, the JNI implementation of the native methods in
  1398. java.net.InetAddress would go in @file{native/jni/java-net/InetAddress.c}.
  1399. ``Internal'' native functions called from the main native method can
  1400. reside in files of any name.
  1401. @end itemize
  1402. @node Character Conversions, Localization, Naming Conventions, Top
  1403. @comment node-name, next, previous, up
  1404. @chapter Character Conversions
  1405. Java uses the Unicode character encoding system internally. This is a
  1406. sixteen bit (two byte) collection of characters encompassing most of the
  1407. world's written languages. However, Java programs must often deal with
  1408. outside interfaces that are byte (eight bit) oriented. For example, a
  1409. Unix file, a stream of data from a network socket, etc. Beginning with
  1410. Java 1.1, the @code{Reader} and @code{Writer} classes provide functionality
  1411. for dealing with character oriented streams. The classes
  1412. @code{InputStreamReader} and @code{OutputStreamWriter} bridge the gap
  1413. between byte streams and character streams by converting bytes to
  1414. Unicode characters and vice versa.
  1415. In Classpath, @code{InputStreamReader} and @code{OutputStreamWriter}
  1416. rely on an internal class called @code{gnu.java.io.EncodingManager} to load
  1417. translators that perform the actual conversion. There are two types of
  1418. converters, encoders and decoders. Encoders are subclasses of
  1419. @code{gnu.java.io.encoder.Encoder}. This type of converter takes a Java
  1420. (Unicode) character stream or buffer and converts it to bytes using
  1421. a specified encoding scheme. Decoders are a subclass of
  1422. @code{gnu.java.io.decoder.Decoder}. This type of converter takes a
  1423. byte stream or buffer and converts it to Unicode characters. The
  1424. @code{Encoder} and @code{Decoder} classes are subclasses of
  1425. @code{Writer} and @code{Reader} respectively, and so can be used in
  1426. contexts that require character streams, but the Classpath implementation
  1427. currently does not make use of them in this fashion.
  1428. The @code{EncodingManager} class searches for requested encoders and
  1429. decoders by name. Since encoders and decoders are separate in Classpath,
  1430. it is possible to have a decoder without an encoder for a particular
  1431. encoding scheme, or vice versa. @code{EncodingManager} searches the
  1432. package path specified by the @code{file.encoding.pkg} property. The
  1433. name of the encoder or decoder is appended to the search path to
  1434. produce the required class name. Note that @code{EncodingManager} knows
  1435. about the default system encoding scheme, which it retrieves from the
  1436. system property @code{file.encoding}, and it will return the proper
  1437. translator for the default encoding if no scheme is specified. Also, the
  1438. Classpath standard translator library, which is the @code{gnu.java.io} package,
  1439. is automatically appended to the end of the path.
  1440. For efficiency, @code{EncodingManager} maintains a cache of translators
  1441. that it has loaded. This eliminates the need to search for a commonly
  1442. used translator each time it is requested.
  1443. Finally, @code{EncodingManager} supports aliasing of encoding scheme names.
  1444. For example, the ISO Latin-1 encoding scheme can be referred to as
  1445. ''8859_1'' or ''ISO-8859-1''. @code{EncodingManager} searches for
  1446. aliases by looking for the existence of a system property called
  1447. @code{gnu.java.io.encoding_scheme_alias.<encoding name>}. If such a
  1448. property exists. The value of that property is assumed to be the
  1449. canonical name of the encoding scheme, and a translator with that name is
  1450. looked up instead of one with the original name.
  1451. Here is an example of how @code{EncodingManager} works. A class requests
  1452. a decoder for the ''UTF-8'' encoding scheme by calling
  1453. @code{EncodingManager.getDecoder("UTF-8")}. First, an alias is searched
  1454. for by looking for the system property
  1455. @code{gnu.java.io.encoding_scheme_alias.UTF-8}. In our example, this
  1456. property exists and has the value ''UTF8''. That is the actual
  1457. decoder that will be searched for. Next, @code{EncodingManager} looks
  1458. in its cache for this translator. Assuming it does not find it, it
  1459. searches the translator path, which is this example consists only of
  1460. the default @code{gnu.java.io}. The ''decoder'' package name is
  1461. appended since we are looking for a decoder. (''encoder'' would be
  1462. used if we were looking for an encoder). Then name name of the translator
  1463. is appended. So @code{EncodingManager} attempts to load a translator
  1464. class called @code{gnu.java.io.decoder.UTF8}. If that class is found,
  1465. an instance of it is returned. If it is not found, a
  1466. @code{UnsupportedEncodingException}.
  1467. To write a new translator, it is only necessary to subclass
  1468. @code{Encoder} and/or @code{Decoder}. Only a handful of abstract
  1469. methods need to be implemented. In general, no methods need to be
  1470. overridden. The needed methods calculate the number of bytes/chars
  1471. that the translation will generate, convert buffers to/from bytes,
  1472. and read/write a requested number of characters to/from a stream.
  1473. Many common encoding schemes use only eight bits to encode characters.
  1474. Writing a translator for these encodings is very easy. There are
  1475. abstract translator classes @code{gnu.java.io.decode.DecoderEightBitLookup}
  1476. and @code{gnu.java.io.encode.EncoderEightBitLookup}. These classes
  1477. implement all of the necessary methods. All that is necessary to
  1478. create a lookup table array that maps bytes to Unicode characters and
  1479. set the class variable @code{lookup_table} equal to it in a static
  1480. initializer. Also, a single constructor that takes an appropriate
  1481. stream as an argument must be supplied. These translators are
  1482. exceptionally easy to create and there are several of them supplied
  1483. in the Classpath distribution.
  1484. Writing multi-byte or variable-byte encodings is more difficult, but
  1485. often not especially challenging. The Classpath distribution ships with
  1486. translators for the UTF8 encoding scheme which uses from one to three
  1487. bytes to encode Unicode characters. This can serve as an example of
  1488. how to write such a translator.
  1489. Many more translators are needed. All major character encodings should
  1490. eventually be supported.
  1491. @node Localization, , Character Conversions, Top
  1492. @comment node-name, next, previous, up
  1493. @chapter Localization
  1494. There are many parts of the Java standard runtime library that must
  1495. be customized to the particular locale the program is being run in.
  1496. These include the parsing and display of dates, times, and numbers;
  1497. sorting words alphabetically; breaking sentences into words, etc.
  1498. In general, Classpath uses general classes for performing these tasks,
  1499. and customizes their behavior with configuration data specific to a
  1500. given locale.
  1501. @menu
  1502. * String Collation:: Sorting strings in different locales
  1503. * Break Iteration:: Breaking up text into words, sentences, and lines
  1504. * Date Formatting and Parsing:: Locale specific date handling
  1505. * Decimal/Currency Formatting and Parsing:: Local specific number handling
  1506. @end menu
  1507. In Classpath, all locale specific data is stored in a
  1508. @code{ListResourceBundle} class in the package @code{gnu/java/locale}.
  1509. The basename of the bundle is @code{LocaleInformation}. See the
  1510. documentation for the @code{java.util.ResourceBundle} class for details
  1511. on how the specific locale classes should be named.
  1512. @code{ListResourceBundle}'s are used instead of
  1513. @code{PropertyResourceBundle}'s because data more complex than simple
  1514. strings need to be provided to configure certain Classpath components.
  1515. Because @code{ListResourceBundle} allows an arbitrary Java object to
  1516. be associated with a given configuration option, it provides the
  1517. needed flexibility to accomodate Classpath's needs.
  1518. Each Java library component that can be localized requires that certain
  1519. configuration options be specified in the resource bundle for it. It is
  1520. important that each and every option be supplied for a specific
  1521. component or a critical runtime error will most likely result.
  1522. As a standard, each option should be assigned a name that is a string.
  1523. If the value is stored in a class or instance variable, then the option
  1524. should name should have the name name as the variable. Also, the value
  1525. associated with each option should be a Java object with the same name
  1526. as the option name (unless a simple scalar value is used). Here is an
  1527. example:
  1528. A class loads a value for the @code{format_string} variable from the
  1529. resource bundle in the specified locale. Here is the code in the
  1530. library class:
  1531. @example
  1532. ListResourceBundle lrb =
  1533. ListResourceBundle.getBundle ("gnu/java/locale/LocaleInformation", locale);
  1534. String format_string = lrb.getString ("format_string");
  1535. @end example
  1536. In the actual resource bundle class, here is how the configuration option
  1537. gets defined:
  1538. @example
  1539. /**
  1540. * This is the format string used for displaying values
  1541. */
  1542. private static final String format_string = "%s %d %i";
  1543. private static final Object[][] contents =
  1544. @{
  1545. @{ "format_string", format_string @}
  1546. @};
  1547. @end example
  1548. Note that each variable should be @code{private}, @code{final}, and
  1549. @code{static}. Each variable should also have a description of what it
  1550. does as a documentation comment. The @code{getContents()} method returns
  1551. the @code{contents} array.
  1552. There are many functional areas of the standard class library that are
  1553. configured using this mechanism. A given locale does not need to support
  1554. each functional area. But if a functional area is supported, then all
  1555. of the specified entries for that area must be supplied. In order to
  1556. determine which functional areas are supported, there is a special key
  1557. that is queried by the affected class or classes. If this key exists,
  1558. and has a value that is a @code{Boolean} object wrappering the
  1559. @code{true} value, then full support is assumed. Otherwise it is
  1560. assumed that no support exists for this functional area. Every class
  1561. using resources for configuration must use this scheme and define a special
  1562. scheme that indicates the functional area is supported. Simply checking
  1563. for the resource bundle's existence is not sufficient to ensure that a
  1564. given functional area is supported.
  1565. The following sections define the functional areas that use resources
  1566. for locale specific configuration in GNU Classpath. Please refer to the
  1567. documentation for the classes mentioned for details on how these values
  1568. are used. You may also wish to look at the source file for
  1569. @file{gnu/java/locale/LocaleInformation_en} as an example.
  1570. @node String Collation, Break Iteration, Localization, Localization
  1571. @comment node-name, next, previous, up
  1572. @section String Collation
  1573. Collation involves the sorting of strings. The Java class library provides
  1574. a public class called @code{java.text.RuleBasedCollator} that performs
  1575. sorting based on a set of sorting rules.
  1576. @itemize @bullet
  1577. @item RuleBasedCollator - A @code{Boolean} wrappering @code{true} to indicate
  1578. that this functional area is supported.
  1579. @item collation_rules - The rules the specify how string collation is to
  1580. be performed.
  1581. @end itemize
  1582. Note that some languages might be too complex for @code{RuleBasedCollator}
  1583. to handle. In this case an entirely new class might need to be written in
  1584. lieu of defining this rule string.
  1585. @node Break Iteration, Date Formatting and Parsing, String Collation, Localization
  1586. @comment node-name, next, previous, up
  1587. @section Break Iteration
  1588. The class @code{java.text.BreakIterator} breaks text into words, sentences,
  1589. and lines. It is configured with the following resource bundle entries:
  1590. @itemize @bullet
  1591. @item BreakIterator - A @code{Boolean} wrappering @code{true} to indicate
  1592. that this functional area is supported.
  1593. @item word_breaks - A @code{String} array of word break character sequences.
  1594. @item sentence_breaks - A @code{String} array of sentence break character
  1595. sequences.
  1596. @item line_breaks - A @code{String} array of line break character sequences.
  1597. @end itemize
  1598. @node Date Formatting and Parsing, Decimal/Currency Formatting and Parsing, Break Iteration, Localization
  1599. @comment node-name, next, previous, up
  1600. @section Date Formatting and Parsing
  1601. Date formatting and parsing is handled by the
  1602. @code{java.text.SimpleDateFormat} class in most locales. This class is
  1603. configured by attaching an instance of the @code{java.text.DateFormatSymbols}
  1604. class. That class simply reads properties from our locale specific
  1605. resource bundle. The following items are required (refer to the
  1606. documentation of the @code{java.text.DateFormatSymbols} class for details
  1607. io what the actual values should be):
  1608. @itemize @bullet
  1609. @item DateFormatSymbols - A @code{Boolean} wrappering @code{true} to indicate
  1610. that this functional area is supported.
  1611. @item months - A @code{String} array of month names.
  1612. @item shortMonths - A @code{String} array of abbreviated month names.
  1613. @item weekdays - A @code{String} array of weekday names.
  1614. @item shortWeekdays - A @code{String} array of abbreviated weekday names.
  1615. @item ampms - A @code{String} array containing AM/PM names.
  1616. @item eras - A @code{String} array containing era (i.e., BC/AD) names.
  1617. @item zoneStrings - An array of information about valid timezones for this
  1618. locale.
  1619. @item localPatternChars - A @code{String} defining date/time pattern symbols.
  1620. @item shortDateFormat - The format string for dates used by
  1621. @code{DateFormat.SHORT}
  1622. @item mediumDateFormat - The format string for dates used by
  1623. @code{DateFormat.MEDIUM}
  1624. @item longDateFormat - The format string for dates used by
  1625. @code{DateFormat.LONG}
  1626. @item fullDateFormat - The format string for dates used by
  1627. @code{DateFormat.FULL}
  1628. @item shortTimeFormat - The format string for times used by
  1629. @code{DateFormat.SHORT}
  1630. @item mediumTimeFormat - The format string for times used by
  1631. @code{DateFormat.MEDIUM}
  1632. @item longTimeFormat - The format string for times used by
  1633. @code{DateFormat.LONG}
  1634. @item fullTimeFormat - The format string for times used by
  1635. @code{DateFormat.FULL}
  1636. @end itemize
  1637. Note that it may not be possible to use this mechanism for all locales.
  1638. In those cases a special purpose class may need to be written to handle
  1639. date/time processing.
  1640. @node Decimal/Currency Formatting and Parsing, , Date Formatting and Parsing, Localization
  1641. @comment node-name, next, previous, up
  1642. @section Decimal/Currency Formatting and Parsing
  1643. @code{NumberFormat} is an abstract class for formatting and parsing numbers.
  1644. The class @code{DecimalFormat} provides a concrete subclass that handles
  1645. this is in a locale independent manner. As with @code{SimpleDateFormat},
  1646. this class gets information on how to format numbers from a class that
  1647. wrappers a collection of locale specific formatting values. In this case,
  1648. the class is @code{DecimalFormatSymbols}. That class reads its default
  1649. values for a locale from the resource bundle. The required entries are:
  1650. @itemize @bullet
  1651. @item DecimalFormatSymbols - A @code{Boolean} wrappering @code{true} to
  1652. indicate that this functional area is supported.
  1653. @item currencySymbol - The string representing the local currency.
  1654. @item intlCurrencySymbol - The string representing the local currency in an
  1655. international context.
  1656. @item decimalSeparator - The character to use as the decimal point as a
  1657. @code{String}.
  1658. @item digit - The character used to represent digits in a format string,
  1659. as a @code{String}.
  1660. @item exponential - The char used to represent the exponent separator of a
  1661. number written in scientific notation, as a @code{String}.
  1662. @item groupingSeparator - The character used to separate groups of numbers
  1663. in a large number, such as the ``,'' separator for thousands in the US, as
  1664. a @code{String}.
  1665. @item infinity - The string representing infinity.
  1666. @item NaN - The string representing the Java not a number value.
  1667. @item minusSign - The character representing the negative sign, as a
  1668. @code{String}.
  1669. @item monetarySeparator - The decimal point used in currency values, as a
  1670. @code{String}.
  1671. @item patternSeparator - The character used to separate positive and
  1672. negative format patterns, as a @code{String}.
  1673. @item percent - The percent sign, as a @code{String}.
  1674. @item perMill - The per mille sign, as a @code{String}.
  1675. @item zeroDigit - The character representing the digit zero, as a @code{String}.
  1676. @end itemize
  1677. Note that several of these values are an individual character. These should
  1678. be wrappered in a @code{String} at character position 0, not in a
  1679. @code{Character} object.
  1680. @bye