java

Spring @Transactional Annotation Best Practice

We are currently discussing the Best Practice for placing the @Transactional annotations in our code. Do you place the @Transactional in the DAO classes and/or their methods or is it better to annotate the Service classed which are calling using the DAO objects? Or does it make sense to annotate both "layers"? ...

Java File Transfer API

I need to transfer files to my web server for processing and I'd like to do it in a generic way if possible. I need to be able to transfer files from the following protocols at a minimum (with more to follow eventually): HTTP FTP SCP I'd really like to be able to send files to SMTP also So my question, is there a toolkit available ...

How to mock a String using mockito?

I need to simulate a test scenario in which I call the getBytes() method of a String object and I get an UnsupportedEncodingException. I have tried to achieve that using the following code: String nonEncodedString = mock(String.class); when(nonEncodedString.getBytes(anyString())).thenThrow(new UnsupportedEncodingException("Parsing erro...

Class object of generic class (java)

is there a way in java to get an instance of something like Class<List<Object>> ? ...

Java: Simple technique for annotation-based code injection?

Is there a way to make this code work? LogonControl.java @Audit(AuditType.LOGON) public void login(String username, String password) { // do login } AuditHandler.java public void audit(AuditType auditType) { // persist audit } Endgame being, that each time login() is called, audit() is also called, with the appropriate audittype...

App engine datastore: How to implement Posts and Tags without joins?

I'm building an application in Google App Engine (Java), where users can make posts and I'm thinking in adding tags to these posts, so I will have something like this: in entity Post: public List<Key> tags; in entity Tag: public List<Key> posts; It would be easy to query, for example, all posts with a certain tag, but how could I ...

How Can a SuperClass name be retrieved from a java file using ASTParser?

I need to retrieve SuperClass name of a java file (which extends a class, i need that class name). In order to do this, I began to use ASTParser but I'm newbie so any example or illustration can be helpful. I use ASTView to comprehend which ways that AST keeps a java file structure but I'm stuck while trying visit(), endvisit() functions...

Regular expression to get an attribute from HTML tag

I am looking for a regular expression that can get me src (case insensitive) tag from following HTML snippets in java. <html><img src="kk.gif" alt="text"/></html> <html><img src='kk.gif' alt="text"/></html> <html><img src = "kk.gif" alt="text"/></html> ...

showing dialog from run method

hi, I am trying to pop up dialog from run method it gives me exception that Looper.prepare not called ,when i call the same method i dont get any exception but there is no pop up dialog shown on the console .As i have used handler in this way , handler = new Handler() { public void handleMessage(Message msg) { ...

Corba sequence<octet> a lot slower than using a socket

I have a corba releated question. In my Java app I use typedef sequence Data; Now I played around with this Data vector. If I am right with the Corba specification sequence will either be converted to xs:base64Binary or xs:hexBinary. It should be an Opaque type and so it should not use any marshalling. I tried different idl styles: v...

Maven Plugin to automatically generate setters/getters?

Is there a Maven Plugin that will automatically generate setters and getters with the corresponding JavaDocs? I am aware that Eclipse/Netbeans will do this when you tell it to; however, it would be nice for the source to simply contain the skeleton and have Maven or another tool generate the repetitive stuff. I would want to modify th...

How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?

I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear The Portal ear file resides in, say /home/foo/bar/ jar xf /home/foo/bar/Portal.ear Binaries.war Will extract the Binaries.war file out of the /home/foo/bar/Portal.ear ...

Spring MVC Domain Object handling Best Practice

Lets assume a simple Spring MVC Controller that receives the ID of a domain object. The Controller should call a service that should do something with that domain object. Where do you "convert" the ID of the domain object into the domain object by loading it from the database? This should not be done by the Controller. So the service m...

good example of Javadoc

is there a good example of a source file containing Javadoc? I can find lots of good examples of Javadoc on the internet, I would just like to find out the particular syntax used to create them, and assume I can pore through the source of some library somewhere but that seems like a lot of work. ...

Passing variable name into GWT's JSNI

Using the JavaScript Native Interface of GWT I can perform the following: public native static String getNativeVariableFoo() /*-{ return $wnd.foo; }-*/; Which will return the contents of a JavaScript variable called foo. How can I expand upon this to accept the variable name as a parameter? ie: public native static String getNat...

What's an example of duck typing in Java?

I just recently heard of duck typing and I read the Wikipedia article about it, but I'm having a hard time translating the examples into Java, which would really help my understanding. Would anyone be able to give a clear example of duck typing in Java and how I might possibly use it? ...

No public execute() in class org.apache.jasper.JspC

I got the error "No public execute() in class org.apache.jasper.JspC" when I tried to build(ant build) the xml file. could you please suggest a solution? thanx in advance ...

How can I load jar files for debugging in Jython?

The title says it all ...

Why do pythonistas call the current reference "self" and not "this"?

Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP. I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self" : the program will work fine. So where does this convention ...

Sorting a List of LIst by the Value of the sublist

private List<String> subList; private List<List<String>> records = new ArrayList<List<String>>(); for(....){ subList = new ArrayList<String>(); ...populate.. records.add(subList); } For example, subList has three Strings - a, b, and c. I want to sort the records by the value of b in subList. records at 0 has a list of "...