java

Accessing Spring bean *not* by dependency injection

We have some domain objects that are created at runtime - not by Spring. These domain objects need access to some service type beans that are being managed by Spring. How can the domain objects that are created at runtime access Spring beans dynamically (not by DI)? ...

Troubleshooting DataNucleus JDO

I am using the Eclipse plugin for Google App Engine 1.2.6 and Web Toolkit 1.7.1 DataNucleus/JDO is driving me mad! I suspect either my creates are silently erroring out before being written AND/OR the reads are inconsistently populating the objects. I could use some tips on figuring out what is really happening. Using a minimally unm...

Is there a way to use a list of string parameters with a regular expression (with groups) to construct a new string?

Let's say for example that I have a regular expression like this: "The quick (red|brown|blue|yellow) fox (jumps|leaps) over the lazy (dog|cat)." This regex has 3 grouped components - if it's matched against a given string, the regex api would allow you to easily extract the value inside each group. Now let's say I have 3 strings: [...

(Java newbie) Instantiating unknown number of objects

Java/OO newbie question: main instantiates Track class. Now I want that object--track1--to instantiate many Clip objects, the number of which will not be known until runtime. From inside the Track class I can make a new Clip like this: Clip clip1 = new Clip(); // this is track1.clip1 from main But when I want to add more clips based...

Problem with Sun Java KeyManagerFactory and null passwords

We are having a problem with the KeyManagerFactory in the Sun JRE 1.6. We are using code similar to the following to upload and use a certificate in p12 format: KeyStore keyStore = KeyStore.getInstance(PKCS12); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(SUN_X509); InputStream certificateFile = getSSLCertificat...

Datastore entity with kind and key has a null property named

After adding a boolean attribute to an object, fetching that object from the datastore results in the error: Datastore entity with kind <Class> and key <Class:ID> has a null property named <attribute> ...

Sorting an ArrayList of Contacts

Ok so I have a been making an addressbook application and have pretty much finished all the key features but I am looking to implement a sort feature in the program. I want to sort an Arraylist which is of a type called Contact (contactArray) which is a separate class which contains four fields; name, home number, mobile number and addr...

Ant + JUnit4 ClassDefNotFoundException - Classpath Issue?

[Edit] Solved, small mistake done by me being an ant beginner. In the test target, it needs to be <classpath refid="my.classpath"/> instead of <classpath id="my.classpath"/>. That obviously overwrote my defined classpath property. That makes it clear that ant is not able to find the library. Note to me: rtfm![/Edit] First things first: ...

Java help. How to draw images

Hi I'm starting to work on this project where I need to have a picture (map of the US) and then I need to circles of different sizes on the map at different locations. Something like this: http://www.npr.org/templates/story/story.php?storyId=110997398 What's the best way to go about doing it? I've never dealt with Java 2-d but I'm guess...

Hibernate and Flyweight

Is there a way to use Flyweight objects with the hibernating persistence mapping? My data model contains many objects that will be the same. Instead of having a separate instance for each of those same objects I'd like to use the Flyweight Design Pattern and reference always the same physical object. How to achieve this in hibernate? Bt...

Is there a use case for creating threads without synchronization and locks?

Since thread execution happens in a pool, and is not guaranteed to queue in any particular order, then why would you ever create threads without the protection of synchronization and locks? In order to protect data attached to an object's state (what I understand to be the primary purpose of using threads), locking appears to be the only...

Get ServletContext on tomcat from jax-rs / jersey

I'm playing around with jax-rs , deploying on tomcat (handling via com.sun.ws.rest.spi.container.servlet.ServletContainer). It's basically @Path("/hello") @Produces({"text/plain"}) public class Hellohandler{ @GET public String hello() { return "Hello World"; } } Is there any way I can get hold of the ServletContext w...

Problem building executable jar with maven

I am trying to generate an executable jar for a small home project called "logmanager" using maven, just like this: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven I added the snippet shown there to the pom.xml, and ran mvn assembly:assembly. It generates two jar files in logma...

Linux\BSD Network Programming

Looking to write an SNMP and Netflow tool for Linux\BSD and seeking advice on language selection, C or Java. The tool will collect Netflows, send and recieve SNMP queries, connect to a Postgresql Databases and will be fronted by a web interface (PHP), in the future it will interface with devices using web services. Normally I would hav...

Why does QuickTime QTSession.open fail when packaged using OSX Jar Bundler?

I am using QuickTime for Java to display video within a Java desktop application. Everything works fine when this application is built as a jar file, but for some reason when I use this maven plugin to package the application to look like a native OSX application bundle, the following code: try { QTSession.open(); } catch (Throwable t...

Java generic parameter itself using generics?

I'm trying to figure out how to structure a program using Java's generics, and wondering if I am doing something fundamentally wrong or just missing a simple bug in my code. Say I have a generic class: public interface Handler<T>{ public void process(T t); } Another generic class takes Handler as a generic parameter (pseudo code):...

Using JOptionPane

if i was using a JOptionPane message dialog box how would I be able to show an the whole array in the message section such as this little snipit? or would that evenbe possible? public void showTheMessage() { JOptionPane.showMessageDialog(null,"These are are all the colors to choosfrom,\n"+ arrayOfcolors[the whole array], "...

Locks in Synchronized Blocks.

I just need a confirmation that i have understood the concept of locks in synchronized blocks correctly. First I will tell what I have understood. Acquiring a lock of an object means that no other thread can access the synchronized code of the object's class. In case of synchronized methods, Threads acquire lock on the object used to inv...

Need to write interrupt based java module

Hi, I want to write a interrupt based java module. which will raise a read interrupt when ever any data received from UDP socket. So that i need not to poll every time to check if data is preasent. Please help. Regards, Aj ...

Using the ternary operator to determine a variable is not null and assigning it to another

Is this an acceptable coding practice? public class MessageFormat { private static final Color DEFAULT_COLOR = Color.RED; private Color messageColor = DEFAULT_COLOR; public MessageFormat(Person person) { Color color = person.getPreferredColor(); messageColor = (color != null) ? color : messageColor; // this...