Tuesday 12 November 2013

How can I get a list of all the implementations of an interface programmatically in Java?


Polymorphism



Polymorphism

When one action is performed by different ways i.e. known as polymorphism. For example: to convense the customer differently, to draw something e.g. shape or rectangle etc.
In java, we use method overloading and method overriding to achieve polymorphism.
Another example can be to speak something e.g. cat speaks meaw, dog barks woof etc.

Saturday 9 November 2013

How to know from where a Class was loaded in Java

import java.security.ProtectionDomain;
import java.io.*;
public class CodeLoc
{
    public void codeLoc()
    {
        ProtectionDomain protectionDomain = getClass().getProtectionDomain();
        File codeLoc = new File(protectionDomain.getCodeSource().getLocation().getFile());
        System.out.println("--------codeLoc="+codeLoc);
    }
    public static void main(String []args)
    {
        CodeLoc cl=new CodeLoc();
        cl.codeLoc();
    }
}

Sunday 3 November 2013

Apply liferay search indexer to custom portlets

Please follow the steps given below if you want , Your custom portlets data to be search by Liferay search portlet.

1.Create custom indexer class that extends BaseIndexer.

2.Make custom class indexer entry in liferay-portlet.xml for example,just beneath <icon> tag.

3.Write codes mentioned below in xxxabcLocalServiceImpl class methods ,for example add,delete .

Indexer indexer = IndexerRegistryUtil.getIndexer(xxxabc.class);

for add and update method

indexer.reindex(object of class);

for delete method you should write like

indexer.delete(object of class);

4.Now deploy your portlet and goto Liferay Portal.

5.Add search portlet to page.

6.Click on search portlet configuration.

7.Click on advance button.

8.Add your model name as already entered there, for example BlogsEntry,DLFileEntry.