java

Best Framework For Accessing OpenLDAP With Seam & JBoss AS?

We are currently implementing a portal to our web based services. The portal and services are written with Seam and we are using OpenLDAP to store the security data such as users, groups and permissions. So far we have looked at writing our own code to access LDAP but are there any existing APIs that we could use? ...

Calling a method on thread termination

I am writing a java program which tracks as threads are created in a program and is then supposed to perform some work as each Thread terminates. I dont see any 'thread termination hooks' out there in the javadoc. Currently the only way I can think of to achieve my requirement is to hold on to the thread objects and query its 'state' a...

What is native implementation in Java

If we look at the Java Object class then we can find some of the methods like public native int hashCode(), protected native Object clone(), so my question is what are these natives and how do these methods work? ...

Retrieving type parameters from an instance of a generic base interface

Hello, Given 2 interfaces: public interface BaseInterface<T> { } public interface ExtendedInterface<T0, T1> extends BaseInterface<T0> {} and a concrete class: public class MyClass implements ExtendedInterface<String, Object> { } How do I find out the type parameter passed to the BaseInterface interface? (I can retrieve the Extend...

How to do simple Spring JDBC transactions outside the IoC container?

The project I'm working on uses straight JDBC data access in all its boilerplate glory and doesn't use any transactions. I feel like using transactions and simplifying the way data access methods are written is important, especially with some changes being made currently. The project has been around for quite a while and isn't suited to ...

How to prevent piracy for java webstart application

I have this java swing application that I intend to sell over the internet. At the moment I'm leaning towards deploying the application using java webstart. The product will be licensed for the user to use the program on one computer at a time only. I am concerned about piracy with this model. I would like to install some security fe...

Java IO implementation of unix/linux "tail -f"

I'm wondering what techniques and/or library to use to implement the functionality of the linux command "tail -f ". I'm essentially looking for a drop in add-on/replacement for java.io.FileReader. Client code could look something like this: TailFileReader lft = new TailFileReader("application.log"); BufferedReader br = new BufferedRea...

how can I wait for a java sound clip to finish playing back?

I am using the following code to play a sound file using the java sound API. Clip clip = AudioSystem.getClip(); AudioInputStream inputStream = AudioSystem.getAudioInputStream(stream); clip.open(inputStream); clip.start(); The method call to the Clip.start() method returns immediately, and the system playbacks the sound...

Pass JSP output stream to a method

I've created a class MyClass that intends to output a large amount of text to a JSP. Rather than having the MyClass object return a string to be displayed on the page, I figured it would be a better idea for the MyClass object to use the page's output stream. Is this a good/possible idea? In testing possible ways to do this... These ou...

IPv4/IPv6 network calculations and validation for Java?

I am looking for a package that is similar to Net_IPv4 and Net_IPv6 but written for Java. It needs to be able to do the following: Verify an address is valid (e.g. 127.0.0.1 is valid, 127.0.0.257 is not) Return if an address is contained within a subnet (e.g. 127.0.0.11 is in 127.0.0.0/28) Return the broadcast address for a given subn...

How a servlet can get the absolute path to a file outside of the servlet?

We have been using System.getProperties("user.dir") to get the location of a properties file. Now that it has been deployed on Tomcat(via servlet), the System call is giving the location as tomcat and not at the location at where the properties file exist. How can we call the the properties file dynamically? Given: Tomcat is not t...

What's the best way to duplicate/extend a static class's functionality?

The application I'm working on has a single class that maintains a database connection. All members of this class are static to enforce a singleton-like pattern, so the actual connection logic is performed in a static initializer block: public class HibernateUtil { private static final SessionFactory sessionFactory; static { ...

Knowledge Management Toolkits

I am writing software (in Java) that requires a mechanism for maintaining for a group of simulated people (agents): Facts they know Things they believe What they think others are doing What they think others think I call something like this Knowledge Management (I know this term means different things in different fields, I'm talking...

Arrays as proper objects

I have written a page here on using arrays as proper objects with their own methods instead of relying on helper classes like Arrays, Arrays and ArrayUtils. ints.sort(); // instead of Arrays.sort(ints); // instead of int[] onemore = ArrayUtils.add(ints, 8); int[] onemore = ints.add(8); I am sure I am not the first with this idea but...

Most efficient way to see if an ArrayList contains an object in Java

I have an ArrayList of objects in Java. The objects have four fields, two of which I'd use to consider the object equal to another. I'm looking for the most efficient way, given those two fields, to see if the array contains that object. The wrench is that these classes are generated based on XSD objects, so I can't modify the classes...

Problem with JSP EL evaluation

Why doesn't the following work: <c:set var="formId" value="#${otherFormId}"/> where <c:set var="formId" value="# ${otherFormId}"/> notice the space ^ works fine (though is invalid for my purposes). Im trying to prepend ${otherFormId} with a # symbol (i.e. creating jquery id selector). The first form ends up with #${o...

How do I get a HttpServletRequest in my spring beans?

I'm developing an app with a Flex-based front end and a Spring/Hibernate back-end. To get Facebook integration working in the way I've got it currently, I need to read the cookies set in javascript on the front end on the back-end and do some validation during login to see whether the user is attempting to spoof his Facebook login. Thi...

How to use regular expressions to match everything before a certain type of word

Hi, I am new to regular expressions. Is it possible to match everything before a word that meets a certain criteria: E.g. THIS IS A TEST - - +++ This is a test I would like it to encounter a word that begins with an uppercase and the next character is lower case. This constitutes a proper word. I would then like to delete everything...

Java implementation of JSON to XML conversion.

Are there existing JARs available to convert from JSON to XML? ...

How to view recent CVS project changes in Eclipse?

Is there a way in Eclipse to view all recent changes of a project? Like in SVN, you can just go "view log" on a right-click menu of a folder. In CVS/Eclipse, I can only view history on a certain file. I am not able to see what files were changed in the last commit. >.<'' Thank you! ...