Lets say you have a hash map
Map currencyMap=new HashMap();
currencyMap=someMapYouGot();
//YOu can iterate thru this map using either the entry set or key set
//here is how
Iterator iterator=currencyMap.keySet().Iterator;
while(iterator.hasNext()){
Object key=iterator.next();
System.out.printn("Key is :"+key.toString());
Object value=currencyMap.get(key);
System.out.println("Value is :"+value.toString());
}
//Other way of doing is:
Iterator iterator=currencyMap.entrySet().iterator;
while(iterator.hasNext()){
Map.Entry entry=(Entry)iterator.next();
Object key=entry.getKey();
Object value=entry.getValue();
}
}
//Yet another way of doing is create a collection of values from the map and iterate thru the list:)
//Here is how
List list=new ArrayList();
Collection coll=currencyMap.values();
list.addAll(coll);
--Happy Coding
}
Wednesday, January 31, 2007
Thursday, January 11, 2007
import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
public class ObjectComparator implements Comparator
{
/** Constant to specify a descending sort for the attribute */
public static final int SORT_DESCENDING = 0;
/** Constant to specify an ascending sort for the attribute */
public static final int SORT_ASCENDING = 1;
/** The fully-qualified class name of the object to be sorted */
private String sortObjectClassName;
/** The actual Class object of the object to be sorted */
private Class sortObjectClass;
/** An array of Method objects that correspond to each sort attribute */
private Method sortFieldGetterMethods[];
/** An array of Strings that represent the argument(s) to pass to the getter method (really only necessary for Map objects) */
private String sortFieldMethodArgs[];
/** An integer array that corresponds to each sort attribute's sort order */
private int sortFieldOrder[];
/** If the classes to sort are instances of map, this is set to true */
private boolean isMap;
/**
* Private Constructor - not used
* @exception ObjectComparatorException
**/
private ObjectComparator() throws ObjectComparatorException
{
}
/**
* Constructor for ObjectComparator when passing in the actual object that will be sorted
* by later on. This is an alternative to passing in the fully-qualified class name for the
* objects that will be sorted.
*
* @param sortObject An instance of the object that will be sorted on
* @param sortFields An array of all the field names to sort by
* @param sortFieldOrder An integer array representing the sort order for the fields that will be sorted.
* Should either contain ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
Object sortObject,
String[] sortFields,
int[] sortFieldOrder)
throws ObjectComparatorException
{
this.sortObjectClass = sortObject.getClass();
this.sortObjectClassName = sortObjectClass.getName();
this.checkIsMap();
loadMethods(sortFields, sortFieldOrder);
}
/**
* Constructor for ObjectComparator when passing in the fully-qualified class name of the objects that will be sorted
* by later on. This is an alternative to passing in an instance of the actual object.
*
* @param sortObjectClassName The fully-qualified class name for the objects that will be sorted
* @param sortFields An array of all the field names to sort by
* @param sortFieldOrder An integer array representing the sort order for the fields that will be sorted.
* Should either contain ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
String sortObjectClassName,
String[] sortFields,
int[] sortFieldOrder)
throws ObjectComparatorException
{
try
{
this.sortObjectClass = Class.forName(sortObjectClassName);
this.sortObjectClassName = sortObjectClassName;
this.checkIsMap();
}
catch (ClassNotFoundException e)
{
throw new ObjectComparatorException(
"Error creating ObjectComparator: " + e);
}
loadMethods(sortFields, sortFieldOrder);
}
/**
* Constructor for ObjectComparator when passing in the actual object that will be sorted
* by later on. This is an alternative to passing in the fully-qualified class name for the
* objects that will be sorted. This constructor is also used when you want to sort by a maximum
* of only 3 fields, as opposed to passing in an array of fields to sort by.
*
* @param sortObject An instance of the object that will be sorted on
* @param sortField1 First field to sort by
* @param sortField1SortOrder Sort order for first field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField2 Second field to sort by
* @param sortField2SortOrder Sort order for second field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField3 Third field to sort by
* @param sortField3SortOrder Sort order for third field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
Object sortObject,
String sortField1,
int sortField1SortOrder,
String sortField2,
int sortField2SortOrder,
String sortField3,
int sortField3SortOrder)
throws ObjectComparatorException
{
this.sortObjectClass = sortObject.getClass();
this.sortObjectClassName = sortObjectClass.getName();
this.checkIsMap();
loadMethods(
sortField1,
sortField1SortOrder,
sortField2,
sortField2SortOrder,
sortField3,
sortField3SortOrder);
}
/**
* Constructor for ObjectComparator when passing in the fully-qualified class name of the objects that will be sorted
* by later on. This is an alternative to passing in an instance of the actual object.
* This constructor is also used when you want to sort by a maximum
* of only 3 fields, as opposed to passing in an array of fields to sort by.
*
* @param sortObjectClassName An instance of the object that will be sorted on
* @param sortField1 First field to sort by
* @param sortField1SortOrder Sort order for first field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField2 Second field to sort by
* @param sortField2SortOrder Sort order for second field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField3 Third field to sort by
* @param sortField3SortOrder Sort order for third field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
String sortObjectClassName,
String sortField1,
int sortField1SortOrder,
String sortField2,
int sortField2SortOrder,
String sortField3,
int sortField3SortOrder)
throws ObjectComparatorException
{
try
{
this.sortObjectClass = Class.forName(sortObjectClassName);
this.sortObjectClassName = sortObjectClassName;
}
catch (ClassNotFoundException e)
{
throw new ObjectComparatorException(
"Error creating ObjectComparator: " + e);
}
loadMethods(
sortField1,
sortField1SortOrder,
sortField2,
sortField2SortOrder,
sortField3,
sortField3SortOrder);
}
/**
* Loads the proper getter method for the field
*
* @param sortFields An array of all the field names to sort by
* @param sortFieldOrder An integer array representing the sort order for the fields that will be sorted.
* Should either contain ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
private void loadMethods(String[] sortFields, int[] sortFieldOrder)
throws ObjectComparatorException
{
if (sortFields.length != sortFieldOrder.length)
{
throw new ObjectComparatorException(
"Error creating ObjectComparator. Sort Fields array count "
+ "doesn't match Sort Field Order array count.");
}
//Determine the appropriate Method object for the field to be sorted by
String sortField = "";
int sortOrder = 0;
int length = sortFields.length;
this.sortFieldGetterMethods = new Method[length];
this.sortFieldOrder = new int[length];
this.sortFieldMethodArgs = new String[length];
int getterCount = 0;
for (int i = 0; i < length; i++)
{
sortField = sortFields[i];
sortOrder = sortFieldOrder[i];
if ((sortField != null && sortField != ""))
{
this.sortFieldGetterMethods[getterCount] =
getMethodName(sortField);
if (this.isMap) this.sortFieldMethodArgs[getterCount]=sortField; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[getterCount] = sortOrder;
getterCount++;
}
}
}
/**
* Loads the proper getter method for the field
*
* @param sortField1 First field to sort by
* @param sortField1SortOrder Sort order for first field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField2 Second field to sort by
* @param sortField2SortOrder Sort order for second field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField3 Third field to sort by
* @param sortField3SortOrder Sort order for third field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
private void loadMethods(
String sortField1,
int sortField1SortOrder,
String sortField2,
int sortField2SortOrder,
String sortField3,
int sortField3SortOrder)
throws ObjectComparatorException
{
this.sortFieldGetterMethods = new Method[3];
this.sortFieldOrder = new int[3];
if (sortField1 != null && !sortField1.equals(""))
{
this.sortFieldGetterMethods[0] = getMethodName(sortField1);
if (this.isMap) this.sortFieldMethodArgs[0]=sortField1; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[0] = sortField1SortOrder;
}
if (sortField2 != null && !sortField2.equals(""))
{
this.sortFieldGetterMethods[1] = getMethodName(sortField2);
if (this.isMap) this.sortFieldMethodArgs[1]=sortField2; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[1] = sortField2SortOrder;
}
if (sortField3 != null && !sortField3.equals(""))
{
this.sortFieldGetterMethods[2] = getMethodName(sortField3);
if (this.isMap) this.sortFieldMethodArgs[2]=sortField3; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[2] = sortField3SortOrder;
}
}
/**
* Checks if the Class object currently set and associated with this ObjectComparator
* implements interface Map
*
*/
private void checkIsMap() {
/*
if (this.sortObjectClass.isInstance( aMapObject ) ) {
this.isMap = true;
}
*/
/*
* The method Class.isInstance(Object) above doesn't seem to work. Even when I created
* an explicit instance of the object to sort (like a 'Hashtable'), it never
* detected the correct object type. Instead, I am trying to get a hard instance
* of the object so I can check instanceof, which *does* seem to work. If I can't
* create an instance of the object using the empty constructor, then I'm assuming
* it's not a Map!
*/
try {
Object o = this.sortObjectClass.newInstance();
if (o instanceof Map) {
this.isMap = true;
}
}
catch (InstantiationException e)
{
// Do nothing, just assume it's not a map
/*
throw new ObjectComparatorException(
"could not check for map '"
+ " (map=" + this.isMap + ") findmap: " + findmap.toString()
+ "'. Error is: "
+ e); */
}
catch (IllegalAccessException e)
{
// Do nothing, just assume it's not a map
}
}
/**
* The implementation of the Comparator interface's compare method
*
* @param obj1 The first object to compare
* @param obj2 The second object to compare
* @return int
* @see java.util.Comparator#compare(Object, Object)
**/
public int compare(Object obj1, Object obj2)
{
int returnVal = 0;
try
{
Object obj1FieldValue = null;
Object obj2FieldValue = null;
int length = sortFieldGetterMethods.length;
Method getterMethod = null;
String[] methodArg = null;
for (int i = 0; i < length; i++)
{
getterMethod = sortFieldGetterMethods[i];
methodArg = new String[] { sortFieldMethodArgs[i] };
if (getterMethod != null)
{
if (this.isMap) {
// If we're a Map, we need to invoke get() method with the key as an argument
obj1FieldValue = getterMethod.invoke(obj1, methodArg);
obj2FieldValue = getterMethod.invoke(obj2, methodArg);
} else {
// If we're not a Map, we need to invoke the getter method
obj1FieldValue = getterMethod.invoke(obj1, null);
obj2FieldValue = getterMethod.invoke(obj2, null);
}
if(obj1FieldValue == null){
if (obj2FieldValue instanceof String )
obj1FieldValue = new String();
else if (obj2FieldValue instanceof Integer )
obj1FieldValue = new Integer(0);
else if (obj2FieldValue instanceof Long)
obj1FieldValue = new Long(0);
else if (obj2FieldValue instanceof Float)
obj1FieldValue = new Float(0);
else if (obj2FieldValue instanceof Double)
obj1FieldValue = new Double(0);
else if (obj2FieldValue instanceof Date)
obj1FieldValue = new Date(0);
else obj1FieldValue = new Object();
}
if (obj1FieldValue instanceof String )
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new String();
}
returnVal =
obj1FieldValue.toString().toUpperCase().compareTo(
obj2FieldValue.toString().toUpperCase());
}
else if (obj1FieldValue instanceof Integer)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Integer(0);
}
Integer obj1Integer = (Integer) obj1FieldValue;
Integer obj2Integer = (Integer) obj2FieldValue;
returnVal = obj1Integer.compareTo(obj2Integer);
}
else if (obj1FieldValue instanceof Long)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Long(0);
}
Long obj1Long = (Long) obj1FieldValue;
Long obj2Long = (Long) obj2FieldValue;
returnVal = obj1Long.compareTo(obj2Long);
}
else if (obj1FieldValue instanceof Float)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Float(0);
}
Float obj1Float = (Float) obj1FieldValue;
Float obj2Float = (Float) obj2FieldValue;
returnVal = obj1Float.compareTo(obj2Float);
}
else if (obj1FieldValue instanceof Double)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Double(0);
}
Double obj1Double = (Double) obj1FieldValue;
Double obj2Double = (Double) obj2FieldValue;
returnVal = obj1Double.compareTo(obj2Double);
}
else if (obj1FieldValue instanceof Date)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Date(0);
}
Date obj1Date = (Date) obj1FieldValue;
Date obj2Date = (Date) obj2FieldValue;
returnVal = obj1Date.compareTo(obj2Date);
}
else
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Object();
}
returnVal =
obj1FieldValue.toString().compareTo(
obj2FieldValue.toString());
}
if (returnVal != 0)
{
if (sortFieldOrder[i] == SORT_DESCENDING)
{
returnVal = returnVal * -1;
}
break;
}
}
}
}
catch (Exception e)
{
//Can't throw an exception since the inherited compare method doesn't define it
// That means any exception when comparing the objects goes into a black hole, and
// you won't be able to know why your compare didn't work.
returnVal = 0;
}
return returnVal;
}
/**
* Used to retrieve the 'getter' method, as a Method object, for the passed in field name
*
* @param fieldName The field name
* @return The getter method
* @throws ObjectComparatorException
**/
private Method getMethodName(String fieldName)
throws ObjectComparatorException
{
Method theMethod = null;
String methodName = null;
Class[] parameterTypes = null;
String firstChar = "";
if (fieldName != null && !fieldName.equals(""))
{
if (this.isMap) {
// If we're a Map, we'll always check for method "get()"
methodName="get";
// Object o = new Object();
Object o = new Object();
parameterTypes = new Class[] { o.getClass() };
} else {
// If we're not a Map, check for bean-style get method (i.e. "getMyProperty()")
firstChar = fieldName.substring(0, 1);
if (fieldName.length() >= 2)
{
methodName =
"get" + firstChar.toUpperCase() + fieldName.substring(1);
}
else
{
methodName = "get" + firstChar.toUpperCase();
}
}
}
try
{
theMethod = sortObjectClass.getMethod(methodName, parameterTypes);
}
catch (NoSuchMethodException e)
{
throw new ObjectComparatorException(
"No getter method matches the field name passed in '"
+ fieldName + " (map=" + this.isMap + ") "
+ "'. Error is: "
+ e);
}
return theMethod;
}
}
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
public class ObjectComparator implements Comparator
{
/** Constant to specify a descending sort for the attribute */
public static final int SORT_DESCENDING = 0;
/** Constant to specify an ascending sort for the attribute */
public static final int SORT_ASCENDING = 1;
/** The fully-qualified class name of the object to be sorted */
private String sortObjectClassName;
/** The actual Class object of the object to be sorted */
private Class sortObjectClass;
/** An array of Method objects that correspond to each sort attribute */
private Method sortFieldGetterMethods[];
/** An array of Strings that represent the argument(s) to pass to the getter method (really only necessary for Map objects) */
private String sortFieldMethodArgs[];
/** An integer array that corresponds to each sort attribute's sort order */
private int sortFieldOrder[];
/** If the classes to sort are instances of map, this is set to true */
private boolean isMap;
/**
* Private Constructor - not used
* @exception ObjectComparatorException
**/
private ObjectComparator() throws ObjectComparatorException
{
}
/**
* Constructor for ObjectComparator when passing in the actual object that will be sorted
* by later on. This is an alternative to passing in the fully-qualified class name for the
* objects that will be sorted.
*
* @param sortObject An instance of the object that will be sorted on
* @param sortFields An array of all the field names to sort by
* @param sortFieldOrder An integer array representing the sort order for the fields that will be sorted.
* Should either contain ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
Object sortObject,
String[] sortFields,
int[] sortFieldOrder)
throws ObjectComparatorException
{
this.sortObjectClass = sortObject.getClass();
this.sortObjectClassName = sortObjectClass.getName();
this.checkIsMap();
loadMethods(sortFields, sortFieldOrder);
}
/**
* Constructor for ObjectComparator when passing in the fully-qualified class name of the objects that will be sorted
* by later on. This is an alternative to passing in an instance of the actual object.
*
* @param sortObjectClassName The fully-qualified class name for the objects that will be sorted
* @param sortFields An array of all the field names to sort by
* @param sortFieldOrder An integer array representing the sort order for the fields that will be sorted.
* Should either contain ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
String sortObjectClassName,
String[] sortFields,
int[] sortFieldOrder)
throws ObjectComparatorException
{
try
{
this.sortObjectClass = Class.forName(sortObjectClassName);
this.sortObjectClassName = sortObjectClassName;
this.checkIsMap();
}
catch (ClassNotFoundException e)
{
throw new ObjectComparatorException(
"Error creating ObjectComparator: " + e);
}
loadMethods(sortFields, sortFieldOrder);
}
/**
* Constructor for ObjectComparator when passing in the actual object that will be sorted
* by later on. This is an alternative to passing in the fully-qualified class name for the
* objects that will be sorted. This constructor is also used when you want to sort by a maximum
* of only 3 fields, as opposed to passing in an array of fields to sort by.
*
* @param sortObject An instance of the object that will be sorted on
* @param sortField1 First field to sort by
* @param sortField1SortOrder Sort order for first field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField2 Second field to sort by
* @param sortField2SortOrder Sort order for second field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField3 Third field to sort by
* @param sortField3SortOrder Sort order for third field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
Object sortObject,
String sortField1,
int sortField1SortOrder,
String sortField2,
int sortField2SortOrder,
String sortField3,
int sortField3SortOrder)
throws ObjectComparatorException
{
this.sortObjectClass = sortObject.getClass();
this.sortObjectClassName = sortObjectClass.getName();
this.checkIsMap();
loadMethods(
sortField1,
sortField1SortOrder,
sortField2,
sortField2SortOrder,
sortField3,
sortField3SortOrder);
}
/**
* Constructor for ObjectComparator when passing in the fully-qualified class name of the objects that will be sorted
* by later on. This is an alternative to passing in an instance of the actual object.
* This constructor is also used when you want to sort by a maximum
* of only 3 fields, as opposed to passing in an array of fields to sort by.
*
* @param sortObjectClassName An instance of the object that will be sorted on
* @param sortField1 First field to sort by
* @param sortField1SortOrder Sort order for first field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField2 Second field to sort by
* @param sortField2SortOrder Sort order for second field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField3 Third field to sort by
* @param sortField3SortOrder Sort order for third field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
public ObjectComparator(
String sortObjectClassName,
String sortField1,
int sortField1SortOrder,
String sortField2,
int sortField2SortOrder,
String sortField3,
int sortField3SortOrder)
throws ObjectComparatorException
{
try
{
this.sortObjectClass = Class.forName(sortObjectClassName);
this.sortObjectClassName = sortObjectClassName;
}
catch (ClassNotFoundException e)
{
throw new ObjectComparatorException(
"Error creating ObjectComparator: " + e);
}
loadMethods(
sortField1,
sortField1SortOrder,
sortField2,
sortField2SortOrder,
sortField3,
sortField3SortOrder);
}
/**
* Loads the proper getter method for the field
*
* @param sortFields An array of all the field names to sort by
* @param sortFieldOrder An integer array representing the sort order for the fields that will be sorted.
* Should either contain ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
private void loadMethods(String[] sortFields, int[] sortFieldOrder)
throws ObjectComparatorException
{
if (sortFields.length != sortFieldOrder.length)
{
throw new ObjectComparatorException(
"Error creating ObjectComparator. Sort Fields array count "
+ "doesn't match Sort Field Order array count.");
}
//Determine the appropriate Method object for the field to be sorted by
String sortField = "";
int sortOrder = 0;
int length = sortFields.length;
this.sortFieldGetterMethods = new Method[length];
this.sortFieldOrder = new int[length];
this.sortFieldMethodArgs = new String[length];
int getterCount = 0;
for (int i = 0; i < length; i++)
{
sortField = sortFields[i];
sortOrder = sortFieldOrder[i];
if ((sortField != null && sortField != ""))
{
this.sortFieldGetterMethods[getterCount] =
getMethodName(sortField);
if (this.isMap) this.sortFieldMethodArgs[getterCount]=sortField; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[getterCount] = sortOrder;
getterCount++;
}
}
}
/**
* Loads the proper getter method for the field
*
* @param sortField1 First field to sort by
* @param sortField1SortOrder Sort order for first field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField2 Second field to sort by
* @param sortField2SortOrder Sort order for second field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
* @param sortField3 Third field to sort by
* @param sortField3SortOrder Sort order for third field, either ObjectComparator.SORT_DESCENDING or ObjectComparator.SORT_ASCENDING
*
* @exception ObjectComparatorException if any errors occurred during creation
**/
private void loadMethods(
String sortField1,
int sortField1SortOrder,
String sortField2,
int sortField2SortOrder,
String sortField3,
int sortField3SortOrder)
throws ObjectComparatorException
{
this.sortFieldGetterMethods = new Method[3];
this.sortFieldOrder = new int[3];
if (sortField1 != null && !sortField1.equals(""))
{
this.sortFieldGetterMethods[0] = getMethodName(sortField1);
if (this.isMap) this.sortFieldMethodArgs[0]=sortField1; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[0] = sortField1SortOrder;
}
if (sortField2 != null && !sortField2.equals(""))
{
this.sortFieldGetterMethods[1] = getMethodName(sortField2);
if (this.isMap) this.sortFieldMethodArgs[1]=sortField2; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[1] = sortField2SortOrder;
}
if (sortField3 != null && !sortField3.equals(""))
{
this.sortFieldGetterMethods[2] = getMethodName(sortField3);
if (this.isMap) this.sortFieldMethodArgs[2]=sortField3; // Map objects use method "get" and pass the field name as an arg
this.sortFieldOrder[2] = sortField3SortOrder;
}
}
/**
* Checks if the Class object currently set and associated with this ObjectComparator
* implements interface Map
*
*/
private void checkIsMap() {
/*
if (this.sortObjectClass.isInstance( aMapObject ) ) {
this.isMap = true;
}
*/
/*
* The method Class.isInstance(Object) above doesn't seem to work. Even when I created
* an explicit instance of the object to sort (like a 'Hashtable'), it never
* detected the correct object type. Instead, I am trying to get a hard instance
* of the object so I can check instanceof, which *does* seem to work. If I can't
* create an instance of the object using the empty constructor, then I'm assuming
* it's not a Map!
*/
try {
Object o = this.sortObjectClass.newInstance();
if (o instanceof Map) {
this.isMap = true;
}
}
catch (InstantiationException e)
{
// Do nothing, just assume it's not a map
/*
throw new ObjectComparatorException(
"could not check for map '"
+ " (map=" + this.isMap + ") findmap: " + findmap.toString()
+ "'. Error is: "
+ e); */
}
catch (IllegalAccessException e)
{
// Do nothing, just assume it's not a map
}
}
/**
* The implementation of the Comparator interface's compare method
*
* @param obj1 The first object to compare
* @param obj2 The second object to compare
* @return int
* @see java.util.Comparator#compare(Object, Object)
**/
public int compare(Object obj1, Object obj2)
{
int returnVal = 0;
try
{
Object obj1FieldValue = null;
Object obj2FieldValue = null;
int length = sortFieldGetterMethods.length;
Method getterMethod = null;
String[] methodArg = null;
for (int i = 0; i < length; i++)
{
getterMethod = sortFieldGetterMethods[i];
methodArg = new String[] { sortFieldMethodArgs[i] };
if (getterMethod != null)
{
if (this.isMap) {
// If we're a Map, we need to invoke get() method with the key as an argument
obj1FieldValue = getterMethod.invoke(obj1, methodArg);
obj2FieldValue = getterMethod.invoke(obj2, methodArg);
} else {
// If we're not a Map, we need to invoke the getter method
obj1FieldValue = getterMethod.invoke(obj1, null);
obj2FieldValue = getterMethod.invoke(obj2, null);
}
if(obj1FieldValue == null){
if (obj2FieldValue instanceof String )
obj1FieldValue = new String();
else if (obj2FieldValue instanceof Integer )
obj1FieldValue = new Integer(0);
else if (obj2FieldValue instanceof Long)
obj1FieldValue = new Long(0);
else if (obj2FieldValue instanceof Float)
obj1FieldValue = new Float(0);
else if (obj2FieldValue instanceof Double)
obj1FieldValue = new Double(0);
else if (obj2FieldValue instanceof Date)
obj1FieldValue = new Date(0);
else obj1FieldValue = new Object();
}
if (obj1FieldValue instanceof String )
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new String();
}
returnVal =
obj1FieldValue.toString().toUpperCase().compareTo(
obj2FieldValue.toString().toUpperCase());
}
else if (obj1FieldValue instanceof Integer)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Integer(0);
}
Integer obj1Integer = (Integer) obj1FieldValue;
Integer obj2Integer = (Integer) obj2FieldValue;
returnVal = obj1Integer.compareTo(obj2Integer);
}
else if (obj1FieldValue instanceof Long)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Long(0);
}
Long obj1Long = (Long) obj1FieldValue;
Long obj2Long = (Long) obj2FieldValue;
returnVal = obj1Long.compareTo(obj2Long);
}
else if (obj1FieldValue instanceof Float)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Float(0);
}
Float obj1Float = (Float) obj1FieldValue;
Float obj2Float = (Float) obj2FieldValue;
returnVal = obj1Float.compareTo(obj2Float);
}
else if (obj1FieldValue instanceof Double)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Double(0);
}
Double obj1Double = (Double) obj1FieldValue;
Double obj2Double = (Double) obj2FieldValue;
returnVal = obj1Double.compareTo(obj2Double);
}
else if (obj1FieldValue instanceof Date)
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Date(0);
}
Date obj1Date = (Date) obj1FieldValue;
Date obj2Date = (Date) obj2FieldValue;
returnVal = obj1Date.compareTo(obj2Date);
}
else
{
if ( obj2FieldValue == null )
{
obj2FieldValue = new Object();
}
returnVal =
obj1FieldValue.toString().compareTo(
obj2FieldValue.toString());
}
if (returnVal != 0)
{
if (sortFieldOrder[i] == SORT_DESCENDING)
{
returnVal = returnVal * -1;
}
break;
}
}
}
}
catch (Exception e)
{
//Can't throw an exception since the inherited compare method doesn't define it
// That means any exception when comparing the objects goes into a black hole, and
// you won't be able to know why your compare didn't work.
returnVal = 0;
}
return returnVal;
}
/**
* Used to retrieve the 'getter' method, as a Method object, for the passed in field name
*
* @param fieldName The field name
* @return The getter method
* @throws ObjectComparatorException
**/
private Method getMethodName(String fieldName)
throws ObjectComparatorException
{
Method theMethod = null;
String methodName = null;
Class[] parameterTypes = null;
String firstChar = "";
if (fieldName != null && !fieldName.equals(""))
{
if (this.isMap) {
// If we're a Map, we'll always check for method "get()"
methodName="get";
// Object o = new Object();
Object o = new Object();
parameterTypes = new Class[] { o.getClass() };
} else {
// If we're not a Map, check for bean-style get method (i.e. "getMyProperty()")
firstChar = fieldName.substring(0, 1);
if (fieldName.length() >= 2)
{
methodName =
"get" + firstChar.toUpperCase() + fieldName.substring(1);
}
else
{
methodName = "get" + firstChar.toUpperCase();
}
}
}
try
{
theMethod = sortObjectClass.getMethod(methodName, parameterTypes);
}
catch (NoSuchMethodException e)
{
throw new ObjectComparatorException(
"No getter method matches the field name passed in '"
+ fieldName + " (map=" + this.isMap + ") "
+ "'. Error is: "
+ e);
}
return theMethod;
}
}
Tuesday, December 19, 2006
Creating a SOAP message
The first step is to create a message using a MessageFactory object. The SAAJ API provides a default implementation of the MessageFactory class, thus making it easy to get an instance. The following code fragment illustrates getting an instance of the default message factory and then using it to create a message.
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
Parts of a Message
A SOAPMessage object is required to have certain elements, and, as stated previously, the SAAJ API simplifies things for you by returning a new SOAPMessage object that already contains these elements. So message, which was created in the preceding line of code, automatically has the following:
I. A SOAPPart object that contains
A. A SOAPEnvelope object that contains
1. An empty SOAPHeader object
2. An empty SOAPBody object
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
OR you can directly access a soap header llike:
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
This example of a SAAJ client does not use a SOAP header, so you can delete it. (You will see more about headers later.) Because all SOAPElement objects, including SOAPHeader objects, are derived from the Node interface, you use the method Node.detachNode to delete header.
header.detachNode();
Adding Content to the Body
SOAPBody body = message.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name bodyName = soapFactory.createName
("GetLastTradePrice", "m", "http://wombat.ztrade.com");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name name = soapFactory.createName("symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("SUNW");
The content that you have just added to your SOAPBody object will look like the following when it is sent over the wire:
SUNW
Getting a SOAPConnection Object
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
Now you can use soapConnectionFactory to create a SOAPConnection object.
SOAPConnection connection =
soapConnectionFactory.createConnection();
Sending a Message
A SAAJ client calls the SOAPConnection method call on a SOAPConnection object to send a message. The call method takes two arguments: the message being sent and the destination to which the message should go. This message is going to the stock quote service indicated by the URL object endpoint.
java.net.URL endpoint = new URL("http://wombat.ztrade.com/quotes");
SOAPMessage response = connection.call(message, endpoint);
The content of the message you sent is the stock symbol SUNW; the SOAPMessage object response should contain the last stock price for Sun Microsystems, which you will retrieve in the next section.
A connection uses a fair amount of resources, so it is a good idea to close a connection as soon as you are finished using it.
connection.close();
Getting the Content of a Message
To add content to the header, you create a SOAPHeaderElement object. As with all new elements, it must have an associated Name object, which you can create using the message's SOAPEnvelope object or a SOAPFactory object.
For example, suppose you want to add a conformance claim header to the message to state that your message conforms to the WS-I Basic Profile. The following code fragment retrieves the SOAPHeader object from message and adds a new SOAPHeaderElement object to it. This SOAPHeaderElement object contains the correct qualified name and attribute for a WS-I conformance claim header.
SOAPHeader header = message.getSOAPHeader();
Name headerName = soapFactory.createName("Claim","wsi", "http://ws-i.org/schemas/conformanceClaim/");
SOAPHeaderElement headerElement = header.addHeaderElement(headerName);
headerElement.addAttribute(soapFactory.createName("conformsTo"), "http://ws-i.org/profiles/basic1.0/");
conformance claim header has no content. This code produces the following XML header:
For a different kind of header, you might want to add content to headerElement. The following line of code uses the method addTextNode to do this.
headerElement.addTextNode("order");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
Parts of a Message
A SOAPMessage object is required to have certain elements, and, as stated previously, the SAAJ API simplifies things for you by returning a new SOAPMessage object that already contains these elements. So message, which was created in the preceding line of code, automatically has the following:
I. A SOAPPart object that contains
A. A SOAPEnvelope object that contains
1. An empty SOAPHeader object
2. An empty SOAPBody object
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
OR you can directly access a soap header llike:
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
This example of a SAAJ client does not use a SOAP header, so you can delete it. (You will see more about headers later.) Because all SOAPElement objects, including SOAPHeader objects, are derived from the Node interface, you use the method Node.detachNode to delete header.
header.detachNode();
Adding Content to the Body
SOAPBody body = message.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name bodyName = soapFactory.createName
("GetLastTradePrice", "m", "http://wombat.ztrade.com");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name name = soapFactory.createName("symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("SUNW");
The content that you have just added to your SOAPBody object will look like the following when it is sent over the wire:
Getting a SOAPConnection Object
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
Now you can use soapConnectionFactory to create a SOAPConnection object.
SOAPConnection connection =
soapConnectionFactory.createConnection();
Sending a Message
A SAAJ client calls the SOAPConnection method call on a SOAPConnection object to send a message. The call method takes two arguments: the message being sent and the destination to which the message should go. This message is going to the stock quote service indicated by the URL object endpoint.
java.net.URL endpoint = new URL("http://wombat.ztrade.com/quotes");
SOAPMessage response = connection.call(message, endpoint);
The content of the message you sent is the stock symbol SUNW; the SOAPMessage object response should contain the last stock price for Sun Microsystems, which you will retrieve in the next section.
A connection uses a fair amount of resources, so it is a good idea to close a connection as soon as you are finished using it.
connection.close();
Getting the Content of a Message
To add content to the header, you create a SOAPHeaderElement object. As with all new elements, it must have an associated Name object, which you can create using the message's SOAPEnvelope object or a SOAPFactory object.
For example, suppose you want to add a conformance claim header to the message to state that your message conforms to the WS-I Basic Profile. The following code fragment retrieves the SOAPHeader object from message and adds a new SOAPHeaderElement object to it. This SOAPHeaderElement object contains the correct qualified name and attribute for a WS-I conformance claim header.
SOAPHeader header = message.getSOAPHeader();
Name headerName = soapFactory.createName("Claim","wsi", "http://ws-i.org/schemas/conformanceClaim/");
SOAPHeaderElement headerElement = header.addHeaderElement(headerName);
headerElement.addAttribute(soapFactory.createName("conformsTo"), "http://ws-i.org/profiles/basic1.0/");
conformance claim header has no content. This code produces the following XML header:
For a different kind of header, you might want to add content to headerElement. The following line of code uses the method addTextNode to do this.
headerElement.addTextNode("order");
Thursday, December 14, 2006
Decode Function in Oracle
Oracle/PLSQL: Decode Function
In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.
The syntax for the decode function is:
decode( expression , search , result [, search , result]... [, default] )
expression is the value to compare.
search is the value that is compared against expression.
result is the value returned, if expression is equal to search.
default is optional.
If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).
For Example:
You could use the decode function in an SQL statement as follows:
SELECT supplier_name,
decode(supplier_id,
10000,
'IBM',
10001,
'Microsoft',
10002,
'Hewlett Packard',
'Gateway') result
FROM suppliers;
The above decode statement is equivalent to the following IF-THEN-ELSE statement:
IF supplier_id = 10000 THEN result := 'IBM';
ELSIF supplier_id = 10001 THEN result := 'Microsoft';
ELSIF supplier_id = 10002 THEN result := 'Hewlett Packard';
ELSE result := 'Gateway';
END IF;
The decode function will compare each supplier_id value, one by one.
Frequently Asked Questions
Question: One of our viewers wanted to know how to use the decode function to compare two dates (ie: date1 and date2), where if date1 > date2, the decode function should return date2. Otherwise, the decode function should return date1.
Answer: To accomplish this, use the decode function as follows:
decode((date1 - date2) - abs(date1 - date2), 0, date2, date1)
The formula below would equal 0, if date1 is greater than date2:
(date1 - date2) - abs(date1 - date2)
Question: I would like to know if it's possible to use decode for ranges of numbers, ie 1-10 = 'category 1', 11-20 = 'category 2', rather than having to individually decode each number.
Answer: Unfortunately, you can not use the decode for ranges of numbers. However, you can try to create a formula that will evaluate to one number for a given range, and another number for the next range, and so on.
For example:
SELECT supplier_id,
decode(trunc ((supplier_id - 1) / 10),
0,
'category 1',
1,
'category 2',
2,
'category 3',
'unknown') result
FROM suppliers;
In this example, based on the formula:
trunc ((supplier_id - 1) / 10
The formula will evaluate to 0, if the supplier_id is between 1 and 10.The formula will evaluate to 1, if the supplier_id is between 11 and 20.The formula will evaluate to 2, if the supplier_id is between 21 and 30.
and so on...
Question: I need to write a decode statement that will return the following:
If yrs_of_service <>= 1 and <> 5 then return 0.06
How can I do this?
Answer: You will need to create a formula that will evaluate to a single number for each one of your ranges.
For example:
SELECT emp_name,
decode(trunc (( yrs_of_service + 3) / 4),
0,
0.04,
1,
0.04,
0.06) as perc_value
FROM employees;
Helpful Tip: One of our viewers suggested combining the SIGN function with the DECODE function as follows:
The date example above could be modified as follows:
DECODE(SIGN(date1-date2), 1, date2, date1)
The SIGN/DECODE combination is also helpful for numeric comparisons e.g. Sales Bonuses
DECODE(SIGN(actual-target), -1, 'NO Bonus for you', 0,'Just made it', 1, 'Congrats, you are a winner'
In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.
The syntax for the decode function is:
decode( expression , search , result [, search , result]... [, default] )
expression is the value to compare.
search is the value that is compared against expression.
result is the value returned, if expression is equal to search.
default is optional.
If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).
For Example:
You could use the decode function in an SQL statement as follows:
SELECT supplier_name,
decode(supplier_id,
10000,
'IBM',
10001,
'Microsoft',
10002,
'Hewlett Packard',
'Gateway') result
FROM suppliers;
The above decode statement is equivalent to the following IF-THEN-ELSE statement:
IF supplier_id = 10000 THEN result := 'IBM';
ELSIF supplier_id = 10001 THEN result := 'Microsoft';
ELSIF supplier_id = 10002 THEN result := 'Hewlett Packard';
ELSE result := 'Gateway';
END IF;
The decode function will compare each supplier_id value, one by one.
Frequently Asked Questions
Question: One of our viewers wanted to know how to use the decode function to compare two dates (ie: date1 and date2), where if date1 > date2, the decode function should return date2. Otherwise, the decode function should return date1.
Answer: To accomplish this, use the decode function as follows:
decode((date1 - date2) - abs(date1 - date2), 0, date2, date1)
The formula below would equal 0, if date1 is greater than date2:
(date1 - date2) - abs(date1 - date2)
Question: I would like to know if it's possible to use decode for ranges of numbers, ie 1-10 = 'category 1', 11-20 = 'category 2', rather than having to individually decode each number.
Answer: Unfortunately, you can not use the decode for ranges of numbers. However, you can try to create a formula that will evaluate to one number for a given range, and another number for the next range, and so on.
For example:
SELECT supplier_id,
decode(trunc ((supplier_id - 1) / 10),
0,
'category 1',
1,
'category 2',
2,
'category 3',
'unknown') result
FROM suppliers;
In this example, based on the formula:
trunc ((supplier_id - 1) / 10
The formula will evaluate to 0, if the supplier_id is between 1 and 10.The formula will evaluate to 1, if the supplier_id is between 11 and 20.The formula will evaluate to 2, if the supplier_id is between 21 and 30.
and so on...
Question: I need to write a decode statement that will return the following:
If yrs_of_service <>= 1 and <> 5 then return 0.06
How can I do this?
Answer: You will need to create a formula that will evaluate to a single number for each one of your ranges.
For example:
SELECT emp_name,
decode(trunc (( yrs_of_service + 3) / 4),
0,
0.04,
1,
0.04,
0.06) as perc_value
FROM employees;
Helpful Tip: One of our viewers suggested combining the SIGN function with the DECODE function as follows:
The date example above could be modified as follows:
DECODE(SIGN(date1-date2), 1, date2, date1)
The SIGN/DECODE combination is also helpful for numeric comparisons e.g. Sales Bonuses
DECODE(SIGN(actual-target), -1, 'NO Bonus for you', 0,'Just made it', 1, 'Congrats, you are a winner'
Wednesday, December 13, 2006
making direct db conn
it didnt get published for some reason hopefully it will now.
import="java.sql.PreparedStatement
import="java.sql.Statement
import="java.util.Hashtable
import="javax.naming.InitialContext"
import="java.text.DecimalFormat"
import="javax.naming.Context"
import="com.jpmchase.srgt.util.SrgtProperties"
Connection conn = null;Statement s = null;
ResultSet rs = null;
PreparedStatement ps = null;
List result = null;
String prividerURL=null;
//Getting the url and datasource from srgtProperties file
String providerURL=SrgtProperties.getProperty("perf_url");
String jndiDS=SrgtProperties.getProperty("perf_srgt_ds");
System.out.println("Provider URL is :"+providerURL);
Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL,providerURL);
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
InitialContext ctx = new InitialContext(ht);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup(jndiDS);
conn=ds.getConnection();
ps = conn.prepareStatement(sqlBuff.toString());
import="java.sql.PreparedStatement
import="java.sql.Statement
import="java.util.Hashtable
import="javax.naming.InitialContext"
import="java.text.DecimalFormat"
import="javax.naming.Context"
import="com.jpmchase.srgt.util.SrgtProperties"
Connection conn = null;Statement s = null;
ResultSet rs = null;
PreparedStatement ps = null;
List result = null;
String prividerURL=null;
//Getting the url and datasource from srgtProperties file
String providerURL=SrgtProperties.getProperty("perf_url");
String jndiDS=SrgtProperties.getProperty("perf_srgt_ds");
System.out.println("Provider URL is :"+providerURL);
Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL,providerURL);
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
InitialContext ctx = new InitialContext(ht);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup(jndiDS);
conn=ds.getConnection();
ps = conn.prepareStatement(sqlBuff.toString());
Monday, December 4, 2006
SCDJWS Exam Objectives
Exam Objectives
Section 1: XML Web Service Standards
1.1 Given XML documents, schemas, and fragments determine whether their syntax and form are correct (according to W3C schema) and whether they conform to the WS-I Basic Profile 1.0a.
1.2 Describe the use of XML schema in J2EE Web services.
1.3 Describe the use of namespaces in an XML document.
Section 2: SOAP 1.1 Web Service Standards
2.1 List and describe the encoding types used in a SOAP message.
2.2 Describe how SOAP message header blocks are used and processed.
2.3 Describe the function of each element contained in a SOAP message, the SOAP binding to HTTP, and how to represent faults that occur when processing a SOAP message.
2.4 Create a SOAP message that contains an attachment.
2.5 Describe the restrictions placed on the use of SOAP by the WS-I Basic Profile 1.0a.
2.6 Describe the function of SOAP in a Web service interaction and the advantages and disadvantages of using SOAP messages.
Section 3: Describing and Publishing (WSDL and UDDI)
3.1 Explain the use of WSDL in Web services, including a description of WSDL's basic elements, binding mechanisms and the basic WSDL operation types as limited by the WS-I Basic Profile 1.0a.
3.2 Describe how W3C XML Schema is used as a typing mechanism in WSDL 1.1.
3.3 Describe the use of UDDI data structures. Consider the requirements imposed on UDDI by the WS-I Basic Profile 1.0a.
3.4 Describe the basic functions provided by the UDDI Publish and Inquiry APIs to interact with a UDDI business registry.
Section 4: JAX-RPC
4.1 Explain the service description model, client connection types, interaction modes, transport mechanisms/protocols, and endpoint types as they relate to JAX-RPC.
4.2 Given a set of requirements for a Web service, such as transactional needs, and security requirements, design and develop Web service applications that use servlet-based endpoints and EJB based endpoints.
4.3 Given an set of requirements, design and develop a Web sevice client, such as a J2EE client and a stand-alone Java client, using the appropriate JAX-RPC client connection style.
4.4 Given a set of requirements, develop and configure a Web service client that accesses a stateful Web service.
4.5 Explain the advantages and disadvantages of a WSDL to Java vs. a Java to WSDL development approach.
4.6 Describe the advantages and disadvantages of web service applications that use either synchronous/request response, one-way RPC, or non-blocking RPC invocation modes.
4.7 Use the JAX-RPC Handler API to create a SOAP message handler, describe the function of a handler chain, and describe the role of SAAJ when creating a message handler. Section
5: SOAP and XML Processing APIs (JAXP, JAXB, and SAAJ)
5.1 Describe the functions and capabilities of the APIs included within JAXP.
5.2 Given a scenario, select the proper mechanism for parsing and processing the information in an XML document.
5.3 Describe the functions and capabilities of JAXB, including the JAXB process flow, such as XML-to-Java and Java-to-XML, and the binding and validation mechanisms provided by JAXB.
5.4 Use the SAAJ APIs to create and manipulate a SOAP message.
Section 6: JAXR
6.1 Describe the function of JAXR in Web service architectural model, the two basic levels of business registry functionality supported by JAXR, and the function of the basic JAXR business objects and how they map to the UDDI data structures.
6.2 Use JAXR to connect to a UDDI business registry, execute queries to locate services that meet specific requirements, and publish or update information about a business service. Section
7: J2EE Web Services
7.1 Identify the characteristics of and the services and APIs included in the J2EE platform.
7.2 Explain the benefits of using the J2EE platform for creating and deploying Web service applications.
7.3 Describe the functions and capabilities of the JAXP, DOM, SAX, JAXR, JAX-RPC, and SAAJ in the J2EE platform.
7.4 Describe the role of the WS-I Basic Profile when designing J2EE Web services.
Section 8: Security
8.1 Explain basic security mechanisms including: transport level security, such as basic and mutual authentication and SSL, message level security, XML encryption, XML Digital Signature, and federated identity and trust.
8.2 Identify the purpose and benefits of Web services security oriented initiatives and standards such as Username Token Profile, SAML, XACML, XKMS, WS-Security, and the Liberty Project.
8.3 Given a scenario, implement J2EE based web service web-tier and/or EJB-tier basic security mechanisms, such as mutual authentication, SSL, and access control.
8.4 Describe factors that impact the security requirements of a Web service, such as the relationship between the client and service provider, the type of data being exchanged, the message format, and the transport mechanism.
Section 9: Developing Web Services
9.1 Describe the steps required to configure, package, and deploy J2EE Web services and service clients, including a description of the packaging formats, such as .ear, .war, .jar, deployment descriptor settings, the associated Web services description file, RPC mapping files, and service reference elements used for EJB and servlet endpoints.
9.2 Given a set of requirements, develop code to process XML files using the SAX, DOM, XSLT, and JAXB APIs.
9.3 Given an XML schema for a document style Web service create a WSDL file that describes the service and generate a service implementation.
9.4 Given a set of requirements, develop code to create an XML-based, document style, Web service using the JAX-RPC APIs.
9.5 Implement a SOAP logging mechanism for testing and debugging a Web service application using J2EE Web Service APIs.
9.6 Given a set of requirements, develop code to handle system and service exceptions and faults received by a Web services client.
Section 10: General Design and Architecture
10.1 Describe the characteristics of a service oriented architecture and how Web services fits to this model.
10.2Given a scenario, design a J2EE service using the business delegate, service locator, and/or proxy client-side design patterns and the adapter, command, Web service broker, and/or faade server-side patterns.
10.3 Describe alternatives for dealing with issues that impact the quality of service provided by a Web service and methods to improve the system reliability, maintainability, security, and performance of a service.
10.4 Describe how to handle the various types of return values, faults, errors, and exceptions that can occur during a Web service interaction.
10.5 Describe the role that Web services play when integrating data, application functions, or business processes in a J2EE application.
10.6 Describe how to design a stateless Web service that exposes the functionality of a stateful business process.
Section 11: Endpoint Design and Architecture
11.1 Given a scenario, design Web service applications using information models that are either procedure-style or document-style.
11.2 Describe the function of the service interaction and processing layers in a Web service.
11.3 Describe the tasks performed by each phase of an XML-based, document oriented, Web service application, including the consumption, business processing, and production phases.
11.4 Design a Web service for an asynchronous, document-style process and describe how to refactor a Web service from a synchronous to an asynchronous model.
11.5 Describe how the characteristics, such as resource utilization, conversational capabilities, and operational modes, of the various types of Web service clients impact the design of a Web service or determine the type of client that might interact with a particular service.
Section 1: XML Web Service Standards
1.1 Given XML documents, schemas, and fragments determine whether their syntax and form are correct (according to W3C schema) and whether they conform to the WS-I Basic Profile 1.0a.
1.2 Describe the use of XML schema in J2EE Web services.
1.3 Describe the use of namespaces in an XML document.
Section 2: SOAP 1.1 Web Service Standards
2.1 List and describe the encoding types used in a SOAP message.
2.2 Describe how SOAP message header blocks are used and processed.
2.3 Describe the function of each element contained in a SOAP message, the SOAP binding to HTTP, and how to represent faults that occur when processing a SOAP message.
2.4 Create a SOAP message that contains an attachment.
2.5 Describe the restrictions placed on the use of SOAP by the WS-I Basic Profile 1.0a.
2.6 Describe the function of SOAP in a Web service interaction and the advantages and disadvantages of using SOAP messages.
Section 3: Describing and Publishing (WSDL and UDDI)
3.1 Explain the use of WSDL in Web services, including a description of WSDL's basic elements, binding mechanisms and the basic WSDL operation types as limited by the WS-I Basic Profile 1.0a.
3.2 Describe how W3C XML Schema is used as a typing mechanism in WSDL 1.1.
3.3 Describe the use of UDDI data structures. Consider the requirements imposed on UDDI by the WS-I Basic Profile 1.0a.
3.4 Describe the basic functions provided by the UDDI Publish and Inquiry APIs to interact with a UDDI business registry.
Section 4: JAX-RPC
4.1 Explain the service description model, client connection types, interaction modes, transport mechanisms/protocols, and endpoint types as they relate to JAX-RPC.
4.2 Given a set of requirements for a Web service, such as transactional needs, and security requirements, design and develop Web service applications that use servlet-based endpoints and EJB based endpoints.
4.3 Given an set of requirements, design and develop a Web sevice client, such as a J2EE client and a stand-alone Java client, using the appropriate JAX-RPC client connection style.
4.4 Given a set of requirements, develop and configure a Web service client that accesses a stateful Web service.
4.5 Explain the advantages and disadvantages of a WSDL to Java vs. a Java to WSDL development approach.
4.6 Describe the advantages and disadvantages of web service applications that use either synchronous/request response, one-way RPC, or non-blocking RPC invocation modes.
4.7 Use the JAX-RPC Handler API to create a SOAP message handler, describe the function of a handler chain, and describe the role of SAAJ when creating a message handler. Section
5: SOAP and XML Processing APIs (JAXP, JAXB, and SAAJ)
5.1 Describe the functions and capabilities of the APIs included within JAXP.
5.2 Given a scenario, select the proper mechanism for parsing and processing the information in an XML document.
5.3 Describe the functions and capabilities of JAXB, including the JAXB process flow, such as XML-to-Java and Java-to-XML, and the binding and validation mechanisms provided by JAXB.
5.4 Use the SAAJ APIs to create and manipulate a SOAP message.
Section 6: JAXR
6.1 Describe the function of JAXR in Web service architectural model, the two basic levels of business registry functionality supported by JAXR, and the function of the basic JAXR business objects and how they map to the UDDI data structures.
6.2 Use JAXR to connect to a UDDI business registry, execute queries to locate services that meet specific requirements, and publish or update information about a business service. Section
7: J2EE Web Services
7.1 Identify the characteristics of and the services and APIs included in the J2EE platform.
7.2 Explain the benefits of using the J2EE platform for creating and deploying Web service applications.
7.3 Describe the functions and capabilities of the JAXP, DOM, SAX, JAXR, JAX-RPC, and SAAJ in the J2EE platform.
7.4 Describe the role of the WS-I Basic Profile when designing J2EE Web services.
Section 8: Security
8.1 Explain basic security mechanisms including: transport level security, such as basic and mutual authentication and SSL, message level security, XML encryption, XML Digital Signature, and federated identity and trust.
8.2 Identify the purpose and benefits of Web services security oriented initiatives and standards such as Username Token Profile, SAML, XACML, XKMS, WS-Security, and the Liberty Project.
8.3 Given a scenario, implement J2EE based web service web-tier and/or EJB-tier basic security mechanisms, such as mutual authentication, SSL, and access control.
8.4 Describe factors that impact the security requirements of a Web service, such as the relationship between the client and service provider, the type of data being exchanged, the message format, and the transport mechanism.
Section 9: Developing Web Services
9.1 Describe the steps required to configure, package, and deploy J2EE Web services and service clients, including a description of the packaging formats, such as .ear, .war, .jar, deployment descriptor settings, the associated Web services description file, RPC mapping files, and service reference elements used for EJB and servlet endpoints.
9.2 Given a set of requirements, develop code to process XML files using the SAX, DOM, XSLT, and JAXB APIs.
9.3 Given an XML schema for a document style Web service create a WSDL file that describes the service and generate a service implementation.
9.4 Given a set of requirements, develop code to create an XML-based, document style, Web service using the JAX-RPC APIs.
9.5 Implement a SOAP logging mechanism for testing and debugging a Web service application using J2EE Web Service APIs.
9.6 Given a set of requirements, develop code to handle system and service exceptions and faults received by a Web services client.
Section 10: General Design and Architecture
10.1 Describe the characteristics of a service oriented architecture and how Web services fits to this model.
10.2Given a scenario, design a J2EE service using the business delegate, service locator, and/or proxy client-side design patterns and the adapter, command, Web service broker, and/or faade server-side patterns.
10.3 Describe alternatives for dealing with issues that impact the quality of service provided by a Web service and methods to improve the system reliability, maintainability, security, and performance of a service.
10.4 Describe how to handle the various types of return values, faults, errors, and exceptions that can occur during a Web service interaction.
10.5 Describe the role that Web services play when integrating data, application functions, or business processes in a J2EE application.
10.6 Describe how to design a stateless Web service that exposes the functionality of a stateful business process.
Section 11: Endpoint Design and Architecture
11.1 Given a scenario, design Web service applications using information models that are either procedure-style or document-style.
11.2 Describe the function of the service interaction and processing layers in a Web service.
11.3 Describe the tasks performed by each phase of an XML-based, document oriented, Web service application, including the consumption, business processing, and production phases.
11.4 Design a Web service for an asynchronous, document-style process and describe how to refactor a Web service from a synchronous to an asynchronous model.
11.5 Describe how the characteristics, such as resource utilization, conversational capabilities, and operational modes, of the various types of Web service clients impact the design of a Web service or determine the type of client that might interact with a particular service.
Thursday, November 30, 2006
Antimatter and Dark Matter
Just read a very interesting Stephen Hawking's article.. wanna know abt him visit : http://www.hawking.org.uk/home/hindex.html . He said, we can achieve the speed of light when matter and antimatter destroy each other the process called annihilation.
Antimatter and Dark Matter
AntiparticlesEvery elementary particle in the Universe appears to have a partner particle called its antiparticle that shares many of the same characteristics, but many other characteristics are the opposite of those for the particle. For example, the electron has as its antiparticle the antielectron. The electron and the antielectron have exactly the same masses, but they have exactly opposite electrical charges.
The common stuff around us appears to be "matter", but we routinely produce antimatter in small quantities in high energy accelerator experiments. When a matter particle meets its antimatter particle they destroy each other completely (the technical term is "annihilation"), releasing the equivalent of their rest masses in the form of pure energy (according to the Einstein E=mc^2 relation). For example, when an electron meets an antielectron, the two annihilate and produce a burst of light having the energy corresponding to the masses of the two particles.
Because the properties of matter and antimatter parallel each other, we believe that the physics and chemistry of a galaxy made entirely from antimatter would closely parallel that of our our matter galaxy. Thus, is is conceivable that life built on antimatter could have evolved at other places in the Universe, just as life based on matter has evolved here. (But if your antimatter twin should show up some day, I would advise against shaking hands---remember that matter and antimatter annihilate each other!) However, we have no evidence thus far for large concentrations of antimatter anywhere in the Universe. Everything that we see so far seems to be matter. If true, this is something of a mystery, because naively there are reasons from fundamental physics to believe that the Universe should have produced about as much matter as antimatter.
Dark MatterDark matter is the general term for matter that we cannot see to this point with our telescopes, but that we know must be there because we see its gravitational influence on the rest of the Universe. Many different experiments indicate that there is probably 10 times more matter in the Universe (because we see its gravitational influence) than the matter that we see. Thus, dark matter is basically what the Universe is made out of, but we don't yet know what it is!
As one simple example of the evidence for dark matter, the velocity of rotation for spiral galaxies depends on the amount of mass contained in them. The outer parts of our own spiral galaxy, the Milky Way, are rotating much too fast to be consistent with the amount of matter that we can detect; in fact the data indicates that there must be about 10 times as much matter as we can see distributed in some diffuse halo of our galaxy to account for its rotation. The same is true for most other spiral galaxies where the velocities can be measured.
There are various candidates for the dark matter, ranging from ordinary matter that we just can't see because it isn't bright enough (for example, ordinary matter bound up in black holes, or very faint stars, or large planet-like objects like Jupiter) to more exotic particles that have yet to be discovered. There are some fairly strong arguments based on the production of the light elements in the Big Bang indicating that the majority of the dark matter cannot be ordinary matter or antimatter (which physicists call "baryonic matter"), and thus that the majority of the mass of the Universe is in a form very different from the matter that makes up us and the world around us (physicists call this "non-baryonic matter"). If that is true, then the matter that we are made of (baryonic matter) is but a small impurity compared to the dominant matter in the universe (non-baryonic matter). As someone has put it, "not only are we not the center of the Universe, we aren't even made of the right stuff!"
The nature of the dark matter is perhaps the most fundamental unsolved problem in modern astronomy.
Could the Dark Matter be Antimatter?It is conceivable that the dark matter (or at least part of it) could be antimatter, but there are very strong experimental reasons to doubt this. For example, if the dark matter out there were antimatter, we would expect it to annihilate with matter whenever it meets up with it, releasing bursts of energy primarily in the form of light. We see no evidence in careful observations for that, which leads most scientists to believe that whatever the dark matter is, it is not antimatter.
Subscribe to:
Posts (Atom)