|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.lightdev.lib.holiday.client.HolidayClient
public class HolidayClient
Major element of the HolidayClient API to access the World Holiday Calendar Service.
Every instance of a HolidayClient object represents one session with the Light Development World Holiday Calendar Service. Class HolidayClient makes available all methods that other applications can use to interact with the service.
It can be used as follows:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import com.lightdev.app.trec.client.Client;
import com.lightdev.lib.holiday.client.HolidayClient;
import com.lightdev.lib.holiday.client.YearEvent;
public class HolidayClientSample {
public HolidayClientSample() {
super();
}
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
HolidayClient holidayClient = new HolidayClient();
try {
holidayClient.login(
"https://secure.lightdev.com/sec/apps",
"",
0,
true,
Client.DEFAULT_AUTHORIZER,
"demo",
"demo");
//
// region id and property are hard wired in the following code for demonstration
// purposes. Typically region ids and property ids are determined by methods
// getRegions and getProperties respectively before calling method getEventList.
//
String region_id_germany = "2";
String property_id_all = "9";
//
// the demo user is entitled to view all observances in the year previous to the
// current year as well as observances in the current year until the current
// month (i.e. no future observances except for future days of the current month)
//
GregorianCalendar now = new GregorianCalendar();
int previousYear = now.get(Calendar.YEAR) - 1;
YearEvent[] events = holidayClient.getEventList(
previousYear, property_id_all, region_id_germany, true, true, true, null);
for(int i = 0; i < events.length; i++) {
String eventName = events[i].toString();
Integer id = (Integer) events[i].getId();
GregorianCalendar[] dates = events[i].getDates();
System.out.println("occurrences in year 2005 for " + id + " " + eventName + ":");
for(int k = 0; k < dates.length; k++) {
GregorianCalendar c = dates[k];
System.out.println(" " + sdf.format(c.getTime()));
}
}
holidayClient.logout(Client.DEFAULT_AUTHORIZER);
}
catch (Throwable e) {
e.printStackTrace();
}
}
}
Please note that the classes required via imports shown above are all included in the HolidayClient API distribution package.
| Constructor Summary | |
|---|---|
HolidayClient()
create a new instance of a HolidayClient object |
|
| Method Summary | |
|---|---|
Object |
deserialize(byte[] bytes)
deserialize a byte array received from the server back to an object |
Vector<HierarchicalItem> |
getChildRegions(int regionId)
get all regions that are children of a region with the given id |
Client |
getClient()
get the TREC client object used to communicate with the server |
YearEvent[] |
getEventList(int year,
String propertyId,
String regionId,
boolean includeParents,
boolean includeChildren,
boolean exWorld,
AsyncCallback listener)
get an array of events matching a given filter criteria |
String[] |
getEventTexts(int eventId,
AsyncCallback listener)
get texts describing an event |
ServerAddress |
getPreferredServer()
get the address of the preferred server |
Property[] |
getProperties()
get all properties |
HierarchicalItem |
getRegion(int regionId)
get the region with a given id |
Vector<HierarchicalItem> |
getRegions()
get all regions |
Vector<HierarchicalItem> |
getRootRegions()
get all regions that have no parent region |
boolean |
isLoggedIn()
determine whether or not this HolidayClient is logged in to the Light Development World Holiday Calendar Service |
String |
login(String url,
String proxyUrl,
int proxyPort,
boolean encrypted,
String agentName,
String userId,
String pw)
login to the World Holiday Calendar Service |
void |
logout(String agentName)
logout from current session. |
byte[] |
serialize(Object obj)
serialize an object to a byte array |
void |
setPreferredServer(ServerAddress sa)
set the preferred server address |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HolidayClient()
| Method Detail |
|---|
public String login(String url,
String proxyUrl,
int proxyPort,
boolean encrypted,
String agentName,
String userId,
String pw)
throws Throwable
url - server URL, https://secure.lightdev.com/sec/apps at the time this version
was createdproxyUrl - url of proxy server to use, set to "" when no proxy is to be usedproxyPort - port number of proxy server to use, set to 0 when no proxy is to be usedencrypted - true, when server at given url communicates via SSL, false if notagentName - name of agent to use for authentication, typically Client.DEFAULT_AUTHORIZERuserId - id of user to loginpw - password of user to login
Throwable - when login attempt failed, e.g. due to wrong user id or password or
when an other error occurred that led to login failurepublic boolean isLoggedIn()
public void logout(String agentName)
throws Throwable
This method assumes that a user logged in previously. The Holiday Client API caches a logged in user in an own session until this logout method is called or until the session is inactive for a certain period of time.
agentName - name of agent to use for authentication, typically Client.DEFAULT_AUTHORIZER
Throwable - e.g. when logout is called although no user is currently logged inpublic HierarchicalItem getRegion(int regionId)
regionId - the id to get the region for
public Vector<HierarchicalItem> getRootRegions()
public Vector<HierarchicalItem> getChildRegions(int regionId)
regionId - id of region to get children of
public String[] getEventTexts(int eventId,
AsyncCallback listener)
throws Throwable
eventId - id of event to get texts for
Exception
Throwable
public YearEvent[] getEventList(int year,
String propertyId,
String regionId,
boolean includeParents,
boolean includeChildren,
boolean exWorld,
AsyncCallback listener)
throws Throwable
year - the year to return occurrences forpropertyId - id of property to get events for,
e.g. legal/public/bank holiday, hindu holiday, etc.regionId - id of region to get events for, e.g. 9 for Germany, etc.includeParents - true when events associated to parent regions should be returned tooincludeChildren - true when events associated to child regions should be returned tooexWorld - true when world should be excluded from parent regionslistener - AsyncCallback object that should handle results of an asynchronous
call, null if method should be executed synchronously, i.e. blocking until it returns
Throwable
public Vector<HierarchicalItem> getRegions()
throws Throwable
Throwable
public Property[] getProperties()
throws Throwable
Throwablepublic Client getClient()
public Object deserialize(byte[] bytes)
throws IOException,
ClassNotFoundException
bytes - the byte array to transform
IOException
ClassNotFoundExceptionpublic byte[] serialize(Object obj)
obj - the object to transform
public ServerAddress getPreferredServer()
public void setPreferredServer(ServerAddress sa)
sa - server address to set
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||