java

Eclipse Abstract Syntax Tree Programmatic Access

Could you provide an example of accessing the Eclipse Abstract Syntax Tree programmatically for a given piece of code? eg getting the AST for: Class1.java package parseable; public class Class1 { /** * @param args */ public static void main(String[] args) { System.out.println("Hello world!"); } } ...

Exception when not finding

What is the rationale behind throwing an exeption in JPA, when something can't be found? Added: This behaviour was seen in EJB2, and has as far been removed from EJB3 - but... It remains when calling Query#getSingleResult() which throws a NoResultException. Normally I would not expect it to be an exception that something could not be fo...

Error with no HashCode, Equals eclipse

Hi, I'm looking for a very specific eclipse plugin that will tell me if a class in my project is not implementing hashCode or/and equals methods. Does anyone know of such a plugin? Thanks ...

Java-based eCommerce Framework

Is there a good java-based eCommerce Framework that you can recommend? I need to implement a quite sophisticated frontend for my customer and most 'ready-to-roll' shopping carts are a mess when it comes to customizing the frontend and changing the application flow. ...

Why can't I use a type argument in a type parameter with multiple bounds?

So, I understand that the following doesn't work, but why doesn't it work? interface Adapter<E> {} class Adaptulator<I> { <E, A extends I E>> void add(Class<E> extl, Class<A> intl) { addAdapterFactory(new AdapterFactory<E, A>(extl, intl)); } } The add() method gives me a compile error, "Cannot specify any additional bou...

Parameterized test case classes in JUnit 3.x

I have a JUnit 3.x TestCase which I would like to be able to parameterize. I'd like to parametrize the entire TestCase (including the fixture). However, the TestSuite.addTestSuite() method does not allow be to pass a TestCase object, just a class: TestSuite suite = new TestSuite("suite"); suite.addTestSuite(MyTestCase.class); I ...

When should I call Naming.unbind()?

I have some code which I am making available via RMI. If my program terminates abnormally, I won't have called Naming.unbind(), and a reference to the object will presumably be hanging around in the RMI registry, and subsequent calls to Naming.bind() with the same name will fail. How do I make sure that rogue references are cleared up?...

Hibernate: Criteria vs. HQL

What are the pros and cons of using Criteria or HQL? The Criteria API is a nice object-oriented way to express queries in Hibernate, but sometimes Criteria Queries are more difficult to understand/build than HQL. When do you use Criteria and when HQL? What do you prefer in which use cases? Or is it just a matter of taste? ...

Hibernate @ManyToMany mapping with composite keys

Hello ! I'm trying to map a ManyToMany relationships between 2 tables, both having composite primary keys LSFOCTB which primary key is composed of : LSFOC_CODSOC,LSFOC_CODLSC,LSFOC_CODFOC LSFORTB which primary key is composed of : LSFOR_CODSOC,LSFOR_CODLSC,LSFOC_CODFOR The table in charge of the ManyToMany relationship is : LSFCFTB,...

Transferring files between web applications running in the same Tomcat Instance

I have two web applications running in the same Tomcat Instance. In one of these applications the user will have the ability to upload files such as images and pdf files. I would like the uploaded files to be available to the second application. Is there a best practice for such a scenario? Or just a pointer to a technology would be fi...

Is there a text wrap function in the java standard library?

The Python standard lib comes with the module textwrap which provides a simple text wrapping functionality. Is there something comparable in the java standard library? in Python it is something like this: >>> t = "a really really long string with lots of characters" >>> import textwrap >>> textwrap.wrap(t, 20) ['a really really long', ...

Why an abstract class implementing an interface can miss the declaration/implementation of one of the interface's methods?

A curious thing happens in Java when you use an abstract class to implement an interface: some of the interface's methods can be completely missing (i.e. neither an abstract declaration or an actual implementation is present), but the compiler does not complain. For example, given the interface: public interface IAnything { void m1()...

Java workflows

Does anyone have experience implementing any of the available open source solutions? If so, which solution would be your recommendation? ...

What causes javac to issue the "uses unchecked or unsafe operations" warning

For example: javac Foo.java Note: Foo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. ...

Need a distributed key-value lookup system

I need a way to do key-value lookups across (potentially) hundreds of GB of data. Ideally something based on a distributed hashtable, that works nicely with Java. It should be fault-tolerant, and open source. The store should be persistent, but would ideally cache data in memory to speed things up. It should be able to support concur...

eclipse beakpoint: stop before leaving a Java method

Is there a way to tell the debugger to stop just before returning, on whichever statement exits from the method, be it return, exception, or fall out the bottom? I am inspired by the fact that the Java editor shows me all the places that my method can exit - it highlights them when you click on the return type of the method declaration, ...

How can I replace the current Java process, like a unix-style exec?

I have a server written in Java that runs as a Windows service (thanks to Install4J). I want this service to be able to download the latest version of the JAR file it runs from, and start running the new code. The stitch is that I don't want the Windows service to fully exit. Ideally, I would accomplish this by a unix-style exec() cal...

How to Parsing "Event XML" in Java?

I'm looking to use Java to parse an ongoing stream of event drive XML generated by a remote device. Here's a simplified sample of two events: <?xml version="1.0"?> <Event> DeviceEventMsg <Param1>SomeParmValue</Param1> </Event> <?xml version="1.0"?> <Event> DeviceEventMsg <Param1>SomeParmValue</Param1> </Event> It seems like SAX is mo...

checkstyle + suppression filters

I have a checkstyle suppression filter setup (e.g. ignore magic numbers in unit test code). The suppression xml file resides in the same folder as the checkstyle xml file. However, where this file actually is varies: on my windows dev box it is in d:\dev\shared\checkstyle\config on the Linux CI server it will be in /root/repo/shared/che...

How do you compare two version Strings in Java?

Is there a standard idiom for comparing version numbers? I can't just use a straight String compareTo because I don't know yet what the maximum number of point releases there will be. I need to compare the versions and have the following hold true: 1.0 < 1.1 1.0.1 < 1.1 1.9 < 1.10 ...