<?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>bassistance.de &#187; Java</title>
	<atom:link href="http://bassistance.de/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://bassistance.de</link>
	<description>Jörn Zaefferer on Bass, Geeks and Rock'n'Roll</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:34:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Java Tricks: Find out who invoked you</title>
		<link>http://bassistance.de/2010/02/10/java-tricks-find-out-who-invoked-you/</link>
		<comments>http://bassistance.de/2010/02/10/java-tricks-find-out-who-invoked-you/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 13:10:58 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://bassistance.de/?p=613</guid>
		<description><![CDATA[There is a setting in the log4j framework that allows you to log the exact location of where the logger was invoked (I&#8217;d provide a link to the related documentation, but I can&#8217;t find it; the lo4j site is a horrible mess). I always wondered how that works, here&#8217;s how: public class Invoker { public [...]]]></description>
			<content:encoded><![CDATA[<p>There is a setting in the log4j framework that allows you to log the exact location of where the logger was invoked (I&#8217;d provide a link to the related documentation, but I can&#8217;t find it; the lo4j site is a horrible mess). I always wondered how that works, here&#8217;s how:</p>
<pre><code class="java">public class Invoker {

        public static void main(String[] args) {
                System.out.println("Invoked from: " + invoker());
                System.out.println("A bit more indirect: " + test());
        }

        private static String test() {
                return invoker();
        }

        public static String invoker() {
                try {
                        throw new RuntimeException();
                } catch(RuntimeException e) {
                        return e.getStackTrace()[1].toString();
                }
        }
}</code></pre>
<p>The output format matches the Exception#printStackTrace format, so that you can click on the result in the Eclipse console and it opens the file at the correct line:</p>
<pre><code>Invoked from: Invoker.main(Invoker.java:4)
A bit more indirect: Invoker.test(Invoker.java:9) </code></pre>
<p>Based on the comment attached to the code where I found this, there is an easier way to obtain the stack in Java 1.5. And with a bit of searching, I found the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#getStackTrace%28%29">getStackTrace method</a>, added to Thread in 1.5. With that, the code becomes even simpler:</p>
<pre><code>public class Invoker {

        public static void main(String[] args) {
                System.out.println("Invoked from: " + invoker());
                System.out.println("A bit more indirect: " + test());
        }

        private static String test() {
                return invoker();
        }

        public static String invoker() {
                return Thread.currentThread().getStackTrace()[2].toString();
        }

} </code></pre>
<p>Note that the call to Thread#getStackTrace ends up on the stack, too, so the interesting StackTraceElement is at index 2, not 1 as before.</p>
<p>A final warning: While this is immensly helpful for log-based debugging, the performance hit should be kept in mind. The log4j documentation warns about that as well, though I suspect that the Java 1.5 methods will have less impact than the try-catch approach. And some very primitive benchmarking proved me wrong&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2010/02/10/java-tricks-find-out-who-invoked-you/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Undo/redo command stack in Java</title>
		<link>http://bassistance.de/2009/11/18/undoredo-command-stack-in-java/</link>
		<comments>http://bassistance.de/2009/11/18/undoredo-command-stack-in-java/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 13:48:21 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://bassistance.de/?p=582</guid>
		<description><![CDATA[Another fragment that turned out to be useless for the project, but may come handy in the future. A port to JavaScript should be easy enough, too: import java.util.ArrayList; import java.util.List; public class CommandStack { /** * Implement for each individual change that can occur in an editor. * * Both {@link #execute()} and {@link [...]]]></description>
			<content:encoded><![CDATA[<p>Another fragment that turned out to be useless for the project, but may come handy in the future. A port to JavaScript should be easy enough, too:</p>
<pre><code class="java">import java.util.ArrayList;
import java.util.List;

public class CommandStack {

	/**
	 * Implement for each individual change that can occur in an editor.
	 *


	 * Both {@link #execute()} and {@link #undo()} should fire property change
	 * events for notifying the editor of an update.
	 */
	public static abstract class Command {

		private String name;

		public Command(String name) {
			this.name = name;
		}

		@Override
		public String toString() {
			return name;
		}

		/**
		 * Implements the actual change.
		 *


		 * Any state-saving for {@link #undo()}
		 * has to occur elsewhere, eg. in the constructor.
		 */
		public abstract void execute();

		/**
		 * Reverts any changes applied by {@link #execute()}.
		 */
		public abstract void undo();

	}

	private final List<Command> commands = new ArrayList<Command>();
	private int currentLocation = -1;
	private int saveLocation = currentLocation;

	public void add(Command command) {
		clearInFrontOfCurrent();
		command.execute();
		commands.add(command);
		currentLocation++;
	}

	public void undo() {
		commands.get(currentLocation).undo();
		currentLocation--;
	}

	public boolean undoEnabled() {
		return currentLocation >= 0;
	}

	public void redo() {
		currentLocation++;
		commands.get(currentLocation).execute();
	}

	public boolean redoEnabled() {
		return currentLocation < commands.size() - 1;
	}

	public boolean dirty() {
		return currentLocation != saveLocation;
	}

	private void clearInFrontOfCurrent() {
		while (currentLocation < commands.size() - 1) {
			commands.remove(currentLocation + 1);
		}
	}

	public void markSaveLocation() {
		saveLocation = currentLocation;
	}

	@Override
	public String toString() {
		return commands.toString();
	}

}</code></pre>
<p>And to illustrate the usage, the JUnit test:</p>
<pre><code class="java">import junit.framework.TestCase;

public class CommandStackTest extends TestCase {

	CommandStack stack = new CommandStack();

	private String name;
	private int age;

	class EditName extends Command {

		private String oldName = name;
		private String newName;

		public EditName(String newName) {
			super("Update name to " + newName);
			this.newName = newName;
		}

		public void execute() {
			name = newName;
		}

		public void undo() {
			name = oldName;
		}
	};

	class EditAge extends Command {

		private int oldAge = age;
		private int newAge;

		public EditAge(int newAge) {
			super("Update age to " + newAge);
			this.newAge = newAge;
		}

		public void execute() {
			age = newAge;
		}

		public void undo() {
			age = oldAge;
		}
	};

	public void test_basics() {
		assertNull(name);
		assertEquals(0, age);
		assertFalse(stack.dirty());
		assertFalse(stack.undoEnabled());
		assertFalse(stack.redoEnabled());

		stack.add(new EditName("Peter"));

		assertTrue(stack.dirty());
		assertEquals("Peter", name);
		assertTrue(stack.undoEnabled());
		assertFalse(stack.redoEnabled());

		stack.undo();

		assertNull(name);
		assertFalse(stack.undoEnabled());
		assertTrue(stack.redoEnabled());
		assertFalse(stack.dirty());

		stack.redo();

		assertTrue(stack.dirty());
		assertEquals("Peter", name);
		assertTrue(stack.undoEnabled());
		assertFalse(stack.redoEnabled());

		stack.markSaveLocation();

		assertFalse(stack.dirty());
		assertEquals("Peter", name);
		assertTrue(stack.undoEnabled());
		assertFalse(stack.redoEnabled());

		stack.add(new EditAge(10));

		assertTrue(stack.dirty());
		assertEquals(10, age);
		assertTrue(stack.undoEnabled());
		assertFalse(stack.redoEnabled());

		stack.undo();

		assertFalse(stack.dirty());
		assertEquals(0, age);
		assertTrue(stack.undoEnabled());
		assertTrue(stack.redoEnabled());

		stack.add(new EditName("Pan"));

		assertTrue(stack.dirty());
		assertEquals("Pan", name);
		assertEquals(0, age);
		assertTrue(stack.undoEnabled());
		assertFalse(stack.redoEnabled());

		stack.undo();
		stack.undo();

		assertTrue(stack.dirty());
		assertNull(name);
		assertEquals(0, age);
		assertFalse(stack.undoEnabled());
		assertTrue(stack.redoEnabled());

		stack.redo();
		stack.redo();

		assertTrue(stack.dirty());
		assertEquals("Pan", name);
		assertEquals(0, age);
		assertTrue(stack.undoEnabled());
		assertFalse(stack.redoEnabled());
	}

}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2009/11/18/undoredo-command-stack-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse Dev: Custom Search Page</title>
		<link>http://bassistance.de/2009/11/17/eclipse-dev-custom-search-page/</link>
		<comments>http://bassistance.de/2009/11/17/eclipse-dev-custom-search-page/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 07:57:28 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://bassistance.de/?p=576</guid>
		<description><![CDATA[This is for the archive and due to lack of useful tutorials on writing custom search pages in your own Eclipse plugin. It turned out that the default text search is good enough for my purposes, so I&#8217;ll stick it here as a future reference. To start, your Eclipse plugin needs to add org.eclipse.search as [...]]]></description>
			<content:encoded><![CDATA[<p>This is for the archive and due to lack of useful tutorials on writing custom search pages in your own Eclipse plugin. It turned out that the default text search is good enough for my purposes, so I&#8217;ll stick it here as a future reference.</p>
<p>To start, your Eclipse plugin needs to add org.eclipse.search as a dependency, and, if you don&#8217;t have it already, org.eclipse.jface.text, too. With that, the Require-Bundle part of your MANIFEST.MF should look something like this:</p>
<pre><code>Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.views,
org.eclipse.core.resources,
org.eclipse.ui.ide,
org.eclipse.ui.workbench.texteditor,
org.eclipse.text,
org.eclipse.ui.editors,
org.eclipse.search,
org.eclipse.jface.text</code></pre>
<p>Next, we&#8217;ll specify the extension for our custom search page, using the plugin.xml editor or just pasting and modifying this snippet:</p>
<pre><code class="html">&lt;extension point="org.eclipse.search.searchPages"&gt;
  &lt;page
    class="com.acm.your.product.CustomSearchPage"
    id="yourplugin.page1"
    label="Your Custom Search, rename this"&gt;
  &lt;/page&gt;
&lt;/extension&gt;</code></pre>
<p>And the actual implementation, providing a textfield as input, initialized with whatever text selection is currently active (thats where the org.eclipse.jface.text dependency comes from), and doing a text search across the full workspace:</p>
<pre><code class="java">package com.acm.your.product;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.TextSearchQueryProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class CustomSearchPage extends DialogPage implements ISearchPage {

	private String selected;
	private Text idText;

	public IdSearchPage() {
		super();
	}

	public IdSearchPage(String title) {
		super(title);
	}

	public boolean performAction() {
		if (idText.getText().length() == 0)
			return false;
		try {
			NewSearchUI.runQueryInBackground(TextSearchQueryProvider.getPreferred().createQuery(idText.getText()));
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (CoreException e) {
			throw new RuntimeException(e);
		}
        return true;
	}

	public void setContainer(ISearchPageContainer container) {
		if (container.getSelection() instanceof TextSelection) {
			selected = ((TextSelection) container.getSelection()).getText();
		}
	}

	public void createControl(Composite parent) {
		GridLayout layout = new GridLayout(1, false);
		layout.horizontalSpacing = 5;
		layout.verticalSpacing = 5;
		parent.setLayout(layout);
		new Label(parent, 0).setText("Containing text:");
		idText = new Text(parent, SWT.BORDER);
		idText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		if (selected != null) {
			idText.setText(selected);
			idText.setSelection(0, selected.length());
		}
		setControl(parent);
	}

	@Override
	public void setVisible(boolean visible) {
		super.setVisible(visible);
		idText.setFocus();
	}

}</code></pre>
<p>You can also restrict the files to search by creating a list first, and pass that to the search provider:</p>
<pre><code class="java">package com.acm.your.product;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.TextSearchQueryProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class CustomSearchPage2 extends DialogPage implements ISearchPage {

	private String selected;
	private Text idText;

	public IdSearchPage() {
		super();
	}

	public IdSearchPage(String title) {
		super(title);
	}

	public boolean performAction() {
		if (idText.getText().length() == 0)
			return false;
		try {
			final List<IResource> files = new ArrayList<IResource>();
			ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceProxyVisitor() {
				public boolean visit(IResourceProxy proxy) throws CoreException {
					if (proxy.getType() == IResource.FILE) {
						IFile file = (IFile) proxy.requestResource();
			            if (file.getLocation().getFileExtension() != null &#038;&#038; file.getLocation().getFileExtension().matches("xml|html|js|css")) {
			            	files.add(file);
			            }
			         }
			         return true;
				}
			}, IResource.DEPTH_INFINITE);
			NewSearchUI.runQueryInBackground(TextSearchQueryProvider.getPreferred().createQuery(idText.getText(), files.toArray(new IResource[0])));
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (CoreException e) {
			throw new RuntimeException(e);
		}
        return true;
	}

	public void setContainer(ISearchPageContainer container) {
		if (container.getSelection() instanceof TextSelection) {
			selected = ((TextSelection) container.getSelection()).getText();
		}
	}

	public void createControl(Composite parent) {
		GridLayout layout = new GridLayout(1, false);
		layout.horizontalSpacing = 5;
		layout.verticalSpacing = 5;
		parent.setLayout(layout);
		new Label(parent, 0).setText("Containing text:");
		idText = new Text(parent, SWT.BORDER);
		idText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		if (selected != null) {
			idText.setText(selected);
			idText.setSelection(0, selected.length());
		}
		setControl(parent);
	}

	@Override
	public void setVisible(boolean visible) {
		super.setVisible(visible);
		idText.setFocus();
	}

}</code></pre>
<p>This in itself doesn&#8217;t yet provide a lot of value, but if you actually need to build a custom search, its a good start.</p>
<p>Roughly based on <a href="http://wiki.eclipse.org/FAQ_How_do_I_write_a_Search_dialog%3F">this sort-of tutorial on the Eclipse wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2009/11/17/eclipse-dev-custom-search-page/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Testing SSL Java web apps with mails</title>
		<link>http://bassistance.de/2009/03/05/testing-ssl-java-web-apps-with-mails/</link>
		<comments>http://bassistance.de/2009/03/05/testing-ssl-java-web-apps-with-mails/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 10:41:32 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://bassistance.de/?p=434</guid>
		<description><![CDATA[The guide How to configure SSL on the Jetty wiki guides you through creating a self-signed certificate, required for developing and testing Java web applications that require SSL. The guide works fine, but causes a hard-to-debug side effect. By creating your own keystore, you exclude the default list of trusted certificates. This is a problem [...]]]></description>
			<content:encoded><![CDATA[<p>The guide <a href="http://docs.codehaus.org/display/JETTY/How+to+configure+SSL">How to configure SSL</a> on the Jetty wiki guides you through creating a self-signed certificate, required for developing and testing Java web applications that require SSL. The guide works fine, but causes a hard-to-debug side effect.</p>
<p>By creating your own keystore, you exclude the default list of trusted certificates. This is a problem when using trying to send mail to a SMTP server with a signed certificate, as that now isn&#8217;t trusted anymore. Specifically, the following exception is thrown when trying to connect to the smtp server:</p>
<pre><code>javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target</code></pre>
<p>To fix this, you have to import the certificate of the server you&#8217;re trying to connect to into your custom keystore. The <a href="http://blogs.sun.com/andreas/entry/no_more_unable_to_find">InstallCert program</a> is the right tool for that.</p>
<p>In my case, I copied the keystore file into my project root, named &#8220;jssecacerts&#8221;, and ran &#8220;java InstallCert smpt.gmail.com:465 password&#8221; (&#8220;password&#8221; is the passphrase as defined when creating the keystore). InstallCert then updates the &#8220;jssecacerts&#8221; file &#8211; now is includes my own self-signed certificate, as well as the Google one. I copied that back to where Jetty could find it, replacing the old keystore file.</p>
<p>Btw., to configure Spring&#8217;s JavaMailSenderImpl to use GMail as the SMTP Server:</p>
<pre><code class="java">public @Bean JavaMailSender mailSender() {
	JavaMailSenderImpl sender = new JavaMailSenderImpl();
	sender.setPort(465);
	sender.setProtocol("smtps");
	sender.setHost("smtp.gmail.com");
	sender.setUsername("your-account@gmail.com");
	sender.setPassword("your-password");
	return sender;
}</code></pre>
<p>I hope this helps someone else to solve this problem in less time then I spend on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2009/03/05/testing-ssl-java-web-apps-with-mails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hotfixing Java frameworks</title>
		<link>http://bassistance.de/2009/01/30/hotfixing-java-frameworks/</link>
		<comments>http://bassistance.de/2009/01/30/hotfixing-java-frameworks/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 09:20:12 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://bassistance.de/?p=409</guid>
		<description><![CDATA[I&#8217;m currently working on a web application that uses the Apache Wicket web framework. While implementing a new feature related to file uploads, I stumbled about a problem that turned out to be a known issue. The bug was already fixed in Wicket&#8217;s trunk, though not yet released. The scheduled version for the release is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a web application that uses the Apache Wicket web framework. While implementing a new feature related to file uploads, I stumbled about a problem that turned out to be a <a href="https://issues.apache.org/jira/browse/WICKET-1931">known issue</a>.</p>
<p>The bug was already fixed in Wicket&#8217;s trunk, though not yet released. The scheduled version for the release is 1.4RC2, which doesn&#8217;t help either, as I&#8217;m still working with Wicket 1.3.5 (the current stable release).</p>
<p>I had to somehow fix this, and I&#8217;d like to present how I got it working until we can update to 1.4: The ticket also included a <a href="https://issues.apache.org/jira/secure/attachment/12394726/wicket-1931.patch">patch to MockHttpServletRequest</a>, and I needed exactly that patch. The getInputStream method isn&#8217;t final, but I couldn&#8217;t just subclass, as the code instantiating MockHttpServletRequest is quite involved. So instead, I copied the class into my project, applying the patch there. The Java classloader loads my modified version instead of the one provided by Wicket&#8217;s jar file, and the issue is resolved.</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2009/01/30/hotfixing-java-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Barrier to entry for PHP and Java web applications</title>
		<link>http://bassistance.de/2008/05/21/barrier-to-entry-for-php-and-java-web-applications/</link>
		<comments>http://bassistance.de/2008/05/21/barrier-to-entry-for-php-and-java-web-applications/#comments</comments>
		<pubDate>Wed, 21 May 2008 19:27:04 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java php hosting webapplications]]></category>

		<guid isPermaLink="false">http://bassistance.de/?p=250</guid>
		<description><![CDATA[Jeff Atwood&#8217;s latest post on PHP sucking hard, while powering a very decent amount of the internet, got my attention. Not so much by the content itself, but rather because I was thinking about PHP and Java web applications a lot lately anyway. This blog is powered by PHP and I write little PHP scripts [...]]]></description>
			<content:encoded><![CDATA[<p>Jeff Atwood&#8217;s latest post on <a href="http://www.codinghorror.com/blog/archives/001119.html">PHP sucking hard, while powering a very decent amount of the internet</a>, got my attention. Not so much by the content itself, but rather because I was thinking about PHP and Java web applications a lot lately anyway.</p>
<p>This blog is powered by PHP and I write little PHP scripts once in a while to mock a server for testing my jQuery plugins. On the other hand, I&#8217;m designing, architecting and writing a web application in Java. In the case of testing jQuery plugins and the application, the tool is the right one for the job. I&#8217;m not so sure about this blog, WordPress and PHP. Jeff&#8217;s post links to more than enough arguments why PHP isn&#8217;t the right tool&#8230;</p>
<p>But the quality of the programming language is a too small part of the picture. I consider the barrier to entry an important part. Its a hell of a lot easier to get started writing a PHP application. Just create a new file. Finding a hoster for that application is easy, too, and can be as cheap as a few bucks per year, literally. Setting up a shared-hosting enviroment is rather easy, too, as each PHP request runs in its own shared-nothing process.</p>
<p>Installing WordPress is frickin&#8217; easy, too. Download the current release, upload it via FTP, enter DB info into a plain text file (&#8220;plain text&#8221; in contrast to verbose xml configuration buried within JNDI datesource defintions), and done! </p>
<p>The barrier to entry for writing and deploying Java web applications is a bit higher. Java hosting is rare and expensive. Writing a Java web application requires at least two files and one folder, one file being an XML configuration file placed inside that folder. Deploying applications heavily depends on the hosting enviroment. Usually it involves uploading a war-file via FTP or webinterface, I don&#8217;t even know how it works in shared-hosting enviroments.</p>
<p>A few hosters support JSPs: Just upload a .jsp file and point the URL. Pretty close to the PHP model, arguably much worse. JSPs invite you to mix HTML and Java, which is much worse then mixing HTML and PHP. A JSP has extra tags to import classes, and of course tags for SQL queries, if you are really desperate. You loose the benefits of static styping while still bearing the cost, unit-testing is somewhere between extremely hard and impossible, certainly not worth it anymore. In other words: JSPs provide no reasonable benefits over PHP.</p>
<p>That leaves us with a lot of work ahead to lower the barrier to entry for Java web applications. The most potential is creating applications. The create-a-file-to-create-an-application mode is as easy as it gets, so we&#8217;d need some abstraction that allow you to create a servlet application with just one file, and no xml configuration, please.</p>
<p>Once creation is a matter of creating a file, deploying should boil down to uploading that file. Once that is possible, hosting will improve &#8211; its than a matter of supply and demand.</p>
<p>I hava few ideas for the necessary abstractions and will post about them. Thoughts and ideas are very welcome &#8211; maybe I&#8217;m looking in the wrong direction here.</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2008/05/21/barrier-to-entry-for-php-and-java-web-applications/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Closures in Java and Scala</title>
		<link>http://bassistance.de/2008/03/27/closures-in-java-and-scala/</link>
		<comments>http://bassistance.de/2008/03/27/closures-in-java-and-scala/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 18:39:59 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://bassistance.de/2008/03/27/closures-in-java-and-scala/</guid>
		<description><![CDATA[People argue that verbose code is easier to understand. Do you agree when reading these two? public List&#60;Item&#62; bought(User user) { List&#60;Item&#62; result = new ArrayList(); for (Item item : currentItems) { if (user.bought(item)) { result.add(item); } } return result; } def bought(user: User): List[Item] = { items.filter(user bought _) } If you are familiar [...]]]></description>
			<content:encoded><![CDATA[<p>People argue that verbose code is easier to understand. Do you agree when reading these two?</p>
<pre><code class="java">public List&lt;Item&gt; bought(User user) {
	List&lt;Item&gt; result = new ArrayList();
	for (Item item : currentItems) {
		if (user.bought(item)) {
			result.add(item);
		}
	}
	return result;
}

def bought(user: User): List[Item] = {
	items.filter(user bought _)
}</code></pre>
<p>If you are familiar with Java, which is more likely then you being familiar with <a href="http://www.scala-lang.org/">Scala</a>, you may tend to the Java-version. Scala has a different syntax for declaring types and generics, and supports closures, including anonymous parameters (the underscore).</p>
<p>When Closures are introduced in one of the next Java releases, JDK 7 or 8, the example could be rewritten like this:</p>
<pre><code class="java">public List&lt;Item&gt; bought(User user) {
	return ListUtils.filter(Item item : items) {
	   user.bought(item);
	}
}</code></pre>
<p>Or with <a href="http://www.jroller.com/scolebourne/entry/java_7_extension_methods">extension methods</a>:</p>
<pre><code class="java">public List&lt;Item&gt; bought(User user) {
	return items.filter(Item item : ) { // <-- note the smily! thats what its all about!
	   user.bought(item);
	}
}</code></pre>
<p>The interesting differences between Java with closures and Scala is the static typing: Scala inferences that items are all of type Item, so there is no need to specify that information again.</p>
<p>So, while the current <a href="http://javac.info/">Java Closures specification</a> is a great step in the right direction, <a href="http://michaelhuettermann.blogspot.com/2008/03/dr-neil-gafter-jugc-and-vip.html">lead by Neil Gafter</a> who is quite the right man for the job, it may not be worth to wait for it, if you have the choice. Its not even sure yet that we'll see that spec implemented in JDK7, and even that is at best one and a half year away.</p>
<p>PS: Pasting Scala code with generic types into a blog is much easier then generic Java, where you need to escape &lt; and &gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2008/03/27/closures-in-java-and-scala/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Why open source?</title>
		<link>http://bassistance.de/2007/07/13/why-open-source/</link>
		<comments>http://bassistance.de/2007/07/13/why-open-source/#comments</comments>
		<pubDate>Fri, 13 Jul 2007 19:11:16 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Worth Reading]]></category>

		<guid isPermaLink="false">http://bassistance.de/2007/08/13/why-open-source/</guid>
		<description><![CDATA[While glancing over Dr. Dobb&#8217;s article Getting Started With jQuery I read this: Whether the motivation behind making their labors freely available is a matter of seeking recognition, resume building, free advertising for other services, bragging rights, or just plain old-fashioned altruism, we can gratefully take advantage of these tools. jQuery is one such tool. [...]]]></description>
			<content:encoded><![CDATA[<p>While glancing over Dr. Dobb&#8217;s article <a href="http://www.ddj.com/dept/java/201000935">Getting Started With jQuery</a> I read this:</p>
<blockquote><p>Whether the motivation behind making their labors freely available is a matter of seeking recognition, resume building, free advertising for other services, bragging rights, or just plain old-fashioned altruism, we can gratefully take advantage of these tools. jQuery is one such tool.</p></blockquote>
<p>I think altruism is very far away from the true motivation in most cases. Most free and open source software I can think of is done because someone needed it anyway. And instead of just writing that little tool you needed that one day, why not release it to the great public <a title="Read Jeff's entry about 'Pick a licsense, any license!', its worth its words, like almost everything he writes" href="http://www.codinghorror.com/blog/archives/000833.html">under some appropiate license</a>? If the tool is worth its code its quite likely that someone else has use for it, too. And because they don&#8217;t have to pay anything and can read and modify the source code, its very easy for them to contribute back whatever they can. And using that feedback is again helping the initial author.</p>
<p>You can find good hints at the eat-your-own-dogfoot principle and where it was applied and where not in a lot of open source products. Consider the update manager in <a href="http://www.eclipse.org">Eclipse</a>. To start with, its hidden under the Help menu. You have to manually copy&#038;paste links from update sites into it. And you always have to choose &#8220;search for new features to install&#8221; even if you want to look for updates, because looking for updates most likely never finishes and yields no result after bugging you 20 times for a mirror to choose from a list. That is the stuff the developers (of Eclipse) mostlikely themselves don&#8217;t use, and therefore don&#8217;t care about.</p>
<p>On the other hand, Eclipse&#8217; Java Development Tools is state-of-the-art: I&#8217;m using it now for almost three years and yet I find new helpful features everyday. Its refactoring support alone is worth some gold. Ever wanted to introduce a new parameter in an interface method and its four implementations? Its something very ugly when doing by hand, with Eclipse its simple as hell: Refactor -> &#8220;Change method signature&#8221;, and you&#8217;re nearly done. Learned how to use that just today.</p>
<p>Eclipse is backed by a big corporation (IBM) and a daily growing list of both small and big eclipse foundation members. This isn&#8217;t the case on projects like jQuery. When asking John Resig about his motivation for releasing jQuery he answered:</p>
<blockquote><p>I&#8217;d have to say Altruism + Recognition &#8211; resume building was a nice side effect, but I didn&#8217;t think about that</p></blockquote>
<p>And he added:</p>
<blockquote><p>I mean, I guess if you&#8217;re wondering why open source vs. &#8220;closed source&#8221; (license-restricted). I guess, technically one could get recognition from either, but I don&#8217;t like restrictive software. I&#8217;ve grown up using open source, and benefited so much from it. It just doesn&#8217;t make sense to me to release closed software. I don&#8217;t see how it could possibly benefit me, or help others.</p>
<p>So for me, restricted software just doesn&#8217;t feel right &#8211; whereas open source feels very good. Helping people and feeding back into the community is really what does it for me. Seeing it do well is a nice side effect &#8211; I mean, on my web site alone I&#8217;ve released over 70 pieces of open source software. A couple have done really well &#8211; only one really took off.</p>
<p>So I definitely wasn&#8217;t expecting recognition, but it was nice that it happened.</p></blockquote>
<p>As always he has some good points to argument with. I spent and keep spending a lot of time working on my jQuery plugins because I know (at least now) that I will be most likely developing web applications in the next years (though so far they are all 100% corporate intranet applications, but still running in browsers). And its great to use features of your own plugins in your own project that someone else contributed. Even questions for support help a lot, because you know where you have to improve APIs and examples.</p>
<p>Releasing JavaScript code as opensource is somehow natural anyway. Reading JavaScript code in the source of other&#8217;s website has been done for years now, and giving the code a property license to motivate &#8220;readers&#8221; to give feedback and contribute has helped a ton to improve the overall quality of written JavaScript by several magnitudes.</p>
<p>Currently I&#8217;m investigating ways to leverage those plugins on the server-side too, which is especially interesting when considering the <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">validation plugin</a>. John&#8217;s work on implementing <a href="http://ejohn.org/blog/bringing-the-browser-to-the-server/">a browser environment in Rhino</a> is amazing. It already is able to run the full jQuery test suite, and the possibilities for building web application frameworks based on jQuery are daunting.</p>
<p>I hope I can also opensource some of the framework code I&#8217;m developing at work some time in the feature. There is already some really nice JSF and Spring related code in our repository&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2007/07/13/why-open-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How would jQuery look like in&#8230; Java?</title>
		<link>http://bassistance.de/2007/02/26/how-would-jquery-look-like-in-java/</link>
		<comments>http://bassistance.de/2007/02/26/how-would-jquery-look-like-in-java/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 21:38:41 +0000</pubDate>
		<dc:creator>Jörn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bassistance.de/2007/02/26/how-would-jquery-look-like-in-java/</guid>
		<description><![CDATA[I was thinking about how jQuery would look like when implemented in other languages: Is it possible to offer the same API jQuery currently provides in JavaScript? Is it easier, or more difficult? What are the differences? Since I&#8217;m most familiar with Java, I started to mock up some classes. I&#8217;m relying on some of [...]]]></description>
			<content:encoded><![CDATA[<p>I was thinking about how jQuery would look like when implemented in other languages: Is it possible to offer the same API jQuery currently provides in JavaScript? Is it easier, or more difficult? What are the differences?</p>
<p>Since I&#8217;m most familiar with Java, I started to mock up some classes. I&#8217;m relying on some of Java 5&#8242;s features to be able to write some nice code. Wouldn&#8217;t want to try that with 1.4.</p>
<p>Let&#8217;s get started with some code that actually uses jQuery</p>
<pre><code class="java">import static com.jquery.jQuery.jQuery;

import com.jquery.Element;
import com.jquery.Event;
import com.jquery.EventListener;
import com.jquery.ReadyListener;
import com.jquery.jQuery;

public class Application {

  public void main() {
    jQuery(new ReadyListener() {
      public void handle(Element document) {
        jQuery("input:checked").val("newvalue").val();

        // need to split declaration and call to click, otherwise
        // we'd get "The local variable anchors may not have been initialized"
        final jQuery anchors = jQuery("a");
        anchors.click(new EventListener() {
          public void handle(Event e) {
            e.preventDefault();
            jQuery(e.target).val("foo");
            anchors.val("bar");
          }
        });
      }
    });
  }

}</code></pre>
<p>Here we have the first use of one Java 5 feature: Static imports. We&#8217;re importing the static jQuery method from the jQuery class:<br />
<code><code class="java">import static com.jquery.jQuery.jQuery;</code></p>
<p>Of course the compiler complains that we are declaring a class method that has the same name as a constructor, but as it is no error, we don't have to worry about that.</p>
<p>Next we import some classes and interfaces to work with, all very simple:</p>
<pre><code class="java">public interface ReadyListener {
	public void handle(Element document);
}
public interface Function {
	public void apply(Element element);
}
public interface Element {
	public String getAttribute(String name);
	public void setAttribute(String name, String value);
}
public interface EventListener {
	public void handle(Event e);
}</code></pre>
<p><code>Event</code> isn't an interface, but an abstract class with a some public final properties. The example has only <code>target</code> and <code>source</code>, other properties like <code>keyCode</code> would be there too.</p>
<pre><code class="java">public abstract class Event {

	public final Element target;
	public final Element source;

	protected Event(Element source, Element target) {
		this.source = source;
		this.target = target;
	}

	public abstract void preventDefault();
	public abstract void stopPropagation();

}
</code></pre>
<p>Now for anyone saying, "but don't ever make fields public, you can't change the implementation then!", take a look at the SWT API, it uses very similar event objects.</p>
<p>Ok, back to our initial example:</p>
<pre><code class="java">public void main() {
  jQuery(new ReadyListener() {
    public void handle(Element document) {
      jQuery("input:checked").val("newvalue").val();

      // need to split declaration and call to click, otherwise
      // we'd get "The local variable anchors may not have been initialized"
      final jQuery anchors = jQuery("a");
      anchors.click(new EventListener() {
        public void handle(Event e) {
          e.preventDefault();
          jQuery(e.target).val("foo");
          anchors.val("bar");
        }
      });
    }
  });
}</code></pre>
<p>This fake main method would be somehow hooked into the browser's API, but that isn't the focus here.</p>
<p>Anyone who has worked with jQuery should recognize everything here. Of course the code for defining anonymous functions is a bit more noisy then JavaScript's plain <code>function() {}</code>, but the purpose of the ReadyListener is clear and can't be confused with a normal EventListener or a Function.</p>
<p>The actual code to select elements and do something with them is extremley close to jQuery itself, thanks to JavaScript having a syntax close to Java: <code class="java">jQuery("input:checked").val("newvalue").val();</code></p>
<p>It is also possible to create closures, though it is a bit more restricted by the compiler, and therefore less error prone. Or more error prone, due to more code. Decide for yourself:</p>
<pre><code class="java">final jQuery anchors = jQuery("a");
anchors.click(new EventListener() {
	public void handle(Event e) {
		e.preventDefault();
		jQuery(e.target).val("foo");
		anchors.val("bar");
	}
});</code></pre>
<p>We need to split the assignment to the final variable "anchors" before we call click, otherwise the compiler complains with "The local variable anchors may not have been initialized". Makes sense to me. I wonder if the problem that is prevented here, executing the handler before the click method returns, can occur in JavaScript?</p>
<p>Ok, now to the actualy jQuery class:</p>
<pre><code class="java">package com.jquery;

import static com.jquery.Window.document;

public class jQuery {

  // use an array instead of a list to guarantee non-destructive behaviour
  private final Element[] elements;

  // private constructors
  private jQuery(Element element) { elements = new Element[] { element }; }
  private jQuery(Element[] elements) { this.elements = elements; }

  // factories
  public static jQuery jQuery(String expression) {
    return new jQuery(document).find(expression);
  }
  public static jQuery jQuery(Element element) {
    return new jQuery(element);
  }
  public static jQuery jQuery(Element[] elements) {
    return new jQuery(elements);
  }
  public static jQuery jQuery(String expression, Element context) {
    return new jQuery(context).find(expression);
  }
  public static void jQuery(ReadyListener listener) {
    new jQuery(document).ready(listener);
  }

  // DOM ready event, manages ready list
  public void ready(ReadyListener listener) {}

  // provide access to all or a single element
  public Element[] get() { return elements; }
  public Element get(int index) { return elements[index]; }

  // find elements and return new jQuery object
  public jQuery find(String expression) { return jQuery(new Element[] {}); }

  // iterate through elements and apply a function
  public jQuery each(Function handler) {
    for (Element current : elements) {
      handler.apply(current);
    }
    return this;
  }

  // get value of first element
  public String val() { return elements[0].getAttribute("value"); }

  // set value of all elements
  public jQuery val(final String value) {
    // use each to iterate
    // actually a for loop would be more efficient here, less code
    return this.each(new Function() {
      public void apply(Element element) {
        element.setAttribute("value", value);
      }
    });
  }

  // manages click event handlers
  public jQuery click(EventListener listener) { return this; }

}</code></pre>
<p>I think implementations of <code>each()</code> and <code>val()</code> are worth some more attention. While we don't win much when using <code class="java">each()</code> internally, it is possible to provide almost the same API as the JavaScript implementation of jQuery. We just need a bit more effort to create the Function object, but a good IDE (Eclipse is my favorite) can help alot. I don't have to type more then "new Function()" and press ctrl+enter inside the parentheses.</p>
<p>I'd find it quite interesting to see how similar implementations, or rather APIs, would look like in other languages, be it PHP, Python, PERL, ColdFusion or Ruby.</p>
<p>Ruby is especially intersting for me. When looking at the progress of JRuby, it <a href="http://www.headius.com/jrubywiki/index.php/Roadmap_%28January_2007_-_June_2007%29">seems like</a> we can get to start using Ruby on the JVM this year. So far the performance isn't outstanding because all code is interpreted, but once they start working on the compiler, compiling Ruby code into bytecode, the performance should improve a lot.</p>
<p>I hope to get some more examples of jQuery in other languages, and will post updates accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://bassistance.de/2007/02/26/how-would-jquery-look-like-in-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
