java

How to add a horizontal gap with a JLabel

I have a JLabel (actually, it is a JXLabel). I have put an icon and text on it. Now I wand to add some spacing on the left side of the component, like this: I DON'T accept suggestion to move the JLabel or add spacing by modifying the image. I just want to know how to do it with plain java code. ...

Good guide to CORBA?

Anyone know of a good guide to CORBA? I've never used it and I'm going to have to write a Java (Not my native language I'm a .Net Developer) proof of concept app that uses CORBA. ...

Aborting upload from a servlet

I'd like to limit the size of the file that can be uploaded to an application. To achieve this, I'd like to abort the upload process from the server side when the size of the file being uploaded exceeds a limit. Is there a way to abort an upload process from the server side without waiting the HTTP request to finish? ...

Create an EML (E-Mail) File in Java

Anybody knows how to do this? I got all the information of the email (body, subject, from , to, cc, bcc) and need to generate an eml-file out of it. ...

Double checked locking Article

Hi all, I was reading this article about "Double-Checked locking" and out of the main topic of the article I was wondering why at some point of the article the author uses the next Idiom: Listing 7. Attempting to solve the out-of-order write problem public static Singleton getInstance() { if (instance == null) { ...

Hibernate SessionFactoryBean for multiple locations of mapping files

We have a project consisting of multiple subprojects. With each subproject we potentially have some hibernate mapping files but in the end only one actual hibernate session. Those subprojects could be combined in several ways, some depend on each other. My problem is that actually I want to have a SessionFactoryBean which would be able t...

Dynamically instantiate a Ruby class similar to Java

How can this line in Java be translated to Ruby: String className = "java.util.Vector"; ... Object o = Class.forName(className).newInstance(); Thanks! ...

Is there a way to establish a HTTPS Connection with Java 1.3?

I have to work on an old 1.3 JVM and I'm asked to create a secure connection to another server. Unfortunately the HttpsURLConnection only appears sinc JVM 1.4. Is there another way to create a secure connection? Is there a library that I could you to add this fonctionnality? ...

obtaining a requestDispatcher

What is the benefit of using the servletContext as opposed the request in order to obtain a requestDispatcher? servletContext.getRequestDispatcher(dispatchPath) and using argRequest.getRequestDispatcher(dispatchPath) ...

Do Java listeners need to be removed? (In general)

Imagine this sample java class: class A { void addListener(Listener obj); void removeListener(Listener obj); } class B { private A a; B() { a = new A(); a.addListener(new Listener() { void listen() {} } } Do I need to add a finalize method to B to call a.removeListener? Assume tha...

How to create ArrayList (ArrayList<T>) from array (T[]) in Java

I have an array that is initialised like: Element[] array = {new Element(1),new Element(2),new Element(3)}; I would like to convert this array into an object of the ArrayList class. ArrayList<Element> arraylist = ???; I am sure I have done this before, but the solution is sitting just at the edge of my memory. ...

Why do SocketChannel writes always complete for the full amount even on non-blocking sockets?

Using the Sun Java VM 1.5 or 1.6 on Windows, I connect a non-blocking socket. I then fill a ByteBuffer with a message to output, and attempt to write() to the SocketChannel. I expect the write to complete only partially if the amount to be written is greater than the amount of space in the socket's TCP output buffer (this is what I exp...

How do you restrict the size of a file being uploaded with JavaScript (or Java) without transferring the entire file?

Is there a way to validate on the client side browser whether the size of a file being uploaded from a JSP page is over a set size limit without forcing the user to upload the entire file only to find out it was too large? I would like to stay away from any proprietary controls or techniques like Flash or ActiveX if possible. Thanks! ...

Why would you ever implement finalize()?

I've been reading through a lot of the rookie Java questions on finalize() and find it kind of bewildering that no one has really made it plain that finalize() is an unreliable way to clean up resources. I saw someone comment that they use it to clean up Connections, which is really scary since the only way to come as close to a guarant...

http/AJAX (GWT) vs Eclipse gui for thin client deployment

I am starting a project for which we will have a thin client, sending requests and getting responses from a server. We are still in the planning stages, so we have a choice to settle on either an Eclipse based GUI (Eclipse plugin) or using GWT as a fromtend for the application. I am not very familiar with Eclipse as a GUI (Nor with GWT...

Is there a way to run a method/class only on tomcat startup?

I have a need to remove temp files on tomcat startup, the pass to a folder which contains temp files is in applicationContext.xml Is there a way to run a method/class only on tomcat startup? ...

Tomcat 6: how to delete temporary files after a web method call has ended?

I have a temporary file with data that's returned as part of a SOAP response via a MTOM binary attachment. I would like to trash it as soon as the method call "ends" (i.e., finishes transferring). What's the best way for me to do this? The best way I can figure out how to do this is to delete them when the session is destroyed, but I'...

MainSoft Grasshopper, .Net to Java

I just stumbled upon MainSoft's Grasshopper, which claims to cross-compile .Net ILM to Java bytecode. It seems to use the Mono implementation of the .Net libraries. All of the samples refer to web apps, but my requirement would be to cross-compile a .Net API (class library) to a Java API so that Java clients can use the API. Does anyone ...

How do I delete a dirset of directories with Ant?

I want to delete all directories and subdirectories under a root directory that are contain "tmp" in their names. This should include any .svn files too. My first guess is to use <delete> <dirset dir="${root}"> <include name="**/*tmp*" /> </dirset> </delete> This does not seem to work as you can't nest a dirset in a...

Implementation Patterns: a function returns a Date, but it is reasonable that a date won't be found, return null or try to apply the NULL object pattern?

So let's say you have a function that returns a date Date myFunc(paramA, paramB){ //conditionally return a date? } So is it appropriate to return null from this function? This seems ugly because it forces clients to check for null. The "null object" pattern is an implementation pattern that addresses this concern. I'm not a hug...