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

<channel>
	<title>Adams Bros Blog</title>
	<atom:link href="http://blog.adamsbros.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adamsbros.org</link>
	<description></description>
	<lastBuildDate>Tue, 16 Feb 2010 10:05:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JAX-RS and RESTful Security</title>
		<link>http://blog.adamsbros.org/2010/02/07/jax-rs-and-restful-security/</link>
		<comments>http://blog.adamsbros.org/2010/02/07/jax-rs-and-restful-security/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 04:37:04 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=192</guid>
		<description><![CDATA[
The use of HTTP, as the driving force of SOA can never be exemplified enough.  In terms of the usefulness of SOA, I think that RESTful SOA is a no brainer, has some great uses, and I've always been confused at why people adopted SOAP nothingness. Or, should I say, SOAP wrappers that achieve nothing.  [...]]]></description>
			<content:encoded><![CDATA[<p><!--What I have found, is that a very large number of developers/programmers resort to basing the technology they use, on a given project, on sheer emotion.  They love to adopt new cool technologies (or even old ones) that they have learned, and use them everywhere.  They don't take a moment to think about whether those technologies are best applied to a given scenario, but instead just start using them.</p>
<p><span class="note"><a href="http://www.google.com/search?q=RESTful" mce_href="http://www.google.com/search?q=RESTful">What is RESTful</a>?</span>RESTful web services have their uses; unfortunately, like many other technologies, it will no doubt suffer from what I call the holy grail syndrome; a syndrome that affects many developers, who insist on using the same technologies, languages, etc, in all scenarios.  A good example is a Java developer, who insists on using Java to do system administrative tasks; anyone ever hear of perl?<br />
--></p>
<p>The use of HTTP, as the driving force of SOA can never be exemplified enough.  In terms of the usefulness of SOA, I think that RESTful SOA is a no brainer, has some great uses, and I've always been confused at why people adopted SOAP nothingness. Or, should I say, SOAP wrappers that achieve nothing.  RESTfulness, on it's basic level, having no required integrated security, is great for</p>
<ol>
<li>public information</li>
<li>lookups of information that should be readily available for many systems, but does not contain user's private information (without a proper authentication/authorization model in place), etc</li>
<li>systems not requiring proper/secure authentication and authorization</li>
</ol>
<p>From a private personal data and security perspective (not that I'm an expert on security, by any means), the RESTful method of SOA really doesn't define much in the way of security.  After all, any authentication method, unless it's directly or indirectly tied to the front end user's credentials, and also propagating those credentials to the back end REST service, with stateful authentication, is not adequate security.  Having a certificate for example, is great to prevent sniffers, but not hackers that have compromised a client web server system.<span id="more-192"></span></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3649591720153253";
/* 125x125, created 1/28/10 */
google_ad_slot = "0838130369";
google_ad_width = 125;
google_ad_height = 125;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><span class="note">Keep in mind, that even in the case of doing proper authentication, using user principals/credentials propagated all the way to the back end service <em>(and <strong>only on the first access</strong>)</em>, a rooted hacker could get the passwords of a few accounts, simply by setting up a proxy with the front end ssl cert, but at least they haven't compromised <strong>EVERYONE'S</strong> account.</span>Consider a HYPOTHETICAL scenario.  Amazon, unbeknown to everyone, has been using SOA, in a RESTful manner, for years, as the back end of their web servers.  They use it for accessing customer information, making changes to customers accounts, storing and retrieving various bits of personal information, etc.  The method of authentication from the front end web server, to the SOA server, is HTTP basic, or SSL client certificates, or a combination thereof.  The credentials and client certificate are of course stored on the front end server.  Suddenly, their front end web server is hacked, because there's a security glitch of some sort.  The hacker actually gets root access; implicitly having access to the client certificate files, as well as the SOA HTTP basic auth username/password.  Now the hacker has programmatic access to the SOA servers on the back end, immediately and without much effort, including query/update/delete privileges on ANY user account.  Unless a RESTful developer is up to doing a lot of extra work, developing their own authentication, authorization, and stateful framework for RESTful, or RESTful v2.0 comes up with something, there's not much hope for system security in a scenario like this.</p>
<p>There's a few solutions to this problem that I can think of off the top of my head.</p>
<ol>
<li>Use HTTP basic auth, or some other method that keeps passing the credentials on each HTTP request, on the front end, and have those propagated to the back-end SOA services as well, and then adopting the stateful method discussed in #2.  The problem with this is that it's a little vulnerable for currently authenticated users; if a hacker gets root, they can also obtain username/passwords of users that are currently authenticated, in addition to those performing new authentications.</li>
<li>Create an authentication caching mechanism on the RESTful backend services, which only stores the username, the authenticated state, and a token.  One method, when using HTTP as the protocol, is to simply use the cookie addition to HTTP.  This would of course require that your client also support it.
<ol>
<li>The initial authentication information is sent from the browser, to the DMZ web server, which forwards it to the RESTful service, and so on and so forth.</li>
<li>The token is generated by the far most back end, and propagated forward to the DMZ web server.</li>
<li>On subsequent requests, the token is passed from the DMZ web server, to the RESTful services, as far back as needed, WITHOUT including private information such as username/password.</li>
<li>No account querying or modification is allowed without a valid token, and perhaps also including IP, and various other information.</li>
<li>After the first request, all account create/update/delete queries will only be tied to the user that is connected to the token, which only the farthest back server knows about.</li>
</ol>
</li>
<li>Use a protocol/framework that is already stateful.  Perhaps EJB, or RMI, may be in order, if one is using Java.
<ol>
<li><span class="note">Only ONE RMI object should be allowed to instantiate any objects that have access to private user data, and that object should be the one providing authentication.</span><a href="http://www.google.com/search?q=java+RMI">RMI</a> provides an easy to use stateful mechanism for calling services on the backend.  The state is maintained entirely automatically by the RMI subsystem.  It does not, however, have an integrated authentication or authorization system.  Such systems are trivial to develop for RMI, as it keeps state for you, and gives you full access to OOD methods.</li>
<li><a href="http://www.google.com/search?q=EJB3">EJB</a> provides a stateful mechanism, with authentication and authorization, all handled by mere server configurations.  Unlike RMI, there is no need to develop your own authentication/authorization system.  In fact, the authentication/authorization of EJB can be propagated down a long chain of EJB servers, including the principals and credentials of the user.  As far as my reading of the EJB3 specification goes, the credentials are not cached, just propagated on the first call of a stateful session bean, and every call on a stateless bean, to establish the state.  In the case of OpenEJB, I tested this by changing the user's password on the standalone OpenEJB server, but not on the front end tomcat server.  It worked great, and complained that the user's password was bad.  Ultimately, what I would like to see here, is the ability to have EJB only authenticate using the back most EJB server, and that authentication gets propagated to the front end.  That way, the security layer is initialized as far back from the DMZ as absolutely possible.  Requiring that the DMZ machine has access to the authentication server as well, is a bit poor.  Ultimately what we want is the authentication server (say LDAP) is completely inaccessible from anything but the farthest back EJB server.  I believe the EJB3 specification indicates that this is possible, but I have yet to investigate how to do it with OpenEJB.</li>
</ol>
</li>
</ol>
<p>A scenario, where security may not be as important, is when the web services are for returning public data, such as postal/zip codes, towns, countries, provinces, product listings, etc.  If someone hacks the web front end in one of those scenarios, and wants to do queries on what the zip code is in some town in Texas, the level of breach is not as significant as it is when they have access to everyone's private information.  In cases like this, RESTful web services are really great, and very much simple.  But, when good security is required, for ensuring the privacy of user information, writing RESTful web services becomes time consuming, and error prone, and a little negligent if the developer does not integrate proper security.</p>
<p><span class="note">Java EE 6 is supposed to support integration of JAX-RS web services, as EJBs.  I'm not sure whether the JAX-RS service would then inherit proper security or not.</span>The whole point of this post, is NOT to discourage the use of JAX-RS, or any RESTful framework, but to think about what you're using a technology for (such as RESTful), and whether it is the best fit for the problem at hand. Without a lot of work, proper web service security for private user information, using most SOA methods (SOAP, RESTful, JAX-RS, JAX-WS, etc) is a pain.  And, if you're looking into developing an enterprise level application, with a need to safe-guard private user information, it may be worth looking at other technologies, such as EJB, RMI, etc.  After all, they provide a lot more other useful features, such as statefulness.</p>
<p>Granted, if someone gets root on your DMZ, you're in big trouble anyhow, ESPECIALLY if you don't know about it.  But, at least you save potentially THOUSANDS of users from having their accounts compromised.  Consider a University, which has tens of thousands of students.  If the authentication is not tied directly to the principals/credentials of each user, or it is being done by simple basic/auth, or even SSL client certificates, the hacker who got root on your machine can mess with, or query, all tens of thousands of accounts.  If you put this three-tier mechanism in place, the only people's accounts they can get access to, are those for whom they have intercepted their passwords.  Which, hopefully, will only be a handful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/02/07/jax-rs-and-restful-security/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is JAXB and JAXB Example Code</title>
		<link>http://blog.adamsbros.org/2010/02/07/jaxb-example-code/</link>
		<comments>http://blog.adamsbros.org/2010/02/07/jaxb-example-code/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 03:12:28 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=200</guid>
		<description><![CDATA[I thought it may be nice for those googlers that want to know about JAXB, to have a quick working example to use.  So, that is the purpose of this post.
First off, what is JAXB?  Well, simply put, JAXB is for converting Java objects to XML or from XML to Java objects.  With the advent [...]]]></description>
			<content:encoded><![CDATA[<p>I thought it may be nice for those <a title="Googlers" href="http://www.google.com">googlers</a> that want to know about JAXB, to have a quick working example to use.  So, that is the purpose of this post.</p>
<p><span id="more-200"></span>First off, what is JAXB?  Well, simply put, JAXB is for converting Java objects to XML or from XML to Java objects.  With the advent of Java 1.5, and annotations, this becomes extremely simple.</p>
<p>Download <a title="JAXB Download" href="http://www.google.com/search?q=jaxb+download">JAXB</a>, dependencies to your local computer, and put them in a folder called "libs". The dependencies JARs I have are...</p>
<ul>
<li>activation-1.1.jar</li>
<li>jaxb-api-2.0.jar</li>
<li>jaxb-impl-2.0.5.jar</li>
<li>jsr173_api-1.0.jar</li>
</ul>
<p>Copy the following Java source code to Employee.java, and proceed with the instructions below</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.bind.JAXBContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.bind.JAXBException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.bind.annotation.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.StringReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.StringWriter</span><span style="color: #339933;">;</span>
&nbsp;
@XmlRootElement<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;employee&quot;</span><span style="color: #009900;">&#41;</span>
@XmlAccessorType<span style="color: #009900;">&#40;</span>XmlAccessType.<span style="color: #006633;">FIELD</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Employee
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JAXBException
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> Employee john <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;John&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setMiddleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Robert&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        john.<span style="color: #006633;">setLastName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Doe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// write it out as XML</span>
        <span style="color: #000000; font-weight: bold;">final</span> JAXBContext jaxbContext <span style="color: #339933;">=</span> JAXBContext.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>Employee.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">StringWriter</span> writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        jaxbContext.<span style="color: #006633;">createMarshaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">marshal</span><span style="color: #009900;">&#40;</span>john, writer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// read it from XML</span>
        <span style="color: #000000; font-weight: bold;">final</span> Employee johnRead <span style="color: #339933;">=</span>
            <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> jaxbContext.<span style="color: #006633;">createUnmarshaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">unmarshal</span><span style="color: #009900;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringReader</span><span style="color: #009900;">&#40;</span>writer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>john.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>johnRead<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// write the new object out as XML again.</span>
            writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            jaxbContext.<span style="color: #006633;">createMarshaller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">marshal</span><span style="color: #009900;">&#40;</span>johnRead, writer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">&quot;johnRead was identical to john: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> writer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;john and johnRead are not equal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @XmlAttribute
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Employee's first name
     */</span>
    @XmlElement
    <span style="color: #000000; font-weight: bold;">private</span>
    <span style="color: #003399;">String</span> firstName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Employee's middle name
     */</span>
    @XmlElement
    <span style="color: #000000; font-weight: bold;">private</span>
    <span style="color: #003399;">String</span> middleName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Employee's last name
     */</span>
    @XmlElement
    <span style="color: #000000; font-weight: bold;">private</span>
    <span style="color: #003399;">String</span> lastName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLastName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> lastName<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastName</span> <span style="color: #339933;">=</span> lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMiddleName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> middleName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMiddleName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> middleName<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">middleName</span> <span style="color: #339933;">=</span> middleName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> firstName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setFirstName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> firstName<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">firstName</span> <span style="color: #339933;">=</span> firstName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span> <span style="color: #339933;">==</span> o<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> o.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
        Employee employee <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> o<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">!=</span> employee.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>firstName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>firstName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">firstName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
            employee.<span style="color: #006633;">firstName</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>lastName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">lastName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
            employee.<span style="color: #006633;">lastName</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>middleName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #339933;">!</span>middleName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">middleName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
            employee.<span style="color: #006633;">middleName</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> hashCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>firstName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> firstName.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>middleName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> middleName.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">*</span> result <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>lastName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> lastName.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Employee{&quot;</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;id=&quot;</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;, firstName='&quot;</span> <span style="color: #339933;">+</span> firstName <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;, middleName='&quot;</span> <span style="color: #339933;">+</span> middleName <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot;, lastName='&quot;</span> <span style="color: #339933;">+</span> lastName <span style="color: #339933;">+</span> <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">'}'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The following commands will compile and run the source, if under a unix OS.  If in windows, you'll need to form your own classpath.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">javac <span style="color: #660033;">-classpath</span> .:$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> jar <span style="color: #000000; font-weight: bold;">in</span> libs<span style="color: #000000; font-weight: bold;">/*</span>.jar; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$jar</span>:&quot;</span>; <span style="color: #000000; font-weight: bold;">done</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Employee.java
java <span style="color: #660033;">-classpath</span> .:$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> jar <span style="color: #000000; font-weight: bold;">in</span> libs<span style="color: #000000; font-weight: bold;">/*</span>.jar; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$jar</span>:&quot;</span>; <span style="color: #000000; font-weight: bold;">done</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Employee</pre></div></div>

<p>The output should be as follows, but the XML will be on a single line...</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">johnRead was identical to john<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span> standalone<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;yes&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;</span>employee id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>firstName<span style="color: #339933;">&gt;</span>John<span style="color: #339933;">&lt;/</span>firstName<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>middleName<span style="color: #339933;">&gt;</span>Robert<span style="color: #339933;">&lt;/</span>middleName<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>lastName<span style="color: #339933;">&gt;</span>Doe<span style="color: #339933;">&lt;/</span>lastName<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>employee<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/02/07/jaxb-example-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZK AJAX Status Bar</title>
		<link>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/</link>
		<comments>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 08:45:43 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=172</guid>
		<description><![CDATA[Seeing that my research project is a mini accounting system, I thought it necessary to be able to display items in a status bar, like a real application.  It is very slightly unfortunate that ZK doesn't have something integrated right in for this purpose.  But, given the versatility of ZK, it's easy enough to resolve.

Features
I [...]]]></description>
			<content:encoded><![CDATA[<p>Seeing that my research project is a mini accounting system, I thought it necessary to be able to display items in a status bar, like a real application.  It is very slightly unfortunate that ZK doesn't have something integrated right in for this purpose.  But, given the versatility of ZK, it's easy enough to resolve.</p>
<p><span id="more-172"></span></p>
<h2>Features</h2>
<p>I thought it important to have some useful features that make sense for what I've seen in status bars.</p>
<ul>
<li>a method to set the status, with a delay before the status bar is cleared</li>
<li>a method to simply set the status, and leave it as is.  It would be up to the developer to clear the status later, if need be.  Or, the next status item would take over.</li>
<li>a very simple interface abstraction in case we want to change the type of component we use later, or something of that nature.  This will help us prevent the need to refactor a lot of code that could be using the status bar; we would only need to refactor the implementing class of the interface, leaving all of the code accessing the status bar entirely intact.</li>
</ul>
<p>Future features might include...</p>
<ul>
<li>methods for setting the status with color text</li>
<li>methods for setting the status with html</li>
<li>any other suggestions are welcome.</li>
</ul>
<h2>Window Width Status Bar</h2>
<p>We first, of course, need to setup the actual status bar.  So, right before the end of the window, we do just that, with a "textbox".  Now, there's no reason you can't use some other type of control, if it makes sense to.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textbox</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;1.2em&quot;</span> <span style="color: #000066;">sclass</span>=<span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000066;">readonly</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;com.example.system.StatusBar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;timer</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;statusTimer&quot;</span> <span style="color: #000066;">running</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">repeats</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">onTimer</span>=<span style="color: #ff0000;">'status.setText(&quot;&quot;);'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>The text box is implemented by a custom class, which we'll delve into in a moment.  We also have a ZK timer, for implementing the automatic clearing feature, because it is illegal to access ZK elements from outside of a ZK event.  i.e. You cannot write your own thread to do it at a later time, as ZK will throw an <strong><span style="color: #3366ff;">IllegalStateException</span></strong>.</p>
<h2>The Code</h2>
<h3>Interface Abstraction</h3>
<p>We've kept the interface very simple, just two methods.  For more information, read the javadoc comments.</p>
<ul>
<li>setStatus(String) allows setting of the status bar permanently</li>
<li>setStatus(String, int) allows setting of the status bar, and automatic clearing of it after a specified delay</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.system</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Handles setting of status bar messages.  All calls to this object must be
 * done from within the ZK framework, such as inside an event.
 *
 * Hides the details of what component is actually a status bar.  It could be a
 * textbox, or something else, but we don't want to be dependant on any specific
 * type of control, in case it changes in the future.
 *
 * Created :  Jan 31, 2010 1:39:37 AM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 * @author Trenton D. Adams
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IStatusBar
<span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Sets the status bar text for the time period indicated.
     *
     * @param statusText status text
     * @param timePeriod delay in seconds, before the status bar will be
     *                   cleared.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Sets the status bar text.  Pass null to clear.
     *
     * @param statusText status text or null to clear
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the status text of the status bar.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Implementation</h3>
<p>Essentially, all we are doing with the implement is as follows</p>
<ul>
<li>implement AfterCompose, so we can setup a session variable to access the status bar from any ZK code, without much trouble</li>
<li>implement the setStatus() methods as described in the feature section.  On takes an extra argument for a delay, indicating how long before the status bar should be cleared.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.system</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.ext.AfterCompose</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Textbox</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Timer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * StatusBar handles setting the status bar text, and clearing it after a given
 * timeout.  Implements IStatusBar, to hide the details of what a status bar is
 * from the client code.  We use a textbox, but we could change that, who knows.
 *
 * Created :  Jan 31, 2010 12:42:29 AM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 * @author Trenton D. Adams
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StatusBar <span style="color: #000000; font-weight: bold;">extends</span> Textbox <span style="color: #000000; font-weight: bold;">implements</span> AfterCompose, IStatusBar
<span style="color: #009900;">&#123;</span>
    @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;ConstantNamingConvention&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>StatusBar.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> StatusBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterCompose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status bar running as &quot;</span> <span style="color: #339933;">+</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// TODO find a better method, getFellow() didn't work</span>
        <span style="color: #000000; font-weight: bold;">final</span> Session session <span style="color: #339933;">=</span> getDesktop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        session.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        setStatus<span style="color: #009900;">&#40;</span>statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// the timer must be in the page, or the page is inactive and this</span>
        <span style="color: #666666; font-style: italic;">// call would never happen?</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Timer</span> timer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Timer</span><span style="color: #009900;">&#41;</span> getFellow<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;statusTimer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timer.<span style="color: #006633;">setDelay</span><span style="color: #009900;">&#40;</span>timePeriod <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timer.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        setText<span style="color: #009900;">&#40;</span>statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Using the Status Bar</h3>
<p>The following code must be used inside of a ZK event handler, such as one that comes from the click of a button, or a mouse over event, etc.  Basically, all we're doing is grabbing the status bar object from the session, and request the status be set.  That's all there is to it.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> Session session <span style="color: #339933;">=</span> getDesktop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> IStatusBar statusBar <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IStatusBar<span style="color: #009900;">&#41;</span> session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
statusBar.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Transaction Posted&quot;</span>, <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Results</h2>
<p>I'm attaching a screen shot of the results of my status bar.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2010/01/status-bar.png"><img class="alignnone size-full wp-image-177" title="status-bar" src="http://blog.adamsbros.org/wp-content/uploads/2010/01/status-bar.png" alt="ZK Status bar" width="530" height="148" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZK Exception Handling and Error Popup</title>
		<link>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/</link>
		<comments>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 01:28:09 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=160</guid>
		<description><![CDATA[Once I had some basic functionality in my mini accounting system that I'm writing (for research purposes), one of my goals was to have an adequate error display for the user, that was the same every time.  Suffice it to say, I was completely thrilled to find out that ZK could do exactly what I [...]]]></description>
			<content:encoded><![CDATA[<p>Once I had some basic functionality in my mini accounting system that I'm writing (for research purposes), one of my goals was to have an adequate error display for the user, that was the same every time.  Suffice it to say, I was completely thrilled to find out that ZK could do exactly what I wanted to do, and I didn't have to write an once of code.  All I did was write some ZUL, which wrapped a JSP inside of a ZK window.  I share how I did that in this post.</p>
<p><span id="more-160"></span></p>
<h2>Configuration</h2>
<p>The first thing to do is to configure ZK to handle your unhandled exceptions, and target a ZUL page for rendering.  This is done through the zk.xml file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exception-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>java.lang.Throwable<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exception-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/error.zul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>ZK error.zul</h2>
<p>The second thing to do is create an error.zul page, which I pulled mostly from the ZK Developers Guide.  I added the bit where I include my error.jsp file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zk</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.zkoss.org/2005/zul&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;window</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;modal&quot;</span> <span style="color: #000066;">sizable</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Error ${requesScope['javax.servlet.error.status_code']}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/jsp/error.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hbox</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;margin-left:auto; margin-right:auto; text-align: center;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Okay&quot;</span> <span style="color: #000066;">onClick</span>=<span style="color: #ff0000;">&quot;spaceOwner.detach()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Reload Page&quot;</span> <span style="color: #000066;">onClick</span>=<span style="color: #ff0000;">&quot;Executions.sendRedirect(null)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/zk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>JSP error.jsp</h2>
<p>I basically pulled this error page from the standard error page that I normally use, and tailored it a bit.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;java.io.PrintWriter&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;java.io.StringWriter&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;com.example.util.Util&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">isErrorPage</span>=<span style="color: #ff0000;">&quot;true&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;ce&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsp/jstl/functions&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;fn&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://jakarta.apache.org/taglibs/string-1.1&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;st&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- BEGIN error.jsp --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;%=exception.getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>An error has occured. If you believe this error is a system problem, and you
  continue to get this error, please contact a special person via
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;mailto:'me@example.com' &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>email<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ce:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;&lt;%=Util.getBooleanItem(\&quot;</span>/debug\<span style="color: #ff0000;">&quot;)%&gt;</span></span>&quot;&gt;
    <span style="color: #009900;">&lt;%</span>
<span style="color: #009900;">      StringWriter sw = new StringWriter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">      PrintWriter pw = new PrintWriter<span style="color: #66cc66;">&#40;</span>sw<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">      exception.printStackTrace<span style="color: #66cc66;">&#40;</span>pw<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">    %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ce:set</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;exceptionStack&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;%=sw.toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ce:set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;debug&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Message : <span style="color: #009900;">&lt;%=exception.getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Exception : <span style="color: #009900;">&lt;%=exception.getClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.getName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Stack : ${fn:escapeXml(exceptionStack)}
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ce:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- END error.jsp --&gt;</span></pre></div></div>

<h2>Sample Error Page</h2>
<p>And, we have the result;  it looks quite nice.  If debug were enabled, it would have my stack trace displayed in a wrap-able fixed width font ; providing much easier diagnostics during development.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2010/02/sample-error.png"><img class="alignnone size-full wp-image-186" title="ZK Sample Error" src="http://blog.adamsbros.org/wp-content/uploads/2010/02/sample-error.png" alt="ZK Sample Error Page" width="558" height="196" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZK AJAX Framework Introduction</title>
		<link>http://blog.adamsbros.org/2010/01/30/zk-ajax-framework-introduction/</link>
		<comments>http://blog.adamsbros.org/2010/01/30/zk-ajax-framework-introduction/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 23:33:43 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=139</guid>
		<description><![CDATA[I am in the process of working with and researching ZK as an AJAX framework to integrate into Java Web Development that I do.  So far, AJAX looks really amazing, and is fully integrated into the J2EE framework.  It is an event driven framework that has the option of hooking directly into existing JSP, or [...]]]></description>
			<content:encoded><![CDATA[<p>I am in the process of working with and researching ZK as an AJAX framework to integrate into Java Web Development that I do.  So far, AJAX looks really amazing, and is fully integrated into the J2EE framework.  It is an event driven framework that has the option of hooking directly into existing JSP, or entirely writing ZK event handlers to do the processing.  There is no wonder that ZK won the <a title="ZK - Simply Ajax and Mobile" href="http://sourceforge.net/blog/potm-200902/">Project of the Month Source Forge award</a>.</p>
<p><span id="more-139"></span></p>
<h2>Integration</h2>
<p>In the case of existing web applications that make heavy use of JSP for display, ZK can be easily integrated into specific controls on the page, such as drop downs, text boxes, etc, to provide AJAX for that individual component.  The component is then submitted using the normal GET/POST method.  You can thereby provide AJAX auto complete, or dynamic load functionality to your heart's content, without affecting the normal working of the page.  If your goal is to move toward entirely using AJAX for that application, you can easily do it incrementally, so as not to have an overly complex and long development cycle.  Just drop some of the ZUL includes directly into your JSP, write some ZSCRIPT or Java component/event classes, handle the processing, and you have yourself some event driven AJAX code.</p>
<h2>GUI Features</h2>
<p>ZUL files are essentially a derivative of XUL, defined for the purpose of AJAX handling in ZK.  You define your GUI layout in XML, and write code to handle each component as you choose.</p>
<p>One of many great benefits of ZK, is that it has many different ZUL components for the normal input text box.  You can make your text box a decimal box, a date box, int box, double box, etc, and AJAX will handle data validation for you, and wrapping it in the appropriate wrapper class such as BigDecimal, Integer, Double, etc.  In fact, in many cases, it won't even let you type in a character that is not allowed.  For example, if you have specified a number box of some type, such as decimal, int, double, etc, it won't even let you type an alpha character.  You can also place constraints on your inputs such as "<strong><span style="color: #3366ff;">no zero</span></strong>", or "<strong><span style="color: #3366ff;">no negative</span></strong>", which would indicate that the box cannot accept a negative or zero input, but could be empty.</p>
<p>Here is a quick example of a decimalbox in action.  I'll give two examples.  The first one has an implementing Java class, which you simply write a class that extends Decimalbox. The implementing class is just below that on the page. The second one achieves the exact same thing, but is not quite as flexible, for the simple reason that it's not as dynamic, because I you cannot go instantiating it from code.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decimalbox</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;com.example.common.LedgerDecimalBox&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;credit-0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decimalbox</span> <span style="color: #000066;">constraint</span>=<span style="color: #ff0000;">&quot;no negative,no zero&quot;</span> <span style="color: #000066;">format</span>=<span style="color: #ff0000;">&quot;#,##0.#&quot;</span> <span style="color: #000066;">scale</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.common</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.util.CVUtil</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.ext.AfterCompose</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Decimalbox</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LedgerDecimalBox <span style="color: #000000; font-weight: bold;">extends</span> Decimalbox <span style="color: #000000; font-weight: bold;">implements</span> AfterCompose
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>LedgerDecimalBox.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> LedgerDecimalBox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// load configured options</span>
        setFormat<span style="color: #009900;">&#40;</span><span style="color: #003399;">Util</span>.<span style="color: #006633;">getStringItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/inputs/decimalbox/format&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setConstraint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Util</span>.<span style="color: #006633;">getStringItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/inputs/decimalbox/constraints&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setScale<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterCompose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id: &quot;</span> <span style="color: #339933;">+</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In all honesty, ZK seems to be absolutely amazing, very rich, very fast, very flexible, etc.  In my opinion, it is probably <strong>THE BEST</strong> AJAX framework on the planet, by a <strong>LONG</strong> shot.</p>
<p>You can totally expect me to write more on ZK, as I learn the framework, and blog about various ways of doing things.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/30/zk-ajax-framework-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RMI Pitfalls and Problems</title>
		<link>http://blog.adamsbros.org/2010/01/25/rmi-pitfalls/</link>
		<comments>http://blog.adamsbros.org/2010/01/25/rmi-pitfalls/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 02:58:13 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=107</guid>
		<description><![CDATA[In this post, I plan on laying out multiple common problems with RMI, that a developer can run into.  I hope that this will be a concise guide to fixing the common RMI problems that beginners run into.  As I come up with more, I will edit this post, rather than creating a new one.  [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I plan on laying out multiple common problems with RMI, that a developer can run into.  I hope that this will be a concise guide to fixing the common RMI problems that beginners run into.  As I come up with more, I will edit this post, rather than creating a new one.  I will then post a comment on this entry; if you are subscribed to the comments (RSS feed), you will get notification when there is an update.</p>
<p>Also, if you are having some sort of RMI trouble, post a comment, and I will let you know if I know the solution.  I may also add the solution directly to this post, if it happens to actually be an RMI related issue.</p>
<h2><span id="more-107"></span>no security manager: RMI class loader disabled</h2>
<p>This is a very common error, and can be a result of various things.  Generally speaking though, it is a result of a class not being accessible to the client machine, that is accessible to the RMI server.  A common developer mistake, is to nest Exception1  inside Exception2, and throw Exception2 to the client.  The client JVM knows nothing about Exception1, and therefore the above message is displayed, with more details as follows.</p>
<blockquote>
<pre>Caused by: java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
 java.lang.ClassNotFoundException: com.example.myapp.Exception1 (no security manager: RMI class loader disabled)</pre>
</blockquote>
<p>The solution to this problem is to either not wrap Exception1, to be propagated to the client side, or to make sure the proper jars are in the CLASSPATH of the client side.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/25/rmi-pitfalls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EJB3 @RolesAllowed, annotation type not applicable to this kind of declaration</title>
		<link>http://blog.adamsbros.org/2010/01/21/ejb3-rolesallowed-annotation-type-not-applicable-to-this-kind-of-declaration/</link>
		<comments>http://blog.adamsbros.org/2010/01/21/ejb3-rolesallowed-annotation-type-not-applicable-to-this-kind-of-declaration/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 18:30:26 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=104</guid>
		<description><![CDATA[I'm just learning EJB3, and I'm stumbling here and there.  When developing an EJB object, I had a problem where the compiler was giving me an error that says "annotation type not applicable to this kind of declaration".  It was on a line like the following...


@RolesAllowed&#40;&#123;&#34;admin&#34;, &#34;entryclerk&#34;&#125;&#41;


Obviously this is normal to use on a method.  [...]]]></description>
			<content:encoded><![CDATA[<p>I'm just learning EJB3, and I'm stumbling here and there.  When developing an EJB object, I had a problem where the compiler was giving me an error that says "<span style="color: #0000ff;">annotation type not applicable to this kind of declaration</span>".  It was on a line like the following...</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@RolesAllowed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;admin&quot;</span>, <span style="color: #0000ff;">&quot;entryclerk&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

</blockquote>
<p>Obviously this is normal to use on a method.  Unfortunately, I had it defined on not just any method, but the constructor method of my Java class.  It took me awhile to figure out why it was happening, so I thought would spare others a bit of grief.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/21/ejb3-rolesallowed-annotation-type-not-applicable-to-this-kind-of-declaration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safe Shrinking of ext3 LVM volumes</title>
		<link>http://blog.adamsbros.org/2010/01/11/safe-shrinking-of-lvm-volumes/</link>
		<comments>http://blog.adamsbros.org/2010/01/11/safe-shrinking-of-lvm-volumes/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 08:53:55 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[LVM]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=102</guid>
		<description><![CDATA[When shrinking your LVM volumes, it is important to do it safely.  I will show you how I like to do that here.
Shrinking
Shrinking an ext3 volume is fairly straight forward, but it's important you don't mount your drive and start doing stuff, before you verify everything worked correctly.

e2fsck -f /dev/vg/lv1
resize2fs -p /dev/vg/lv1 ###G
e2fsck /dev/vg/lv1
lvresize -L [...]]]></description>
			<content:encoded><![CDATA[<p>When shrinking your LVM volumes, it is important to do it safely.  I will show you how I like to do that here.</p>
<h3><span id="more-102"></span>Shrinking</h3>
<p>Shrinking an ext3 volume is fairly straight forward, but it's important you don't mount your drive and start doing stuff, before you verify everything worked correctly.</p>
<ol>
<li>e2fsck -f /dev/vg/lv1</li>
<li>resize2fs -p /dev/vg/lv1 ###G</li>
<li>e2fsck /dev/vg/lv1</li>
<li>lvresize -L ###G /dev/vg/lv1</li>
<li>e2fsck /dev/vg/lv1</li>
</ol>
<p>Step #5 is the most important step; as steps 1-3 will not have any problems unless you have a system failure, a corrupted file system to start with, disk failure, or hardware failure.  Step 5 however, could be due to sys-admin error, from shrinking the LVM volume too much.  If you receive an error similar to the following, then you probably shrunk the volume too much, and your file system is not completely accessible.</p>
<blockquote>
<pre>e2fsck 1.41.9 (22-Aug-2009)
The filesystem size (according to the superblock) is 113634135 blocks
The physical size of the device is 112197632 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort&lt;y&gt;? cancelled!</pre>
</blockquote>
<p>If the error is due to shrinking too far, then this is easy to recover from; simply do another <strong>lvresize</strong>, with a large size specified, and do another <strong>e2fsck</strong> afterward.</p>
<p>Generally speaking, you should make the LVM maybe 2% or so larger than the file system was reduced to, so that there's room for file system overhead.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/11/safe-shrinking-of-lvm-volumes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intel WIFI 5300 AGN Unknown error 132</title>
		<link>http://blog.adamsbros.org/2009/12/20/intel-wifi-5300-agn-unknown-error-132/</link>
		<comments>http://blog.adamsbros.org/2009/12/20/intel-wifi-5300-agn-unknown-error-132/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 01:39:07 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=100</guid>
		<description><![CDATA[See comments for latest updates
Recently I started having problems with my Intel Corporation PRO/Wireless 5300 AGN card.  It simply quit working after I did a kernel upgrade.  It was giving errors like "Unknown error 132", and "deauthenticated (Reason: 9)".  The hardware switch did not seem to affect it, and the errors were the same whether [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">See comments for latest updates</span></p>
<p>Recently I started having problems with my Intel Corporation PRO/Wireless 5300 AGN card.  It simply quit working after I did a kernel upgrade.  It was giving errors like "Unknown error 132", and "deauthenticated (Reason: 9)".  The hardware switch did not seem to affect it, and the errors were the same whether I had the switch on, or off; so I'm assuming it had to do with the hardware not being initialized properly when the module loaded.</p>
<p><span id="more-100"></span>I'm using gentoo linux, and I had previously been using kernel "2.6.30-gentoo-r5".  when I upgraded to "2.6.31-gentoo-r6", my system started having trouble with the Intel Wifi.  I was getting errors like the following.</p>
<blockquote>
<pre>tdanotebook ~ # /etc/init.d/net.wlan0 restart
* Stopping wlan0
*   Bringing down wlan0
*     Shutting down wlan0 ...                                    [ ok ]
*     Stopping wpa_cli on wlan0 ...                              [ ok ]
*     Stopping wpa_supplicant on wlan0 ...                       [ ok ]
* Starting wlan0
RTNETLINK answers: Unknown error 132
RTNETLINK answers: Unknown error 132
*   Starting wpa_supplicant on wlan0 ...                         [ ok ]
*   Starting wpa_cli on wlan0 ...                                [ ok ]
*     Backgrounding ...

/var/log/messages
Dec 20 15:20:04 tdanotebook kernel: wlan0: direct probe to AP 00:1f:f3:c3:88:b4 try 1
Dec 20 15:20:04 tdanotebook kernel: wlan0 direct probe responded
Dec 20 15:20:04 tdanotebook kernel: wlan0: authenticate with AP 00:1f:f3:c3:88:b4
Dec 20 15:20:04 tdanotebook kernel: wlan0: authenticated
Dec 20 15:20:04 tdanotebook kernel: wlan0: associate with AP 00:1f:f3:c3:88:b4
Dec 20 15:20:05 tdanotebook kernel: wlan0: associate with AP 00:1f:f3:c3:88:b4
Dec 20 15:20:05 tdanotebook kernel: wlan0: deauthenticated (Reason: 9)
Dec 20 15:20:05 tdanotebook kernel: wlan0: deauthenticating by local choice (reason=3)</pre>
</blockquote>
<p>So, I decided to try the latest unmasked vanilla kernel "2.6.31.6", and everything just started working.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2009/12/20/intel-wifi-5300-agn-unknown-error-132/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gentoo Portage Python Update issues</title>
		<link>http://blog.adamsbros.org/2009/12/05/gentoo-portage-python-update-issues/</link>
		<comments>http://blog.adamsbros.org/2009/12/05/gentoo-portage-python-update-issues/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 02:47:49 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=96</guid>
		<description><![CDATA[I have been having some gentoo portage problems due to my system being out of sync.  When I finally updated a month or two later, it simply wasn't working.  I was getting an error like the following...

Performing Global Updates: /usr/portage/profiles/updates/3Q-2009
(Could take a couple of minutes if you have a lot of binary packages.)
 [...]]]></description>
			<content:encoded><![CDATA[<p>I have been having some gentoo portage problems due to my system being out of sync.  When I finally updated a month or two later, it simply wasn't working.  I was getting an error like the following...</p>
<blockquote>
<pre>Performing Global Updates: /usr/portage/profiles/updates/3Q-2009
(Could take a couple of minutes if you have a lot of binary packages.)
 .='update pass'  *='binary update'  #='/var/db update'  @='/var/db move'
 s='/var/db SLOT move'  %='binary move'  S='binary SLOT move'
 p='update /etc/portage/package.*'
......................................................                    

Performing Global Updates: /usr/portage/profiles/updates/4Q-2009
(Could take a couple of minutes if you have a lot of binary packages.)
 .='update pass'  *='binary update'  #='/var/db update'  @='/var/db move'
 s='/var/db SLOT move'  %='binary move'  S='binary SLOT move'
 p='update /etc/portage/package.*'
..................
Traceback (most recent call last):
 File "/usr/bin/emerge", line 40, in &lt;module&gt;
 retval = emerge_main()
 File "/usr/lib64/portage/pym/_emerge/main.py", line 1328, in emerge_main
 return action_sync(settings, trees, mtimedb, myopts, myaction)
 File "/usr/lib64/portage/pym/_emerge/actions.py", line 2173, in action_sync
 if portage._global_updates(trees, mtimedb["updates"]):
 File "/usr/lib64/portage/pym/portage/__init__.py", line 8572, in _global_updates
 moves = bindb.move_ent(update_cmd)
 File "/usr/lib64/portage/pym/portage/dbapi/bintree.py", line 273, in move_ent
 mytbz2.recompose_mem(portage.xpak.xpak_mem(mydata))
 File "/usr/lib64/portage/pym/portage/xpak.py", line 106, in xpak_mem
 indexglob=indexglob+encodeint(len(x))+x+encodeint(datapos)+encodeint(mydatasize)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 49: ordinal not in range(128)</pre>
</blockquote>
<p><span id="more-96"></span>The solution is simple, but not necessarily easy to think of.  All that needs to be done is to move the 4Q-2009 and 3Q-2009 files somehwere else, and then update python/portage.</p>
<pre>[19:31 root@joseph updates] # eselect python list                    
Available python interpreters:                                       
 [1]   python2.4                                                    
 [2]   python2.5 *                                                  
 [3]   python2.6                                                    
[19:31 root@joseph updates] # eselect python set 3
[19:35 root@joseph updates] # emerge -1 portage</pre>
<p>Then, move the 4Q-2009 and 3Q-2009 back to the proper locations, and everything should be working.  Next, it's probably good to do a "python-updater -p", followed by your world update.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2009/12/05/gentoo-portage-python-update-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
