Monday, July 13, 2009

J2ME Bluetooth connection steps


Following are the connection setup steps for J2ME Bluetooth.
(example shows Connecting to Server mode connection already
created with btspp)
  1. Inititate Search for devices.
  2. Method "deviceDiscovered" called by flatform for each device.
  3. Method "inquiryCompleted" called by flatform when device search completes.
  4. Then do a service search for selected device.
  5. Method "servicesDiscovered" called by flatform for each service.
  6. Method "serviceSearchCompleted" called by platform when service search completes.
  7. (there open a StreamConnection to chosen service URL)



//step 1
public void SearchAvailDevices() {
try {
//First get the local device and obtain the discovery agent.
m_LclDevice = LocalDevice.getLocalDevice();

m_DscrAgent = m_LclDevice.getDiscoveryAgent();

m_DscrAgent.startInquiry(DiscoveryAgent.GIAC, this);
} catch (BluetoothStateException ex) {
vobt.addLog("Problem in searching the blue tooth devices : " + ex.getMessage());
System.out.println("Problem in searching the blue tooth devices");
ex.printStackTrace();
}

}
//step 2 -- PLATFORM CALL
//Called when device is found during inquiry
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {

try {
// Get Device Info
System.out.println("Device Discovered");
System.out.println("Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
System.out.println("Bluetooth Address: " + btDevice.getBluetoothAddress());
System.out.println("Bluetooth Friendly Name: " + btDevice.getFriendlyName(true));
vobt.addLog("**Device Discovered**");
vobt.addLog("#Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
vobt.addLog("#Bluetooth Address: " + btDevice.getBluetoothAddress());

//put remote devices in Array
remoteDevicesArray[deviceCount] = btDevice;
deviceClassesArray [deviceCount] = cod;
deviceCount++;
} catch (Exception e) {
System.out.println("Device Discovered Error: " + e);
vobt.addLog("deviceDiscovered : " + e);
}
//step 3--PLATFORM CALL
//when device search completes
public void inquiryCompleted(int discType) { }
//step 4
//Search for srvices in Given device as following
public void serviceSearch(int selectedIndex)
{
try {
UUID[] uuidSet = new UUID[1];
uuidSet[0] = RFCOMM_UUID; // UUID USED TO INITIATE SERVER
int searchID = m_DscrAgent.searchServices(null, uuidSet, remoteDevicesArray[selectedIndex], this);
} catch (BluetoothStateException ex) {
ex.printStackTrace();
vobt.addLog("deviceDiscovered : " + ex);
}
}
// step 5 -- PLATFORM CALL
//when service found during service search (for each time new service found)
public void servicesDiscovered(int transID, ServiceRecord[] records) {

for (int i = 0; i < records.length; i++) {
m_strUrl = records[i].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);

System.out.println(m_strUrl);
if (m_strUrl.startsWith("btspp")) //search for URLS with btspp
{
m_bServerFound = true;
m_bInitClient = true;
break;
}

}
}


// step6 -- PLATFORM CALL
// when service search complete for given device
public void serviceSearchCompleted(int transID, int respCode) {
try { // open stream connection with needed URL
StrmConn = (StreamConnection) Connector.open(m_strUrl);
}
catch()
{}
}




Share Article : J2ME Bluetooth connection steps
Share/Save/Bookmark

Sunday, July 12, 2009

Hibernate querying and iteration using JSTL


1.If a query return a single raw with data from mulitple tables
(unique result with mulitple objects in-hibernate),
it returns array of Entity Objects.
A[0]
A[n]
....

2.If a query return multiple raws with data from mulitple tabels
it return List of Array objects.
L[0] ---
|+--- A[0]...A[m]
L[n] ---
|+--- A[0]...A[m]
.....

Code for situation 1

SQLQuery query = session.createSQLQuery(sql);
query.addEntity("person", Person.class);
query.addEntity("specializations", Entity.Specializations.class);

Object obj = query.uniqueResult();
// obj is an array
//A[0] will be a "person" and A[1] will be a "specializations" Object

View using JSTL

${objectArray[0].salutationText}. ${objectArray[0].nameWithInitials}
${objectArray[1].specializationText}



Code for situation 2

SQLQuery query = session.createSQLQuery(sql);
query.addEntity("session", Entity.Session.class);
query.addEntity("person", Person.class);

list = query.list();
// this return List of Arrays
// where L[n] A[0] -- "session" , A[1] -- "person"

Iterate using JSTL


${p[0].sessionId}
${p[0].sessionDate}
${p[1].name}
${p[1].address}





Share Article : Hibernate querying and iteration using JSTL
Share/Save/Bookmark

Friday, July 10, 2009

SMS-Gmail Password Recovery over SMS


We forget our passwords from time to time. Then what a hassel, forms forms, security questions and login to secondary email address. But now with Gmail, we just have to enter Username here(Password Assisatance Page), they sms a Recovery Code to phone, Simple.Befor that you have to set up under account settings. I tried and it works :) give it a try
Important-Supported Carries (for Sri Lanka)
  • Dialog Telekom Ltd
  • Mobitel Sri Lanka
  • Tigo (Private) Limited

Share Article : SMS-Gmail Password Recovery over SMS
Share/Save/Bookmark

Thursday, July 9, 2009

United Air Break Guitars- leeds to YouTube Hit Song


Canadian musician Dave Carroll's guitar had beeing smashed by United Airlines
workers and the airline had refused to pay $US1200 cost to repair it. Everything for good,
at last he did a song with anger and now it's a youtube hit 900 000+ views :) have a look.




Share Article : United Air Break Guitars- leeds to YouTube Hit Song
Share/Save/Bookmark