There are several performance issues that you should keep in mind while deploying XML parsing in a MIDP application:

  • Increase in size: An XML parser is code-intensive and increases the overall size of an application. This is a particularly important consideration for resource-constrained MIDP devices. There are several optimization techniques you can use to fight code expansion. First, you should remove resource files that are not in use. You should also use obfuscators that will remove unused classes, unused methods, and variables from your JAD file.
  • Heavy string parsing: XML parsers use intensive string parsing to perform their jobs; this will add to the overhead in MIDP applications with low runtime memory. XML documents that J2ME applications parse need to be small and contain as much useful information as possible.
  • Slow response time: As the MIDP application parses a relatively large amount of XML data, the response time will increase. The XML files to be parsed should be small, and the parsing should be done in a thread of execution that is separate from the main application.

Problem comes when you want to use rendered, actionListener and action attributes of < a:actionLink> with variable ‘r’.

Actually the problem is not of < a:actionLink> or of ‘r’ value but of the working process of jsf framework itself.
After rendered, JSF again checks the ‘r’ value and call for the action. And at that time it does not find the value of ‘r’ so fails to perform the action means ‘r’ is not available.

Solution:

To solve this problem you can wrap the < a:actionLink> with < a:booleanEvaluator> tag
and then there is no need to use rendered in < a:actionLink> because the condition can be checked in  < a:booleanEvaluator>.

Sample code looks like this:-

< a:booleanEvaluator value=”#{r.myVariable == true/false}” id=”some-id”>

< a:actionLink value=”" id=”newid” image=”someImage.gif” action=”dialog:MyDialog” actionListener=”#{MyDialog.anyAction}” tooltip=”tooltip” showLink=”false”>

< f:param name=”paramName” value=”#{r.paramValue}”/>

< /a:actionLink>

< /a:booleanEvaluator>

Keep AlgoBlogging!!!

Scenario: you need to find noderef of a folder which contains a document of given node id

Solution:

1. First create the NodeRef for the given node id.

StoreRef storeRef = Repository.getStoreRef();
NodeRef documentNodeRef = new NodeRef(storeRef, documentId);

Where documentId is the Node Id for which you are trying to get the parent folder NodeRef.

2. Now you would need to take help of “NodeService” to get the parent folder NodeRef. Suppose you have NodeService available in your bean (you can always get the NodeService from getNodeService() method of ServiceRegistry OR get if from session):

ChildAssociationRef childAssociationRef = this.nodeService.getPrimaryParent(documentNodeRef);
NodeRef documentParentNodeRef = childAssociationRef.getParentRef();

documentParentNodeRef is what you were looking for :)

Happy AlgoBlogging!!!

Using interface as a type
Posted on December 15, 2008

You can use an interface as a data type.Every object you assign to that reference variable must be an instance of the class that implements that interface.

interface MyInterface{
public int isLargerThan(Object o);
}

public class NumberTest implements MyInterface {
int number;

Length(int number) {
this. number = number;
}

public int isLargerThan(Object o) {
int thisNum = this. number;
int anotherNum = ((NumberTest)o). number;
if(thisNum > anotherNum)
System.out.println(thisNum +” is larger than ” + anotherNum);

}
}

public class MyTest {
public static void main(String[] args) {
NumberTest  num1 = new NumberTest(100);
NumberTest  num2 = new NumberTest(50);
NumberTest larger = (NumberTest)findLargest(num1,num2);

/*here num1 and num2 are 2 instances of class NumberTest  which implements MyInterface interface so i can convert these objects in MyInterface type.
*/
System.out.println(”larger = ” + larger);
MyInterface myinterface1 = new NumberTest (12);
MyInterface myinterface2 = new NumberTest (32);
MyInterface myinterface = (MyInterface)findLargest(myinterface1, myinterface2);
System.out.println(”myinterface = ” + myinterface);
}

public static Object findLargest(Object object1, Object object2) {
MyInterface obj1 = (MyInterface)object1;
MyInterface obj2 = (MyInterface)object2;
if (obj1.isLargerThan(obj2) > 0)
return object1;
else
return object2;
}
}