What is an example of the use of Application.UnprocessedKeyHandler in Apache Pivot? - apache-pivot

What is an example of the use of Application.UnprocessedKeyHandler in Apache Pivot? I've checked Google and the Pivot docs and see no examples, and the Javadoc isn't enlightening. There's a tease of sample code in the mailing list archives, but the code attachment is not available.
Thanks!

The answer is really simple, the Javadoc confused me for some reason. Just add the UnprocessedKeyHandler interface to whatever class in the project is implementing org.apache.pivot.wtk.Application, and then of course implement in that class the methods from the interface.
A start of an example would be to take, say:
public class HelloWorld implements Application
And change it to:
public class HelloWorld implements Application, UnprocessedKeyHandler
The thread that led to this solution can be found here.

Related

Location of Documentation for Groovy Process.waitFor()

I am trying to find the javadoc style documentation for Groovy's Process.waitFor() method.
I am currently using the method, so I know it exists.
It is shown in example code on the codehaus website: http://groovy.codehaus.org/Process+Management
Yet, it is not referenced in the Groovy documentation for Process:
http://groovy.codehaus.org/groovy-jdk/java/lang/Process.html
I would think this would be easy to Google for, but so far no luck.
The waitFor method is in Java's Process class

Webappclass loader unable to load superclass in a hook?

I am using liferay ce 6.1.0.I need to extend LayoutAction class in a hook.But the class cannot be loaded in the hook by the class loader
Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/action/LayoutAction
java.lang.ClassNotFoundException: com.liferay.portal.action.LayoutAction
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
Is this the issue with the class loader or am I supposed use a different subclass of the following in order to extends.
Thanks in advance
I want to override includeLayoutContent() method of LayoutAction class in order to have a track on the number of views of a page.If this class cannot be extended,is there any other means or class which can be extended to achieve the same
com.liferay.portal.action.LayoutAction is in portal-impl.jar, which is not available to hooks. Therefor you cannot do this.
If you would give us a hint what you want to achieve with this, somebody might be able to tell you how to do what you want to do.
With your added information I'll give you a hint: Typically, a write operation for every pageview is considered to be quite expensive: Your portal's performance will suffer from this. I'd rather advise to use external tools like google anayltics, piwik or similar ones to generate statistics, including the pageviews for specific pages.
Another method, if you can live with the lower potential performance, is to embed such a method in your theme - the theme gets access to the current page and can execute additional functionality with this. Preferably you'll position this at the end of the page, when everything else has already been rendered and sent to the client.

What is the difference between a Groovy object and a Java object with regards to functionality in Groovy code?

First of all, excuse me if I say something obvious because I did not research the answer to this question, it's just something that came to mind and couldn't find an answer to with a quick google search (I also don't know Groovy well).
I'm reading Groovy in action (1st ed) and in section 7.6 it states that "If you want a usual Java class to be recognized as a Groovy class, you only have to implement the GroovyObject interface. For convenience, you can also subclass the abstract class GroovyObjectSupport, which provides default implementations."
So I'm trying out some Java/Groovy (trying to find ways to make coding in Java faster/easier), and I'm instantiating this object Person, which is a Java object and the Person class does not have anything to do with Groovy (i.e. doesn't implement GroovyObject or anything). Person has a protected field, name, with getters/setters. I am able to access this like so in a groovy test case (extends GroovyTestCase), which btw is in a different package and should not be accessible like this:
Person person = new Person('joe')
println "Name: ${person.name}"
Isn't that using the meta info which a Groovy object would have i.e. Groovy would intercept, get the "name" part of "person.name" and call the getName() method or something like that? But person is a Java object... i.e. it shouldn't have that logic available.
I have not implemented GroovyObject or extended GroovyObjectSupport, yet it seems like this Java object has Groovy features I can use.
My question is, what can I assume from Java objects used in Groovy? There is obviously something being done behind the scenes to augment Java defined classes with some Groovy features... but, which features?
So, I guess my question boils down to: "What is done to Java classes when used within a Groovy context?"
Any info regarding the subject would be appreciated, thanks :)
Groovy indeed enhances your Java classes. The problem is when you want to use these enhanced Java classes from Java. Then you need to go for the GroovyObject and GroovyObjectSupport strategy.
About what you can expect, you can check the groovy docs:
the groovy-jdk shows the Groovy enhancements to the JDK
the groovy-api shows the stuff specific from the Groovy library
Also the eclipse plugin works great in autocompleting your Java classes from Groovy.
Java objects are enhanced through Groovy's Meta Object Protocol (MOP), which intercepts and makes its own dispatch to methods and attributes. That is why you can intercept stuff and that's how new methods are added to Java's final classes.
The Groovy's MOP uses cached strategy and reflector classes to achieve a good performance.
You can also read Groovy objects via ObjectInputStream by overriding the resolveClass method and changing the class loader.
See http://www.feiteira.org/2013/04/reading-groovy-objects-from-java.html

How add custom method and fields to Liferay User model class

I want to add 3 more methods and one field to liferay.portal.model.User class. Anyone knows how can I do this? Can I switch the class by hook like this:
<service>
<service-type>com.liferay.portal.model.User</service-type>
<service-impl>my.pack.userExpanded</service-impl>
</service>
I want to have a close look at service builder but can't find good sources which will show how to switch liferay class with my own class (cause of too many uses).
So second question is does anyone know about some good tutorial or blogs regarding this? Especially I am interested in adding extra methods and fields.
The standard Liferay Developer Documentation is good:
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/overriding-a-portal-servi-4
Another alternative is to add Custom Fields to User entity:
You can't modify a liferay entity. Neither you can use hook to modify these things, hook can only modify limited things as suggested by the documentation.
I don't think you can even use a EXT to modify a liferay entity.
So now the what comes to my mind remains is to create custom-fields for your field requirement and build a helper utility class which will provide you with your required User methods.
You can make the helper class available to the portal by packaging in a jar and pasting it in the global path (in tomcat [TOMCAT_HOME]/lib/ext).

Dynamically create class that mocks another class (like remotingProxy) in haxe

I want to be able to dynamically create a new class that has all of the methods of another class. In particular, I want to make my own kind of remoting proxy.
class ApiProxy extends haxe.remoting.Proxy { }
The new class ApiProxy would have all of the same method names and signatures as Api, and would be compile time checked. Only every invocation is done over the wire, instead of handled locally.
I think that remoting.Proxy is a magic internal class - is this true? Do regular users have the ability to define a class that is as powerfully static as this? I've never seen this done in Java and I'm impressed with it's capabilities in Haxe.
How would I implement my own class like remoting.Proxy?
you can achieve this with macros
take a look at this post to get the idea:
http://haxe.1354130.n2.nabble.com/Macros-Are-Awesome-tc5945711.html
You can write, save to filesystem and register a new Class inside of a Macro, based on type information that was passed to the function.
haxe.remoting.Proxy is indeed "magic", it is described that way in the source comments:
http://code.google.com/p/haxe/source/browse/trunk/std/haxe/remoting/Proxy.hx?r=3592
You can't replicate with "normal" haxe code. Adding/modifying functionality to haxe.remoting.Proxy for your own class will be difficult, but maybe not impossible.
Check the tutorial for the "equivalent" api implementing code:
http://haxe.org/doc/remoting/proxy
However, something like this is probably possible with macros:
http://haxe.org/manual/macros
Working with macros is challenging right now. There is little in the way of documentation or examples, and the macro feature is still under development. However, it lets you have a some control over the compiler during the compilation process, which can be amazingly useful at times.
good luck!

Resources