Replace tabs with spaces
This commit is contained in:
@@ -279,7 +279,7 @@ JNIEXPORT jintArray JNICALL Java_com_jacob_com_Dispatch_getIDsOfNames
|
||||
{
|
||||
USES_CONVERSION;
|
||||
jstring s = (jstring)env->GetObjectArrayElement(names, i);
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
const char *nm = env->GetStringUTFChars(s, NULL);
|
||||
LPOLESTR nmos = A2W(nm);
|
||||
env->ReleaseStringUTFChars(s, nm);
|
||||
@@ -319,8 +319,8 @@ static char* BasicToCharString(const BSTR inBasicString)
|
||||
if (charStrSize > 1)
|
||||
{
|
||||
charString = new char[charStrSize];
|
||||
size_t convertedSize;
|
||||
::wcstombs_s(&convertedSize, charString, charStrSize, inBasicString, charStrSize);
|
||||
size_t convertedSize;
|
||||
::wcstombs_s(&convertedSize, charString, charStrSize, inBasicString, charStrSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -394,14 +394,14 @@ static wchar_t* CreateErrorMsgFromInfo(HRESULT inResult, EXCEPINFO* ioInfo,
|
||||
const size_t MSG_LEN = ::wcslen(methNameW) + ::wcslen(msg2) + 256;
|
||||
msg = new wchar_t[MSG_LEN];
|
||||
::wcsncpy_s(msg, MSG_LEN,
|
||||
L"A COM exception has been encountered:\nAt Invoke of: ",
|
||||
wcslen(L"A COM exception has been encountered:\nAt Invoke of: "));
|
||||
L"A COM exception has been encountered:\nAt Invoke of: ",
|
||||
wcslen(L"A COM exception has been encountered:\nAt Invoke of: "));
|
||||
::wcsncat_s(msg, MSG_LEN, methNameW, wcslen(methNameW));
|
||||
::wcsncat_s(msg, MSG_LEN, L"\nDescription: ", wcslen(L"\nDescription: "));
|
||||
::wcsncat_s(msg, MSG_LEN, msg2, wcslen(msg2));
|
||||
// jacob-msg 1075 - SF 1053872 : Documentation says "use LocalFree"!!
|
||||
//delete msg2;
|
||||
LocalFree(msg2);
|
||||
LocalFree(msg2);
|
||||
}
|
||||
delete methNameW;
|
||||
return msg;
|
||||
@@ -494,15 +494,15 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
jint count = env->GetArrayLength(uArgErr);
|
||||
if ( count != 0 )
|
||||
{
|
||||
jint *uAE = env->GetIntArrayElements(uArgErr, NULL);
|
||||
hr = pIDispatch->Invoke(dispID,IID_NULL,
|
||||
lcid,(WORD)wFlags,&dispparams,v,&excepInfo,(unsigned int *)uAE); // SF 1689061
|
||||
env->ReleaseIntArrayElements(uArgErr, uAE, 0);
|
||||
jint *uAE = env->GetIntArrayElements(uArgErr, NULL);
|
||||
hr = pIDispatch->Invoke(dispID,IID_NULL,
|
||||
lcid,(WORD)wFlags,&dispparams,v,&excepInfo,(unsigned int *)uAE); // SF 1689061
|
||||
env->ReleaseIntArrayElements(uArgErr, uAE, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = pIDispatch->Invoke(dispID,IID_NULL,
|
||||
lcid,(WORD)wFlags,&dispparams,v,&excepInfo, NULL); // SF 1689061
|
||||
hr = pIDispatch->Invoke(dispID,IID_NULL,
|
||||
lcid,(WORD)wFlags,&dispparams,v,&excepInfo, NULL); // SF 1689061
|
||||
}
|
||||
if (num_args)
|
||||
{
|
||||
@@ -531,30 +531,30 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
// this method can get called with a name or a dispatch id
|
||||
// we need to handle both SF 1114159
|
||||
if (name != NULL){
|
||||
const char *nm = env->GetStringUTFChars(name, NULL);
|
||||
buf = CreateErrorMsgFromInfo(hr, &excepInfo, nm);
|
||||
env->ReleaseStringUTFChars(name, nm);
|
||||
const char *nm = env->GetStringUTFChars(name, NULL);
|
||||
buf = CreateErrorMsgFromInfo(hr, &excepInfo, nm);
|
||||
env->ReleaseStringUTFChars(name, nm);
|
||||
} else {
|
||||
dispIdAsName = new char[256];
|
||||
// get the id string
|
||||
_itoa_s (dispID, dispIdAsName, 256,10);
|
||||
//continue on mostly as before
|
||||
buf = CreateErrorMsgFromInfo(hr,&excepInfo,dispIdAsName);
|
||||
dispIdAsName = new char[256];
|
||||
// get the id string
|
||||
_itoa_s (dispID, dispIdAsName, 256,10);
|
||||
//continue on mostly as before
|
||||
buf = CreateErrorMsgFromInfo(hr,&excepInfo,dispIdAsName);
|
||||
}
|
||||
|
||||
// jacob-msg 3696 - SF 1053866
|
||||
if(hr == DISP_E_EXCEPTION)
|
||||
{
|
||||
if(excepInfo.scode != 0)
|
||||
{
|
||||
hr = excepInfo.scode;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = _com_error::WCodeToHRESULT(excepInfo.wCode);
|
||||
}
|
||||
}
|
||||
|
||||
if(hr == DISP_E_EXCEPTION)
|
||||
{
|
||||
if(excepInfo.scode != 0)
|
||||
{
|
||||
hr = excepInfo.scode;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = _com_error::WCodeToHRESULT(excepInfo.wCode);
|
||||
}
|
||||
}
|
||||
|
||||
ThrowComFailUnicode(env, buf, hr);
|
||||
if (buf) delete buf;
|
||||
if (dispIdAsName) delete dispIdAsName;
|
||||
@@ -568,20 +568,20 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
* Wait method added so folks could wait until a com server terminated
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Dispatch_hasExited
|
||||
(JNIEnv *env,jclass clazz, jobject disp, jint dispid, jint lcid) {
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) {
|
||||
// should we return 0?
|
||||
return NULL;
|
||||
}
|
||||
ITypeInfo *v;
|
||||
HRESULT hr = pIDispatch->GetTypeInfo(dispid, lcid, &v);
|
||||
if (hr == RPC_E_SERVERCALL_RETRYLATER || hr == RPC_E_CALL_REJECTED || hr
|
||||
== 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
(JNIEnv *env,jclass clazz, jobject disp, jint dispid, jint lcid) {
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) {
|
||||
// should we return 0?
|
||||
return NULL;
|
||||
}
|
||||
ITypeInfo *v;
|
||||
HRESULT hr = pIDispatch->GetTypeInfo(dispid, lcid, &v);
|
||||
if (hr == RPC_E_SERVERCALL_RETRYLATER || hr == RPC_E_CALL_REJECTED || hr
|
||||
== 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,32 +74,32 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init3
|
||||
jstring _progid,
|
||||
jstring _typelib)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
USES_CONVERSION;
|
||||
|
||||
if (_typelib != NULL && _progid == NULL){
|
||||
// both are required if typelib exists
|
||||
ThrowComFail(env,"TypeLib was specified but no program id was",-1);
|
||||
return;
|
||||
// both are required if typelib exists
|
||||
ThrowComFail(env,"TypeLib was specified but no program id was",-1);
|
||||
return;
|
||||
}
|
||||
|
||||
BSTR typeLib = NULL;
|
||||
if (_typelib != NULL){
|
||||
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||
const char *typelib = env->GetStringUTFChars(_typelib, NULL);
|
||||
typeLib = A2W(typelib);
|
||||
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||
|
||||
//printf("we have a type lib %ls\n",typeLib);
|
||||
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||
const char *typelib = env->GetStringUTFChars(_typelib, NULL);
|
||||
typeLib = A2W(typelib);
|
||||
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||
|
||||
//printf("we have a type lib %ls\n",typeLib);
|
||||
}
|
||||
|
||||
// find progid if any
|
||||
LPOLESTR bsProgId = NULL;
|
||||
if (_progid!=NULL) {
|
||||
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||
bsProgId = A2W(progid);
|
||||
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||
//printf("we have an applicaton %ls\n",bsProgId);
|
||||
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||
bsProgId = A2W(progid);
|
||||
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||
//printf("we have an applicaton %ls\n",bsProgId);
|
||||
}
|
||||
|
||||
// get the IDispatch for the source object
|
||||
@@ -119,15 +119,15 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init3
|
||||
DISPID *mIDs;
|
||||
int n_EventMethods;
|
||||
if (_typelib == NULL){
|
||||
if (!GetEventIID(pUnk, &eventIID, &mNames, &mIDs, &n_EventMethods,bsProgId)) {
|
||||
ThrowComFail(env, "Can't find event iid", -1);
|
||||
return;
|
||||
}
|
||||
if (!GetEventIID(pUnk, &eventIID, &mNames, &mIDs, &n_EventMethods,bsProgId)) {
|
||||
ThrowComFail(env, "Can't find event iid", -1);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!GetEventIIDForTypeLib(typeLib, &eventIID, &mNames, &mIDs, &n_EventMethods,bsProgId)) {
|
||||
ThrowComFail(env, "Can't find event iid for type lib", -1);
|
||||
return;
|
||||
}
|
||||
if (!GetEventIIDForTypeLib(typeLib, &eventIID, &mNames, &mIDs, &n_EventMethods,bsProgId)) {
|
||||
ThrowComFail(env, "Can't find event iid for type lib", -1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// hook up to the default source iid
|
||||
@@ -153,10 +153,10 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_release
|
||||
{
|
||||
EventProxy *ep = extractProxy(env, _this);
|
||||
if (ep) {
|
||||
// Disconnect must be called to reduce the ref count to the EventProxy otherwise
|
||||
// the destructor will never be called (to actually do the disconnect)
|
||||
ep->Disconnect(); // SF 3412922
|
||||
// this is the line that blows up in IETest
|
||||
// Disconnect must be called to reduce the ref count to the EventProxy otherwise
|
||||
// the destructor will never be called (to actually do the disconnect)
|
||||
ep->Disconnect(); // SF 3412922
|
||||
// this is the line that blows up in IETest
|
||||
ep->Release();
|
||||
putProxy(env, _this, NULL);
|
||||
}
|
||||
@@ -219,15 +219,15 @@ BOOL GetEventIID(IUnknown *m_pObject, IID* piid,
|
||||
{
|
||||
//printf("got IProvideClassInfo\n");
|
||||
ATLASSERT(pPCI != NULL);
|
||||
HRESULT hr = pPCI->GetClassInfo(&pClassInfo);
|
||||
HRESULT hr = pPCI->GetClassInfo(&pClassInfo);
|
||||
pPCI->Release();
|
||||
if (!SUCCEEDED(hr)) return false;
|
||||
}
|
||||
else if (getClassInfoFromProgId(bsProgId,&pClassInfo)) {
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
printf("GetEventIID: couldn't get IProvideClassInfo\n");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return MapEventIIDs(piid, mNames, mIDs, nmeth, bsProgId, pClassInfo);
|
||||
@@ -249,7 +249,7 @@ BOOL MapEventIIDs(IID* piid,
|
||||
int nFlags;
|
||||
HREFTYPE hRefType;
|
||||
|
||||
//printf("MapEventIIDs: looking at %d class attribute impl types \n");
|
||||
//printf("MapEventIIDs: looking at %d class attribute impl types \n");
|
||||
for (unsigned int i = 0; i < pClassAttr->cImplTypes; i++)
|
||||
{
|
||||
if (SUCCEEDED(pClassInfo->GetImplTypeFlags(i, &nFlags)) &&
|
||||
@@ -300,25 +300,25 @@ BOOL getClassInfoFromProgId(LPOLESTR bsProgId,LPTYPEINFO *pClassInfo)
|
||||
LONG lVal;
|
||||
lVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE"),0,KEY_READ,&keySoftware);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keySoftware,_T("Classes"),0,KEY_READ,&keyClasses);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keyClasses,_T("CLSID"),0,KEY_READ,&keyCLSID);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
_TCHAR *tsProgId = W2T(bsProgId);
|
||||
lVal = RegOpenKeyEx(keyCLSID,tsProgId,0,KEY_READ,&keyXXXX);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keyXXXX,_T("TypeLib"),0,KEY_READ,&keyTypeLib);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegQueryValueExA(keyTypeLib,NULL,NULL,&dwType,abData,&dwCountData);
|
||||
RegCloseKey(keyTypeLib);
|
||||
}
|
||||
RegCloseKey(keyXXXX);
|
||||
}
|
||||
RegCloseKey(keyCLSID);
|
||||
}
|
||||
RegCloseKey(keyClasses);
|
||||
}
|
||||
RegCloseKey(keySoftware);
|
||||
lVal = RegOpenKeyEx(keySoftware,_T("Classes"),0,KEY_READ,&keyClasses);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keyClasses,_T("CLSID"),0,KEY_READ,&keyCLSID);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
_TCHAR *tsProgId = W2T(bsProgId);
|
||||
lVal = RegOpenKeyEx(keyCLSID,tsProgId,0,KEY_READ,&keyXXXX);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keyXXXX,_T("TypeLib"),0,KEY_READ,&keyTypeLib);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegQueryValueExA(keyTypeLib,NULL,NULL,&dwType,abData,&dwCountData);
|
||||
RegCloseKey(keyTypeLib);
|
||||
}
|
||||
RegCloseKey(keyXXXX);
|
||||
}
|
||||
RegCloseKey(keyCLSID);
|
||||
}
|
||||
RegCloseKey(keyClasses);
|
||||
}
|
||||
RegCloseKey(keySoftware);
|
||||
}
|
||||
if (lVal!=ERROR_SUCCESS) return false;
|
||||
BSTR bsLibId = A2BSTR((char*)abData);
|
||||
@@ -344,7 +344,7 @@ BOOL getClassInfoFromProgIdTypeLib(BSTR typeLib, LPOLESTR bsProgId, LPTYPEINFO *
|
||||
if (FAILED(StringFromCLSID(clsid,&bsProgId))) return false;
|
||||
|
||||
ITypeLib* pITypeLib;
|
||||
if (FAILED(LoadTypeLib(typeLib, &pITypeLib))) return false;
|
||||
if (FAILED(LoadTypeLib(typeLib, &pITypeLib))) return false;
|
||||
|
||||
//Find ITypeInfo for coclass.
|
||||
pITypeLib->GetTypeInfoOfGuid(clsid, pClassInfo);
|
||||
@@ -358,9 +358,9 @@ BOOL GetEventIIDForTypeLib(BSTR typeLib, IID* piid,
|
||||
LPTYPEINFO pClassInfo = NULL;
|
||||
if(getClassInfoFromProgIdTypeLib(typeLib, bsProgId,&pClassInfo))
|
||||
{
|
||||
if (pClassInfo == NULL){
|
||||
printf("we had a successful return but pClassInfo is null\n");
|
||||
}
|
||||
if (pClassInfo == NULL){
|
||||
printf("we had a successful return but pClassInfo is null\n");
|
||||
}
|
||||
return MapEventIIDs(piid, mNames, mIDs, nmeth, bsProgId, pClassInfo);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -97,7 +97,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchProxy_release
|
||||
IStream *ps = extractStream(env, _this);
|
||||
if (ps) {
|
||||
ps->Release();
|
||||
jclass argClass = env->GetObjectClass(_this);
|
||||
jclass argClass = env->GetObjectClass(_this);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "J");
|
||||
env->SetLongField(_this, ajf, 0ll);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ JNIEXPORT jint JNICALL
|
||||
Java_com_jacob_com_EnumVariant_Next(JNIEnv* env, jobject _this, jobjectArray vars)
|
||||
{
|
||||
IEnumVARIANT* self = extractEnumVariant(env, _this);
|
||||
//printf("self=%x\n", self);
|
||||
//printf("self=%x\n", self);
|
||||
if(self == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1877,7 +1877,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setString__ILjava_lang_Strin
|
||||
env->ReleaseStringChars(s, str);
|
||||
VariantClear(&v);
|
||||
} else if (vt == VT_BSTR) {
|
||||
// SF 2847577 support unicode move from GetStringUTFChars() to GetStringChars()
|
||||
// SF 2847577 support unicode move from GetStringUTFChars() to GetStringChars()
|
||||
const jchar *str = env->GetStringChars(s, NULL);
|
||||
CComBSTR bs((LPCOLESTR)str);
|
||||
SafeArrayPutElement(sa,&idx,bs.Detach());
|
||||
@@ -2623,12 +2623,12 @@ JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setVariants
|
||||
}
|
||||
|
||||
/* PLEASE NOTE THE LINE:
|
||||
jint *jIndices = env->GetIntArrayElements(indices, NULL);
|
||||
which I added to replace "long idx[2] = {i,j};" from the 2D case.
|
||||
Not sure if this is correct. Also, check that I am doing the null test and
|
||||
dimension test correctly.
|
||||
Would really like to call env->ReleaseIntArrayElements(indices, jIndices, NULL);
|
||||
in here but I can't get it to work
|
||||
jint *jIndices = env->GetIntArrayElements(indices, NULL);
|
||||
which I added to replace "long idx[2] = {i,j};" from the 2D case.
|
||||
Not sure if this is correct. Also, check that I am doing the null test and
|
||||
dimension test correctly.
|
||||
Would really like to call env->ReleaseIntArrayElements(indices, jIndices, NULL);
|
||||
in here but I can't get it to work
|
||||
*/
|
||||
|
||||
#define GETNDCODE(varType, varAccess, jtyp) \
|
||||
@@ -2669,12 +2669,12 @@ JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setVariants
|
||||
//---------------------------------
|
||||
|
||||
/* PLEASE NOTE THE LINE:
|
||||
jint *jIndices = env->GetIntArrayElements(indices, NULL);
|
||||
which I added to replace "long idx[2] = {i,j};" from the 2D case.
|
||||
Not sure if this is correct. Also, check that I am doing the null test and
|
||||
dimension test correctly.
|
||||
Would really like to call env->ReleaseIntArrayElements(indices, jIndices, NULL);
|
||||
in here but I can't get it to work
|
||||
jint *jIndices = env->GetIntArrayElements(indices, NULL);
|
||||
which I added to replace "long idx[2] = {i,j};" from the 2D case.
|
||||
Not sure if this is correct. Also, check that I am doing the null test and
|
||||
dimension test correctly.
|
||||
Would really like to call env->ReleaseIntArrayElements(indices, jIndices, NULL);
|
||||
in here but I can't get it to work
|
||||
*/
|
||||
|
||||
#define SETNDCODE(varType, varAccess) \
|
||||
|
||||
@@ -116,26 +116,26 @@ void zeroVariant(JNIEnv *env, jobject _this)
|
||||
JNIEXPORT jbyteArray JNICALL Java_com_jacob_com_Variant_SerializationWriteToBytes
|
||||
(JNIEnv *env, jobject _this){
|
||||
VARIANT *v = extractVariant(env, _this);
|
||||
if (v)
|
||||
{
|
||||
DWORD flags = MSHCTX_LOCAL;
|
||||
jint size = VARIANT_UserSize(&flags, 0L, v);
|
||||
// allocate a byte array of the right length
|
||||
jbyte* pBuf = new jbyte[size];
|
||||
// clear it out
|
||||
ZeroMemory(pBuf, size);
|
||||
// marshall the Variant into the buffer
|
||||
VARIANT_UserMarshal(&flags, (unsigned char *)pBuf, v);
|
||||
// need to convert the buffer to a java byte ba[]
|
||||
jbyteArray ba = env->NewByteArray(size);
|
||||
env->SetByteArrayRegion(ba, 0, size, pBuf);
|
||||
// and delete the original memory
|
||||
delete [] pBuf;
|
||||
return ba;
|
||||
} else {
|
||||
jbyteArray ba = env->NewByteArray(0);
|
||||
return ba;
|
||||
}
|
||||
if (v)
|
||||
{
|
||||
DWORD flags = MSHCTX_LOCAL;
|
||||
jint size = VARIANT_UserSize(&flags, 0L, v);
|
||||
// allocate a byte array of the right length
|
||||
jbyte* pBuf = new jbyte[size];
|
||||
// clear it out
|
||||
ZeroMemory(pBuf, size);
|
||||
// marshall the Variant into the buffer
|
||||
VARIANT_UserMarshal(&flags, (unsigned char *)pBuf, v);
|
||||
// need to convert the buffer to a java byte ba[]
|
||||
jbyteArray ba = env->NewByteArray(size);
|
||||
env->SetByteArrayRegion(ba, 0, size, pBuf);
|
||||
// and delete the original memory
|
||||
delete [] pBuf;
|
||||
return ba;
|
||||
} else {
|
||||
jbyteArray ba = env->NewByteArray(0);
|
||||
return ba;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,17 +148,17 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_SerializationReadFromBytes
|
||||
(JNIEnv *env, jobject _this, jbyteArray ba){
|
||||
|
||||
VARIANT *v = extractVariant(env, _this);
|
||||
if (v){
|
||||
// get a buffer from it
|
||||
jbyte *pBuf = env->GetByteArrayElements(ba, 0);
|
||||
// unmarshall the Variant from the buffer
|
||||
DWORD flags = MSHCTX_LOCAL;
|
||||
printf("about to unmarshall array elements\n");
|
||||
VARIANT_UserUnmarshal(&flags, (unsigned char *)pBuf, v);
|
||||
// release the byte array
|
||||
printf("about to release array elements\n");
|
||||
env->ReleaseByteArrayElements(ba, pBuf, 0);
|
||||
}
|
||||
if (v){
|
||||
// get a buffer from it
|
||||
jbyte *pBuf = env->GetByteArrayElements(ba, 0);
|
||||
// unmarshall the Variant from the buffer
|
||||
DWORD flags = MSHCTX_LOCAL;
|
||||
printf("about to unmarshall array elements\n");
|
||||
VARIANT_UserUnmarshal(&flags, (unsigned char *)pBuf, v);
|
||||
// release the byte array
|
||||
printf("about to release array elements\n");
|
||||
env->ReleaseByteArrayElements(ba, pBuf, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,13 +272,13 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantStringRef
|
||||
if (v) {
|
||||
VariantClear(v); // whatever was there before
|
||||
|
||||
const jchar *cStr = env->GetStringChars(s,NULL);
|
||||
// SF 1314116
|
||||
// DBeck: 2005-09-23: changed CComBSTR c-tor to accept
|
||||
// Unicode string (no terminating NULL) provided by GetStringChars
|
||||
const jsize numChars = env->GetStringLength(s);
|
||||
const jchar *cStr = env->GetStringChars(s,NULL);
|
||||
// SF 1314116
|
||||
// DBeck: 2005-09-23: changed CComBSTR c-tor to accept
|
||||
// Unicode string (no terminating NULL) provided by GetStringChars
|
||||
const jsize numChars = env->GetStringLength(s);
|
||||
//CComBSTR bs(cStr);
|
||||
CComBSTR bs( numChars, (LPCOLESTR)cStr ); // SR cast SF 1689061
|
||||
CComBSTR bs( numChars, (LPCOLESTR)cStr ); // SR cast SF 1689061
|
||||
|
||||
BSTR *pbs = (BSTR *)CoTaskMemAlloc(sizeof(BSTR));
|
||||
bs.CopyTo(pbs);
|
||||
@@ -802,11 +802,11 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantString
|
||||
|
||||
const jchar *cStr = env->GetStringChars(s,NULL);
|
||||
// SF 1314116
|
||||
// DBeck: 2005-09-23: changed CComBSTR c-tor to accept
|
||||
// Unicode string (no terminating NULL) provided by GetStringChars
|
||||
const jsize numChars = env->GetStringLength(s);
|
||||
// DBeck: 2005-09-23: changed CComBSTR c-tor to accept
|
||||
// Unicode string (no terminating NULL) provided by GetStringChars
|
||||
const jsize numChars = env->GetStringLength(s);
|
||||
//CComBSTR bs(cStr);
|
||||
CComBSTR bs( numChars, (LPCOLESTR)cStr ); // SR cast SF 1689061
|
||||
CComBSTR bs( numChars, (LPCOLESTR)cStr ); // SR cast SF 1689061
|
||||
|
||||
V_VT(v) = VT_BSTR;
|
||||
V_BSTR(v) = bs.Copy();
|
||||
@@ -975,7 +975,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNoParam
|
||||
{
|
||||
VARIANT *v = extractVariant(env, _this);
|
||||
if (v) {
|
||||
// SF 3377279 clear variable to fix leak
|
||||
// SF 3377279 clear variable to fix leak
|
||||
VariantClear(v);
|
||||
V_VT(v) = VT_ERROR;
|
||||
V_ERROR(v) = DISP_E_PARAMNOTFOUND;
|
||||
@@ -1041,7 +1041,7 @@ JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantType
|
||||
/**
|
||||
* this is a big cover method that returns TRUE if
|
||||
* the variant type is
|
||||
* VT_EMPTY, VT_NULL, VT_ERROR or VT_DISPATCH with no dispatch object
|
||||
* VT_EMPTY, VT_NULL, VT_ERROR or VT_DISPATCH with no dispatch object
|
||||
* */
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isVariantConsideredNull
|
||||
(JNIEnv *env, jobject _this)
|
||||
@@ -1110,14 +1110,14 @@ JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantVariant
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VARIANT *refVar = V_VARIANTREF(v);
|
||||
VARIANT *refVar = V_VARIANTREF(v);
|
||||
|
||||
// we could have made a copy of refV here but we aren't every going to free
|
||||
// it outside of the scope of the enclosing context so we will just used the
|
||||
// enclosed. This relies on the java layer to zero out its ref to this
|
||||
// enclosed variant before the gc can come along and free the memory out from
|
||||
// under this enclosing variant.
|
||||
return (jlong)refVar;
|
||||
// we could have made a copy of refV here but we aren't every going to free
|
||||
// it outside of the scope of the enclosing context so we will just used the
|
||||
// enclosed. This relies on the java layer to zero out its ref to this
|
||||
// enclosed variant before the gc can come along and free the memory out from
|
||||
// under this enclosing variant.
|
||||
return (jlong)refVar;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -1136,9 +1136,9 @@ JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantVariant
|
||||
DECIMAL *pd = (DECIMAL *)CoTaskMemAlloc(sizeof(DECIMAL));
|
||||
pd->scale = scale;
|
||||
if (signum == 1 || signum == 0){
|
||||
pd->sign = 0;
|
||||
pd->sign = 0;
|
||||
} else {
|
||||
pd->sign = 0x80;
|
||||
pd->sign = 0x80;
|
||||
}
|
||||
pd->Hi32 = hi;
|
||||
pd->Mid32 = mid;
|
||||
@@ -1163,9 +1163,9 @@ JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantVariant
|
||||
d = (DECIMAL*)v;
|
||||
d->scale = scale;
|
||||
if (signum == 1 || signum == 0){
|
||||
d->sign = 0;
|
||||
d->sign = 0;
|
||||
} else {
|
||||
d->sign = 0x80;
|
||||
d->sign = 0x80;
|
||||
}
|
||||
d->Hi32 = hi;
|
||||
d->Mid32 = mid;
|
||||
|
||||
@@ -37,7 +37,7 @@ void ThrowComFail(JNIEnv *env, const char* desc, jint hr)
|
||||
jmethodID failCons =
|
||||
env->GetMethodID(failClass, "<init>", "(ILjava/lang/String;)V");
|
||||
if (!desc) {
|
||||
desc = "Java/COM Error";
|
||||
desc = "Java/COM Error";
|
||||
}
|
||||
jstring js = env->NewStringUTF(desc);
|
||||
jthrowable fail = (jthrowable)env->NewObject(failClass, failCons, hr, js);
|
||||
@@ -47,7 +47,7 @@ void ThrowComFail(JNIEnv *env, const char* desc, jint hr)
|
||||
void ThrowComFailUnicode(JNIEnv *env, const wchar_t* desc, jint hr)
|
||||
{
|
||||
if (!desc) {
|
||||
ThrowComFail(env, "Java/COM Error", hr);
|
||||
ThrowComFail(env, "Java/COM Error", hr);
|
||||
}
|
||||
jclass failClass = env->FindClass("com/jacob/com/ComFailException");
|
||||
// call the constructor that takes hr and message
|
||||
@@ -67,9 +67,9 @@ int CheckEnv(JNIEnv *env1, JNIEnv *env2)
|
||||
jmethodID failCons =
|
||||
env1->GetMethodID(failClass, "<init>", "()V");
|
||||
env1->ThrowNew(failClass, "Wrong Thread");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
* Signature: (Ljava/lang/Object;I;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Dispatch_hasExited
|
||||
(JNIEnv *, jclass, jobject, jint, jint);
|
||||
(JNIEnv *, jclass, jobject, jint, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ class EventProxy : public IDispatch
|
||||
{
|
||||
private:
|
||||
int connected;
|
||||
LONG m_cRef; // a reference counter
|
||||
LONG m_cRef; // a reference counter
|
||||
CComPtr<IConnectionPoint> pCP; // the connection point
|
||||
DWORD dwEventCookie; // connection point cookie
|
||||
jobject javaSinkObj; // the java object to delegate calls
|
||||
|
||||
IID eventIID; // the interface iid passed in
|
||||
int MethNum; // number of methods in the callback interface
|
||||
int MethNum; // number of methods in the callback interface
|
||||
CComBSTR *MethName; // Array of method names
|
||||
DISPID *MethID; // Array of method ids, used to match invokations to method names
|
||||
JavaVM *jvm; // The java vm we are running
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
// constuct with a global JNI ref to a sink object
|
||||
// to which we will delegate event callbacks
|
||||
EventProxy(JNIEnv *jenv,
|
||||
jobject aSinkObj,
|
||||
jobject aSinkObj,
|
||||
CComPtr<IConnectionPoint> pConn,
|
||||
IID eventIID,
|
||||
CComBSTR *mName,
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
{
|
||||
LONG res = InterlockedDecrement(&m_cRef);
|
||||
if (res == 0) {
|
||||
delete this;
|
||||
delete this;
|
||||
}
|
||||
return res;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,23 +29,23 @@ namespace ATL
|
||||
|
||||
inline errno_t AtlCrtErrorCheck(_In_ errno_t nError)
|
||||
{
|
||||
switch(nError)
|
||||
{
|
||||
case ENOMEM:
|
||||
AtlThrow(E_OUTOFMEMORY);
|
||||
break;
|
||||
case EINVAL:
|
||||
case ERANGE:
|
||||
AtlThrow(E_INVALIDARG);
|
||||
break;
|
||||
case 0:
|
||||
case STRUNCATE:
|
||||
break;
|
||||
default:
|
||||
AtlThrow(E_FAIL);
|
||||
break;
|
||||
}
|
||||
return nError;
|
||||
switch(nError)
|
||||
{
|
||||
case ENOMEM:
|
||||
AtlThrow(E_OUTOFMEMORY);
|
||||
break;
|
||||
case EINVAL:
|
||||
case ERANGE:
|
||||
AtlThrow(E_INVALIDARG);
|
||||
break;
|
||||
case 0:
|
||||
case STRUNCATE:
|
||||
break;
|
||||
default:
|
||||
AtlThrow(E_FAIL);
|
||||
break;
|
||||
}
|
||||
return nError;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -61,331 +61,331 @@ namespace Checked
|
||||
#endif
|
||||
|
||||
inline void __cdecl memcpy_s(
|
||||
_Out_bytecap_post_bytecount_(_S1max,_N) void *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_bytecount_(_N) const void *_S2,
|
||||
_In_ size_t _N)
|
||||
_Out_bytecap_post_bytecount_(_S1max,_N) void *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_bytecount_(_N) const void *_S2,
|
||||
_In_ size_t _N)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::memcpy_s(_S1, _S1max, _S2, _N));
|
||||
ATLMFC_CRT_ERRORCHECK(::memcpy_s(_S1, _S1max, _S2, _N));
|
||||
}
|
||||
|
||||
inline void __cdecl wmemcpy_s(
|
||||
_Out_cap_post_count_(_N1,_N) wchar_t *_S1,
|
||||
_In_ size_t _N1,
|
||||
_In_count_(_N) const wchar_t *_S2,
|
||||
_In_ size_t _N)
|
||||
_Out_cap_post_count_(_N1,_N) wchar_t *_S1,
|
||||
_In_ size_t _N1,
|
||||
_In_count_(_N) const wchar_t *_S2,
|
||||
_In_ size_t _N)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::wmemcpy_s(_S1, _N1, _S2, _N));
|
||||
ATLMFC_CRT_ERRORCHECK(::wmemcpy_s(_S1, _N1, _S2, _N));
|
||||
}
|
||||
|
||||
inline void __cdecl memmove_s(
|
||||
_Out_bytecap_post_bytecount_(_S1max,_N) void *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_bytecount_(_N) const void *_S2,
|
||||
_In_ size_t _N)
|
||||
_Out_bytecap_post_bytecount_(_S1max,_N) void *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_bytecount_(_N) const void *_S2,
|
||||
_In_ size_t _N)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::memmove_s(_S1, _S1max, _S2, _N));
|
||||
ATLMFC_CRT_ERRORCHECK(::memmove_s(_S1, _S1max, _S2, _N));
|
||||
}
|
||||
|
||||
inline void __cdecl strcpy_s(
|
||||
_Out_z_cap_(_S1max) char *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_z_ const char *_S2)
|
||||
_Out_z_cap_(_S1max) char *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_z_ const char *_S2)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::strcpy_s(_S1, _S1max, _S2));
|
||||
ATLMFC_CRT_ERRORCHECK(::strcpy_s(_S1, _S1max, _S2));
|
||||
}
|
||||
|
||||
inline void __cdecl wcscpy_s(
|
||||
_Out_z_cap_(_S1max) wchar_t *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_z_ const wchar_t *_S2)
|
||||
_Out_z_cap_(_S1max) wchar_t *_S1,
|
||||
_In_ size_t _S1max,
|
||||
_In_z_ const wchar_t *_S2)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_S1, _S1max, _S2));
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_S1, _S1max, _S2));
|
||||
}
|
||||
|
||||
inline void __cdecl tcscpy_s(
|
||||
_Out_z_cap_(_SizeInChars) TCHAR * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR * _Src)
|
||||
_Out_z_cap_(_SizeInChars) TCHAR * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR * _Src)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcscpy_s(_Dst, _SizeInChars, _Src));
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcscpy_s(_Dst, _SizeInChars, _Src));
|
||||
}
|
||||
|
||||
inline errno_t __cdecl strncpy_s(
|
||||
_Out_z_cap_(_SizeInChars) char *_Dest,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const char *_Source,
|
||||
_In_ size_t _Count)
|
||||
_Out_z_cap_(_SizeInChars) char *_Dest,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const char *_Source,
|
||||
_In_ size_t _Count)
|
||||
{
|
||||
return ATLMFC_CRT_ERRORCHECK(::strncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
return ATLMFC_CRT_ERRORCHECK(::strncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
}
|
||||
|
||||
inline errno_t __cdecl wcsncpy_s(
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Dest,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const wchar_t *_Source,
|
||||
_In_ size_t _Count)
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Dest,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const wchar_t *_Source,
|
||||
_In_ size_t _Count)
|
||||
{
|
||||
return ATLMFC_CRT_ERRORCHECK(::wcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
return ATLMFC_CRT_ERRORCHECK(::wcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
}
|
||||
|
||||
inline errno_t __cdecl tcsncpy_s(
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Dest,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR *_Source,
|
||||
_In_ size_t _Count)
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Dest,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR *_Source,
|
||||
_In_ size_t _Count)
|
||||
{
|
||||
return ATLMFC_CRT_ERRORCHECK(::_tcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
return ATLMFC_CRT_ERRORCHECK(::_tcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
}
|
||||
|
||||
inline void __cdecl strcat_s(
|
||||
_Inout_z_cap_(_SizeInChars) char * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const char * _Src)
|
||||
_Inout_z_cap_(_SizeInChars) char * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const char * _Src)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::strcat_s(_Dst, _SizeInChars, _Src));
|
||||
ATLMFC_CRT_ERRORCHECK(::strcat_s(_Dst, _SizeInChars, _Src));
|
||||
}
|
||||
|
||||
inline void __cdecl wcscat_s(
|
||||
_Inout_z_cap_(_SizeInChars) wchar_t * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const wchar_t * _Src)
|
||||
_Inout_z_cap_(_SizeInChars) wchar_t * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const wchar_t * _Src)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscat_s(_Dst, _SizeInChars, _Src));
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscat_s(_Dst, _SizeInChars, _Src));
|
||||
}
|
||||
|
||||
inline void __cdecl tcscat_s(
|
||||
_Inout_z_cap_(_SizeInChars) TCHAR * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR * _Src)
|
||||
_Inout_z_cap_(_SizeInChars) TCHAR * _Dst,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR * _Src)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcscat_s(_Dst, _SizeInChars, _Src));
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcscat_s(_Dst, _SizeInChars, _Src));
|
||||
}
|
||||
|
||||
inline void __cdecl strlwr_s(
|
||||
_Inout_z_cap_(_SizeInChars) char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_cap_(_SizeInChars) char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_strlwr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_strlwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl wcslwr_s(
|
||||
_Inout_z_cap_(_SizeInChars) wchar_t * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_cap_(_SizeInChars) wchar_t * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcslwr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcslwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl mbslwr_s(
|
||||
_Inout_z_bytecap_(_SizeInChars) unsigned char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_bytecap_(_SizeInChars) unsigned char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_mbslwr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_mbslwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl tcslwr_s(
|
||||
_Inout_z_cap_(_SizeInChars) TCHAR * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_cap_(_SizeInChars) TCHAR * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcslwr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcslwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl strupr_s(
|
||||
_Inout_z_cap_(_SizeInChars) char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_cap_(_SizeInChars) char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_strupr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_strupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl wcsupr_s(
|
||||
_Inout_z_cap_(_SizeInChars) wchar_t * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_cap_(_SizeInChars) wchar_t * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcsupr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcsupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl mbsupr_s(
|
||||
_Inout_z_bytecap_(_SizeInChars) unsigned char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_bytecap_(_SizeInChars) unsigned char * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_mbsupr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_mbsupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl tcsupr_s(
|
||||
_Inout_z_cap_(_SizeInChars) TCHAR * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
_Inout_z_cap_(_SizeInChars) TCHAR * _Str,
|
||||
_In_ size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcsupr_s(_Str, _SizeInChars));
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcsupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl itoa_s(
|
||||
_In_ int _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ int _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_itoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_itoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl itot_s(
|
||||
_In_ int _Val,
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ int _Val,
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_itot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_itot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ltoa_s(
|
||||
_In_ long _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ long _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ltoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ltoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ltot_s(
|
||||
_In_ long _Val,
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ long _Val,
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ltot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ltot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ultoa_s(
|
||||
_In_ unsigned long _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ unsigned long _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ultow_s(
|
||||
_In_ unsigned long _Val,
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ unsigned long _Val,
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ultot_s(
|
||||
_In_ unsigned long _Val,
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ unsigned long _Val,
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl i64toa_s(
|
||||
_In_ __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_i64toa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_i64toa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl i64tow_s(
|
||||
_In_ __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_i64tow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_i64tow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ui64toa_s(
|
||||
_In_ unsigned __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ unsigned __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) char *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ui64toa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ui64toa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ui64tow_s(
|
||||
_In_ unsigned __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
_In_ unsigned __int64 _Val,
|
||||
_Out_z_cap_(_SizeInChars) wchar_t *_Buf,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ui64tow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
ATLMFC_CRT_ERRORCHECK(::_ui64tow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl gcvt_s(
|
||||
_Out_z_cap_(_SizeInChars) char *_Buffer,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ double _Value,
|
||||
_In_ int _Ndec)
|
||||
_Out_z_cap_(_SizeInChars) char *_Buffer,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_ double _Value,
|
||||
_In_ int _Ndec)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_gcvt_s(_Buffer, _SizeInChars, _Value, _Ndec));
|
||||
ATLMFC_CRT_ERRORCHECK(::_gcvt_s(_Buffer, _SizeInChars, _Value, _Ndec));
|
||||
}
|
||||
|
||||
inline void __cdecl tsplitpath_s(
|
||||
_In_z_ const TCHAR *_Path,
|
||||
_Out_opt_z_cap_(_Drive_len) TCHAR *_Drive,
|
||||
_In_ size_t _Drive_len,
|
||||
_Out_opt_z_cap_(_Dir_len) TCHAR *_Dir,
|
||||
_In_ size_t _Dir_len,
|
||||
_Out_opt_z_cap_(_Fname_len) TCHAR *_Fname,
|
||||
_In_ size_t _Fname_len,
|
||||
_Out_opt_z_cap_(_Ext_len) TCHAR *_Ext,
|
||||
_In_ size_t _Ext_len)
|
||||
_In_z_ const TCHAR *_Path,
|
||||
_Out_opt_z_cap_(_Drive_len) TCHAR *_Drive,
|
||||
_In_ size_t _Drive_len,
|
||||
_Out_opt_z_cap_(_Dir_len) TCHAR *_Dir,
|
||||
_In_ size_t _Dir_len,
|
||||
_Out_opt_z_cap_(_Fname_len) TCHAR *_Fname,
|
||||
_In_ size_t _Fname_len,
|
||||
_Out_opt_z_cap_(_Ext_len) TCHAR *_Ext,
|
||||
_In_ size_t _Ext_len)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tsplitpath_s(_Path, _Drive, _Drive_len, _Dir, _Dir_len, _Fname, _Fname_len, _Ext, _Ext_len));
|
||||
ATLMFC_CRT_ERRORCHECK(::_tsplitpath_s(_Path, _Drive, _Drive_len, _Dir, _Dir_len, _Fname, _Fname_len, _Ext, _Ext_len));
|
||||
}
|
||||
|
||||
inline void __cdecl tmakepath_s(
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Path,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR *_Drive,
|
||||
_In_z_ const TCHAR *_Dir,
|
||||
_In_z_ const TCHAR *_Fname,
|
||||
_In_z_ const TCHAR *_Ext)
|
||||
_Out_z_cap_(_SizeInChars) TCHAR *_Path,
|
||||
_In_ size_t _SizeInChars,
|
||||
_In_z_ const TCHAR *_Drive,
|
||||
_In_z_ const TCHAR *_Dir,
|
||||
_In_z_ const TCHAR *_Fname,
|
||||
_In_z_ const TCHAR *_Ext)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tmakepath_s(_Path, _SizeInChars, _Drive, _Dir, _Fname, _Ext));
|
||||
ATLMFC_CRT_ERRORCHECK(::_tmakepath_s(_Path, _SizeInChars, _Drive, _Dir, _Fname, _Ext));
|
||||
}
|
||||
|
||||
inline size_t __cdecl strnlen(
|
||||
_In_z_count_(_Maxsize) const char *_Str,
|
||||
_In_ size_t _Maxsize)
|
||||
_In_z_count_(_Maxsize) const char *_Str,
|
||||
_In_ size_t _Maxsize)
|
||||
{
|
||||
return ::strnlen(_Str, _Maxsize);
|
||||
return ::strnlen(_Str, _Maxsize);
|
||||
}
|
||||
|
||||
inline size_t __cdecl wcsnlen(
|
||||
_In_z_count_(_Maxsize) const wchar_t *_Wcs,
|
||||
_In_ size_t _Maxsize)
|
||||
_In_z_count_(_Maxsize) const wchar_t *_Wcs,
|
||||
_In_ size_t _Maxsize)
|
||||
{
|
||||
return ::wcsnlen(_Wcs, _Maxsize);
|
||||
return ::wcsnlen(_Wcs, _Maxsize);
|
||||
}
|
||||
|
||||
inline size_t __cdecl tcsnlen(
|
||||
_In_z_count_(_Maxsize) const TCHAR *_Str,
|
||||
_In_ size_t _Maxsize)
|
||||
_In_z_count_(_Maxsize) const TCHAR *_Str,
|
||||
_In_ size_t _Maxsize)
|
||||
{
|
||||
return ::_tcsnlen(_Str, _Maxsize);
|
||||
return ::_tcsnlen(_Str, _Maxsize);
|
||||
}
|
||||
|
||||
inline int get_errno() throw()
|
||||
{
|
||||
int nErrNo=0;
|
||||
errno_t nErrCall=::_get_errno(&nErrNo);
|
||||
if(nErrCall)
|
||||
{
|
||||
return nErrCall;
|
||||
}
|
||||
return nErrNo;
|
||||
int nErrNo=0;
|
||||
errno_t nErrCall=::_get_errno(&nErrNo);
|
||||
if(nErrCall)
|
||||
{
|
||||
return nErrCall;
|
||||
}
|
||||
return nErrNo;
|
||||
}
|
||||
|
||||
inline void set_errno(_In_ int _Value)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_set_errno(_Value));
|
||||
ATLMFC_CRT_ERRORCHECK(::_set_errno(_Value));
|
||||
}
|
||||
|
||||
} // namespace Checked
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -41,41 +41,41 @@ namespace ATL
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Verify that a null-terminated string points to valid memory
|
||||
inline BOOL AtlIsValidString(
|
||||
_In_z_count_(nMaxLength) LPCWSTR psz,
|
||||
_In_ size_t nMaxLength = INT_MAX)
|
||||
_In_z_count_(nMaxLength) LPCWSTR psz,
|
||||
_In_ size_t nMaxLength = INT_MAX)
|
||||
{
|
||||
(nMaxLength);
|
||||
return (psz != NULL);
|
||||
(nMaxLength);
|
||||
return (psz != NULL);
|
||||
}
|
||||
|
||||
// Verify that a null-terminated string points to valid memory
|
||||
inline BOOL AtlIsValidString(
|
||||
_In_z_count_(nMaxLength) LPCSTR psz,
|
||||
_In_ size_t nMaxLength = UINT_MAX)
|
||||
_In_z_count_(nMaxLength) LPCSTR psz,
|
||||
_In_ size_t nMaxLength = UINT_MAX)
|
||||
{
|
||||
(nMaxLength);
|
||||
return (psz != NULL);
|
||||
(nMaxLength);
|
||||
return (psz != NULL);
|
||||
}
|
||||
|
||||
// Verify that a pointer points to valid memory
|
||||
inline BOOL AtlIsValidAddress(
|
||||
_In_opt_bytecount_(nBytes) const void* p,
|
||||
_In_ size_t nBytes,
|
||||
_In_ BOOL bReadWrite = TRUE)
|
||||
_In_opt_bytecount_(nBytes) const void* p,
|
||||
_In_ size_t nBytes,
|
||||
_In_ BOOL bReadWrite = TRUE)
|
||||
{
|
||||
(bReadWrite);
|
||||
(nBytes);
|
||||
return (p != NULL);
|
||||
(bReadWrite);
|
||||
(nBytes);
|
||||
return (p != NULL);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void AtlAssertValidObject(
|
||||
_In_opt_ _Prepost_opt_bytecount_x_(sizeof(T)) const T *pOb)
|
||||
_In_opt_ _Prepost_opt_bytecount_x_(sizeof(T)) const T *pOb)
|
||||
{
|
||||
ATLASSERT(pOb);
|
||||
ATLASSERT(AtlIsValidAddress(pOb, sizeof(T)));
|
||||
if(pOb)
|
||||
pOb->AssertValid();
|
||||
ATLASSERT(pOb);
|
||||
ATLASSERT(AtlIsValidAddress(pOb, sizeof(T)));
|
||||
if(pOb)
|
||||
pOb->AssertValid();
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
#define ATLASSERT_VALID(x) ATL::AtlAssertValidObject(x)
|
||||
@@ -87,143 +87,143 @@ inline void AtlAssertValidObject(
|
||||
class CComCriticalSection
|
||||
{
|
||||
public:
|
||||
CComCriticalSection() throw()
|
||||
{
|
||||
memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
|
||||
}
|
||||
~CComCriticalSection()
|
||||
{
|
||||
}
|
||||
HRESULT Lock() throw()
|
||||
{
|
||||
EnterCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Unlock() throw()
|
||||
{
|
||||
LeaveCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
HRESULT hRes = S_OK;
|
||||
CComCriticalSection() throw()
|
||||
{
|
||||
memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
|
||||
}
|
||||
~CComCriticalSection()
|
||||
{
|
||||
}
|
||||
HRESULT Lock() throw()
|
||||
{
|
||||
EnterCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Unlock() throw()
|
||||
{
|
||||
LeaveCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
HRESULT hRes = S_OK;
|
||||
|
||||
if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0))
|
||||
{
|
||||
hRes = HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0))
|
||||
{
|
||||
hRes = HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
|
||||
return hRes;
|
||||
}
|
||||
return hRes;
|
||||
}
|
||||
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
DeleteCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
CRITICAL_SECTION m_sec;
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
DeleteCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
CRITICAL_SECTION m_sec;
|
||||
};
|
||||
|
||||
class CComAutoCriticalSection :
|
||||
public CComCriticalSection
|
||||
public CComCriticalSection
|
||||
{
|
||||
public:
|
||||
CComAutoCriticalSection()
|
||||
{
|
||||
HRESULT hr = CComCriticalSection::Init();
|
||||
if (FAILED(hr))
|
||||
AtlThrow(hr);
|
||||
}
|
||||
~CComAutoCriticalSection() throw()
|
||||
{
|
||||
CComCriticalSection::Term();
|
||||
}
|
||||
CComAutoCriticalSection()
|
||||
{
|
||||
HRESULT hr = CComCriticalSection::Init();
|
||||
if (FAILED(hr))
|
||||
AtlThrow(hr);
|
||||
}
|
||||
~CComAutoCriticalSection() throw()
|
||||
{
|
||||
CComCriticalSection::Term();
|
||||
}
|
||||
private :
|
||||
HRESULT Init(); // Not implemented. CComAutoCriticalSection::Init should never be called
|
||||
HRESULT Term(); // Not implemented. CComAutoCriticalSection::Term should never be called
|
||||
HRESULT Init(); // Not implemented. CComAutoCriticalSection::Init should never be called
|
||||
HRESULT Term(); // Not implemented. CComAutoCriticalSection::Term should never be called
|
||||
};
|
||||
|
||||
class CComSafeDeleteCriticalSection :
|
||||
public CComCriticalSection
|
||||
public CComCriticalSection
|
||||
{
|
||||
public:
|
||||
CComSafeDeleteCriticalSection(): m_bInitialized(false)
|
||||
{
|
||||
}
|
||||
CComSafeDeleteCriticalSection(): m_bInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
~CComSafeDeleteCriticalSection() throw()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_bInitialized = false;
|
||||
CComCriticalSection::Term();
|
||||
}
|
||||
~CComSafeDeleteCriticalSection() throw()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_bInitialized = false;
|
||||
CComCriticalSection::Term();
|
||||
}
|
||||
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
ATLASSERT( !m_bInitialized );
|
||||
HRESULT hr = CComCriticalSection::Init();
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
m_bInitialized = true;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
ATLASSERT( !m_bInitialized );
|
||||
HRESULT hr = CComCriticalSection::Init();
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
m_bInitialized = true;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
m_bInitialized = false;
|
||||
return CComCriticalSection::Term();
|
||||
}
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
m_bInitialized = false;
|
||||
return CComCriticalSection::Term();
|
||||
}
|
||||
|
||||
HRESULT Lock()
|
||||
{
|
||||
// CComSafeDeleteCriticalSection::Init or CComAutoDeleteCriticalSection::Init
|
||||
// not called or failed.
|
||||
// m_critsec member of CComObjectRootEx is now of type
|
||||
// CComAutoDeleteCriticalSection. It has to be initialized
|
||||
// by calling CComObjectRootEx::_AtlInitialConstruct
|
||||
ATLASSUME(m_bInitialized);
|
||||
return CComCriticalSection::Lock();
|
||||
}
|
||||
HRESULT Lock()
|
||||
{
|
||||
// CComSafeDeleteCriticalSection::Init or CComAutoDeleteCriticalSection::Init
|
||||
// not called or failed.
|
||||
// m_critsec member of CComObjectRootEx is now of type
|
||||
// CComAutoDeleteCriticalSection. It has to be initialized
|
||||
// by calling CComObjectRootEx::_AtlInitialConstruct
|
||||
ATLASSUME(m_bInitialized);
|
||||
return CComCriticalSection::Lock();
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_bInitialized;
|
||||
bool m_bInitialized;
|
||||
};
|
||||
|
||||
class CComAutoDeleteCriticalSection :
|
||||
public CComSafeDeleteCriticalSection
|
||||
public CComSafeDeleteCriticalSection
|
||||
{
|
||||
private:
|
||||
// CComAutoDeleteCriticalSection::Term should never be called
|
||||
HRESULT Term() throw();
|
||||
// CComAutoDeleteCriticalSection::Term should never be called
|
||||
HRESULT Term() throw();
|
||||
};
|
||||
|
||||
class CComFakeCriticalSection
|
||||
{
|
||||
public:
|
||||
HRESULT Lock() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Unlock() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Lock() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Unlock() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -232,40 +232,40 @@ public:
|
||||
// Used by any project that uses ATL
|
||||
struct _ATL_BASE_MODULE70
|
||||
{
|
||||
UINT cbSize;
|
||||
HINSTANCE m_hInst;
|
||||
HINSTANCE m_hInstResource;
|
||||
DWORD dwAtlBuildVer;
|
||||
const GUID* pguidVer;
|
||||
CComCriticalSection m_csResource;
|
||||
CSimpleArray<HINSTANCE> m_rgResourceInstance;
|
||||
UINT cbSize;
|
||||
HINSTANCE m_hInst;
|
||||
HINSTANCE m_hInstResource;
|
||||
DWORD dwAtlBuildVer;
|
||||
const GUID* pguidVer;
|
||||
CComCriticalSection m_csResource;
|
||||
CSimpleArray<HINSTANCE> m_rgResourceInstance;
|
||||
};
|
||||
typedef _ATL_BASE_MODULE70 _ATL_BASE_MODULE;
|
||||
|
||||
class CAtlBaseModule :
|
||||
public _ATL_BASE_MODULE
|
||||
public _ATL_BASE_MODULE
|
||||
{
|
||||
public :
|
||||
static bool m_bInitFailed;
|
||||
CAtlBaseModule() throw();
|
||||
~CAtlBaseModule() throw ();
|
||||
static bool m_bInitFailed;
|
||||
CAtlBaseModule() throw();
|
||||
~CAtlBaseModule() throw ();
|
||||
|
||||
HINSTANCE GetModuleInstance() throw()
|
||||
{
|
||||
return m_hInst;
|
||||
}
|
||||
HINSTANCE GetResourceInstance() throw()
|
||||
{
|
||||
return m_hInstResource;
|
||||
}
|
||||
HINSTANCE SetResourceInstance(_In_ HINSTANCE hInst) throw()
|
||||
{
|
||||
return static_cast< HINSTANCE >(InterlockedExchangePointer((void**)&m_hInstResource, hInst));
|
||||
}
|
||||
HINSTANCE GetModuleInstance() throw()
|
||||
{
|
||||
return m_hInst;
|
||||
}
|
||||
HINSTANCE GetResourceInstance() throw()
|
||||
{
|
||||
return m_hInstResource;
|
||||
}
|
||||
HINSTANCE SetResourceInstance(_In_ HINSTANCE hInst) throw()
|
||||
{
|
||||
return static_cast< HINSTANCE >(InterlockedExchangePointer((void**)&m_hInstResource, hInst));
|
||||
}
|
||||
|
||||
bool AddResourceInstance(_In_ HINSTANCE hInst) throw();
|
||||
bool RemoveResourceInstance(_In_ HINSTANCE hInst) throw();
|
||||
HINSTANCE GetHInstanceAt(_In_ int i) throw();
|
||||
bool AddResourceInstance(_In_ HINSTANCE hInst) throw();
|
||||
bool RemoveResourceInstance(_In_ HINSTANCE hInst) throw();
|
||||
HINSTANCE GetHInstanceAt(_In_ int i) throw();
|
||||
};
|
||||
|
||||
__declspec(selectany) bool CAtlBaseModule::m_bInitFailed = false;
|
||||
@@ -276,199 +276,199 @@ extern CAtlBaseModule _AtlBaseModule;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4200)
|
||||
struct ATLSTRINGRESOURCEIMAGE
|
||||
{
|
||||
WORD nLength;
|
||||
WCHAR achString[];
|
||||
};
|
||||
#pragma warning(pop) // C4200
|
||||
struct ATLSTRINGRESOURCEIMAGE
|
||||
{
|
||||
WORD nLength;
|
||||
WCHAR achString[];
|
||||
};
|
||||
#pragma warning(pop) // C4200
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* _AtlGetStringResourceImage(
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ HRSRC hResource,
|
||||
_In_ UINT id) throw()
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ HRSRC hResource,
|
||||
_In_ UINT id) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* pImage;
|
||||
const ATLSTRINGRESOURCEIMAGE* pImageEnd;
|
||||
ULONG nResourceSize;
|
||||
HGLOBAL hGlobal;
|
||||
UINT iIndex;
|
||||
const ATLSTRINGRESOURCEIMAGE* pImage;
|
||||
const ATLSTRINGRESOURCEIMAGE* pImageEnd;
|
||||
ULONG nResourceSize;
|
||||
HGLOBAL hGlobal;
|
||||
UINT iIndex;
|
||||
|
||||
hGlobal = ::LoadResource( hInstance, hResource );
|
||||
if( hGlobal == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
hGlobal = ::LoadResource( hInstance, hResource );
|
||||
if( hGlobal == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
pImage = (const ATLSTRINGRESOURCEIMAGE*)::LockResource( hGlobal );
|
||||
if( pImage == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
pImage = (const ATLSTRINGRESOURCEIMAGE*)::LockResource( hGlobal );
|
||||
if( pImage == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
nResourceSize = ::SizeofResource( hInstance, hResource );
|
||||
pImageEnd = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+nResourceSize);
|
||||
iIndex = id&0x000f;
|
||||
nResourceSize = ::SizeofResource( hInstance, hResource );
|
||||
pImageEnd = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+nResourceSize);
|
||||
iIndex = id&0x000f;
|
||||
|
||||
while( (iIndex > 0) && (pImage < pImageEnd) )
|
||||
{
|
||||
pImage = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+(sizeof( ATLSTRINGRESOURCEIMAGE )+(pImage->nLength*sizeof( WCHAR ))));
|
||||
iIndex--;
|
||||
}
|
||||
if( pImage >= pImageEnd )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
if( pImage->nLength == 0 )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
while( (iIndex > 0) && (pImage < pImageEnd) )
|
||||
{
|
||||
pImage = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+(sizeof( ATLSTRINGRESOURCEIMAGE )+(pImage->nLength*sizeof( WCHAR ))));
|
||||
iIndex--;
|
||||
}
|
||||
if( pImage >= pImageEnd )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
if( pImage->nLength == 0 )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( pImage );
|
||||
return( pImage );
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage(
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ UINT id) throw()
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ UINT id) throw()
|
||||
{
|
||||
HRSRC hResource;
|
||||
/*
|
||||
The and operation (& static_cast<WORD>(~0)) protects the expression from being greater
|
||||
than WORD - this would cause a runtime error when the application is compiled with /RTCc flag.
|
||||
*/
|
||||
hResource = ::FindResourceW(hInstance, MAKEINTRESOURCEW( (((id>>4)+1) & static_cast<WORD>(~0)) ), (LPWSTR) RT_STRING);
|
||||
if( hResource == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
HRSRC hResource;
|
||||
/*
|
||||
The and operation (& static_cast<WORD>(~0)) protects the expression from being greater
|
||||
than WORD - this would cause a runtime error when the application is compiled with /RTCc flag.
|
||||
*/
|
||||
hResource = ::FindResourceW(hInstance, MAKEINTRESOURCEW( (((id>>4)+1) & static_cast<WORD>(~0)) ), (LPWSTR) RT_STRING);
|
||||
if( hResource == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return _AtlGetStringResourceImage( hInstance, hResource, id );
|
||||
return _AtlGetStringResourceImage( hInstance, hResource, id );
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage(
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ UINT id,
|
||||
_In_ WORD wLanguage) throw()
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ UINT id,
|
||||
_In_ WORD wLanguage) throw()
|
||||
{
|
||||
HRSRC hResource;
|
||||
/*
|
||||
The and operation (& static_cast<WORD>(~0)) protects the expression from being greater
|
||||
than WORD - this would cause a runtime error when the application is compiled with /RTCc flag.
|
||||
*/
|
||||
hResource = ::FindResourceExW(hInstance, (LPWSTR) RT_STRING, MAKEINTRESOURCEW( (((id>>4)+1) & static_cast<WORD>(~0)) ), wLanguage);
|
||||
if( hResource == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
HRSRC hResource;
|
||||
/*
|
||||
The and operation (& static_cast<WORD>(~0)) protects the expression from being greater
|
||||
than WORD - this would cause a runtime error when the application is compiled with /RTCc flag.
|
||||
*/
|
||||
hResource = ::FindResourceExW(hInstance, (LPWSTR) RT_STRING, MAKEINTRESOURCEW( (((id>>4)+1) & static_cast<WORD>(~0)) ), wLanguage);
|
||||
if( hResource == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return _AtlGetStringResourceImage( hInstance, hResource, id );
|
||||
return _AtlGetStringResourceImage( hInstance, hResource, id );
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage(_In_ UINT id) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, id);
|
||||
}
|
||||
return p;
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, id);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage(
|
||||
_In_ UINT id,
|
||||
_In_ WORD wLanguage) throw()
|
||||
_In_ UINT id,
|
||||
_In_ WORD wLanguage) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, id, wLanguage);
|
||||
}
|
||||
return p;
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, id, wLanguage);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline int AtlLoadString(
|
||||
_In_ UINT nID,
|
||||
_Out_z_cap_post_count_(nBufferMax, return + 1) LPTSTR lpBuffer,
|
||||
_In_ int nBufferMax) throw()
|
||||
_In_ UINT nID,
|
||||
_Out_z_cap_post_count_(nBufferMax, return + 1) LPTSTR lpBuffer,
|
||||
_In_ int nBufferMax) throw()
|
||||
{
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
int nRet = 0;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
int nRet = 0;
|
||||
|
||||
for (int i = 1; hInst != NULL && nRet == 0; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
nRet = LoadString(hInst, nID, lpBuffer, nBufferMax);
|
||||
}
|
||||
return nRet;
|
||||
for (int i = 1; hInst != NULL && nRet == 0; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
nRet = LoadString(hInst, nID, lpBuffer, nBufferMax);
|
||||
}
|
||||
return nRet;
|
||||
}
|
||||
|
||||
inline HINSTANCE AtlFindResourceInstance(
|
||||
_In_z_ LPCTSTR lpName,
|
||||
_In_z_ LPCTSTR lpType,
|
||||
_In_ WORD wLanguage = 0) throw()
|
||||
_In_z_ LPCTSTR lpName,
|
||||
_In_z_ LPCTSTR lpType,
|
||||
_In_ WORD wLanguage = 0) throw()
|
||||
{
|
||||
ATLASSERT(lpType != RT_STRING); // Call AtlFindStringResourceInstance to find the string
|
||||
if (lpType == RT_STRING)
|
||||
return NULL;
|
||||
ATLASSERT(lpType != RT_STRING); // Call AtlFindStringResourceInstance to find the string
|
||||
if (lpType == RT_STRING)
|
||||
return NULL;
|
||||
|
||||
if (ATL_IS_INTRESOURCE(lpType))
|
||||
{
|
||||
/* Prefast false warnings caused by bad-shaped definition of MAKEINTRESOURCE macro from PSDK */
|
||||
if (lpType == ATL_RT_ICON)
|
||||
{
|
||||
lpType = ATL_RT_GROUP_ICON;
|
||||
}
|
||||
else if (lpType == ATL_RT_CURSOR)
|
||||
{
|
||||
lpType = ATL_RT_GROUP_CURSOR;
|
||||
}
|
||||
}
|
||||
if (ATL_IS_INTRESOURCE(lpType))
|
||||
{
|
||||
/* Prefast false warnings caused by bad-shaped definition of MAKEINTRESOURCE macro from PSDK */
|
||||
if (lpType == ATL_RT_ICON)
|
||||
{
|
||||
lpType = ATL_RT_GROUP_ICON;
|
||||
}
|
||||
else if (lpType == ATL_RT_CURSOR)
|
||||
{
|
||||
lpType = ATL_RT_GROUP_CURSOR;
|
||||
}
|
||||
}
|
||||
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
HRSRC hResource = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
HRSRC hResource = NULL;
|
||||
|
||||
for (int i = 1; hInst != NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
hResource = ::FindResourceEx(hInst, lpType, lpName, wLanguage);
|
||||
if (hResource != NULL)
|
||||
{
|
||||
return hInst;
|
||||
}
|
||||
}
|
||||
for (int i = 1; hInst != NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
hResource = ::FindResourceEx(hInst, lpType, lpName, wLanguage);
|
||||
if (hResource != NULL)
|
||||
{
|
||||
return hInst;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline HINSTANCE AtlFindResourceInstance(
|
||||
_In_ UINT nID,
|
||||
_In_z_ LPCTSTR lpType,
|
||||
_In_ WORD wLanguage = 0) throw()
|
||||
_In_ UINT nID,
|
||||
_In_z_ LPCTSTR lpType,
|
||||
_In_ WORD wLanguage = 0) throw()
|
||||
{
|
||||
/*
|
||||
The and operation (& static_cast<WORD>(~0)) protects the expression from being greater
|
||||
than WORD - this would cause a runtime error when the application is compiled with /RTCc flag.
|
||||
*/
|
||||
return AtlFindResourceInstance(MAKEINTRESOURCE(nID & static_cast<WORD>(~0)), lpType, wLanguage);
|
||||
/*
|
||||
The and operation (& static_cast<WORD>(~0)) protects the expression from being greater
|
||||
than WORD - this would cause a runtime error when the application is compiled with /RTCc flag.
|
||||
*/
|
||||
return AtlFindResourceInstance(MAKEINTRESOURCE(nID & static_cast<WORD>(~0)), lpType, wLanguage);
|
||||
}
|
||||
|
||||
inline HINSTANCE AtlFindStringResourceInstance(
|
||||
_In_ UINT nID,
|
||||
_In_ WORD wLanguage = 0) throw()
|
||||
_In_ UINT nID,
|
||||
_In_ WORD wLanguage = 0) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, nID, wLanguage);
|
||||
if (p != NULL)
|
||||
return hInst;
|
||||
}
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, nID, wLanguage);
|
||||
if (p != NULL)
|
||||
return hInst;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -505,39 +505,39 @@ inline HRESULT AtlSafeArrayGetActualVartype(
|
||||
template <typename _CharType>
|
||||
inline _CharType* AtlCharNext(_In_ const _CharType* p) throw()
|
||||
{
|
||||
ATLASSUME(p != NULL); // Too expensive to check separately here
|
||||
if (*p == '\0') // ::CharNextA won't increment if we're at a \0 already
|
||||
return const_cast<_CharType*>(p+1);
|
||||
else
|
||||
return ::CharNextA(p);
|
||||
ATLASSUME(p != NULL); // Too expensive to check separately here
|
||||
if (*p == '\0') // ::CharNextA won't increment if we're at a \0 already
|
||||
return const_cast<_CharType*>(p+1);
|
||||
else
|
||||
return ::CharNextA(p);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline wchar_t* AtlCharNext<wchar_t>(_In_ const wchar_t* p) throw()
|
||||
{
|
||||
return const_cast< wchar_t* >( p+1 );
|
||||
return const_cast< wchar_t* >( p+1 );
|
||||
}
|
||||
template<typename CharType>
|
||||
inline const CharType* AtlstrchrT(
|
||||
_In_z_ const CharType* p,
|
||||
_In_ CharType ch) throw()
|
||||
_In_z_ const CharType* p,
|
||||
_In_ CharType ch) throw()
|
||||
{
|
||||
ATLASSERT(p != NULL);
|
||||
if(p==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
while( *p != 0 )
|
||||
{
|
||||
if (*p == ch)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
p = AtlCharNext(p);
|
||||
}
|
||||
//strchr for '\0' should succeed - the while loop terminates
|
||||
//*p == 0, but ch also == 0, so NULL terminator address is returned
|
||||
return (*p == ch) ? p : NULL;
|
||||
ATLASSERT(p != NULL);
|
||||
if(p==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
while( *p != 0 )
|
||||
{
|
||||
if (*p == ch)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
p = AtlCharNext(p);
|
||||
}
|
||||
//strchr for '\0' should succeed - the while loop terminates
|
||||
//*p == 0, but ch also == 0, so NULL terminator address is returned
|
||||
return (*p == ch) ? p : NULL;
|
||||
}
|
||||
//Ansi and Unicode versions of printf, used with templated CharType trait classes.
|
||||
#pragma warning(push)
|
||||
@@ -545,12 +545,12 @@ inline const CharType* AtlstrchrT(
|
||||
template<typename CharType>
|
||||
inline int AtlprintfT(_In_z_ _Printf_format_string_ const CharType* pszFormat,...) throw()
|
||||
{
|
||||
int retval=0;
|
||||
va_list argList;
|
||||
va_start( argList, pszFormat );
|
||||
retval=vprintf(pszFormat,argList);
|
||||
va_end( argList );
|
||||
return retval;
|
||||
int retval=0;
|
||||
va_list argList;
|
||||
va_start( argList, pszFormat );
|
||||
retval=vprintf(pszFormat,argList);
|
||||
va_end( argList );
|
||||
return retval;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
@@ -559,43 +559,43 @@ inline int AtlprintfT(_In_z_ _Printf_format_string_ const CharType* pszFormat,..
|
||||
template<>
|
||||
inline int AtlprintfT(_In_z_ _Printf_format_string_ const wchar_t* pszFormat,... ) throw()
|
||||
{
|
||||
int retval=0;
|
||||
va_list argList;
|
||||
va_start( argList, pszFormat );
|
||||
retval=vwprintf(pszFormat, argList);
|
||||
va_end( argList );
|
||||
return retval;
|
||||
int retval=0;
|
||||
va_list argList;
|
||||
va_start( argList, pszFormat );
|
||||
retval=vwprintf(pszFormat, argList);
|
||||
va_end( argList );
|
||||
return retval;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
inline BOOL AtlConvertSystemTimeToVariantTime(
|
||||
_In_ const SYSTEMTIME& systimeSrc,
|
||||
_Out_ double* pVarDtTm)
|
||||
_In_ const SYSTEMTIME& systimeSrc,
|
||||
_Out_ double* pVarDtTm)
|
||||
{
|
||||
ATLENSURE(pVarDtTm!=NULL);
|
||||
//Convert using ::SystemTimeToVariantTime and store the result in pVarDtTm then
|
||||
//convert variant time back to system time and compare to original system time.
|
||||
BOOL ok = ::SystemTimeToVariantTime(const_cast<SYSTEMTIME*>(&systimeSrc), pVarDtTm);
|
||||
SYSTEMTIME sysTime;
|
||||
::ZeroMemory(&sysTime, sizeof(SYSTEMTIME));
|
||||
ATLENSURE(pVarDtTm!=NULL);
|
||||
//Convert using ::SystemTimeToVariantTime and store the result in pVarDtTm then
|
||||
//convert variant time back to system time and compare to original system time.
|
||||
BOOL ok = ::SystemTimeToVariantTime(const_cast<SYSTEMTIME*>(&systimeSrc), pVarDtTm);
|
||||
SYSTEMTIME sysTime;
|
||||
::ZeroMemory(&sysTime, sizeof(SYSTEMTIME));
|
||||
|
||||
ok = ok && ::VariantTimeToSystemTime(*pVarDtTm, &sysTime);
|
||||
ok = ok && (systimeSrc.wYear == sysTime.wYear &&
|
||||
systimeSrc.wMonth == sysTime.wMonth &&
|
||||
systimeSrc.wDay == sysTime.wDay &&
|
||||
systimeSrc.wHour == sysTime.wHour &&
|
||||
systimeSrc.wMinute == sysTime.wMinute &&
|
||||
systimeSrc.wSecond == sysTime.wSecond);
|
||||
ok = ok && ::VariantTimeToSystemTime(*pVarDtTm, &sysTime);
|
||||
ok = ok && (systimeSrc.wYear == sysTime.wYear &&
|
||||
systimeSrc.wMonth == sysTime.wMonth &&
|
||||
systimeSrc.wDay == sysTime.wDay &&
|
||||
systimeSrc.wHour == sysTime.wHour &&
|
||||
systimeSrc.wMinute == sysTime.wMinute &&
|
||||
systimeSrc.wSecond == sysTime.wSecond);
|
||||
|
||||
return ok;
|
||||
return ok;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace ATL
|
||||
} // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef _ATL_ALL_WARNINGS
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
#endif // __ATLCORE_H__
|
||||
#endif // __ATLCORE_H__
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#pragma warning(disable : 4619) // there is no warning number
|
||||
#pragma warning(disable : 4619) // there is no warning number
|
||||
|
||||
#include <atlrc.h>
|
||||
#include <errno.h>
|
||||
@@ -33,11 +33,11 @@
|
||||
#ifndef RC_INVOKED
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error ATL requires C++ compilation (use a .cpp suffix)
|
||||
#error ATL requires C++ compilation (use a .cpp suffix)
|
||||
#endif
|
||||
|
||||
#ifdef UNDER_CE
|
||||
#error This version of ATL is not currently supported for CE. Look for the CE specific version.
|
||||
#error This version of ATL is not currently supported for CE. Look for the CE specific version.
|
||||
#endif
|
||||
|
||||
// If you are mixing compilation units that are built as
|
||||
@@ -47,7 +47,7 @@
|
||||
#if !defined(_ATL_MIXED)
|
||||
namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
{
|
||||
struct _Please_define_it_the_same_throughout_your_project { };
|
||||
struct _Please_define_it_the_same_throughout_your_project { };
|
||||
}
|
||||
#else
|
||||
namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
@@ -57,28 +57,28 @@ namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
#else
|
||||
#pragma comment(linker, "/include:??3@YAXPEAX@Z")
|
||||
#endif
|
||||
struct _Please_define_it_the_same_throughout_your_project { virtual void one(){} };
|
||||
struct _Please_define_it_the_same_throughout_your_project { virtual void one(){} };
|
||||
}
|
||||
#endif
|
||||
namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
{
|
||||
__declspec(selectany) _Please_define_it_the_same_throughout_your_project clash = _Please_define_it_the_same_throughout_your_project ();
|
||||
__declspec(selectany) _Please_define_it_the_same_throughout_your_project clash = _Please_define_it_the_same_throughout_your_project ();
|
||||
}
|
||||
|
||||
#if !defined(_ATL_MIXED)
|
||||
namespace Define_the_symbol__ATL_MIXED
|
||||
{
|
||||
#if defined(_M_CEE)
|
||||
struct Thank_you { };
|
||||
struct Thank_you { };
|
||||
#else
|
||||
#ifdef _M_IX86
|
||||
#pragma comment(linker, "/include:??3@YAXPAX@Z")
|
||||
#else
|
||||
#pragma comment(linker, "/include:??3@YAXPEAX@Z")
|
||||
#endif
|
||||
struct Thank_you { virtual void one(){} };
|
||||
struct Thank_you { virtual void one(){} };
|
||||
#endif
|
||||
__declspec(selectany) Thank_you clash = Thank_you();
|
||||
__declspec(selectany) Thank_you clash = Thank_you();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Define_the_symbol__ATL_MIXED
|
||||
#if defined(_PREFAST_) && (_MSC_VER < 1600)
|
||||
#define ATLSTATIC_ASSERT(expr, comment)
|
||||
#else
|
||||
#define ATLSTATIC_ASSERT(expr, comment) static_assert(expr, comment)
|
||||
#define ATLSTATIC_ASSERT(expr, comment) static_assert(expr, comment)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
@@ -184,19 +184,19 @@ Sometimes we have code like
|
||||
|
||||
HRESULT ComMethod(void)
|
||||
{
|
||||
ATLASSUME(m_pFoo);
|
||||
return m_pFoo->Method();
|
||||
ATLASSUME(m_pFoo);
|
||||
return m_pFoo->Method();
|
||||
}
|
||||
|
||||
We could add
|
||||
if(!m_pFoo) return E_POINTER;
|
||||
if(!m_pFoo) return E_POINTER;
|
||||
|
||||
But this is very unlikely to help, since it removes the ability of the developer to debug this problem if it's seen in a retail
|
||||
build of the application.
|
||||
|
||||
We could try something more severe
|
||||
|
||||
if(!m_pFoo) terminate(); // or your favourite shutdown function
|
||||
if(!m_pFoo) terminate(); // or your favourite shutdown function
|
||||
|
||||
This would ensure good reporting (because VC8 terminate generates a Windows Error Report and crash dump), but hardly seems a big win
|
||||
over the previous crash.
|
||||
@@ -233,9 +233,9 @@ So we've done a broad replace of all the member-related ATLASSERT to ATLASSUME.
|
||||
#ifndef ATLENSURE_THROW
|
||||
#define ATLENSURE_THROW(expr, hr) \
|
||||
do { \
|
||||
int __atl_condVal=!!(expr); \
|
||||
ATLASSUME(__atl_condVal); \
|
||||
if(!(__atl_condVal)) AtlThrow(hr); \
|
||||
int __atl_condVal=!!(expr); \
|
||||
ATLASSUME(__atl_condVal); \
|
||||
if(!(__atl_condVal)) AtlThrow(hr); \
|
||||
} while (0)
|
||||
#endif // ATLENSURE_THROW
|
||||
|
||||
@@ -251,9 +251,9 @@ do { \
|
||||
#ifndef ATLENSURE_RETURN_VAL
|
||||
#define ATLENSURE_RETURN_VAL(expr, val) \
|
||||
do { \
|
||||
int __atl_condVal=!!(expr); \
|
||||
ATLASSERT(__atl_condVal); \
|
||||
if(!(__atl_condVal)) return val; \
|
||||
int __atl_condVal=!!(expr); \
|
||||
ATLASSERT(__atl_condVal); \
|
||||
if(!(__atl_condVal)) return val; \
|
||||
} while (0)
|
||||
#endif // ATLENSURE_RETURN_VAL
|
||||
|
||||
@@ -278,17 +278,17 @@ ATLENSURE_RETURN_HR is HRESULT-specific, though currently the same as _VAL
|
||||
#ifndef ATL_CRT_ERRORCHECK_SPRINTF
|
||||
#define ATL_CRT_ERRORCHECK_SPRINTF(expr) \
|
||||
do { \
|
||||
errno_t _saveErrno = errno; \
|
||||
errno = 0; \
|
||||
(expr); \
|
||||
if(0 != errno) \
|
||||
{ \
|
||||
AtlCrtErrorCheck(errno); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
errno = _saveErrno; \
|
||||
} \
|
||||
errno_t _saveErrno = errno; \
|
||||
errno = 0; \
|
||||
(expr); \
|
||||
if(0 != errno) \
|
||||
{ \
|
||||
AtlCrtErrorCheck(errno); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
errno = _saveErrno; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif // ATL_CRT_ERRORCHECK_SPRINTF
|
||||
|
||||
@@ -383,33 +383,33 @@ do { \
|
||||
#endif
|
||||
|
||||
#if defined(_ATL_DLL)
|
||||
#define ATLAPI extern "C" HRESULT __declspec(dllimport) __stdcall
|
||||
#define ATLAPI_(x) extern "C" __declspec(dllimport) x __stdcall
|
||||
#define ATLINLINE
|
||||
#define ATLAPIINL extern "C" inline HRESULT __stdcall
|
||||
#define ATLAPIINL_(x) extern "C" inline x __stdcall
|
||||
#define ATLAPI extern "C" HRESULT __declspec(dllimport) __stdcall
|
||||
#define ATLAPI_(x) extern "C" __declspec(dllimport) x __stdcall
|
||||
#define ATLINLINE
|
||||
#define ATLAPIINL extern "C" inline HRESULT __stdcall
|
||||
#define ATLAPIINL_(x) extern "C" inline x __stdcall
|
||||
#elif defined(_ATL_DLL_IMPL)
|
||||
#define ATLAPI extern "C" inline HRESULT __stdcall
|
||||
#define ATLAPI_(x) extern "C" inline x __stdcall
|
||||
#define ATLAPIINL ATLAPI
|
||||
#define ATLAPIINL_(x) ATLAPI_(x)
|
||||
#define ATLINLINE
|
||||
#define ATLAPI extern "C" inline HRESULT __stdcall
|
||||
#define ATLAPI_(x) extern "C" inline x __stdcall
|
||||
#define ATLAPIINL ATLAPI
|
||||
#define ATLAPIINL_(x) ATLAPI_(x)
|
||||
#define ATLINLINE
|
||||
#else
|
||||
#define ATLAPI __declspec(nothrow) HRESULT __stdcall
|
||||
#define ATLAPI_(x) __declspec(nothrow) x __stdcall
|
||||
#define ATLAPIINL ATLAPI
|
||||
#define ATLAPIINL_(x) ATLAPI_(x)
|
||||
#define ATLINLINE inline
|
||||
#define ATLAPI __declspec(nothrow) HRESULT __stdcall
|
||||
#define ATLAPI_(x) __declspec(nothrow) x __stdcall
|
||||
#define ATLAPIINL ATLAPI
|
||||
#define ATLAPIINL_(x) ATLAPI_(x)
|
||||
#define ATLINLINE inline
|
||||
#endif
|
||||
|
||||
#ifdef _ATL_NO_EXCEPTIONS
|
||||
#ifdef _AFX
|
||||
// #error MFC projects cannot define _ATL_NO_EXCEPTIONS
|
||||
#endif
|
||||
#ifdef _AFX
|
||||
// #error MFC projects cannot define _ATL_NO_EXCEPTIONS
|
||||
#endif
|
||||
#else
|
||||
#ifndef _CPPUNWIND
|
||||
#define _ATL_NO_EXCEPTIONS
|
||||
#endif
|
||||
#ifndef _CPPUNWIND
|
||||
#define _ATL_NO_EXCEPTIONS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _CPPUNWIND
|
||||
@@ -421,9 +421,9 @@ do { \
|
||||
#else
|
||||
/* prefast noise VSW 489981 */
|
||||
#define ATLTRYALLOC(x) __pragma(warning(push)) __pragma(warning(disable: 4571)) try{x;} catch(...) {} __pragma(warning(pop))
|
||||
#endif //__AFX
|
||||
#endif //__AFX
|
||||
|
||||
#endif //ATLTRYALLOC
|
||||
#endif //ATLTRYALLOC
|
||||
|
||||
// If you define _ATLTRY before including this file, then
|
||||
// you should define _ATLCATCH and _ATLRETHROW as well.
|
||||
@@ -444,7 +444,7 @@ do { \
|
||||
#endif
|
||||
|
||||
#define _ATLRETHROW throw
|
||||
#endif // _ATLTRY
|
||||
#endif // _ATLTRY
|
||||
|
||||
/*
|
||||
COM functions should not throw. Which means we should protect their callers from C++ exceptions leaking out. These macros
|
||||
@@ -454,38 +454,38 @@ this end
|
||||
|
||||
#ifndef _ATL_COM_BEGIN
|
||||
#define _ATL_COM_BEGIN \
|
||||
HRESULT __hrAtlComMethod=S_OK; \
|
||||
try \
|
||||
{
|
||||
HRESULT __hrAtlComMethod=S_OK; \
|
||||
try \
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _AFX
|
||||
/* Nice to do something more complex here in future to translate an MFC exception to a better HR */
|
||||
#define _AFX_COM_END_PART \
|
||||
catch(CException *e) \
|
||||
{ \
|
||||
if(e) \
|
||||
{ \
|
||||
e->Delete(); \
|
||||
} \
|
||||
__hrAtlComMethod=E_FAIL; \
|
||||
}
|
||||
catch(CException *e) \
|
||||
{ \
|
||||
if(e) \
|
||||
{ \
|
||||
e->Delete(); \
|
||||
} \
|
||||
__hrAtlComMethod=E_FAIL; \
|
||||
}
|
||||
#else
|
||||
#define _AFX_COM_END_PART \
|
||||
catch(CAtlException e) \
|
||||
{ \
|
||||
__hrAtlComMethod=e.m_hr; \
|
||||
}
|
||||
catch(CAtlException e) \
|
||||
{ \
|
||||
__hrAtlComMethod=e.m_hr; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _ATL_COM_END
|
||||
#define _ATL_COM_END \
|
||||
_AFX_COM_END_PART \
|
||||
catch(...) \
|
||||
{ \
|
||||
__hrAtlComMethod=E_FAIL; \
|
||||
} \
|
||||
return hr;
|
||||
_AFX_COM_END_PART \
|
||||
catch(...) \
|
||||
{ \
|
||||
__hrAtlComMethod=E_FAIL; \
|
||||
} \
|
||||
return hr;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -494,7 +494,7 @@ this end
|
||||
|
||||
#ifndef ATLTRYALLOC
|
||||
#define ATLTRYALLOC(x) x;
|
||||
#endif //ATLTRYALLOC
|
||||
#endif //ATLTRYALLOC
|
||||
|
||||
// if _ATLTRY is defined before including this file then
|
||||
// _ATLCATCH and _ATLRETHROW should be defined as well.
|
||||
@@ -504,13 +504,13 @@ this end
|
||||
#define _ATLCATCHALL() __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop))
|
||||
#define _ATLDELETEEXCEPTION(e)
|
||||
#define _ATLRETHROW
|
||||
#endif // _ATLTRY
|
||||
#endif // _ATLTRY
|
||||
|
||||
#endif //_CPPUNWIND
|
||||
#endif //_CPPUNWIND
|
||||
|
||||
#ifndef ATLTRY
|
||||
#define ATLTRY(x) ATLTRYALLOC(x)
|
||||
#endif //ATLTRY
|
||||
#endif //ATLTRY
|
||||
|
||||
#define offsetofclass(base, derived) ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)
|
||||
|
||||
@@ -558,19 +558,19 @@ this end
|
||||
#ifndef NOMCX
|
||||
#define NOMCX
|
||||
#endif
|
||||
#endif // ATL_NO_LEAN_AND_MEAN
|
||||
#endif // ATL_NO_LEAN_AND_MEAN
|
||||
|
||||
#ifdef NOSERVICE
|
||||
#ifndef _ATL_NO_SERVICE
|
||||
#define _ATL_NO_SERVICE
|
||||
#endif // _ATL_NO_SERVICE
|
||||
#endif // _ATL_NO_SERVICE
|
||||
#else
|
||||
#ifdef _ATL_NO_SERVICE
|
||||
#ifndef NOSERVICE
|
||||
#define NOSERVICE
|
||||
#endif // NOSERVICE
|
||||
#endif // _ATL_NO_SERVICE
|
||||
#endif // NOSERVICE
|
||||
#endif // NOSERVICE
|
||||
#endif // _ATL_NO_SERVICE
|
||||
#endif // NOSERVICE
|
||||
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
@@ -580,15 +580,15 @@ this end
|
||||
// Warning: if you define the above symbol, you will have
|
||||
// to provide your own definition of the ATLASSERT(x) macro
|
||||
// in order to compile ATL
|
||||
#include <crtdbg.h>
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#endif // RC_INVOKED
|
||||
|
||||
// Note : we can not use macros to generate the window class names because it
|
||||
// will require nested macros. rc.exe does not handle nested macros.
|
||||
// #define ATLAXWIN_CLASS _ATL_STRINGIZE(_ATL_APPEND(AtlAxWin, _ATL_FILENAME_VER_NUM))
|
||||
// #define ATLAXWINLIC_CLASS _ATL_STRINGIZE(_ATL_APPEND(AtlAxWinLic, _ATL_FILENAME_VER_NUM))
|
||||
// #define ATLAXWIN_CLASS _ATL_STRINGIZE(_ATL_APPEND(AtlAxWin, _ATL_FILENAME_VER_NUM))
|
||||
// #define ATLAXWINLIC_CLASS _ATL_STRINGIZE(_ATL_APPEND(AtlAxWinLic, _ATL_FILENAME_VER_NUM))
|
||||
|
||||
#define ATLAXWIN_CLASS "AtlAxWin100"
|
||||
#define ATLAXWINLIC_CLASS "AtlAxWinLic100"
|
||||
@@ -622,10 +622,10 @@ that we consider it dangerous to even throw an exception
|
||||
#else
|
||||
#if !defined(__MINGW32__)
|
||||
#define PTM_WARNING_DISABLE \
|
||||
__pragma(warning( push )) \
|
||||
__pragma(warning( disable : 4867 ))
|
||||
__pragma(warning( push )) \
|
||||
__pragma(warning( disable : 4867 ))
|
||||
#define PTM_WARNING_RESTORE \
|
||||
__pragma(warning( pop ))
|
||||
__pragma(warning( pop ))
|
||||
#else
|
||||
#define PTM_WARNING_DISABLE
|
||||
#define PTM_WARNING_RESTORE
|
||||
@@ -695,13 +695,13 @@ that we consider it dangerous to even throw an exception
|
||||
#define ATLPREFAST_SUPPRESS(x)
|
||||
#define ATLPREFAST_UNSUPPRESS()
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _FormatMessage_format_string_
|
||||
#define _FormatMessage_format_string_
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Helper functions for SAL annotation
|
||||
Helper functions for SAL annotation
|
||||
*/
|
||||
namespace ATL {
|
||||
|
||||
|
||||
@@ -27,32 +27,32 @@ namespace ATL
|
||||
// Exception raise (for functions that cannot return an error code)
|
||||
|
||||
inline void __declspec(noreturn) _AtlRaiseException(
|
||||
_In_ DWORD dwExceptionCode,
|
||||
_In_ DWORD dwExceptionFlags = EXCEPTION_NONCONTINUABLE)
|
||||
_In_ DWORD dwExceptionCode,
|
||||
_In_ DWORD dwExceptionFlags = EXCEPTION_NONCONTINUABLE)
|
||||
{
|
||||
RaiseException( dwExceptionCode, dwExceptionFlags, 0, NULL );
|
||||
RaiseException( dwExceptionCode, dwExceptionFlags, 0, NULL );
|
||||
}
|
||||
|
||||
class CAtlException
|
||||
{
|
||||
public:
|
||||
CAtlException() throw() :
|
||||
m_hr( E_FAIL )
|
||||
{
|
||||
}
|
||||
CAtlException() throw() :
|
||||
m_hr( E_FAIL )
|
||||
{
|
||||
}
|
||||
|
||||
CAtlException(_In_ HRESULT hr) throw() :
|
||||
m_hr( hr )
|
||||
{
|
||||
}
|
||||
CAtlException(_In_ HRESULT hr) throw() :
|
||||
m_hr( hr )
|
||||
{
|
||||
}
|
||||
|
||||
operator HRESULT() const throw()
|
||||
{
|
||||
return( m_hr );
|
||||
}
|
||||
operator HRESULT() const throw()
|
||||
{
|
||||
return( m_hr );
|
||||
}
|
||||
|
||||
public:
|
||||
HRESULT m_hr;
|
||||
HRESULT m_hr;
|
||||
};
|
||||
|
||||
#ifndef ATL_NOINLINE
|
||||
@@ -73,15 +73,15 @@ public:
|
||||
#else
|
||||
ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowImpl(_In_ HRESULT hr)
|
||||
{
|
||||
throw CAtlException( hr );
|
||||
throw CAtlException( hr );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Throw a CAtlException corresponding to the result of ::GetLastError
|
||||
ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowLastWin32()
|
||||
{
|
||||
DWORD dwError = ::GetLastError();
|
||||
AtlThrowImpl( HRESULT_FROM_WIN32( dwError ) );
|
||||
DWORD dwError = ::GetLastError();
|
||||
AtlThrowImpl( HRESULT_FROM_WIN32( dwError ) );
|
||||
}
|
||||
|
||||
#else // no exception handling
|
||||
@@ -91,25 +91,25 @@ ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowLastWin32()
|
||||
|
||||
ATL_NOINLINE inline void WINAPI AtlThrowImpl(_In_ HRESULT hr)
|
||||
{
|
||||
ATLASSERT( false );
|
||||
DWORD dwExceptionCode;
|
||||
switch(hr)
|
||||
{
|
||||
case E_OUTOFMEMORY:
|
||||
dwExceptionCode = STATUS_NO_MEMORY;
|
||||
break;
|
||||
default:
|
||||
dwExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
||||
}
|
||||
_AtlRaiseException((DWORD)dwExceptionCode);
|
||||
ATLASSERT( false );
|
||||
DWORD dwExceptionCode;
|
||||
switch(hr)
|
||||
{
|
||||
case E_OUTOFMEMORY:
|
||||
dwExceptionCode = STATUS_NO_MEMORY;
|
||||
break;
|
||||
default:
|
||||
dwExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
||||
}
|
||||
_AtlRaiseException((DWORD)dwExceptionCode);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Throw a CAtlException corresponding to the result of ::GetLastError
|
||||
ATL_NOINLINE inline void WINAPI AtlThrowLastWin32()
|
||||
{
|
||||
DWORD dwError = ::GetLastError();
|
||||
AtlThrowImpl( HRESULT_FROM_WIN32( dwError ) );
|
||||
DWORD dwError = ::GetLastError();
|
||||
AtlThrowImpl( HRESULT_FROM_WIN32( dwError ) );
|
||||
}
|
||||
|
||||
#endif // no exception handling
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -49,64 +49,64 @@ template <class T>
|
||||
class CSimpleArrayEqualHelper
|
||||
{
|
||||
public:
|
||||
static bool IsEqual(
|
||||
_In_ const T& t1,
|
||||
_In_ const T& t2)
|
||||
{
|
||||
return (t1 == t2);
|
||||
}
|
||||
static bool IsEqual(
|
||||
_In_ const T& t1,
|
||||
_In_ const T& t2)
|
||||
{
|
||||
return (t1 == t2);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class CSimpleArrayEqualHelperFalse
|
||||
{
|
||||
public:
|
||||
static bool IsEqual(
|
||||
_In_ const T&,
|
||||
_In_ const T&)
|
||||
{
|
||||
ATLASSERT(false);
|
||||
return false;
|
||||
}
|
||||
static bool IsEqual(
|
||||
_In_ const T&,
|
||||
_In_ const T&)
|
||||
{
|
||||
ATLASSERT(false);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class TKey, class TVal>
|
||||
class CSimpleMapEqualHelper
|
||||
{
|
||||
public:
|
||||
static bool IsEqualKey(
|
||||
_In_ const TKey& k1,
|
||||
_In_ const TKey& k2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TKey>::IsEqual(k1, k2);
|
||||
}
|
||||
static bool IsEqualKey(
|
||||
_In_ const TKey& k1,
|
||||
_In_ const TKey& k2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TKey>::IsEqual(k1, k2);
|
||||
}
|
||||
|
||||
static bool IsEqualValue(
|
||||
_In_ const TVal& v1,
|
||||
_In_ const TVal& v2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TVal>::IsEqual(v1, v2);
|
||||
}
|
||||
static bool IsEqualValue(
|
||||
_In_ const TVal& v1,
|
||||
_In_ const TVal& v2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TVal>::IsEqual(v1, v2);
|
||||
}
|
||||
};
|
||||
|
||||
template <class TKey, class TVal>
|
||||
class CSimpleMapEqualHelperFalse
|
||||
{
|
||||
public:
|
||||
static bool IsEqualKey(
|
||||
_In_ const TKey& k1,
|
||||
_In_ const TKey& k2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TKey>::IsEqual(k1, k2);
|
||||
}
|
||||
static bool IsEqualKey(
|
||||
_In_ const TKey& k1,
|
||||
_In_ const TKey& k2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TKey>::IsEqual(k1, k2);
|
||||
}
|
||||
|
||||
static bool IsEqualValue(
|
||||
_In_ const TVal&,
|
||||
_In_ const TVal&)
|
||||
{
|
||||
ATLASSERT(FALSE);
|
||||
return false;
|
||||
}
|
||||
static bool IsEqualValue(
|
||||
_In_ const TVal&,
|
||||
_In_ const TVal&)
|
||||
{
|
||||
ATLASSERT(FALSE);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class TEqual = CSimpleArrayEqualHelper< T > >
|
||||
@@ -114,193 +114,193 @@ class CSimpleArray
|
||||
{
|
||||
public:
|
||||
// Construction/destruction
|
||||
CSimpleArray() :
|
||||
m_aT(NULL), m_nSize(0), m_nAllocSize(0)
|
||||
{
|
||||
}
|
||||
CSimpleArray() :
|
||||
m_aT(NULL), m_nSize(0), m_nAllocSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
~CSimpleArray();
|
||||
~CSimpleArray();
|
||||
|
||||
CSimpleArray(_In_ const CSimpleArray< T, TEqual >& src) :
|
||||
m_aT(NULL), m_nSize(0), m_nAllocSize(0)
|
||||
{
|
||||
CSimpleArray(_In_ const CSimpleArray< T, TEqual >& src) :
|
||||
m_aT(NULL), m_nSize(0), m_nAllocSize(0)
|
||||
{
|
||||
if (src.GetSize())
|
||||
{
|
||||
m_aT = (T*)nb_calloc(src.GetSize(), sizeof(T));
|
||||
if (m_aT != NULL)
|
||||
{
|
||||
m_nAllocSize = src.GetSize();
|
||||
for (int i=0; i<src.GetSize(); i++)
|
||||
Add(src[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
CSimpleArray< T, TEqual >& operator=(_In_ const CSimpleArray< T, TEqual >& src)
|
||||
{
|
||||
if (GetSize() != src.GetSize())
|
||||
{
|
||||
RemoveAll();
|
||||
m_aT = (T*)nb_calloc(src.GetSize(), sizeof(T));
|
||||
if (m_aT != NULL)
|
||||
m_nAllocSize = src.GetSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = GetSize(); i > 0; i--)
|
||||
RemoveAt(i - 1);
|
||||
}
|
||||
for (int i=0; i<src.GetSize(); i++)
|
||||
Add(src[i]);
|
||||
return *this;
|
||||
}
|
||||
m_aT = (T*)nb_calloc(src.GetSize(), sizeof(T));
|
||||
if (m_aT != NULL)
|
||||
{
|
||||
m_nAllocSize = src.GetSize();
|
||||
for (int i=0; i<src.GetSize(); i++)
|
||||
Add(src[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
CSimpleArray< T, TEqual >& operator=(_In_ const CSimpleArray< T, TEqual >& src)
|
||||
{
|
||||
if (GetSize() != src.GetSize())
|
||||
{
|
||||
RemoveAll();
|
||||
m_aT = (T*)nb_calloc(src.GetSize(), sizeof(T));
|
||||
if (m_aT != NULL)
|
||||
m_nAllocSize = src.GetSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = GetSize(); i > 0; i--)
|
||||
RemoveAt(i - 1);
|
||||
}
|
||||
for (int i=0; i<src.GetSize(); i++)
|
||||
Add(src[i]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Operations
|
||||
int GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
BOOL Add(_In_ const T& t)
|
||||
{
|
||||
if(m_nSize == m_nAllocSize)
|
||||
{
|
||||
// Make sure newElement is not a reference to an element in the array.
|
||||
// Or else, it will be invalidated by the reallocation.
|
||||
ATLENSURE( (&t < m_aT) ||
|
||||
(&t >= (m_aT + m_nAllocSize) ) );
|
||||
|
||||
T* aT;
|
||||
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
|
||||
|
||||
if (nNewAllocSize<0||nNewAllocSize>INT_MAX/sizeof(T))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
aT = (T*)_recalloc(m_aT, nNewAllocSize, sizeof(T));
|
||||
if(aT == NULL)
|
||||
return FALSE;
|
||||
m_nAllocSize = nNewAllocSize;
|
||||
m_aT = aT;
|
||||
}
|
||||
InternalSetAtIndex(m_nSize, t);
|
||||
m_nSize++;
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Remove(_In_ const T& t)
|
||||
{
|
||||
int nIndex = Find(t);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
return RemoveAt(nIndex);
|
||||
}
|
||||
BOOL RemoveAt(_In_ int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
m_aT[nIndex].~T();
|
||||
if(nIndex != (m_nSize - 1))
|
||||
Checked::memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T));
|
||||
m_nSize--;
|
||||
return TRUE;
|
||||
}
|
||||
void RemoveAll()
|
||||
{
|
||||
if(m_aT != NULL)
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
m_aT[i].~T();
|
||||
nb_free(m_aT);
|
||||
m_aT = NULL;
|
||||
}
|
||||
m_nSize = 0;
|
||||
m_nAllocSize = 0;
|
||||
int GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
const T& operator[] (_In_ int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
{
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
T& operator[] (_In_ int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
{
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
T* GetData() const
|
||||
{
|
||||
return m_aT;
|
||||
}
|
||||
BOOL Add(_In_ const T& t)
|
||||
{
|
||||
if(m_nSize == m_nAllocSize)
|
||||
{
|
||||
// Make sure newElement is not a reference to an element in the array.
|
||||
// Or else, it will be invalidated by the reallocation.
|
||||
ATLENSURE( (&t < m_aT) ||
|
||||
(&t >= (m_aT + m_nAllocSize) ) );
|
||||
|
||||
int Find(_In_ const T& t) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqual(m_aT[i], t))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
T* aT;
|
||||
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
|
||||
|
||||
BOOL SetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const T& t)
|
||||
{
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
InternalSetAtIndex(nIndex, t);
|
||||
return TRUE;
|
||||
}
|
||||
if (nNewAllocSize<0||nNewAllocSize>INT_MAX/sizeof(T))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
aT = (T*)_recalloc(m_aT, nNewAllocSize, sizeof(T));
|
||||
if(aT == NULL)
|
||||
return FALSE;
|
||||
m_nAllocSize = nNewAllocSize;
|
||||
m_aT = aT;
|
||||
}
|
||||
InternalSetAtIndex(m_nSize, t);
|
||||
m_nSize++;
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Remove(_In_ const T& t)
|
||||
{
|
||||
int nIndex = Find(t);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
return RemoveAt(nIndex);
|
||||
}
|
||||
BOOL RemoveAt(_In_ int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
m_aT[nIndex].~T();
|
||||
if(nIndex != (m_nSize - 1))
|
||||
Checked::memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T));
|
||||
m_nSize--;
|
||||
return TRUE;
|
||||
}
|
||||
void RemoveAll()
|
||||
{
|
||||
if(m_aT != NULL)
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
m_aT[i].~T();
|
||||
nb_free(m_aT);
|
||||
m_aT = NULL;
|
||||
}
|
||||
m_nSize = 0;
|
||||
m_nAllocSize = 0;
|
||||
}
|
||||
const T& operator[] (_In_ int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
{
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
T& operator[] (_In_ int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
{
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
T* GetData() const
|
||||
{
|
||||
return m_aT;
|
||||
}
|
||||
|
||||
int Find(_In_ const T& t) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqual(m_aT[i], t))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
BOOL SetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const T& t)
|
||||
{
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
InternalSetAtIndex(nIndex, t);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Implementation
|
||||
class Wrapper
|
||||
{
|
||||
public:
|
||||
Wrapper(_In_ const T& _t) : t(_t)
|
||||
{
|
||||
}
|
||||
template <class _Ty>
|
||||
void * __cdecl operator new(
|
||||
_In_ size_t,
|
||||
_In_ _Ty* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
template <class _Ty>
|
||||
void __cdecl operator delete(
|
||||
_In_ void* /* pv */,
|
||||
_In_ _Ty* /* p */)
|
||||
{
|
||||
}
|
||||
T t;
|
||||
};
|
||||
class Wrapper
|
||||
{
|
||||
public:
|
||||
Wrapper(_In_ const T& _t) : t(_t)
|
||||
{
|
||||
}
|
||||
template <class _Ty>
|
||||
void * __cdecl operator new(
|
||||
_In_ size_t,
|
||||
_In_ _Ty* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
template <class _Ty>
|
||||
void __cdecl operator delete(
|
||||
_In_ void* /* pv */,
|
||||
_In_ _Ty* /* p */)
|
||||
{
|
||||
}
|
||||
T t;
|
||||
};
|
||||
|
||||
// Implementation
|
||||
void InternalSetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const T& t)
|
||||
{
|
||||
new(m_aT + nIndex) Wrapper(t);
|
||||
}
|
||||
void InternalSetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const T& t)
|
||||
{
|
||||
new(m_aT + nIndex) Wrapper(t);
|
||||
}
|
||||
|
||||
typedef T _ArrayElementType;
|
||||
T* m_aT;
|
||||
int m_nSize;
|
||||
int m_nAllocSize;
|
||||
typedef T _ArrayElementType;
|
||||
T* m_aT;
|
||||
int m_nSize;
|
||||
int m_nAllocSize;
|
||||
};
|
||||
|
||||
#define CSimpleValArray CSimpleArray
|
||||
|
||||
template <class T, class TEqual> inline CSimpleArray<T, TEqual>::~CSimpleArray()
|
||||
{
|
||||
RemoveAll();
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
// intended for small number of simple types or pointers
|
||||
@@ -308,204 +308,204 @@ template <class TKey, class TVal, class TEqual = CSimpleMapEqualHelper< TKey, TV
|
||||
class CSimpleMap
|
||||
{
|
||||
public:
|
||||
TKey* m_aKey;
|
||||
TVal* m_aVal;
|
||||
int m_nSize;
|
||||
TKey* m_aKey;
|
||||
TVal* m_aVal;
|
||||
int m_nSize;
|
||||
|
||||
typedef TKey _ArrayKeyType;
|
||||
typedef TVal _ArrayElementType;
|
||||
typedef TKey _ArrayKeyType;
|
||||
typedef TVal _ArrayElementType;
|
||||
|
||||
// Construction/destruction
|
||||
CSimpleMap() :
|
||||
m_aKey(NULL), m_aVal(NULL), m_nSize(0)
|
||||
{
|
||||
}
|
||||
CSimpleMap() :
|
||||
m_aKey(NULL), m_aVal(NULL), m_nSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
~CSimpleMap()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
~CSimpleMap()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
// Operations
|
||||
int GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
BOOL Add(
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
TKey* pKey;
|
||||
pKey = (TKey*)_recalloc(m_aKey, (m_nSize + 1), sizeof(TKey));
|
||||
if(pKey == NULL)
|
||||
return FALSE;
|
||||
m_aKey = pKey;
|
||||
TVal* pVal;
|
||||
pVal = (TVal*)_recalloc(m_aVal, (m_nSize + 1), sizeof(TVal));
|
||||
if(pVal == NULL)
|
||||
return FALSE;
|
||||
m_aVal = pVal;
|
||||
InternalSetAtIndex(m_nSize, key, val);
|
||||
m_nSize++;
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Remove(_In_ const TKey& key)
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
return RemoveAt(nIndex);
|
||||
}
|
||||
BOOL RemoveAt(_In_ int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
m_aKey[nIndex].~TKey();
|
||||
m_aVal[nIndex].~TVal();
|
||||
if(nIndex != (m_nSize - 1))
|
||||
{
|
||||
Checked::memmove_s((void*)(m_aKey + nIndex), (m_nSize - nIndex) * sizeof(TKey), (void*)(m_aKey + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TKey));
|
||||
Checked::memmove_s((void*)(m_aVal + nIndex), (m_nSize - nIndex) * sizeof(TVal), (void*)(m_aVal + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TVal));
|
||||
}
|
||||
TKey* pKey;
|
||||
pKey = (TKey*)_recalloc(m_aKey, (m_nSize - 1), sizeof(TKey));
|
||||
if(pKey != NULL || m_nSize == 1)
|
||||
m_aKey = pKey;
|
||||
TVal* pVal;
|
||||
pVal = (TVal*)_recalloc(m_aVal, (m_nSize - 1), sizeof(TVal));
|
||||
if(pVal != NULL || m_nSize == 1)
|
||||
m_aVal = pVal;
|
||||
m_nSize--;
|
||||
return TRUE;
|
||||
}
|
||||
void RemoveAll()
|
||||
{
|
||||
if(m_aKey != NULL)
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
m_aKey[i].~TKey();
|
||||
m_aVal[i].~TVal();
|
||||
}
|
||||
nb_free(m_aKey);
|
||||
m_aKey = NULL;
|
||||
}
|
||||
if(m_aVal != NULL)
|
||||
{
|
||||
nb_free(m_aVal);
|
||||
m_aVal = NULL;
|
||||
}
|
||||
int GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
BOOL Add(
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
TKey* pKey;
|
||||
pKey = (TKey*)_recalloc(m_aKey, (m_nSize + 1), sizeof(TKey));
|
||||
if(pKey == NULL)
|
||||
return FALSE;
|
||||
m_aKey = pKey;
|
||||
TVal* pVal;
|
||||
pVal = (TVal*)_recalloc(m_aVal, (m_nSize + 1), sizeof(TVal));
|
||||
if(pVal == NULL)
|
||||
return FALSE;
|
||||
m_aVal = pVal;
|
||||
InternalSetAtIndex(m_nSize, key, val);
|
||||
m_nSize++;
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Remove(_In_ const TKey& key)
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
return RemoveAt(nIndex);
|
||||
}
|
||||
BOOL RemoveAt(_In_ int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
m_aKey[nIndex].~TKey();
|
||||
m_aVal[nIndex].~TVal();
|
||||
if(nIndex != (m_nSize - 1))
|
||||
{
|
||||
Checked::memmove_s((void*)(m_aKey + nIndex), (m_nSize - nIndex) * sizeof(TKey), (void*)(m_aKey + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TKey));
|
||||
Checked::memmove_s((void*)(m_aVal + nIndex), (m_nSize - nIndex) * sizeof(TVal), (void*)(m_aVal + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TVal));
|
||||
}
|
||||
TKey* pKey;
|
||||
pKey = (TKey*)_recalloc(m_aKey, (m_nSize - 1), sizeof(TKey));
|
||||
if(pKey != NULL || m_nSize == 1)
|
||||
m_aKey = pKey;
|
||||
TVal* pVal;
|
||||
pVal = (TVal*)_recalloc(m_aVal, (m_nSize - 1), sizeof(TVal));
|
||||
if(pVal != NULL || m_nSize == 1)
|
||||
m_aVal = pVal;
|
||||
m_nSize--;
|
||||
return TRUE;
|
||||
}
|
||||
void RemoveAll()
|
||||
{
|
||||
if(m_aKey != NULL)
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
m_aKey[i].~TKey();
|
||||
m_aVal[i].~TVal();
|
||||
}
|
||||
nb_free(m_aKey);
|
||||
m_aKey = NULL;
|
||||
}
|
||||
if(m_aVal != NULL)
|
||||
{
|
||||
nb_free(m_aVal);
|
||||
m_aVal = NULL;
|
||||
}
|
||||
|
||||
m_nSize = 0;
|
||||
}
|
||||
BOOL SetAt(
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
m_aKey[nIndex].~TKey();
|
||||
m_aVal[nIndex].~TVal();
|
||||
InternalSetAtIndex(nIndex, key, val);
|
||||
return TRUE;
|
||||
}
|
||||
TVal Lookup(_In_ const TKey& key) const
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return NULL; // must be able to convert
|
||||
return GetValueAt(nIndex);
|
||||
}
|
||||
TKey ReverseLookup(_In_ const TVal& val) const
|
||||
{
|
||||
int nIndex = FindVal(val);
|
||||
if(nIndex == -1)
|
||||
return NULL; // must be able to convert
|
||||
return GetKeyAt(nIndex);
|
||||
}
|
||||
TKey& GetKeyAt(_In_ int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
m_nSize = 0;
|
||||
}
|
||||
BOOL SetAt(
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
m_aKey[nIndex].~TKey();
|
||||
m_aVal[nIndex].~TVal();
|
||||
InternalSetAtIndex(nIndex, key, val);
|
||||
return TRUE;
|
||||
}
|
||||
TVal Lookup(_In_ const TKey& key) const
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return NULL; // must be able to convert
|
||||
return GetValueAt(nIndex);
|
||||
}
|
||||
TKey ReverseLookup(_In_ const TVal& val) const
|
||||
{
|
||||
int nIndex = FindVal(val);
|
||||
if(nIndex == -1)
|
||||
return NULL; // must be able to convert
|
||||
return GetKeyAt(nIndex);
|
||||
}
|
||||
TKey& GetKeyAt(_In_ int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
|
||||
return m_aKey[nIndex];
|
||||
}
|
||||
TVal& GetValueAt(_In_ int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
return m_aKey[nIndex];
|
||||
}
|
||||
TVal& GetValueAt(_In_ int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
|
||||
return m_aVal[nIndex];
|
||||
}
|
||||
return m_aVal[nIndex];
|
||||
}
|
||||
|
||||
int FindKey(_In_ const TKey& key) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqualKey(m_aKey[i], key))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
int FindVal(_In_ const TVal& val) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqualValue(m_aVal[i], val))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
int FindKey(_In_ const TKey& key) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqualKey(m_aKey[i], key))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
int FindVal(_In_ const TVal& val) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqualValue(m_aVal[i], val))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
BOOL SetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
InternalSetAtIndex(nIndex, key, val);
|
||||
return TRUE;
|
||||
}
|
||||
BOOL SetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
InternalSetAtIndex(nIndex, key, val);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Implementation
|
||||
|
||||
template <typename T>
|
||||
class Wrapper
|
||||
{
|
||||
public:
|
||||
Wrapper(_In_ const T& _t) : t(_t)
|
||||
{
|
||||
}
|
||||
template <class _Ty>
|
||||
void *operator new(
|
||||
_In_ size_t,
|
||||
_In_ _Ty* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
template <class _Ty>
|
||||
void operator delete(
|
||||
_In_ void* /* pv */,
|
||||
_In_ _Ty* /* p */)
|
||||
{
|
||||
}
|
||||
T t;
|
||||
};
|
||||
void InternalSetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
new(m_aKey + nIndex) Wrapper<TKey>(key);
|
||||
new(m_aVal + nIndex) Wrapper<TVal>(val);
|
||||
}
|
||||
template <typename T>
|
||||
class Wrapper
|
||||
{
|
||||
public:
|
||||
Wrapper(_In_ const T& _t) : t(_t)
|
||||
{
|
||||
}
|
||||
template <class _Ty>
|
||||
void *operator new(
|
||||
_In_ size_t,
|
||||
_In_ _Ty* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
template <class _Ty>
|
||||
void operator delete(
|
||||
_In_ void* /* pv */,
|
||||
_In_ _Ty* /* p */)
|
||||
{
|
||||
}
|
||||
T t;
|
||||
};
|
||||
void InternalSetAtIndex(
|
||||
_In_ int nIndex,
|
||||
_In_ const TKey& key,
|
||||
_In_ const TVal& val)
|
||||
{
|
||||
new(m_aKey + nIndex) Wrapper<TKey>(key);
|
||||
new(m_aVal + nIndex) Wrapper<TVal>(val);
|
||||
}
|
||||
};
|
||||
|
||||
#pragma pop_macro("new")
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.activeX;
|
||||
|
||||
@@ -54,72 +54,72 @@ import com.jacob.com.InvocationProxy;
|
||||
*/
|
||||
public class ActiveXDispatchEvents extends DispatchEvents {
|
||||
|
||||
/**
|
||||
* This is the most commonly used constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
*/
|
||||
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
|
||||
super(sourceOfEvent, eventSink, null);
|
||||
}
|
||||
/**
|
||||
* This is the most commonly used constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
*/
|
||||
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
|
||||
super(sourceOfEvent, eventSink, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* None of the samples use this constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
* @param progId
|
||||
* ???
|
||||
*/
|
||||
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId) {
|
||||
super(sourceOfEvent, eventSink, progId, null);
|
||||
}
|
||||
/**
|
||||
* None of the samples use this constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
* @param progId
|
||||
* ???
|
||||
*/
|
||||
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId) {
|
||||
super(sourceOfEvent, eventSink, progId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
*
|
||||
* <pre>
|
||||
* >ActiveXDispatchEvents de =
|
||||
* new ActiveXDispatchEvents(someDispatch,someEventHAndler,
|
||||
* "Excel.Application",
|
||||
* "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE");
|
||||
*
|
||||
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink Java object that wants to receive the events
|
||||
* @param progId , mandatory if the typelib is specified
|
||||
* @param typeLib The location of the typelib to use
|
||||
*
|
||||
*/
|
||||
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId, String typeLib) {
|
||||
super(sourceOfEvent, eventSink, progId, typeLib);
|
||||
}
|
||||
/**
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
*
|
||||
* <pre>
|
||||
* >ActiveXDispatchEvents de =
|
||||
* new ActiveXDispatchEvents(someDispatch,someEventHAndler,
|
||||
* "Excel.Application",
|
||||
* "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE");
|
||||
*
|
||||
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink Java object that wants to receive the events
|
||||
* @param progId , mandatory if the typelib is specified
|
||||
* @param typeLib The location of the typelib to use
|
||||
*
|
||||
*/
|
||||
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId, String typeLib) {
|
||||
super(sourceOfEvent, eventSink, progId, typeLib);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.DispatchEvents#getInvocationProxy(java.lang.Object)
|
||||
*/
|
||||
protected InvocationProxy getInvocationProxy(Object pTargetObject) {
|
||||
InvocationProxy newProxy = new ActiveXInvocationProxy();
|
||||
newProxy.setTarget(pTargetObject);
|
||||
return newProxy;
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.DispatchEvents#getInvocationProxy(java.lang.Object)
|
||||
*/
|
||||
protected InvocationProxy getInvocationProxy(Object pTargetObject) {
|
||||
InvocationProxy newProxy = new ActiveXInvocationProxy();
|
||||
newProxy.setTarget(pTargetObject);
|
||||
return newProxy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.activeX;
|
||||
|
||||
@@ -72,131 +72,131 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class ActiveXInvocationProxy extends InvocationProxy {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.InvocationProxy#invoke(java.lang.String,
|
||||
* com.jacob.com.Variant[])
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Variant invoke(String methodName, Variant targetParameters[]) {
|
||||
Variant mVariantToBeReturned = null;
|
||||
if (mTargetObject == null) {
|
||||
// structured programming guidlines say this return should not be up
|
||||
// here
|
||||
return null;
|
||||
}
|
||||
Class targetClass = mTargetObject.getClass();
|
||||
if (methodName == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing method name");
|
||||
}
|
||||
if (targetParameters == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing Variant parameters");
|
||||
}
|
||||
try {
|
||||
Method targetMethod;
|
||||
Object parametersAsJavaObjects[] = getParametersAsJavaObjects(targetParameters);
|
||||
Class parametersAsJavaClasses[] = getParametersAsJavaClasses(parametersAsJavaObjects);
|
||||
targetMethod = targetClass.getMethod(methodName,
|
||||
parametersAsJavaClasses);
|
||||
if (targetMethod != null) {
|
||||
// protected classes can't be invoked against even if they
|
||||
// let you grab the method. you could do
|
||||
// targetMethod.setAccessible(true);
|
||||
// but that should be stopped by the security manager
|
||||
Object mReturnedByInvocation = null;
|
||||
mReturnedByInvocation = targetMethod.invoke(mTargetObject,
|
||||
parametersAsJavaObjects);
|
||||
if (mReturnedByInvocation == null) {
|
||||
mVariantToBeReturned = null;
|
||||
} else if (!(mReturnedByInvocation instanceof Variant)) {
|
||||
mVariantToBeReturned = new Variant(mReturnedByInvocation);
|
||||
} else {
|
||||
mVariantToBeReturned = (Variant) mReturnedByInvocation;
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
// what causes this exception?
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
// this happens whenever the listener doesn't implement all the
|
||||
// methods
|
||||
} catch (IllegalArgumentException e) {
|
||||
// we can throw these inside the catch block so need to re-throw it
|
||||
Exception oneWeShouldToss = new IllegalArgumentException(
|
||||
"Unable to map parameters for method " + methodName + ": "
|
||||
+ e.toString());
|
||||
oneWeShouldToss.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// can't access the method on the target instance for some reason
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// invocation of target method failed
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mVariantToBeReturned;
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.InvocationProxy#invoke(java.lang.String,
|
||||
* com.jacob.com.Variant[])
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Variant invoke(String methodName, Variant targetParameters[]) {
|
||||
Variant mVariantToBeReturned = null;
|
||||
if (mTargetObject == null) {
|
||||
// structured programming guidlines say this return should not be up
|
||||
// here
|
||||
return null;
|
||||
}
|
||||
Class targetClass = mTargetObject.getClass();
|
||||
if (methodName == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing method name");
|
||||
}
|
||||
if (targetParameters == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing Variant parameters");
|
||||
}
|
||||
try {
|
||||
Method targetMethod;
|
||||
Object parametersAsJavaObjects[] = getParametersAsJavaObjects(targetParameters);
|
||||
Class parametersAsJavaClasses[] = getParametersAsJavaClasses(parametersAsJavaObjects);
|
||||
targetMethod = targetClass.getMethod(methodName,
|
||||
parametersAsJavaClasses);
|
||||
if (targetMethod != null) {
|
||||
// protected classes can't be invoked against even if they
|
||||
// let you grab the method. you could do
|
||||
// targetMethod.setAccessible(true);
|
||||
// but that should be stopped by the security manager
|
||||
Object mReturnedByInvocation = null;
|
||||
mReturnedByInvocation = targetMethod.invoke(mTargetObject,
|
||||
parametersAsJavaObjects);
|
||||
if (mReturnedByInvocation == null) {
|
||||
mVariantToBeReturned = null;
|
||||
} else if (!(mReturnedByInvocation instanceof Variant)) {
|
||||
mVariantToBeReturned = new Variant(mReturnedByInvocation);
|
||||
} else {
|
||||
mVariantToBeReturned = (Variant) mReturnedByInvocation;
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
// what causes this exception?
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
// this happens whenever the listener doesn't implement all the
|
||||
// methods
|
||||
} catch (IllegalArgumentException e) {
|
||||
// we can throw these inside the catch block so need to re-throw it
|
||||
Exception oneWeShouldToss = new IllegalArgumentException(
|
||||
"Unable to map parameters for method " + methodName + ": "
|
||||
+ e.toString());
|
||||
oneWeShouldToss.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// can't access the method on the target instance for some reason
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// invocation of target method failed
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mVariantToBeReturned;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a method signature compatible array of classes from an array of
|
||||
* parameters
|
||||
*
|
||||
* @param parametersAsJavaObjects
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class[] getParametersAsJavaClasses(Object[] parametersAsJavaObjects) {
|
||||
if (parametersAsJavaObjects == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"This only works with an array of parameters");
|
||||
}
|
||||
int numParameters = parametersAsJavaObjects.length;
|
||||
Class parametersAsJavaClasses[] = new Class[numParameters];
|
||||
for (int parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) {
|
||||
Object oneParameterObject = parametersAsJavaObjects[parameterIndex];
|
||||
if (oneParameterObject == null) {
|
||||
parametersAsJavaClasses[parameterIndex] = null;
|
||||
} else {
|
||||
Class oneParameterClass = oneParameterObject.getClass();
|
||||
parametersAsJavaClasses[parameterIndex] = oneParameterClass;
|
||||
}
|
||||
}
|
||||
return parametersAsJavaClasses;
|
||||
}
|
||||
/**
|
||||
* creates a method signature compatible array of classes from an array of
|
||||
* parameters
|
||||
*
|
||||
* @param parametersAsJavaObjects
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class[] getParametersAsJavaClasses(Object[] parametersAsJavaObjects) {
|
||||
if (parametersAsJavaObjects == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"This only works with an array of parameters");
|
||||
}
|
||||
int numParameters = parametersAsJavaObjects.length;
|
||||
Class parametersAsJavaClasses[] = new Class[numParameters];
|
||||
for (int parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) {
|
||||
Object oneParameterObject = parametersAsJavaObjects[parameterIndex];
|
||||
if (oneParameterObject == null) {
|
||||
parametersAsJavaClasses[parameterIndex] = null;
|
||||
} else {
|
||||
Class oneParameterClass = oneParameterObject.getClass();
|
||||
parametersAsJavaClasses[parameterIndex] = oneParameterClass;
|
||||
}
|
||||
}
|
||||
return parametersAsJavaClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts an array of Variants to their associated Java types
|
||||
*
|
||||
* @param targetParameters
|
||||
* @return
|
||||
*/
|
||||
private Object[] getParametersAsJavaObjects(Variant[] targetParameters) {
|
||||
if (targetParameters == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"This only works with an array of parameters");
|
||||
}
|
||||
int numParameters = targetParameters.length;
|
||||
Object parametersAsJavaObjects[] = new Object[numParameters];
|
||||
for (int parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) {
|
||||
Variant oneParameterObject = targetParameters[parameterIndex];
|
||||
if (oneParameterObject == null) {
|
||||
parametersAsJavaObjects[parameterIndex] = null;
|
||||
} else {
|
||||
try {
|
||||
parametersAsJavaObjects[parameterIndex] = oneParameterObject
|
||||
.toJavaObject();
|
||||
} catch (NotImplementedException nie) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't convert parameter " + parameterIndex
|
||||
+ " type " + oneParameterObject.getvt()
|
||||
+ " to java object: " + nie.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return parametersAsJavaObjects;
|
||||
}
|
||||
/**
|
||||
* converts an array of Variants to their associated Java types
|
||||
*
|
||||
* @param targetParameters
|
||||
* @return
|
||||
*/
|
||||
private Object[] getParametersAsJavaObjects(Variant[] targetParameters) {
|
||||
if (targetParameters == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"This only works with an array of parameters");
|
||||
}
|
||||
int numParameters = targetParameters.length;
|
||||
Object parametersAsJavaObjects[] = new Object[numParameters];
|
||||
for (int parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) {
|
||||
Variant oneParameterObject = targetParameters[parameterIndex];
|
||||
if (oneParameterObject == null) {
|
||||
parametersAsJavaObjects[parameterIndex] = null;
|
||||
} else {
|
||||
try {
|
||||
parametersAsJavaObjects[parameterIndex] = oneParameterObject
|
||||
.toJavaObject();
|
||||
} catch (NotImplementedException nie) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't convert parameter " + parameterIndex
|
||||
+ " type " + oneParameterObject.getvt()
|
||||
+ " to java object: " + nie.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return parametersAsJavaObjects;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -43,118 +43,118 @@ package com.jacob.com;
|
||||
*/
|
||||
public abstract class ComException extends JacobException {
|
||||
|
||||
/**
|
||||
* COM code initializes this filed with an appropriate return code that was
|
||||
* returned by the underlying com code
|
||||
*/
|
||||
protected int hr;
|
||||
/**
|
||||
* No documentation is available at this time. Someone should document this
|
||||
* field
|
||||
*/
|
||||
protected int m_helpContext;
|
||||
/**
|
||||
* No documentation is available at this time. Someone should document this
|
||||
* field
|
||||
*/
|
||||
protected String m_helpFile;
|
||||
/**
|
||||
* No documentation is available at this time. Someone should document this
|
||||
* field
|
||||
*/
|
||||
protected String m_source;
|
||||
/**
|
||||
* COM code initializes this filed with an appropriate return code that was
|
||||
* returned by the underlying com code
|
||||
*/
|
||||
protected int hr;
|
||||
/**
|
||||
* No documentation is available at this time. Someone should document this
|
||||
* field
|
||||
*/
|
||||
protected int m_helpContext;
|
||||
/**
|
||||
* No documentation is available at this time. Someone should document this
|
||||
* field
|
||||
*/
|
||||
protected String m_helpFile;
|
||||
/**
|
||||
* No documentation is available at this time. Someone should document this
|
||||
* field
|
||||
*/
|
||||
protected String m_source;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
*/
|
||||
public ComException() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
*/
|
||||
public ComException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor with error code?
|
||||
*
|
||||
* @param newHr ??
|
||||
*/
|
||||
public ComException(int newHr) {
|
||||
super();
|
||||
this.hr = newHr;
|
||||
}
|
||||
/**
|
||||
* constructor with error code?
|
||||
*
|
||||
* @param newHr ??
|
||||
*/
|
||||
public ComException(int newHr) {
|
||||
super();
|
||||
this.hr = newHr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newHr
|
||||
* @param description
|
||||
*/
|
||||
public ComException(int newHr, String description) {
|
||||
super(description);
|
||||
this.hr = newHr;
|
||||
}
|
||||
/**
|
||||
* @param newHr
|
||||
* @param description
|
||||
*/
|
||||
public ComException(int newHr, String description) {
|
||||
super(description);
|
||||
this.hr = newHr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newHr
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComException(int newHr, String source, String helpFile,
|
||||
int helpContext) {
|
||||
super();
|
||||
this.hr = newHr;
|
||||
m_source = source;
|
||||
m_helpFile = helpFile;
|
||||
m_helpContext = helpContext;
|
||||
}
|
||||
/**
|
||||
* @param newHr
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComException(int newHr, String source, String helpFile,
|
||||
int helpContext) {
|
||||
super();
|
||||
this.hr = newHr;
|
||||
m_source = source;
|
||||
m_helpFile = helpFile;
|
||||
m_helpContext = helpContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newHr
|
||||
* @param description
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComException(int newHr, String description, String source,
|
||||
String helpFile, int helpContext) {
|
||||
super(description);
|
||||
this.hr = newHr;
|
||||
m_source = source;
|
||||
m_helpFile = helpFile;
|
||||
m_helpContext = helpContext;
|
||||
}
|
||||
/**
|
||||
* @param newHr
|
||||
* @param description
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComException(int newHr, String description, String source,
|
||||
String helpFile, int helpContext) {
|
||||
super(description);
|
||||
this.hr = newHr;
|
||||
m_source = source;
|
||||
m_helpFile = helpFile;
|
||||
m_helpContext = helpContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description
|
||||
*/
|
||||
public ComException(String description) {
|
||||
super(description);
|
||||
}
|
||||
/**
|
||||
* @param description
|
||||
*/
|
||||
public ComException(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int representation of the help context
|
||||
*/
|
||||
// Methods
|
||||
public int getHelpContext() {
|
||||
return m_helpContext;
|
||||
}
|
||||
/**
|
||||
* @return int representation of the help context
|
||||
*/
|
||||
// Methods
|
||||
public int getHelpContext() {
|
||||
return m_helpContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String ??? help file
|
||||
*/
|
||||
public String getHelpFile() {
|
||||
return m_helpFile;
|
||||
}
|
||||
/**
|
||||
* @return String ??? help file
|
||||
*/
|
||||
public String getHelpFile() {
|
||||
return m_helpFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int hr result ??
|
||||
*/
|
||||
public int getHResult() {
|
||||
return hr;
|
||||
}
|
||||
/**
|
||||
* @return int hr result ??
|
||||
*/
|
||||
public int getHResult() {
|
||||
return hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String source ??
|
||||
*/
|
||||
public String getSource() {
|
||||
return m_source;
|
||||
}
|
||||
/**
|
||||
* @return String source ??
|
||||
*/
|
||||
public String getSource() {
|
||||
return m_source;
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -42,66 +42,66 @@ package com.jacob.com;
|
||||
* COM Fail Exception class raised when there is a problem
|
||||
*/
|
||||
public class ComFailException extends ComException {
|
||||
/**
|
||||
* eclipse generated to get rid of a wanring
|
||||
*/
|
||||
private static final long serialVersionUID = -266047261992987700L;
|
||||
/**
|
||||
* eclipse generated to get rid of a wanring
|
||||
*/
|
||||
private static final long serialVersionUID = -266047261992987700L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param hrNew
|
||||
*/
|
||||
public ComFailException(int hrNew) {
|
||||
super(hrNew);
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param hrNew
|
||||
*/
|
||||
public ComFailException(int hrNew) {
|
||||
super(hrNew);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param hrNew
|
||||
* @param message
|
||||
*/
|
||||
public ComFailException(int hrNew, String message) {
|
||||
super(hrNew, message);
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param hrNew
|
||||
* @param message
|
||||
*/
|
||||
public ComFailException(int hrNew, String message) {
|
||||
super(hrNew, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hrNew
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComFailException(int hrNew, String source, String helpFile,
|
||||
int helpContext) {
|
||||
super(hrNew, source, helpFile, helpContext);
|
||||
}
|
||||
/**
|
||||
* @param hrNew
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComFailException(int hrNew, String source, String helpFile,
|
||||
int helpContext) {
|
||||
super(hrNew, source, helpFile, helpContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param hrNew
|
||||
* @param description
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComFailException(int hrNew, String description, String source,
|
||||
String helpFile, int helpContext) {
|
||||
super(hrNew, description, source, helpFile, helpContext);
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param hrNew
|
||||
* @param description
|
||||
* @param source
|
||||
* @param helpFile
|
||||
* @param helpContext
|
||||
*/
|
||||
public ComFailException(int hrNew, String description, String source,
|
||||
String helpFile, int helpContext) {
|
||||
super(hrNew, description, source, helpFile, helpContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* No argument Constructor
|
||||
*/
|
||||
public ComFailException() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* No argument Constructor
|
||||
*/
|
||||
public ComFailException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public ComFailException(String message) {
|
||||
super(message);
|
||||
}
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public ComFailException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -43,146 +43,146 @@ package com.jacob.com;
|
||||
* methods are static and no instances are ever created.
|
||||
*/
|
||||
public abstract class ComThread {
|
||||
private static final int MTA = 0x0;
|
||||
private static final int MTA = 0x0;
|
||||
|
||||
private static final int STA = 0x2;
|
||||
private static final int STA = 0x2;
|
||||
|
||||
/**
|
||||
* Comment for <code>haveSTA</code>
|
||||
*/
|
||||
public static boolean haveSTA = false;
|
||||
/**
|
||||
* Comment for <code>haveSTA</code>
|
||||
*/
|
||||
public static boolean haveSTA = false;
|
||||
|
||||
/**
|
||||
* Comment for <code>mainSTA</code>
|
||||
*/
|
||||
public static MainSTA mainSTA = null;
|
||||
/**
|
||||
* Comment for <code>mainSTA</code>
|
||||
*/
|
||||
public static MainSTA mainSTA = null;
|
||||
|
||||
/**
|
||||
* Initialize the current java thread to be part of the Multi-threaded COM
|
||||
* Apartment
|
||||
*/
|
||||
public static synchronized void InitMTA() {
|
||||
InitMTA(false);
|
||||
}
|
||||
/**
|
||||
* Initialize the current java thread to be part of the Multi-threaded COM
|
||||
* Apartment
|
||||
*/
|
||||
public static synchronized void InitMTA() {
|
||||
InitMTA(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the current java thread to be an STA
|
||||
*/
|
||||
public static synchronized void InitSTA() {
|
||||
InitSTA(false);
|
||||
}
|
||||
/**
|
||||
* Initialize the current java thread to be an STA
|
||||
*/
|
||||
public static synchronized void InitSTA() {
|
||||
InitSTA(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the current java thread to be part of the Multi-threaded COM
|
||||
* Apartment, if createMainSTA is true, create a separate MainSTA thread
|
||||
* that will house all Apartment Threaded components
|
||||
*
|
||||
* @param createMainSTA
|
||||
*/
|
||||
public static synchronized void InitMTA(boolean createMainSTA) {
|
||||
Init(createMainSTA, MTA);
|
||||
}
|
||||
/**
|
||||
* Initialize the current java thread to be part of the Multi-threaded COM
|
||||
* Apartment, if createMainSTA is true, create a separate MainSTA thread
|
||||
* that will house all Apartment Threaded components
|
||||
*
|
||||
* @param createMainSTA
|
||||
*/
|
||||
public static synchronized void InitMTA(boolean createMainSTA) {
|
||||
Init(createMainSTA, MTA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the current java thread to be an STA COM Apartment, if
|
||||
* createMainSTA is true, create a separate MainSTA thread that will house
|
||||
* all Apartment Threaded components
|
||||
*
|
||||
* @param createMainSTA
|
||||
*/
|
||||
public static synchronized void InitSTA(boolean createMainSTA) {
|
||||
Init(createMainSTA, STA);
|
||||
}
|
||||
/**
|
||||
* Initialize the current java thread to be an STA COM Apartment, if
|
||||
* createMainSTA is true, create a separate MainSTA thread that will house
|
||||
* all Apartment Threaded components
|
||||
*
|
||||
* @param createMainSTA
|
||||
*/
|
||||
public static synchronized void InitSTA(boolean createMainSTA) {
|
||||
Init(createMainSTA, STA);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static synchronized void startMainSTA() {
|
||||
mainSTA = new MainSTA();
|
||||
haveSTA = true;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static synchronized void startMainSTA() {
|
||||
mainSTA = new MainSTA();
|
||||
haveSTA = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static synchronized void quitMainSTA() {
|
||||
if (mainSTA != null)
|
||||
mainSTA.quit();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static synchronized void quitMainSTA() {
|
||||
if (mainSTA != null)
|
||||
mainSTA.quit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the current java thread to be part of the MTA/STA COM
|
||||
* Apartment
|
||||
*
|
||||
* @param createMainSTA
|
||||
* @param mode
|
||||
*/
|
||||
public static synchronized void Init(boolean createMainSTA, int mode) {
|
||||
if (createMainSTA && !haveSTA) {
|
||||
// if the current thread is going to be in the MTA and there
|
||||
// is no STA thread yet, then create a main STA thread
|
||||
// to avoid COM creating its own
|
||||
startMainSTA();
|
||||
}
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: before Init: " + mode);
|
||||
}
|
||||
doCoInitialize(mode);
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: after Init: " + mode);
|
||||
}
|
||||
ROT.addThread();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: after ROT.addThread: " + mode);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Initialize the current java thread to be part of the MTA/STA COM
|
||||
* Apartment
|
||||
*
|
||||
* @param createMainSTA
|
||||
* @param mode
|
||||
*/
|
||||
public static synchronized void Init(boolean createMainSTA, int mode) {
|
||||
if (createMainSTA && !haveSTA) {
|
||||
// if the current thread is going to be in the MTA and there
|
||||
// is no STA thread yet, then create a main STA thread
|
||||
// to avoid COM creating its own
|
||||
startMainSTA();
|
||||
}
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: before Init: " + mode);
|
||||
}
|
||||
doCoInitialize(mode);
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: after Init: " + mode);
|
||||
}
|
||||
ROT.addThread();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: after ROT.addThread: " + mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call CoUninitialize to release this java thread from COM
|
||||
*/
|
||||
public static synchronized void Release() {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: before clearObjects");
|
||||
}
|
||||
ROT.clearObjects();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: before UnInit");
|
||||
}
|
||||
doCoUninitialize();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: after UnInit");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Call CoUninitialize to release this java thread from COM
|
||||
*/
|
||||
public static synchronized void Release() {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: before clearObjects");
|
||||
}
|
||||
ROT.clearObjects();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: before UnInit");
|
||||
}
|
||||
doCoUninitialize();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ComThread: after UnInit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated the java model leave the responsibility of clearing up
|
||||
* objects to the Garbage Collector. Our programming model
|
||||
* should not require that the user specifically remove object
|
||||
* from the thread.
|
||||
*
|
||||
* This will remove an object from the ROT
|
||||
* @param o
|
||||
*/
|
||||
@Deprecated
|
||||
public static synchronized void RemoveObject(JacobObject o) {
|
||||
ROT.removeObject(o);
|
||||
}
|
||||
/**
|
||||
* @deprecated the java model leave the responsibility of clearing up
|
||||
* objects to the Garbage Collector. Our programming model
|
||||
* should not require that the user specifically remove object
|
||||
* from the thread.
|
||||
*
|
||||
* This will remove an object from the ROT
|
||||
* @param o
|
||||
*/
|
||||
@Deprecated
|
||||
public static synchronized void RemoveObject(JacobObject o) {
|
||||
ROT.removeObject(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param threadModel
|
||||
*/
|
||||
public static native void doCoInitialize(int threadModel);
|
||||
/**
|
||||
* @param threadModel
|
||||
*/
|
||||
public static native void doCoInitialize(int threadModel);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static native void doCoUninitialize();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static native void doCoUninitialize();
|
||||
|
||||
/**
|
||||
* load the Jacob DLL. We do this in case COMThread is called before any
|
||||
* other reference to one of the JacboObject subclasses is made.
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
/**
|
||||
* load the Jacob DLL. We do this in case COMThread is called before any
|
||||
* other reference to one of the JacboObject subclasses is made.
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -49,81 +49,81 @@ package com.jacob.com;
|
||||
* In the future, this should convert to and from BigDecimal or Double
|
||||
*/
|
||||
public class Currency {
|
||||
Long embeddedValue = null;
|
||||
Long embeddedValue = null;
|
||||
|
||||
/**
|
||||
* constructor that takes a long already in COM representation
|
||||
*
|
||||
* @param newValue
|
||||
*/
|
||||
public Currency(long newValue) {
|
||||
embeddedValue = new Long(newValue);
|
||||
}
|
||||
/**
|
||||
* constructor that takes a long already in COM representation
|
||||
*
|
||||
* @param newValue
|
||||
*/
|
||||
public Currency(long newValue) {
|
||||
embeddedValue = new Long(newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor that takes a String already in COM representation
|
||||
*
|
||||
* @param newValue
|
||||
*/
|
||||
public Currency(String newValue) {
|
||||
embeddedValue = new Long(newValue);
|
||||
}
|
||||
/**
|
||||
* constructor that takes a String already in COM representation
|
||||
*
|
||||
* @param newValue
|
||||
*/
|
||||
public Currency(String newValue) {
|
||||
embeddedValue = new Long(newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the currency as a primitive long
|
||||
*/
|
||||
public long longValue() {
|
||||
return embeddedValue.longValue();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return the currency as a primitive long
|
||||
*/
|
||||
public long longValue() {
|
||||
return embeddedValue.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* getter to the inner storage so that cmpareTo can work
|
||||
*
|
||||
* @return the embedded long value
|
||||
*/
|
||||
protected Long getLongValue() {
|
||||
return embeddedValue;
|
||||
}
|
||||
/**
|
||||
* getter to the inner storage so that cmpareTo can work
|
||||
*
|
||||
* @return the embedded long value
|
||||
*/
|
||||
protected Long getLongValue() {
|
||||
return embeddedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* compares the values of two currencies
|
||||
*
|
||||
* @param anotherCurrency
|
||||
* @return the usual compareTo results
|
||||
*/
|
||||
public int compareTo(Currency anotherCurrency) {
|
||||
return embeddedValue.compareTo(anotherCurrency.getLongValue());
|
||||
}
|
||||
/**
|
||||
* compares the values of two currencies
|
||||
*
|
||||
* @param anotherCurrency
|
||||
* @return the usual compareTo results
|
||||
*/
|
||||
public int compareTo(Currency anotherCurrency) {
|
||||
return embeddedValue.compareTo(anotherCurrency.getLongValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* standard comparison
|
||||
*
|
||||
* @param o
|
||||
* must be Currency or Long
|
||||
* @return the usual compareTo results
|
||||
*/
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof Currency) {
|
||||
return compareTo((Currency) o);
|
||||
} else if (o instanceof Long) {
|
||||
return embeddedValue.compareTo((Long) o);
|
||||
} else
|
||||
throw new IllegalArgumentException(
|
||||
"Can only compare to Long and Currency not "
|
||||
+ o.getClass().getName());
|
||||
}
|
||||
/**
|
||||
* standard comparison
|
||||
*
|
||||
* @param o
|
||||
* must be Currency or Long
|
||||
* @return the usual compareTo results
|
||||
*/
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof Currency) {
|
||||
return compareTo((Currency) o);
|
||||
} else if (o instanceof Long) {
|
||||
return embeddedValue.compareTo((Long) o);
|
||||
} else
|
||||
throw new IllegalArgumentException(
|
||||
"Can only compare to Long and Currency not "
|
||||
+ o.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
} else if (compareTo(o) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
} else if (compareTo(o) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -49,76 +49,76 @@ import java.util.Date;
|
||||
*/
|
||||
public class DateUtilities {
|
||||
|
||||
/**
|
||||
* converts a windows time to a Java Date Object
|
||||
*
|
||||
* @param comTime
|
||||
* @return Date object representing the windows time as specified in comTime
|
||||
*/
|
||||
static public Date convertWindowsTimeToDate(double comTime) {
|
||||
return new Date(convertWindowsTimeToMilliseconds(comTime));
|
||||
}
|
||||
/**
|
||||
* converts a windows time to a Java Date Object
|
||||
*
|
||||
* @param comTime
|
||||
* @return Date object representing the windows time as specified in comTime
|
||||
*/
|
||||
static public Date convertWindowsTimeToDate(double comTime) {
|
||||
return new Date(convertWindowsTimeToMilliseconds(comTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a COM time from functions Date(), Time(), Now() to a Java time
|
||||
* (milliseconds). Visual Basic time values are based to 30.12.1899, Java
|
||||
* time values are based to 1.1.1970 (= 0 milliseconds). The difference is
|
||||
* added to the Visual Basic value to get the corresponding Java value. The
|
||||
* Visual Basic double value reads: <day count delta since 30.12.1899>.<1
|
||||
* day percentage fraction>, e.g. "38100.6453" means: 38100 days since
|
||||
* 30.12.1899 plus (24 hours * 0.6453). Example usage:
|
||||
* <code>Date javaDate = new Date(toMilliseconds (vbDate));</code>.
|
||||
*
|
||||
* @param comTime
|
||||
* COM time.
|
||||
* @return Java time.
|
||||
*/
|
||||
static public long convertWindowsTimeToMilliseconds(double comTime) {
|
||||
long result = 0;
|
||||
/**
|
||||
* Convert a COM time from functions Date(), Time(), Now() to a Java time
|
||||
* (milliseconds). Visual Basic time values are based to 30.12.1899, Java
|
||||
* time values are based to 1.1.1970 (= 0 milliseconds). The difference is
|
||||
* added to the Visual Basic value to get the corresponding Java value. The
|
||||
* Visual Basic double value reads: <day count delta since 30.12.1899>.<1
|
||||
* day percentage fraction>, e.g. "38100.6453" means: 38100 days since
|
||||
* 30.12.1899 plus (24 hours * 0.6453). Example usage:
|
||||
* <code>Date javaDate = new Date(toMilliseconds (vbDate));</code>.
|
||||
*
|
||||
* @param comTime
|
||||
* COM time.
|
||||
* @return Java time.
|
||||
*/
|
||||
static public long convertWindowsTimeToMilliseconds(double comTime) {
|
||||
long result = 0;
|
||||
|
||||
// code from jacobgen:
|
||||
comTime = comTime - 25569D;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
result = Math.round(86400000L * comTime)
|
||||
- cal.get(Calendar.ZONE_OFFSET);
|
||||
cal.setTime(new Date(result));
|
||||
result -= cal.get(Calendar.DST_OFFSET);
|
||||
// code from jacobgen:
|
||||
comTime = comTime - 25569D;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
result = Math.round(86400000L * comTime)
|
||||
- cal.get(Calendar.ZONE_OFFSET);
|
||||
cal.setTime(new Date(result));
|
||||
result -= cal.get(Calendar.DST_OFFSET);
|
||||
|
||||
return result;
|
||||
}// convertWindowsTimeToMilliseconds()
|
||||
return result;
|
||||
}// convertWindowsTimeToMilliseconds()
|
||||
|
||||
/**
|
||||
* converts a java date to a windows time object (is this timezone safe?)
|
||||
*
|
||||
* @param javaDate
|
||||
* the java date to be converted to windows time
|
||||
* @return the double representing the date in a form windows understands
|
||||
*/
|
||||
static public double convertDateToWindowsTime(Date javaDate) {
|
||||
if (javaDate == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"cannot convert null to windows time");
|
||||
}
|
||||
return convertMillisecondsToWindowsTime(javaDate.getTime());
|
||||
}
|
||||
/**
|
||||
* converts a java date to a windows time object (is this timezone safe?)
|
||||
*
|
||||
* @param javaDate
|
||||
* the java date to be converted to windows time
|
||||
* @return the double representing the date in a form windows understands
|
||||
*/
|
||||
static public double convertDateToWindowsTime(Date javaDate) {
|
||||
if (javaDate == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"cannot convert null to windows time");
|
||||
}
|
||||
return convertMillisecondsToWindowsTime(javaDate.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Java time to a COM time.
|
||||
*
|
||||
* @param milliseconds
|
||||
* Java time.
|
||||
* @return COM time.
|
||||
*/
|
||||
static public double convertMillisecondsToWindowsTime(long milliseconds) {
|
||||
double result = 0.0;
|
||||
/**
|
||||
* Convert a Java time to a COM time.
|
||||
*
|
||||
* @param milliseconds
|
||||
* Java time.
|
||||
* @return COM time.
|
||||
*/
|
||||
static public double convertMillisecondsToWindowsTime(long milliseconds) {
|
||||
double result = 0.0;
|
||||
|
||||
// code from jacobgen:
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(milliseconds);
|
||||
milliseconds += (cal.get(Calendar.ZONE_OFFSET) + cal
|
||||
.get(Calendar.DST_OFFSET)); // add GMT offset
|
||||
result = (milliseconds / 86400000D) + 25569D;
|
||||
// code from jacobgen:
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(milliseconds);
|
||||
milliseconds += (cal.get(Calendar.ZONE_OFFSET) + cal
|
||||
.get(Calendar.DST_OFFSET)); // add GMT offset
|
||||
result = (milliseconds / 86400000D) + 25569D;
|
||||
|
||||
return result;
|
||||
}// convertMillisecondsToWindowsTime()
|
||||
return result;
|
||||
}// convertMillisecondsToWindowsTime()
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -59,180 +59,180 @@ package com.jacob.com;
|
||||
*/
|
||||
public class DispatchEvents extends JacobObject {
|
||||
|
||||
/**
|
||||
* pointer to an MS data struct. The COM layer knows the name of this
|
||||
* variable and puts the windows memory pointer here.
|
||||
*/
|
||||
int m_pConnPtProxy = 0;
|
||||
/**
|
||||
* pointer to an MS data struct. The COM layer knows the name of this
|
||||
* variable and puts the windows memory pointer here.
|
||||
*/
|
||||
int m_pConnPtProxy = 0;
|
||||
|
||||
/**
|
||||
* the wrapper for the event sink. This object is the one that will be sent
|
||||
* a message when an event occurs in the MS layer. Normally, the
|
||||
* InvocationProxy will forward the messages to a wrapped object that it
|
||||
* contains.
|
||||
*/
|
||||
InvocationProxy mInvocationProxy = null;
|
||||
/**
|
||||
* the wrapper for the event sink. This object is the one that will be sent
|
||||
* a message when an event occurs in the MS layer. Normally, the
|
||||
* InvocationProxy will forward the messages to a wrapped object that it
|
||||
* contains.
|
||||
*/
|
||||
InvocationProxy mInvocationProxy = null;
|
||||
|
||||
/**
|
||||
* This is the most commonly used constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
* <p>
|
||||
* Can be used on any object that implements IProvideClassInfo.
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
*/
|
||||
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
|
||||
this(sourceOfEvent, eventSink, null);
|
||||
}
|
||||
/**
|
||||
* This is the most commonly used constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
* <p>
|
||||
* Can be used on any object that implements IProvideClassInfo.
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
*/
|
||||
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
|
||||
this(sourceOfEvent, eventSink, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* None of the samples use this constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
* <p>
|
||||
* Used when the program doesn't implement IProvideClassInfo. It provides a
|
||||
* way to find the TypeLib in the registry based on the programId. The
|
||||
* TypeLib is looked up in the registry on the path
|
||||
* HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/(CLID drived from
|
||||
* progid)/ProgID/Typelib
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
* @param progId
|
||||
* program id in the registry that has a TypeLib subkey. The
|
||||
* progrId is mapped to a CLSID that is they used to look up the
|
||||
* key to the Typelib
|
||||
*/
|
||||
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId) {
|
||||
this(sourceOfEvent, eventSink, progId, null);
|
||||
}
|
||||
/**
|
||||
* None of the samples use this constructor.
|
||||
* <p>
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
* <p>
|
||||
* Used when the program doesn't implement IProvideClassInfo. It provides a
|
||||
* way to find the TypeLib in the registry based on the programId. The
|
||||
* TypeLib is looked up in the registry on the path
|
||||
* HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/(CLID drived from
|
||||
* progid)/ProgID/Typelib
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
* @param progId
|
||||
* program id in the registry that has a TypeLib subkey. The
|
||||
* progrId is mapped to a CLSID that is they used to look up the
|
||||
* key to the Typelib
|
||||
*/
|
||||
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId) {
|
||||
this(sourceOfEvent, eventSink, progId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
* <p>
|
||||
* This method was added because Excel doesn't implement IProvideClassInfo
|
||||
* and the registry entry for Excel.Application doesn't include a typelib
|
||||
* key.
|
||||
*
|
||||
* <pre>
|
||||
* DispatchEvents de = new DispatchEvents(someDispatch, someEventHAndler,
|
||||
* "Excel.Application",
|
||||
* "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE");
|
||||
* </pre>
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
* @param progId ,
|
||||
* mandatory if the typelib is specified
|
||||
* @param typeLib
|
||||
* The location of the typelib to use
|
||||
*/
|
||||
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId, String typeLib) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
System.out.println("DispatchEvents: Registering " + eventSink
|
||||
+ "for events ");
|
||||
}
|
||||
if (eventSink instanceof InvocationProxy) {
|
||||
mInvocationProxy = (InvocationProxy) eventSink;
|
||||
} else {
|
||||
mInvocationProxy = getInvocationProxy(eventSink);
|
||||
}
|
||||
if (mInvocationProxy != null) {
|
||||
init3(sourceOfEvent, mInvocationProxy, progId, typeLib);
|
||||
} else {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("Cannot register null event sink for events");
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot register null event sink for events");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates the event callback linkage between the the MS program represented
|
||||
* by the Dispatch object and the Java object that will receive the
|
||||
* callback.
|
||||
* <p>
|
||||
* This method was added because Excel doesn't implement IProvideClassInfo
|
||||
* and the registry entry for Excel.Application doesn't include a typelib
|
||||
* key.
|
||||
*
|
||||
* <pre>
|
||||
* DispatchEvents de = new DispatchEvents(someDispatch, someEventHAndler,
|
||||
* "Excel.Application",
|
||||
* "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE");
|
||||
* </pre>
|
||||
*
|
||||
* @param sourceOfEvent
|
||||
* Dispatch object who's MS app will generate callbacks
|
||||
* @param eventSink
|
||||
* Java object that wants to receive the events
|
||||
* @param progId ,
|
||||
* mandatory if the typelib is specified
|
||||
* @param typeLib
|
||||
* The location of the typelib to use
|
||||
*/
|
||||
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink,
|
||||
String progId, String typeLib) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
System.out.println("DispatchEvents: Registering " + eventSink
|
||||
+ "for events ");
|
||||
}
|
||||
if (eventSink instanceof InvocationProxy) {
|
||||
mInvocationProxy = (InvocationProxy) eventSink;
|
||||
} else {
|
||||
mInvocationProxy = getInvocationProxy(eventSink);
|
||||
}
|
||||
if (mInvocationProxy != null) {
|
||||
init3(sourceOfEvent, mInvocationProxy, progId, typeLib);
|
||||
} else {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("Cannot register null event sink for events");
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot register null event sink for events");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the proxy configured with pTargetObject as its
|
||||
* target
|
||||
*
|
||||
* @param pTargetObject
|
||||
* @return InvocationProxy an instance of the proxy this DispatchEvents will
|
||||
* send to the COM layer
|
||||
*/
|
||||
protected InvocationProxy getInvocationProxy(Object pTargetObject) {
|
||||
InvocationProxy newProxy = new InvocationProxyAllVariants();
|
||||
newProxy.setTarget(pTargetObject);
|
||||
return newProxy;
|
||||
}
|
||||
/**
|
||||
* Returns an instance of the proxy configured with pTargetObject as its
|
||||
* target
|
||||
*
|
||||
* @param pTargetObject
|
||||
* @return InvocationProxy an instance of the proxy this DispatchEvents will
|
||||
* send to the COM layer
|
||||
*/
|
||||
protected InvocationProxy getInvocationProxy(Object pTargetObject) {
|
||||
InvocationProxy newProxy = new InvocationProxyAllVariants();
|
||||
newProxy.setTarget(pTargetObject);
|
||||
return newProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* hooks up a connection point proxy by progId event methods on the sink
|
||||
* object will be called by name with a signature of <name>(Variant[] args)
|
||||
*
|
||||
* You must specify the location of the typeLib.
|
||||
*
|
||||
* @param src
|
||||
* dispatch that is the source of the messages
|
||||
* @param sink
|
||||
* the object that will receive the messages
|
||||
* @param progId
|
||||
* optional program id. most folks don't need this either
|
||||
* @param typeLib
|
||||
* optional parameter for those programs that don't register
|
||||
* their type libs (like Excel)
|
||||
*/
|
||||
private native void init3(Dispatch src, Object sink, String progId,
|
||||
String typeLib);
|
||||
/**
|
||||
* hooks up a connection point proxy by progId event methods on the sink
|
||||
* object will be called by name with a signature of <name>(Variant[] args)
|
||||
*
|
||||
* You must specify the location of the typeLib.
|
||||
*
|
||||
* @param src
|
||||
* dispatch that is the source of the messages
|
||||
* @param sink
|
||||
* the object that will receive the messages
|
||||
* @param progId
|
||||
* optional program id. most folks don't need this either
|
||||
* @param typeLib
|
||||
* optional parameter for those programs that don't register
|
||||
* their type libs (like Excel)
|
||||
*/
|
||||
private native void init3(Dispatch src, Object sink, String progId,
|
||||
String typeLib);
|
||||
|
||||
/**
|
||||
* now private so only this object can asccess was: call this to explicitly
|
||||
* release the com object before gc
|
||||
*
|
||||
*/
|
||||
private native void release();
|
||||
/**
|
||||
* now private so only this object can asccess was: call this to explicitly
|
||||
* release the com object before gc
|
||||
*
|
||||
*/
|
||||
private native void release();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
protected void finalize() {
|
||||
safeRelease();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
protected void finalize() {
|
||||
safeRelease();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.JacobObject#safeRelease()
|
||||
*/
|
||||
public void safeRelease() {
|
||||
if (mInvocationProxy != null) {
|
||||
mInvocationProxy.setTarget(null);
|
||||
}
|
||||
mInvocationProxy = null;
|
||||
super.safeRelease();
|
||||
if (m_pConnPtProxy != 0) {
|
||||
release();
|
||||
m_pConnPtProxy = 0;
|
||||
} else {
|
||||
// looks like a double release
|
||||
if (isDebugEnabled()) {
|
||||
debug("DispatchEvents:" + this.hashCode() + " double release");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.JacobObject#safeRelease()
|
||||
*/
|
||||
public void safeRelease() {
|
||||
if (mInvocationProxy != null) {
|
||||
mInvocationProxy.setTarget(null);
|
||||
}
|
||||
mInvocationProxy = null;
|
||||
super.safeRelease();
|
||||
if (m_pConnPtProxy != 0) {
|
||||
release();
|
||||
m_pConnPtProxy = 0;
|
||||
} else {
|
||||
// looks like a double release
|
||||
if (isDebugEnabled()) {
|
||||
debug("DispatchEvents:" + this.hashCode() + " double release");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/**
|
||||
*
|
||||
@@ -47,74 +47,74 @@ package com.jacob.com;
|
||||
*/
|
||||
public class DispatchIdentifier {
|
||||
|
||||
private DispatchIdentifier() {
|
||||
// This is utility class so there is no constructor.
|
||||
}
|
||||
private DispatchIdentifier() {
|
||||
// This is utility class so there is no constructor.
|
||||
}
|
||||
|
||||
public static final int DISPID_UNKNOWN = -1;
|
||||
public static final int DISPID_VALUE = 0;
|
||||
public static final int DISPID_PROPERTYPUT = -3;
|
||||
public static final int DISPID_NEWENUM = -4;
|
||||
public static final int DISPID_EVALUATE = -5;
|
||||
public static final int DISPID_CONSTRUCTOR = -6;
|
||||
public static final int DISPID_DESTRUCTOR = -7;
|
||||
public static final int DISPID_COLLECT = -8;
|
||||
public static final int DISPID_AUTOSIZE = -500;
|
||||
public static final int DISPID_BACKCOLOR = -501;
|
||||
public static final int DISPID_BACKSTYLE = -502;
|
||||
public static final int DISPID_BORDERCOLOR = -503;
|
||||
public static final int DISPID_BORDERSTYLE = -504;
|
||||
public static final int DISPID_BORDERWIDTH = -505;
|
||||
public static final int DISPID_DRAWMODE = -507;
|
||||
public static final int DISPID_DRAWSTYLE = -508;
|
||||
public static final int DISPID_DRAWWIDTH = -509;
|
||||
public static final int DISPID_FILLCOLOR = -510;
|
||||
public static final int DISPID_FILLSTYLE = -511;
|
||||
public static final int DISPID_FONT = -512;
|
||||
public static final int DISPID_FORECOLOR = -513;
|
||||
public static final int DISPID_ENABLED = -514;
|
||||
public static final int DISPID_HWND = -515;
|
||||
public static final int DISPID_TABSTOP = -516;
|
||||
public static final int DISPID_TEXT = -517;
|
||||
public static final int DISPID_CAPTION = -518;
|
||||
public static final int DISPID_BORDERVISIBLE = -519;
|
||||
public static final int DISPID_APPEARANCE = -520;
|
||||
public static final int DISPID_MOUSEPOINTER = -521;
|
||||
public static final int DISPID_MOUSEICON = -522;
|
||||
public static final int DISPID_PICTURE = -523;
|
||||
public static final int DISPID_VALID = -524;
|
||||
public static final int DISPID_READYSTATE = -525;
|
||||
public static final int DISPID_REFRESH = -550;
|
||||
public static final int DISPID_DOCLICK = -551;
|
||||
public static final int DISPID_ABOUTBOX = -552;
|
||||
public static final int DISPID_CLICK = -600;
|
||||
public static final int DISPID_DBLCLICK = -601;
|
||||
public static final int DISPID_KEYDOWN = -602;
|
||||
public static final int DISPID_KEYPRESS = -603;
|
||||
public static final int DISPID_KEYUP = -604;
|
||||
public static final int DISPID_MOUSEDOWN = -605;
|
||||
public static final int DISPID_MOUSEMOVE = -606;
|
||||
public static final int DISPID_MOUSEUP = -607;
|
||||
public static final int DISPID_ERROREVENT = -608;
|
||||
public static final int DISPID_READYSTATECHANGE = -609;
|
||||
public static final int DISPID_AMBIENT_BACKCOLOR = -701;
|
||||
public static final int DISPID_AMBIENT_DISPLAYNAME = -702;
|
||||
public static final int DISPID_AMBIENT_FONT = -703;
|
||||
public static final int DISPID_AMBIENT_FORECOLOR = -704;
|
||||
public static final int DISPID_AMBIENT_LOCALEID = -705;
|
||||
public static final int DISPID_AMBIENT_MESSAGEREFLECT = -706;
|
||||
public static final int DISPID_AMBIENT_SCALEUNITS = -707;
|
||||
public static final int DISPID_AMBIENT_TEXTALIGN = -708;
|
||||
public static final int DISPID_AMBIENT_USERMODE = -709;
|
||||
public static final int DISPID_AMBIENT_UIDEAD = -710;
|
||||
public static final int DISPID_AMBIENT_SHOWGRABHANDLES = -711;
|
||||
public static final int DISPID_AMBIENT_SHOWHATCHING = -712;
|
||||
public static final int DISPID_AMBIENT_DISPLAYASDEFAULT = -713;
|
||||
public static final int DISPID_AMBIENT_SUPPORTSMNEMONICS = -714;
|
||||
public static final int DISPID_AMBIENT_AUTOCLIP = -715;
|
||||
public static final int DISPID_AMBIENT_APPEARANCE = -716;
|
||||
public static final int DISPID_AMBIENT_CODEPAGE = -725;
|
||||
public static final int DISPID_AMBIENT_PALETTE = -726;
|
||||
public static final int DISPID_AMBIENT_CHARSET = -727;
|
||||
public static final int DISPID_AMBIENT_TRANSFERPRIORITY = -728;
|
||||
public static final int DISPID_UNKNOWN = -1;
|
||||
public static final int DISPID_VALUE = 0;
|
||||
public static final int DISPID_PROPERTYPUT = -3;
|
||||
public static final int DISPID_NEWENUM = -4;
|
||||
public static final int DISPID_EVALUATE = -5;
|
||||
public static final int DISPID_CONSTRUCTOR = -6;
|
||||
public static final int DISPID_DESTRUCTOR = -7;
|
||||
public static final int DISPID_COLLECT = -8;
|
||||
public static final int DISPID_AUTOSIZE = -500;
|
||||
public static final int DISPID_BACKCOLOR = -501;
|
||||
public static final int DISPID_BACKSTYLE = -502;
|
||||
public static final int DISPID_BORDERCOLOR = -503;
|
||||
public static final int DISPID_BORDERSTYLE = -504;
|
||||
public static final int DISPID_BORDERWIDTH = -505;
|
||||
public static final int DISPID_DRAWMODE = -507;
|
||||
public static final int DISPID_DRAWSTYLE = -508;
|
||||
public static final int DISPID_DRAWWIDTH = -509;
|
||||
public static final int DISPID_FILLCOLOR = -510;
|
||||
public static final int DISPID_FILLSTYLE = -511;
|
||||
public static final int DISPID_FONT = -512;
|
||||
public static final int DISPID_FORECOLOR = -513;
|
||||
public static final int DISPID_ENABLED = -514;
|
||||
public static final int DISPID_HWND = -515;
|
||||
public static final int DISPID_TABSTOP = -516;
|
||||
public static final int DISPID_TEXT = -517;
|
||||
public static final int DISPID_CAPTION = -518;
|
||||
public static final int DISPID_BORDERVISIBLE = -519;
|
||||
public static final int DISPID_APPEARANCE = -520;
|
||||
public static final int DISPID_MOUSEPOINTER = -521;
|
||||
public static final int DISPID_MOUSEICON = -522;
|
||||
public static final int DISPID_PICTURE = -523;
|
||||
public static final int DISPID_VALID = -524;
|
||||
public static final int DISPID_READYSTATE = -525;
|
||||
public static final int DISPID_REFRESH = -550;
|
||||
public static final int DISPID_DOCLICK = -551;
|
||||
public static final int DISPID_ABOUTBOX = -552;
|
||||
public static final int DISPID_CLICK = -600;
|
||||
public static final int DISPID_DBLCLICK = -601;
|
||||
public static final int DISPID_KEYDOWN = -602;
|
||||
public static final int DISPID_KEYPRESS = -603;
|
||||
public static final int DISPID_KEYUP = -604;
|
||||
public static final int DISPID_MOUSEDOWN = -605;
|
||||
public static final int DISPID_MOUSEMOVE = -606;
|
||||
public static final int DISPID_MOUSEUP = -607;
|
||||
public static final int DISPID_ERROREVENT = -608;
|
||||
public static final int DISPID_READYSTATECHANGE = -609;
|
||||
public static final int DISPID_AMBIENT_BACKCOLOR = -701;
|
||||
public static final int DISPID_AMBIENT_DISPLAYNAME = -702;
|
||||
public static final int DISPID_AMBIENT_FONT = -703;
|
||||
public static final int DISPID_AMBIENT_FORECOLOR = -704;
|
||||
public static final int DISPID_AMBIENT_LOCALEID = -705;
|
||||
public static final int DISPID_AMBIENT_MESSAGEREFLECT = -706;
|
||||
public static final int DISPID_AMBIENT_SCALEUNITS = -707;
|
||||
public static final int DISPID_AMBIENT_TEXTALIGN = -708;
|
||||
public static final int DISPID_AMBIENT_USERMODE = -709;
|
||||
public static final int DISPID_AMBIENT_UIDEAD = -710;
|
||||
public static final int DISPID_AMBIENT_SHOWGRABHANDLES = -711;
|
||||
public static final int DISPID_AMBIENT_SHOWHATCHING = -712;
|
||||
public static final int DISPID_AMBIENT_DISPLAYASDEFAULT = -713;
|
||||
public static final int DISPID_AMBIENT_SUPPORTSMNEMONICS = -714;
|
||||
public static final int DISPID_AMBIENT_AUTOCLIP = -715;
|
||||
public static final int DISPID_AMBIENT_APPEARANCE = -716;
|
||||
public static final int DISPID_AMBIENT_CODEPAGE = -725;
|
||||
public static final int DISPID_AMBIENT_PALETTE = -726;
|
||||
public static final int DISPID_AMBIENT_CHARSET = -727;
|
||||
public static final int DISPID_AMBIENT_TRANSFERPRIORITY = -728;
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -48,64 +48,64 @@ package com.jacob.com;
|
||||
* construct a separate DispatchProxy instance for each such case!
|
||||
*/
|
||||
public class DispatchProxy extends JacobObject {
|
||||
/**
|
||||
* Comment for <code>m_pStream</code>
|
||||
*/
|
||||
public int m_pStream;
|
||||
/**
|
||||
* Comment for <code>m_pStream</code>
|
||||
*/
|
||||
public int m_pStream;
|
||||
|
||||
/**
|
||||
* Marshals the passed in dispatch into the stream
|
||||
*
|
||||
* @param localDispatch
|
||||
*/
|
||||
public DispatchProxy(Dispatch localDispatch) {
|
||||
MarshalIntoStream(localDispatch);
|
||||
}
|
||||
/**
|
||||
* Marshals the passed in dispatch into the stream
|
||||
*
|
||||
* @param localDispatch
|
||||
*/
|
||||
public DispatchProxy(Dispatch localDispatch) {
|
||||
MarshalIntoStream(localDispatch);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Dispatch the dispatch retrieved from the stream
|
||||
*/
|
||||
public Dispatch toDispatch() {
|
||||
return MarshalFromStream();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return Dispatch the dispatch retrieved from the stream
|
||||
*/
|
||||
public Dispatch toDispatch() {
|
||||
return MarshalFromStream();
|
||||
}
|
||||
|
||||
private native void MarshalIntoStream(Dispatch d);
|
||||
private native void MarshalIntoStream(Dispatch d);
|
||||
|
||||
private native Dispatch MarshalFromStream();
|
||||
private native Dispatch MarshalFromStream();
|
||||
|
||||
/**
|
||||
* now private so only this object can access was: call this to explicitly
|
||||
* release the com object before gc
|
||||
*
|
||||
*/
|
||||
private native void release();
|
||||
/**
|
||||
* now private so only this object can access was: call this to explicitly
|
||||
* release the com object before gc
|
||||
*
|
||||
*/
|
||||
private native void release();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
public void finalize() {
|
||||
safeRelease();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
public void finalize() {
|
||||
safeRelease();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.JacobObject#safeRelease()
|
||||
*/
|
||||
public void safeRelease() {
|
||||
super.safeRelease();
|
||||
if (m_pStream != 0) {
|
||||
release();
|
||||
m_pStream = 0;
|
||||
} else {
|
||||
// looks like a double release
|
||||
if (isDebugEnabled()) {
|
||||
debug(this.getClass().getName() + ":" + this.hashCode()
|
||||
+ " double release");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.JacobObject#safeRelease()
|
||||
*/
|
||||
public void safeRelease() {
|
||||
super.safeRelease();
|
||||
if (m_pStream != 0) {
|
||||
release();
|
||||
m_pStream = 0;
|
||||
} else {
|
||||
// looks like a double release
|
||||
if (isDebugEnabled()) {
|
||||
debug(this.getClass().getName() + ":" + this.hashCode()
|
||||
+ " double release");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -43,133 +43,133 @@ package com.jacob.com;
|
||||
* (mailto:Thomas.Hallgren@eoncompany.com)
|
||||
*/
|
||||
public class EnumVariant extends JacobObject implements
|
||||
java.util.Enumeration<Variant> {
|
||||
private int m_pIEnumVARIANT;
|
||||
java.util.Enumeration<Variant> {
|
||||
private int m_pIEnumVARIANT;
|
||||
|
||||
private final Variant[] m_recBuf = new Variant[1];
|
||||
private final Variant[] m_recBuf = new Variant[1];
|
||||
|
||||
// this only gets called from JNI
|
||||
//
|
||||
protected EnumVariant(int pIEnumVARIANT) {
|
||||
m_pIEnumVARIANT = pIEnumVARIANT;
|
||||
}
|
||||
// this only gets called from JNI
|
||||
//
|
||||
protected EnumVariant(int pIEnumVARIANT) {
|
||||
m_pIEnumVARIANT = pIEnumVARIANT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param disp
|
||||
*/
|
||||
public EnumVariant(Dispatch disp) {
|
||||
int[] hres = new int[1];
|
||||
Variant evv = Dispatch.invokev(disp, DispatchIdentifier.DISPID_NEWENUM,
|
||||
Dispatch.Get, new Variant[0], hres);
|
||||
if (evv.getvt() != Variant.VariantObject)
|
||||
//
|
||||
// The DISPID_NEWENUM did not result in a valid object
|
||||
//
|
||||
throw new ComFailException("Can't obtain EnumVARIANT");
|
||||
/**
|
||||
* @param disp
|
||||
*/
|
||||
public EnumVariant(Dispatch disp) {
|
||||
int[] hres = new int[1];
|
||||
Variant evv = Dispatch.invokev(disp, DispatchIdentifier.DISPID_NEWENUM,
|
||||
Dispatch.Get, new Variant[0], hres);
|
||||
if (evv.getvt() != Variant.VariantObject)
|
||||
//
|
||||
// The DISPID_NEWENUM did not result in a valid object
|
||||
//
|
||||
throw new ComFailException("Can't obtain EnumVARIANT");
|
||||
|
||||
EnumVariant tmp = evv.toEnumVariant();
|
||||
m_pIEnumVARIANT = tmp.m_pIEnumVARIANT;
|
||||
tmp.m_pIEnumVARIANT = 0;
|
||||
}
|
||||
EnumVariant tmp = evv.toEnumVariant();
|
||||
m_pIEnumVARIANT = tmp.m_pIEnumVARIANT;
|
||||
tmp.m_pIEnumVARIANT = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements java.util.Enumeration
|
||||
*
|
||||
* @return boolean true if there are more elements in this enumeration
|
||||
*/
|
||||
public boolean hasMoreElements() {
|
||||
{
|
||||
if (m_recBuf[0] == null) {
|
||||
if (this.Next(m_recBuf) <= 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Implements java.util.Enumeration
|
||||
*
|
||||
* @return boolean true if there are more elements in this enumeration
|
||||
*/
|
||||
public boolean hasMoreElements() {
|
||||
{
|
||||
if (m_recBuf[0] == null) {
|
||||
if (this.Next(m_recBuf) <= 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements java.util.Enumeration
|
||||
*
|
||||
* @return next element in the enumeration
|
||||
*/
|
||||
public Variant nextElement() {
|
||||
Variant last = m_recBuf[0];
|
||||
if (last == null) {
|
||||
if (this.Next(m_recBuf) <= 0)
|
||||
throw new java.util.NoSuchElementException();
|
||||
last = m_recBuf[0];
|
||||
}
|
||||
m_recBuf[0] = null;
|
||||
return last;
|
||||
}
|
||||
/**
|
||||
* Implements java.util.Enumeration
|
||||
*
|
||||
* @return next element in the enumeration
|
||||
*/
|
||||
public Variant nextElement() {
|
||||
Variant last = m_recBuf[0];
|
||||
if (last == null) {
|
||||
if (this.Next(m_recBuf) <= 0)
|
||||
throw new java.util.NoSuchElementException();
|
||||
last = m_recBuf[0];
|
||||
}
|
||||
m_recBuf[0] = null;
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next element in collection or null if at end
|
||||
*
|
||||
* @return Variant that is next in the collection
|
||||
* @deprecated use nextElement() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Variant Next() {
|
||||
if (hasMoreElements())
|
||||
return nextElement();
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Get next element in collection or null if at end
|
||||
*
|
||||
* @return Variant that is next in the collection
|
||||
* @deprecated use nextElement() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Variant Next() {
|
||||
if (hasMoreElements())
|
||||
return nextElement();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be private and wrapped to protect JNI layer.
|
||||
*
|
||||
* @param receiverArray
|
||||
* @return Returns the next variant object pointer as an int from windows
|
||||
* layer
|
||||
*/
|
||||
public native int Next(Variant[] receiverArray);
|
||||
/**
|
||||
* This should be private and wrapped to protect JNI layer.
|
||||
*
|
||||
* @param receiverArray
|
||||
* @return Returns the next variant object pointer as an int from windows
|
||||
* layer
|
||||
*/
|
||||
public native int Next(Variant[] receiverArray);
|
||||
|
||||
/**
|
||||
* This should be private and wrapped to protect JNI layer.
|
||||
*
|
||||
* @param count
|
||||
* number to skip
|
||||
*/
|
||||
public native void Skip(int count);
|
||||
/**
|
||||
* This should be private and wrapped to protect JNI layer.
|
||||
*
|
||||
* @param count
|
||||
* number to skip
|
||||
*/
|
||||
public native void Skip(int count);
|
||||
|
||||
/**
|
||||
* This should be private and wrapped to protect JNI layer
|
||||
*/
|
||||
public native void Reset();
|
||||
/**
|
||||
* This should be private and wrapped to protect JNI layer
|
||||
*/
|
||||
public native void Reset();
|
||||
|
||||
/**
|
||||
* now private so only this object can access was: call this to explicitly
|
||||
* release the com object before gc
|
||||
*
|
||||
*/
|
||||
private native void release();
|
||||
/**
|
||||
* now private so only this object can access was: call this to explicitly
|
||||
* release the com object before gc
|
||||
*
|
||||
*/
|
||||
private native void release();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
protected void finalize() {
|
||||
safeRelease();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
protected void finalize() {
|
||||
safeRelease();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.JacobObject#safeRelease()
|
||||
*/
|
||||
public void safeRelease() {
|
||||
super.safeRelease();
|
||||
if (m_pIEnumVARIANT != 0) {
|
||||
this.release();
|
||||
m_pIEnumVARIANT = 0;
|
||||
} else {
|
||||
// looks like a double release
|
||||
if (isDebugEnabled()) {
|
||||
debug(this.getClass().getName() + ":" + this.hashCode()
|
||||
+ " double release");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.JacobObject#safeRelease()
|
||||
*/
|
||||
public void safeRelease() {
|
||||
super.safeRelease();
|
||||
if (m_pIEnumVARIANT != 0) {
|
||||
this.release();
|
||||
m_pIEnumVARIANT = 0;
|
||||
} else {
|
||||
// looks like a double release
|
||||
if (isDebugEnabled()) {
|
||||
debug(this.getClass().getName() + ":" + this.hashCode()
|
||||
+ " double release");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -58,70 +58,70 @@ package com.jacob.com;
|
||||
*/
|
||||
public abstract class InvocationProxy {
|
||||
|
||||
/**
|
||||
* the object we will try and forward to.
|
||||
*/
|
||||
protected Object mTargetObject = null;
|
||||
/**
|
||||
* the object we will try and forward to.
|
||||
*/
|
||||
protected Object mTargetObject = null;
|
||||
|
||||
/**
|
||||
* dummy constructor for subclasses that don't actually wrap anything and
|
||||
* just want to override the invoke() method
|
||||
*/
|
||||
protected InvocationProxy() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* dummy constructor for subclasses that don't actually wrap anything and
|
||||
* just want to override the invoke() method
|
||||
*/
|
||||
protected InvocationProxy() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* The method actually invoked by EventProxy.cpp. The method name is
|
||||
* calculated by the underlying JNI code from the MS windows Callback
|
||||
* function name. The method is assumed to take an array of Variant objects.
|
||||
* The method may return a Variant or be a void. Those are the only two
|
||||
* options that will not blow up.
|
||||
* <p>
|
||||
* Subclasses that override this should make sure mTargetObject is not null
|
||||
* before processing.
|
||||
*
|
||||
* @param methodName
|
||||
* name of method in mTargetObject we will invoke
|
||||
* @param targetParameters
|
||||
* Variant[] that is the single parameter to the method
|
||||
* @return an object that will be returned to the com event caller
|
||||
*/
|
||||
public abstract Variant invoke(String methodName,
|
||||
Variant targetParameters[]);
|
||||
/**
|
||||
* The method actually invoked by EventProxy.cpp. The method name is
|
||||
* calculated by the underlying JNI code from the MS windows Callback
|
||||
* function name. The method is assumed to take an array of Variant objects.
|
||||
* The method may return a Variant or be a void. Those are the only two
|
||||
* options that will not blow up.
|
||||
* <p>
|
||||
* Subclasses that override this should make sure mTargetObject is not null
|
||||
* before processing.
|
||||
*
|
||||
* @param methodName
|
||||
* name of method in mTargetObject we will invoke
|
||||
* @param targetParameters
|
||||
* Variant[] that is the single parameter to the method
|
||||
* @return an object that will be returned to the com event caller
|
||||
*/
|
||||
public abstract Variant invoke(String methodName,
|
||||
Variant targetParameters[]);
|
||||
|
||||
/**
|
||||
* used by EventProxy.cpp to create variant objects in the right thread
|
||||
*
|
||||
* @return Variant object that will be used by the COM layer
|
||||
*/
|
||||
public Variant getVariant() {
|
||||
return new VariantViaEvent();
|
||||
}
|
||||
/**
|
||||
* used by EventProxy.cpp to create variant objects in the right thread
|
||||
*
|
||||
* @return Variant object that will be used by the COM layer
|
||||
*/
|
||||
public Variant getVariant() {
|
||||
return new VariantViaEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target for this InvocationProxy.
|
||||
*
|
||||
* @param pTargetObject
|
||||
* @throws IllegalArgumentException
|
||||
* if target is not publicly accessible
|
||||
*/
|
||||
public void setTarget(Object pTargetObject) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: setting target "
|
||||
+ pTargetObject);
|
||||
}
|
||||
if (pTargetObject != null) {
|
||||
// JNI code apparently bypasses this check and could operate against
|
||||
// protected classes. This seems like a security issue...
|
||||
// maybe it was because JNI code isn't in a package?
|
||||
if (!java.lang.reflect.Modifier.isPublic(pTargetObject.getClass()
|
||||
.getModifiers())) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy only public classes can receive event notifications");
|
||||
}
|
||||
}
|
||||
mTargetObject = pTargetObject;
|
||||
}
|
||||
/**
|
||||
* Sets the target for this InvocationProxy.
|
||||
*
|
||||
* @param pTargetObject
|
||||
* @throws IllegalArgumentException
|
||||
* if target is not publicly accessible
|
||||
*/
|
||||
public void setTarget(Object pTargetObject) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: setting target "
|
||||
+ pTargetObject);
|
||||
}
|
||||
if (pTargetObject != null) {
|
||||
// JNI code apparently bypasses this check and could operate against
|
||||
// protected classes. This seems like a security issue...
|
||||
// maybe it was because JNI code isn't in a package?
|
||||
if (!java.lang.reflect.Modifier.isPublic(pTargetObject.getClass()
|
||||
.getModifiers())) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy only public classes can receive event notifications");
|
||||
}
|
||||
}
|
||||
mTargetObject = pTargetObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -55,88 +55,88 @@ import java.lang.reflect.Method;
|
||||
*/
|
||||
public class InvocationProxyAllVariants extends InvocationProxy {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.InvocationProxy#invoke(java.lang.String,
|
||||
* com.jacob.com.Variant[])
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Variant invoke(String methodName, Variant targetParameters[]) {
|
||||
Variant mVariantToBeReturned = null;
|
||||
if (mTargetObject == null) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: received notification ("
|
||||
+ methodName + ") with no target set");
|
||||
}
|
||||
// structured programming guidlines say this return should not be up
|
||||
// here
|
||||
return null;
|
||||
}
|
||||
Class targetClass = mTargetObject.getClass();
|
||||
if (methodName == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing method name");
|
||||
}
|
||||
if (targetParameters == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing Variant parameters");
|
||||
}
|
||||
try {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: trying to invoke "
|
||||
+ methodName + " on " + mTargetObject);
|
||||
}
|
||||
Method targetMethod;
|
||||
targetMethod = targetClass.getMethod(methodName,
|
||||
new Class[] { Variant[].class });
|
||||
if (targetMethod != null) {
|
||||
// protected classes can't be invoked against even if they
|
||||
// let you grab the method. you could do
|
||||
// targetMethod.setAccessible(true);
|
||||
// but that should be stopped by the security manager
|
||||
Object mReturnedByInvocation = null;
|
||||
mReturnedByInvocation = targetMethod.invoke(mTargetObject,
|
||||
new Object[] { targetParameters });
|
||||
if (mReturnedByInvocation == null) {
|
||||
mVariantToBeReturned = null;
|
||||
} else if (!(mReturnedByInvocation instanceof Variant)) {
|
||||
// could try and convert to Variant here.
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: invokation of target method returned "
|
||||
+ "non-null non-variant object: "
|
||||
+ mReturnedByInvocation);
|
||||
} else {
|
||||
mVariantToBeReturned = (Variant) mReturnedByInvocation;
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
// what causes this exception?
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
// this happens whenever the listener doesn't implement all the
|
||||
// methods
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: listener (" + mTargetObject
|
||||
+ ") doesn't implement " + methodName);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
// we can throw these inside the catch block so need to re-throw it
|
||||
throw e;
|
||||
} catch (IllegalAccessException e) {
|
||||
// can't access the method on the target instance for some reason
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject
|
||||
.debug("InvocationProxy: probably tried to access public method on non public class"
|
||||
+ methodName);
|
||||
}
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// invocation of target method failed
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mVariantToBeReturned;
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.jacob.com.InvocationProxy#invoke(java.lang.String,
|
||||
* com.jacob.com.Variant[])
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Variant invoke(String methodName, Variant targetParameters[]) {
|
||||
Variant mVariantToBeReturned = null;
|
||||
if (mTargetObject == null) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: received notification ("
|
||||
+ methodName + ") with no target set");
|
||||
}
|
||||
// structured programming guidlines say this return should not be up
|
||||
// here
|
||||
return null;
|
||||
}
|
||||
Class targetClass = mTargetObject.getClass();
|
||||
if (methodName == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing method name");
|
||||
}
|
||||
if (targetParameters == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: missing Variant parameters");
|
||||
}
|
||||
try {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: trying to invoke "
|
||||
+ methodName + " on " + mTargetObject);
|
||||
}
|
||||
Method targetMethod;
|
||||
targetMethod = targetClass.getMethod(methodName,
|
||||
new Class[] { Variant[].class });
|
||||
if (targetMethod != null) {
|
||||
// protected classes can't be invoked against even if they
|
||||
// let you grab the method. you could do
|
||||
// targetMethod.setAccessible(true);
|
||||
// but that should be stopped by the security manager
|
||||
Object mReturnedByInvocation = null;
|
||||
mReturnedByInvocation = targetMethod.invoke(mTargetObject,
|
||||
new Object[] { targetParameters });
|
||||
if (mReturnedByInvocation == null) {
|
||||
mVariantToBeReturned = null;
|
||||
} else if (!(mReturnedByInvocation instanceof Variant)) {
|
||||
// could try and convert to Variant here.
|
||||
throw new IllegalArgumentException(
|
||||
"InvocationProxy: invokation of target method returned "
|
||||
+ "non-null non-variant object: "
|
||||
+ mReturnedByInvocation);
|
||||
} else {
|
||||
mVariantToBeReturned = (Variant) mReturnedByInvocation;
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
// what causes this exception?
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
// this happens whenever the listener doesn't implement all the
|
||||
// methods
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("InvocationProxy: listener (" + mTargetObject
|
||||
+ ") doesn't implement " + methodName);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
// we can throw these inside the catch block so need to re-throw it
|
||||
throw e;
|
||||
} catch (IllegalAccessException e) {
|
||||
// can't access the method on the target instance for some reason
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject
|
||||
.debug("InvocationProxy: probably tried to access public method on non public class"
|
||||
+ methodName);
|
||||
}
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// invocation of target method failed
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mVariantToBeReturned;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -45,24 +45,24 @@ package com.jacob.com;
|
||||
*/
|
||||
public class JacobException extends RuntimeException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1637125318746002715L;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1637125318746002715L;
|
||||
|
||||
/**
|
||||
* Default constructor. Calls super with a "No Message Provided" string
|
||||
*/
|
||||
public JacobException() {
|
||||
super("No Message Provided");
|
||||
}
|
||||
/**
|
||||
* Default constructor. Calls super with a "No Message Provided" string
|
||||
*/
|
||||
public JacobException() {
|
||||
super("No Message Provided");
|
||||
}
|
||||
|
||||
/**
|
||||
* standard constructor
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public JacobException(String message) {
|
||||
super(message);
|
||||
}
|
||||
/**
|
||||
* standard constructor
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public JacobException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -53,78 +53,78 @@ package com.jacob.com;
|
||||
*/
|
||||
public class JacobObject {
|
||||
|
||||
/**
|
||||
* Standard constructor that adds this JacobObject to the memory management
|
||||
* pool.
|
||||
*/
|
||||
public JacobObject() {
|
||||
ROT.addObject(this);
|
||||
}
|
||||
/**
|
||||
* Standard constructor that adds this JacobObject to the memory management
|
||||
* pool.
|
||||
*/
|
||||
public JacobObject() {
|
||||
ROT.addObject(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizers call this method. This method should release any COM data
|
||||
* structures in a way that it can be called multiple times. This can happen
|
||||
* if someone manually calls this and then a finalizer calls it.
|
||||
*/
|
||||
public void safeRelease() {
|
||||
// currently does nothing - subclasses may do something
|
||||
if (isDebugEnabled()) {
|
||||
// this used to do a toString() but that is bad for SafeArray
|
||||
debug("SafeRelease: " + this.getClass().getName());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Finalizers call this method. This method should release any COM data
|
||||
* structures in a way that it can be called multiple times. This can happen
|
||||
* if someone manually calls this and then a finalizer calls it.
|
||||
*/
|
||||
public void safeRelease() {
|
||||
// currently does nothing - subclasses may do something
|
||||
if (isDebugEnabled()) {
|
||||
// this used to do a toString() but that is bad for SafeArray
|
||||
debug("SafeRelease: " + this.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When things go wrong, it is useful to be able to debug the ROT.
|
||||
*/
|
||||
private static final boolean DEBUG =
|
||||
// true;
|
||||
"true".equalsIgnoreCase(System.getProperty("com.jacob.debug"));
|
||||
/**
|
||||
* When things go wrong, it is useful to be able to debug the ROT.
|
||||
*/
|
||||
private static final boolean DEBUG =
|
||||
// true;
|
||||
"true".equalsIgnoreCase(System.getProperty("com.jacob.debug"));
|
||||
|
||||
protected static boolean isDebugEnabled() {
|
||||
// return true;
|
||||
return DEBUG;
|
||||
}
|
||||
protected static boolean isDebugEnabled() {
|
||||
// return true;
|
||||
return DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads JacobVersion.Properties and returns the value of version in it
|
||||
*
|
||||
* @deprecated use JacobReleaseInfo.getBuildDate() instead.
|
||||
* @return String value of version in JacobVersion.Properties or "" if none
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getBuildDate() {
|
||||
return JacobReleaseInfo.getBuildDate();
|
||||
}
|
||||
/**
|
||||
* Loads JacobVersion.Properties and returns the value of version in it
|
||||
*
|
||||
* @deprecated use JacobReleaseInfo.getBuildDate() instead.
|
||||
* @return String value of version in JacobVersion.Properties or "" if none
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getBuildDate() {
|
||||
return JacobReleaseInfo.getBuildDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads JacobVersion.Properties and returns the value of version in it
|
||||
*
|
||||
* @deprecated use JacobReleaseInfo.getBuildVersion() instead.
|
||||
* @return String value of version in JacobVersion.Properties or "" if none
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getBuildVersion() {
|
||||
return JacobReleaseInfo.getBuildVersion();
|
||||
}
|
||||
/**
|
||||
* Loads JacobVersion.Properties and returns the value of version in it
|
||||
*
|
||||
* @deprecated use JacobReleaseInfo.getBuildVersion() instead.
|
||||
* @return String value of version in JacobVersion.Properties or "" if none
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getBuildVersion() {
|
||||
return JacobReleaseInfo.getBuildVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Very basic debugging function.
|
||||
*
|
||||
* @param istrMessage
|
||||
*/
|
||||
protected static void debug(String istrMessage) {
|
||||
if (isDebugEnabled()) {
|
||||
System.out.println(Thread.currentThread().getName() + ": "
|
||||
+ istrMessage);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Very basic debugging function.
|
||||
*
|
||||
* @param istrMessage
|
||||
*/
|
||||
protected static void debug(String istrMessage) {
|
||||
if (isDebugEnabled()) {
|
||||
System.out.println(Thread.currentThread().getName() + ": "
|
||||
+ istrMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* force the jacob DLL to be loaded whenever this class is referenced
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
/**
|
||||
* force the jacob DLL to be loaded whenever this class is referenced
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -49,86 +49,86 @@ import java.util.Properties;
|
||||
*/
|
||||
public class JacobReleaseInfo {
|
||||
|
||||
/**
|
||||
* holds the build version as retrieved from the version properties file
|
||||
* that exists in the JAR. This can be retrieved by calling the static
|
||||
* method getBuildVersion()
|
||||
*
|
||||
* @see #getBuildVersion()
|
||||
*/
|
||||
private static String buildVersion = "";
|
||||
/**
|
||||
* holds the build date as retrieved from the version properties file that
|
||||
* exists in the JAR This can be retrieved by calling the static method
|
||||
* getBuildDate()
|
||||
*
|
||||
* @see #getBuildDate()
|
||||
*/
|
||||
private static String buildDate = "";
|
||||
/** the name of the jacob version properties file */
|
||||
private static final String PROPERTY_FILE_NAME = "META-INF/JacobVersion.properties";
|
||||
/**
|
||||
* holds the build version as retrieved from the version properties file
|
||||
* that exists in the JAR. This can be retrieved by calling the static
|
||||
* method getBuildVersion()
|
||||
*
|
||||
* @see #getBuildVersion()
|
||||
*/
|
||||
private static String buildVersion = "";
|
||||
/**
|
||||
* holds the build date as retrieved from the version properties file that
|
||||
* exists in the JAR This can be retrieved by calling the static method
|
||||
* getBuildDate()
|
||||
*
|
||||
* @see #getBuildDate()
|
||||
*/
|
||||
private static String buildDate = "";
|
||||
/** the name of the jacob version properties file */
|
||||
private static final String PROPERTY_FILE_NAME = "META-INF/JacobVersion.properties";
|
||||
|
||||
/**
|
||||
* Loads version information from PROPERTY_FILE_NAME that was built as part
|
||||
* of this release.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* when it can't find the version properties file
|
||||
*/
|
||||
private static void loadVersionProperties() {
|
||||
Properties versionProps = new Properties();
|
||||
// can't use system class loader cause won't work in JavaWebStart
|
||||
InputStream stream = JacobReleaseInfo.class.getClassLoader()
|
||||
.getResourceAsStream(PROPERTY_FILE_NAME);
|
||||
// This should never happen. This is an attempt to make something work
|
||||
// for WebSphere. They may be using some kind of Servlet loader that
|
||||
// needs an absolute path based search
|
||||
if (stream == null) {
|
||||
stream = JacobReleaseInfo.class.getClassLoader()
|
||||
.getResourceAsStream("/" + PROPERTY_FILE_NAME);
|
||||
}
|
||||
// A report came in that WebSphere had trouble finding the file
|
||||
// so lets trap it. Plus, it's a good idea anyway.
|
||||
if (stream == null) {
|
||||
throw new IllegalStateException(
|
||||
"Can't find "
|
||||
+ PROPERTY_FILE_NAME
|
||||
+ " using JacobReleaseInfo.class.getClassLoader().getResourceAsStream()");
|
||||
} else {
|
||||
try {
|
||||
versionProps.load(stream);
|
||||
stream.close();
|
||||
buildVersion = (String) versionProps.get("version");
|
||||
buildDate = (String) versionProps.get("build.date");
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
System.err.println("Warning! Couldn't load props " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Loads version information from PROPERTY_FILE_NAME that was built as part
|
||||
* of this release.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* when it can't find the version properties file
|
||||
*/
|
||||
private static void loadVersionProperties() {
|
||||
Properties versionProps = new Properties();
|
||||
// can't use system class loader cause won't work in JavaWebStart
|
||||
InputStream stream = JacobReleaseInfo.class.getClassLoader()
|
||||
.getResourceAsStream(PROPERTY_FILE_NAME);
|
||||
// This should never happen. This is an attempt to make something work
|
||||
// for WebSphere. They may be using some kind of Servlet loader that
|
||||
// needs an absolute path based search
|
||||
if (stream == null) {
|
||||
stream = JacobReleaseInfo.class.getClassLoader()
|
||||
.getResourceAsStream("/" + PROPERTY_FILE_NAME);
|
||||
}
|
||||
// A report came in that WebSphere had trouble finding the file
|
||||
// so lets trap it. Plus, it's a good idea anyway.
|
||||
if (stream == null) {
|
||||
throw new IllegalStateException(
|
||||
"Can't find "
|
||||
+ PROPERTY_FILE_NAME
|
||||
+ " using JacobReleaseInfo.class.getClassLoader().getResourceAsStream()");
|
||||
} else {
|
||||
try {
|
||||
versionProps.load(stream);
|
||||
stream.close();
|
||||
buildVersion = (String) versionProps.get("version");
|
||||
buildDate = (String) versionProps.get("build.date");
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
System.err.println("Warning! Couldn't load props " + ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* loads PROPERT_FILE_NAME and returns the value of version in it
|
||||
*
|
||||
* @return String value of version in PROPERT_FILE_NAME or "" if none
|
||||
*/
|
||||
public static String getBuildDate() {
|
||||
if (buildDate.equals("")) {
|
||||
loadVersionProperties();
|
||||
}
|
||||
return buildDate;
|
||||
}
|
||||
/**
|
||||
* loads PROPERT_FILE_NAME and returns the value of version in it
|
||||
*
|
||||
* @return String value of version in PROPERT_FILE_NAME or "" if none
|
||||
*/
|
||||
public static String getBuildDate() {
|
||||
if (buildDate.equals("")) {
|
||||
loadVersionProperties();
|
||||
}
|
||||
return buildDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads PROPERT_FILE_NAME and returns the value of version in it
|
||||
*
|
||||
* @return String value of version in PROPERT_FILE_NAME or "" if none
|
||||
*/
|
||||
public static String getBuildVersion() {
|
||||
if (buildVersion.equals("")) {
|
||||
loadVersionProperties();
|
||||
}
|
||||
return buildVersion;
|
||||
}
|
||||
/**
|
||||
* loads PROPERT_FILE_NAME and returns the value of version in it
|
||||
*
|
||||
* @return String value of version in PROPERT_FILE_NAME or "" if none
|
||||
*/
|
||||
public static String getBuildVersion() {
|
||||
if (buildVersion.equals("")) {
|
||||
loadVersionProperties();
|
||||
}
|
||||
return buildVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -47,13 +47,13 @@ import com.github.boukefalos.jlibloader.Native;
|
||||
* @author Jason Smith
|
||||
*/
|
||||
public final class LibraryLoader {
|
||||
/**
|
||||
* Load the jacob dll
|
||||
*
|
||||
* @throws UnsatisfiedLinkError
|
||||
* if the library does not exist.
|
||||
*/
|
||||
public static void loadJacobLibrary() {
|
||||
Native.load("com.github.boukefalos", "jlibcom");
|
||||
}
|
||||
/**
|
||||
* Load the jacob dll
|
||||
*
|
||||
* @throws UnsatisfiedLinkError
|
||||
* if the library does not exist.
|
||||
*/
|
||||
public static void loadJacobLibrary() {
|
||||
Native.load("com.github.boukefalos", "jlibcom");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -45,16 +45,16 @@ package com.jacob.com;
|
||||
*/
|
||||
public class NotImplementedException extends JacobException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -9169900832852356445L;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -9169900832852356445L;
|
||||
|
||||
/**
|
||||
* @param description
|
||||
*/
|
||||
public NotImplementedException(String description) {
|
||||
super(description);
|
||||
}
|
||||
/**
|
||||
* @param description
|
||||
*/
|
||||
public NotImplementedException(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -60,239 +60,239 @@ import java.util.WeakHashMap;
|
||||
* Is [ 1116101 ] jacob-msg 0284 relevant???
|
||||
*/
|
||||
public abstract class ROT {
|
||||
/**
|
||||
* Manual garbage collection was the only option pre 1.9 Can staticly cache
|
||||
* the results because only one value and we don't let it change during a
|
||||
* run
|
||||
*/
|
||||
protected static final boolean USE_AUTOMATIC_GARBAGE_COLLECTION = "true"
|
||||
.equalsIgnoreCase(System.getProperty("com.jacob.autogc"));
|
||||
/**
|
||||
* Manual garbage collection was the only option pre 1.9 Can staticly cache
|
||||
* the results because only one value and we don't let it change during a
|
||||
* run
|
||||
*/
|
||||
protected static final boolean USE_AUTOMATIC_GARBAGE_COLLECTION = "true"
|
||||
.equalsIgnoreCase(System.getProperty("com.jacob.autogc"));
|
||||
|
||||
/**
|
||||
* If the code is ran from an applet that is called from javascript the Java
|
||||
* Plugin does not give full permissions to the code and thus System
|
||||
* properties cannot be accessed. They can be accessed at class
|
||||
* initialization time.
|
||||
*
|
||||
* The default behavior is to include all classes in the ROT, setting a
|
||||
* boolean here to indicate this prevents a call to System.getProperty as
|
||||
* part of the general call flow.
|
||||
*/
|
||||
protected static final Boolean INCLUDE_ALL_CLASSES_IN_ROT = Boolean
|
||||
.valueOf(System.getProperty("com.jacob.includeAllClassesInROT",
|
||||
"true"));
|
||||
/**
|
||||
* If the code is ran from an applet that is called from javascript the Java
|
||||
* Plugin does not give full permissions to the code and thus System
|
||||
* properties cannot be accessed. They can be accessed at class
|
||||
* initialization time.
|
||||
*
|
||||
* The default behavior is to include all classes in the ROT, setting a
|
||||
* boolean here to indicate this prevents a call to System.getProperty as
|
||||
* part of the general call flow.
|
||||
*/
|
||||
protected static final Boolean INCLUDE_ALL_CLASSES_IN_ROT = Boolean
|
||||
.valueOf(System.getProperty("com.jacob.includeAllClassesInROT",
|
||||
"true"));
|
||||
|
||||
/**
|
||||
* Suffix added to class name to make up property name that determines if
|
||||
* this object should be stored in the ROT. This 1.13 "feature" makes it
|
||||
* possible to cause VariantViaEvent objects to not be added to the ROT in
|
||||
* event callbacks.
|
||||
* <p>
|
||||
* We don't have a static for the actual property because there is a
|
||||
* different property for each class that may make use of this feature.
|
||||
*/
|
||||
protected static String PUT_IN_ROT_SUFFIX = ".PutInROT";
|
||||
/**
|
||||
* Suffix added to class name to make up property name that determines if
|
||||
* this object should be stored in the ROT. This 1.13 "feature" makes it
|
||||
* possible to cause VariantViaEvent objects to not be added to the ROT in
|
||||
* event callbacks.
|
||||
* <p>
|
||||
* We don't have a static for the actual property because there is a
|
||||
* different property for each class that may make use of this feature.
|
||||
*/
|
||||
protected static String PUT_IN_ROT_SUFFIX = ".PutInROT";
|
||||
|
||||
/**
|
||||
* A hash table where each element is another HashMap that represents a
|
||||
* thread. Each thread HashMap contains the com objects created in that
|
||||
* thread
|
||||
*/
|
||||
private static HashMap<String, Map<JacobObject, String>> rot = new HashMap<String, Map<JacobObject, String>>();
|
||||
/**
|
||||
* A hash table where each element is another HashMap that represents a
|
||||
* thread. Each thread HashMap contains the com objects created in that
|
||||
* thread
|
||||
*/
|
||||
private static HashMap<String, Map<JacobObject, String>> rot = new HashMap<String, Map<JacobObject, String>>();
|
||||
|
||||
/**
|
||||
* adds a new thread storage area to rot
|
||||
*
|
||||
* @return Map corresponding to the thread that this call was made in
|
||||
*/
|
||||
protected synchronized static Map<JacobObject, String> addThread() {
|
||||
// should use the id here instead of the name because the name can be
|
||||
// changed
|
||||
String t_name = Thread.currentThread().getName();
|
||||
if (rot.containsKey(t_name)) {
|
||||
// nothing to do
|
||||
} else {
|
||||
Map<JacobObject, String> tab = null;
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: Automatic GC flag == "
|
||||
+ USE_AUTOMATIC_GARBAGE_COLLECTION);
|
||||
}
|
||||
if (!USE_AUTOMATIC_GARBAGE_COLLECTION) {
|
||||
tab = new HashMap<JacobObject, String>();
|
||||
} else {
|
||||
tab = new WeakHashMap<JacobObject, String>();
|
||||
}
|
||||
rot.put(t_name, tab);
|
||||
}
|
||||
return getThreadObjects(false);
|
||||
}
|
||||
/**
|
||||
* adds a new thread storage area to rot
|
||||
*
|
||||
* @return Map corresponding to the thread that this call was made in
|
||||
*/
|
||||
protected synchronized static Map<JacobObject, String> addThread() {
|
||||
// should use the id here instead of the name because the name can be
|
||||
// changed
|
||||
String t_name = Thread.currentThread().getName();
|
||||
if (rot.containsKey(t_name)) {
|
||||
// nothing to do
|
||||
} else {
|
||||
Map<JacobObject, String> tab = null;
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: Automatic GC flag == "
|
||||
+ USE_AUTOMATIC_GARBAGE_COLLECTION);
|
||||
}
|
||||
if (!USE_AUTOMATIC_GARBAGE_COLLECTION) {
|
||||
tab = new HashMap<JacobObject, String>();
|
||||
} else {
|
||||
tab = new WeakHashMap<JacobObject, String>();
|
||||
}
|
||||
rot.put(t_name, tab);
|
||||
}
|
||||
return getThreadObjects(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pool for this thread if it exists. can create a new one if
|
||||
* you wish by passing in TRUE
|
||||
*
|
||||
* @param createIfDoesNotExist
|
||||
* @return Map the collection that holds the objects created in the current
|
||||
* thread
|
||||
*/
|
||||
protected synchronized static Map<JacobObject, String> getThreadObjects(
|
||||
boolean createIfDoesNotExist) {
|
||||
String t_name = Thread.currentThread().getName();
|
||||
if (!rot.containsKey(t_name) && createIfDoesNotExist) {
|
||||
addThread();
|
||||
}
|
||||
return rot.get(t_name);
|
||||
}
|
||||
/**
|
||||
* Returns the pool for this thread if it exists. can create a new one if
|
||||
* you wish by passing in TRUE
|
||||
*
|
||||
* @param createIfDoesNotExist
|
||||
* @return Map the collection that holds the objects created in the current
|
||||
* thread
|
||||
*/
|
||||
protected synchronized static Map<JacobObject, String> getThreadObjects(
|
||||
boolean createIfDoesNotExist) {
|
||||
String t_name = Thread.currentThread().getName();
|
||||
if (!rot.containsKey(t_name) && createIfDoesNotExist) {
|
||||
addThread();
|
||||
}
|
||||
return rot.get(t_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates across all of the entries in the Hashmap in the rot that
|
||||
* corresponds to this thread. This calls safeRelease() on each entry and
|
||||
* then clears the map when done and removes it from the rot. All traces of
|
||||
* this thread's objects will disappear. This is called by COMThread in the
|
||||
* tear down and provides a synchronous way of releasing memory
|
||||
*/
|
||||
protected static void clearObjects() {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: " + rot.keySet().size()
|
||||
+ " thread tables exist");
|
||||
}
|
||||
/**
|
||||
* Iterates across all of the entries in the Hashmap in the rot that
|
||||
* corresponds to this thread. This calls safeRelease() on each entry and
|
||||
* then clears the map when done and removes it from the rot. All traces of
|
||||
* this thread's objects will disappear. This is called by COMThread in the
|
||||
* tear down and provides a synchronous way of releasing memory
|
||||
*/
|
||||
protected static void clearObjects() {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: " + rot.keySet().size()
|
||||
+ " thread tables exist");
|
||||
}
|
||||
|
||||
Map<JacobObject, String> tab = getThreadObjects(false);
|
||||
if (tab != null) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: " + tab.keySet().size()
|
||||
+ " objects to clear in this thread's ROT ");
|
||||
}
|
||||
// walk the values
|
||||
Iterator<JacobObject> it = tab.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
JacobObject o = it.next();
|
||||
if (o != null
|
||||
// can't use this cause creates a Variant if calling SafeAray
|
||||
// and we get an exception modifying the collection while
|
||||
// iterating
|
||||
// && o.toString() != null
|
||||
) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
if (o instanceof SafeArray) {
|
||||
// SafeArray create more objects when calling
|
||||
// toString()
|
||||
// which causes a concurrent modification exception
|
||||
// in HashMap
|
||||
JacobObject.debug("ROT: removing "
|
||||
+ o.getClass().getName());
|
||||
} else {
|
||||
// Variant toString() is probably always bad in here
|
||||
JacobObject.debug("ROT: removing " + o.hashCode()
|
||||
+ "->" + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
o.safeRelease();
|
||||
}
|
||||
}
|
||||
// empty the collection
|
||||
tab.clear();
|
||||
// remove the collection from rot
|
||||
ROT.removeThread();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: thread table cleared and removed");
|
||||
}
|
||||
} else {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: nothing to clear!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<JacobObject, String> tab = getThreadObjects(false);
|
||||
if (tab != null) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: " + tab.keySet().size()
|
||||
+ " objects to clear in this thread's ROT ");
|
||||
}
|
||||
// walk the values
|
||||
Iterator<JacobObject> it = tab.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
JacobObject o = it.next();
|
||||
if (o != null
|
||||
// can't use this cause creates a Variant if calling SafeAray
|
||||
// and we get an exception modifying the collection while
|
||||
// iterating
|
||||
// && o.toString() != null
|
||||
) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
if (o instanceof SafeArray) {
|
||||
// SafeArray create more objects when calling
|
||||
// toString()
|
||||
// which causes a concurrent modification exception
|
||||
// in HashMap
|
||||
JacobObject.debug("ROT: removing "
|
||||
+ o.getClass().getName());
|
||||
} else {
|
||||
// Variant toString() is probably always bad in here
|
||||
JacobObject.debug("ROT: removing " + o.hashCode()
|
||||
+ "->" + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
o.safeRelease();
|
||||
}
|
||||
}
|
||||
// empty the collection
|
||||
tab.clear();
|
||||
// remove the collection from rot
|
||||
ROT.removeThread();
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: thread table cleared and removed");
|
||||
}
|
||||
} else {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: nothing to clear!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the map from the rot that is associated with the current thread.
|
||||
*/
|
||||
private synchronized static void removeThread() {
|
||||
// should this see if it exists first?
|
||||
rot.remove(Thread.currentThread().getName());
|
||||
}
|
||||
/**
|
||||
* Removes the map from the rot that is associated with the current thread.
|
||||
*/
|
||||
private synchronized static void removeThread() {
|
||||
// should this see if it exists first?
|
||||
rot.remove(Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated the java model leave the responsibility of clearing up
|
||||
* objects to the Garbage Collector. Our programming model
|
||||
* should not require that the user specifically remove object
|
||||
* from the thread. <br>
|
||||
* This will remove an object from the ROT <br>
|
||||
* This does not need to be synchronized because only the rot
|
||||
* modification related methods need to synchronized. Each
|
||||
* individual map is only modified in a single thread.
|
||||
* @param o
|
||||
*/
|
||||
@Deprecated
|
||||
protected static void removeObject(JacobObject o) {
|
||||
Map<JacobObject, String> tab = ROT.getThreadObjects(false);
|
||||
if (tab != null) {
|
||||
tab.remove(o);
|
||||
}
|
||||
o.safeRelease();
|
||||
}
|
||||
/**
|
||||
* @deprecated the java model leave the responsibility of clearing up
|
||||
* objects to the Garbage Collector. Our programming model
|
||||
* should not require that the user specifically remove object
|
||||
* from the thread. <br>
|
||||
* This will remove an object from the ROT <br>
|
||||
* This does not need to be synchronized because only the rot
|
||||
* modification related methods need to synchronized. Each
|
||||
* individual map is only modified in a single thread.
|
||||
* @param o
|
||||
*/
|
||||
@Deprecated
|
||||
protected static void removeObject(JacobObject o) {
|
||||
Map<JacobObject, String> tab = ROT.getThreadObjects(false);
|
||||
if (tab != null) {
|
||||
tab.remove(o);
|
||||
}
|
||||
o.safeRelease();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an object to the HashMap for the current thread. <br>
|
||||
* <p>
|
||||
* This method does not need to be threaded because the only concurrent
|
||||
* modification risk is on the hash map that contains all of the thread
|
||||
* related hash maps. The individual thread related maps are only used on a
|
||||
* per thread basis so there isn't a locking issue.
|
||||
* <p>
|
||||
* In addition, this method cannot be threaded because it calls
|
||||
* ComThread.InitMTA. The ComThread object has some methods that call ROT so
|
||||
* we could end up deadlocked. This method should be safe without the
|
||||
* synchronization because the ROT works on per thread basis and the methods
|
||||
* that add threads and remove thread related entries are all synchronized
|
||||
*
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
protected static void addObject(JacobObject o) {
|
||||
String shouldIncludeClassInROT = "true";
|
||||
// only call System.getProperty if we are not including all classes in
|
||||
// the ROT. This lets us run with standard Jacob behavior in Applets
|
||||
// without the security exception raised by System.getProperty in the
|
||||
// flow
|
||||
if (!ROT.INCLUDE_ALL_CLASSES_IN_ROT) {
|
||||
shouldIncludeClassInROT = System.getProperty(o.getClass().getName()
|
||||
+ PUT_IN_ROT_SUFFIX, "true");
|
||||
}
|
||||
if (shouldIncludeClassInROT.equalsIgnoreCase("false")) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("JacobObject: New instance of "
|
||||
+ o.getClass().getName() + " not added to ROT");
|
||||
}
|
||||
} else {
|
||||
// first see if we have a table for this thread
|
||||
Map<JacobObject, String> tab = getThreadObjects(false);
|
||||
if (tab == null) {
|
||||
// this thread has not been initialized as a COM thread
|
||||
// so make it part of MTA for backwards compatibility
|
||||
ComThread.InitMTA(false);
|
||||
// don't really need the "true" because the InitMTA will have
|
||||
// called back to the ROT to create a table for this thread
|
||||
tab = getThreadObjects(true);
|
||||
}
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: adding " + o + "->"
|
||||
+ o.getClass().getName()
|
||||
+ " table size prior to addition:" + tab.size());
|
||||
}
|
||||
// add the object to the table that is specific to this thread
|
||||
if (tab != null) {
|
||||
tab.put(o, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds an object to the HashMap for the current thread. <br>
|
||||
* <p>
|
||||
* This method does not need to be threaded because the only concurrent
|
||||
* modification risk is on the hash map that contains all of the thread
|
||||
* related hash maps. The individual thread related maps are only used on a
|
||||
* per thread basis so there isn't a locking issue.
|
||||
* <p>
|
||||
* In addition, this method cannot be threaded because it calls
|
||||
* ComThread.InitMTA. The ComThread object has some methods that call ROT so
|
||||
* we could end up deadlocked. This method should be safe without the
|
||||
* synchronization because the ROT works on per thread basis and the methods
|
||||
* that add threads and remove thread related entries are all synchronized
|
||||
*
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
protected static void addObject(JacobObject o) {
|
||||
String shouldIncludeClassInROT = "true";
|
||||
// only call System.getProperty if we are not including all classes in
|
||||
// the ROT. This lets us run with standard Jacob behavior in Applets
|
||||
// without the security exception raised by System.getProperty in the
|
||||
// flow
|
||||
if (!ROT.INCLUDE_ALL_CLASSES_IN_ROT) {
|
||||
shouldIncludeClassInROT = System.getProperty(o.getClass().getName()
|
||||
+ PUT_IN_ROT_SUFFIX, "true");
|
||||
}
|
||||
if (shouldIncludeClassInROT.equalsIgnoreCase("false")) {
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("JacobObject: New instance of "
|
||||
+ o.getClass().getName() + " not added to ROT");
|
||||
}
|
||||
} else {
|
||||
// first see if we have a table for this thread
|
||||
Map<JacobObject, String> tab = getThreadObjects(false);
|
||||
if (tab == null) {
|
||||
// this thread has not been initialized as a COM thread
|
||||
// so make it part of MTA for backwards compatibility
|
||||
ComThread.InitMTA(false);
|
||||
// don't really need the "true" because the InitMTA will have
|
||||
// called back to the ROT to create a table for this thread
|
||||
tab = getThreadObjects(true);
|
||||
}
|
||||
if (JacobObject.isDebugEnabled()) {
|
||||
JacobObject.debug("ROT: adding " + o + "->"
|
||||
+ o.getClass().getName()
|
||||
+ " table size prior to addition:" + tab.size());
|
||||
}
|
||||
// add the object to the table that is specific to this thread
|
||||
if (tab != null) {
|
||||
tab.put(o, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ROT can't be a subclass of JacobObject because of the way ROT pools are
|
||||
* managed so we force a DLL load here by referencing JacobObject
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
/**
|
||||
* ROT can't be a subclass of JacobObject because of the way ROT pools are
|
||||
* managed so we force a DLL load here by referencing JacobObject
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -44,77 +44,77 @@ package com.jacob.com;
|
||||
* component that wants to run in an STA other than the main STA.
|
||||
*/
|
||||
public class STA extends Thread {
|
||||
/**
|
||||
* referenced by STA.cpp
|
||||
*/
|
||||
public int threadID;
|
||||
/**
|
||||
* referenced by STA.cpp
|
||||
*/
|
||||
public int threadID;
|
||||
|
||||
/**
|
||||
* constructor for STA
|
||||
*/
|
||||
public STA() {
|
||||
start(); // start the thread
|
||||
}
|
||||
/**
|
||||
* constructor for STA
|
||||
*/
|
||||
public STA() {
|
||||
start(); // start the thread
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Thread#run()
|
||||
*/
|
||||
public void run() {
|
||||
// init COM
|
||||
ComThread.InitSTA();
|
||||
if (OnInit()) {
|
||||
// this call blocks in the win32 message loop
|
||||
// until quitMessagePump is called
|
||||
doMessagePump();
|
||||
}
|
||||
OnQuit();
|
||||
// uninit COM
|
||||
ComThread.Release();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Thread#run()
|
||||
*/
|
||||
public void run() {
|
||||
// init COM
|
||||
ComThread.InitSTA();
|
||||
if (OnInit()) {
|
||||
// this call blocks in the win32 message loop
|
||||
// until quitMessagePump is called
|
||||
doMessagePump();
|
||||
}
|
||||
OnQuit();
|
||||
// uninit COM
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to create and initialize any COM component that you
|
||||
* want to run in this thread. If anything fails, return false to terminate
|
||||
* the thread.
|
||||
*
|
||||
* @return always returns true
|
||||
*/
|
||||
public boolean OnInit() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Override this method to create and initialize any COM component that you
|
||||
* want to run in this thread. If anything fails, return false to terminate
|
||||
* the thread.
|
||||
*
|
||||
* @return always returns true
|
||||
*/
|
||||
public boolean OnInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to destroy any resource before the thread exits and
|
||||
* COM in uninitialized
|
||||
*/
|
||||
public void OnQuit() {
|
||||
// there is nothing to see here
|
||||
}
|
||||
/**
|
||||
* Override this method to destroy any resource before the thread exits and
|
||||
* COM in uninitialized
|
||||
*/
|
||||
public void OnQuit() {
|
||||
// there is nothing to see here
|
||||
}
|
||||
|
||||
/**
|
||||
* calls quitMessagePump
|
||||
*/
|
||||
public void quit() {
|
||||
quitMessagePump();
|
||||
}
|
||||
/**
|
||||
* calls quitMessagePump
|
||||
*/
|
||||
public void quit() {
|
||||
quitMessagePump();
|
||||
}
|
||||
|
||||
/**
|
||||
* run a message pump for the main STA
|
||||
*/
|
||||
public native void doMessagePump();
|
||||
/**
|
||||
* run a message pump for the main STA
|
||||
*/
|
||||
public native void doMessagePump();
|
||||
|
||||
/**
|
||||
* quit message pump for the main STA
|
||||
*/
|
||||
public native void quitMessagePump();
|
||||
/**
|
||||
* quit message pump for the main STA
|
||||
*/
|
||||
public native void quitMessagePump();
|
||||
|
||||
/**
|
||||
* STA isn't a subclass of JacobObject so a reference to it doesn't load the
|
||||
* DLL without this
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
/**
|
||||
* STA isn't a subclass of JacobObject so a reference to it doesn't load the
|
||||
* DLL without this
|
||||
*/
|
||||
static {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/**
|
||||
*
|
||||
@@ -51,485 +51,485 @@ import java.util.Date;
|
||||
* A utility class used to convert between Java objects and Variants
|
||||
*/
|
||||
public final class VariantUtilities {
|
||||
private VariantUtilities() {
|
||||
// utility class with only static methods don't need constructors
|
||||
}
|
||||
private VariantUtilities() {
|
||||
// utility class with only static methods don't need constructors
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a variant object from a java object. This method attempts to
|
||||
* figure out the appropriate Variant type
|
||||
*
|
||||
* @param targetVariant
|
||||
* @param pValueObject
|
||||
* @param fByRef
|
||||
*/
|
||||
protected static void populateVariant(Variant targetVariant,
|
||||
Object pValueObject, boolean fByRef) {
|
||||
if (pValueObject == null) {
|
||||
targetVariant.putEmpty();
|
||||
} else if (pValueObject instanceof Integer) {
|
||||
if (fByRef) {
|
||||
targetVariant.putIntRef(((Integer) pValueObject).intValue());
|
||||
} else {
|
||||
targetVariant.putInt(((Integer) pValueObject).intValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Short) {
|
||||
if (fByRef) {
|
||||
targetVariant.putShortRef(((Short) pValueObject).shortValue());
|
||||
} else {
|
||||
targetVariant.putShort(((Short) pValueObject).shortValue());
|
||||
}
|
||||
} else if (pValueObject instanceof String) {
|
||||
if (fByRef) {
|
||||
targetVariant.putStringRef((String) pValueObject);
|
||||
} else {
|
||||
targetVariant.putString((String) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Boolean) {
|
||||
if (fByRef) {
|
||||
targetVariant.putBooleanRef(((Boolean) pValueObject)
|
||||
.booleanValue());
|
||||
} else {
|
||||
targetVariant.putBoolean(((Boolean) pValueObject)
|
||||
.booleanValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Double) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDoubleRef(((Double) pValueObject)
|
||||
.doubleValue());
|
||||
} else {
|
||||
targetVariant.putDouble(((Double) pValueObject).doubleValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Float) {
|
||||
if (fByRef) {
|
||||
targetVariant.putFloatRef(((Float) pValueObject).floatValue());
|
||||
} else {
|
||||
targetVariant.putFloat(((Float) pValueObject).floatValue());
|
||||
}
|
||||
} else if (pValueObject instanceof BigDecimal) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDecimalRef(((BigDecimal) pValueObject));
|
||||
} else {
|
||||
targetVariant.putDecimal(((BigDecimal) pValueObject));
|
||||
}
|
||||
} else if (pValueObject instanceof Byte) {
|
||||
if (fByRef) {
|
||||
targetVariant.putByteRef(((Byte) pValueObject).byteValue());
|
||||
} else {
|
||||
targetVariant.putByte(((Byte) pValueObject).byteValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Date) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDateRef((Date) pValueObject);
|
||||
} else {
|
||||
targetVariant.putDate((Date) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Long) {
|
||||
if (fByRef) {
|
||||
targetVariant.putLongRef(((Long) pValueObject).longValue());
|
||||
} else {
|
||||
targetVariant.putLong(((Long) pValueObject).longValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Currency) {
|
||||
if (fByRef) {
|
||||
targetVariant.putCurrencyRef(((Currency) pValueObject));
|
||||
} else {
|
||||
targetVariant.putCurrency(((Currency) pValueObject));
|
||||
}
|
||||
} else if (pValueObject instanceof SafeArray) {
|
||||
if (fByRef) {
|
||||
targetVariant.putSafeArrayRef((SafeArray) pValueObject);
|
||||
} else {
|
||||
targetVariant.putSafeArray((SafeArray) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Dispatch) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDispatchRef((Dispatch) pValueObject);
|
||||
} else {
|
||||
targetVariant.putDispatch((Dispatch) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Variant) {
|
||||
// newly added 1.12-pre6 to support VT_VARIANT
|
||||
targetVariant.putVariant(pValueObject);
|
||||
} else {
|
||||
// sourceforge patch 2171967
|
||||
// used to rely on coercion but sometimes crashed VM
|
||||
throw new NotImplementedException(
|
||||
"populateVariant() not implemented for "
|
||||
+ pValueObject.getClass());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Populates a variant object from a java object. This method attempts to
|
||||
* figure out the appropriate Variant type
|
||||
*
|
||||
* @param targetVariant
|
||||
* @param pValueObject
|
||||
* @param fByRef
|
||||
*/
|
||||
protected static void populateVariant(Variant targetVariant,
|
||||
Object pValueObject, boolean fByRef) {
|
||||
if (pValueObject == null) {
|
||||
targetVariant.putEmpty();
|
||||
} else if (pValueObject instanceof Integer) {
|
||||
if (fByRef) {
|
||||
targetVariant.putIntRef(((Integer) pValueObject).intValue());
|
||||
} else {
|
||||
targetVariant.putInt(((Integer) pValueObject).intValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Short) {
|
||||
if (fByRef) {
|
||||
targetVariant.putShortRef(((Short) pValueObject).shortValue());
|
||||
} else {
|
||||
targetVariant.putShort(((Short) pValueObject).shortValue());
|
||||
}
|
||||
} else if (pValueObject instanceof String) {
|
||||
if (fByRef) {
|
||||
targetVariant.putStringRef((String) pValueObject);
|
||||
} else {
|
||||
targetVariant.putString((String) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Boolean) {
|
||||
if (fByRef) {
|
||||
targetVariant.putBooleanRef(((Boolean) pValueObject)
|
||||
.booleanValue());
|
||||
} else {
|
||||
targetVariant.putBoolean(((Boolean) pValueObject)
|
||||
.booleanValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Double) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDoubleRef(((Double) pValueObject)
|
||||
.doubleValue());
|
||||
} else {
|
||||
targetVariant.putDouble(((Double) pValueObject).doubleValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Float) {
|
||||
if (fByRef) {
|
||||
targetVariant.putFloatRef(((Float) pValueObject).floatValue());
|
||||
} else {
|
||||
targetVariant.putFloat(((Float) pValueObject).floatValue());
|
||||
}
|
||||
} else if (pValueObject instanceof BigDecimal) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDecimalRef(((BigDecimal) pValueObject));
|
||||
} else {
|
||||
targetVariant.putDecimal(((BigDecimal) pValueObject));
|
||||
}
|
||||
} else if (pValueObject instanceof Byte) {
|
||||
if (fByRef) {
|
||||
targetVariant.putByteRef(((Byte) pValueObject).byteValue());
|
||||
} else {
|
||||
targetVariant.putByte(((Byte) pValueObject).byteValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Date) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDateRef((Date) pValueObject);
|
||||
} else {
|
||||
targetVariant.putDate((Date) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Long) {
|
||||
if (fByRef) {
|
||||
targetVariant.putLongRef(((Long) pValueObject).longValue());
|
||||
} else {
|
||||
targetVariant.putLong(((Long) pValueObject).longValue());
|
||||
}
|
||||
} else if (pValueObject instanceof Currency) {
|
||||
if (fByRef) {
|
||||
targetVariant.putCurrencyRef(((Currency) pValueObject));
|
||||
} else {
|
||||
targetVariant.putCurrency(((Currency) pValueObject));
|
||||
}
|
||||
} else if (pValueObject instanceof SafeArray) {
|
||||
if (fByRef) {
|
||||
targetVariant.putSafeArrayRef((SafeArray) pValueObject);
|
||||
} else {
|
||||
targetVariant.putSafeArray((SafeArray) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Dispatch) {
|
||||
if (fByRef) {
|
||||
targetVariant.putDispatchRef((Dispatch) pValueObject);
|
||||
} else {
|
||||
targetVariant.putDispatch((Dispatch) pValueObject);
|
||||
}
|
||||
} else if (pValueObject instanceof Variant) {
|
||||
// newly added 1.12-pre6 to support VT_VARIANT
|
||||
targetVariant.putVariant(pValueObject);
|
||||
} else {
|
||||
// sourceforge patch 2171967
|
||||
// used to rely on coercion but sometimes crashed VM
|
||||
throw new NotImplementedException(
|
||||
"populateVariant() not implemented for "
|
||||
+ pValueObject.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map arguments based on msdn documentation. This method relies on the
|
||||
* variant constructor except for arrays.
|
||||
*
|
||||
* @param objectToBeMadeIntoVariant
|
||||
* @return Variant that represents the object
|
||||
*/
|
||||
protected static Variant objectToVariant(Object objectToBeMadeIntoVariant) {
|
||||
if (objectToBeMadeIntoVariant == null) {
|
||||
return new Variant();
|
||||
} else if (objectToBeMadeIntoVariant instanceof Variant) {
|
||||
// if a variant was passed in then be a slacker and just return it
|
||||
return (Variant) objectToBeMadeIntoVariant;
|
||||
} else if (objectToBeMadeIntoVariant.getClass().isArray()) {
|
||||
// automatically convert arrays using reflection
|
||||
// handle it differently based on the type of array
|
||||
// added primitive support sourceforge 2762275
|
||||
SafeArray sa = null;
|
||||
int len1 = Array.getLength(objectToBeMadeIntoVariant);
|
||||
Class componentType = objectToBeMadeIntoVariant.getClass()
|
||||
.getComponentType();
|
||||
/**
|
||||
* Map arguments based on msdn documentation. This method relies on the
|
||||
* variant constructor except for arrays.
|
||||
*
|
||||
* @param objectToBeMadeIntoVariant
|
||||
* @return Variant that represents the object
|
||||
*/
|
||||
protected static Variant objectToVariant(Object objectToBeMadeIntoVariant) {
|
||||
if (objectToBeMadeIntoVariant == null) {
|
||||
return new Variant();
|
||||
} else if (objectToBeMadeIntoVariant instanceof Variant) {
|
||||
// if a variant was passed in then be a slacker and just return it
|
||||
return (Variant) objectToBeMadeIntoVariant;
|
||||
} else if (objectToBeMadeIntoVariant.getClass().isArray()) {
|
||||
// automatically convert arrays using reflection
|
||||
// handle it differently based on the type of array
|
||||
// added primitive support sourceforge 2762275
|
||||
SafeArray sa = null;
|
||||
int len1 = Array.getLength(objectToBeMadeIntoVariant);
|
||||
Class componentType = objectToBeMadeIntoVariant.getClass()
|
||||
.getComponentType();
|
||||
|
||||
if (componentType.isArray()) { // array of arrays
|
||||
int max = 0;
|
||||
for (int i = 0; i < len1; i++) {
|
||||
Object e1 = Array.get(objectToBeMadeIntoVariant, i);
|
||||
int len2 = Array.getLength(e1);
|
||||
if (max < len2) {
|
||||
max = len2;
|
||||
}
|
||||
}
|
||||
sa = new SafeArray(Variant.VariantVariant, len1, max);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
Object e1 = Array.get(objectToBeMadeIntoVariant, i);
|
||||
for (int j = 0; j < Array.getLength(e1); j++) {
|
||||
sa.setVariant(i, j, objectToVariant(Array.get(e1, j)));
|
||||
}
|
||||
}
|
||||
} else if (byte.class.equals(componentType)) {
|
||||
byte[] arr = (byte[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantByte, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setByte(i, arr[i]);
|
||||
}
|
||||
} else if (int.class.equals(componentType)) {
|
||||
int[] arr = (int[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantInt, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setInt(i, arr[i]);
|
||||
}
|
||||
} else if (double.class.equals(componentType)) {
|
||||
double[] arr = (double[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantDouble, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setDouble(i, arr[i]);
|
||||
}
|
||||
} else if (long.class.equals(componentType)) {
|
||||
long[] arr = (long[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantLongInt, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setLong(i, arr[i]);
|
||||
}
|
||||
} else {
|
||||
// array of object
|
||||
sa = new SafeArray(Variant.VariantVariant, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setVariant(i, objectToVariant(Array.get(
|
||||
objectToBeMadeIntoVariant, i)));
|
||||
}
|
||||
}
|
||||
Variant returnVariant = new Variant();
|
||||
populateVariant(returnVariant, sa, false);
|
||||
return returnVariant;
|
||||
} else {
|
||||
// rely on populateVariant to throw an exception if its an
|
||||
// invalid type
|
||||
Variant returnVariant = new Variant();
|
||||
populateVariant(returnVariant, objectToBeMadeIntoVariant, false);
|
||||
return returnVariant;
|
||||
}
|
||||
}
|
||||
if (componentType.isArray()) { // array of arrays
|
||||
int max = 0;
|
||||
for (int i = 0; i < len1; i++) {
|
||||
Object e1 = Array.get(objectToBeMadeIntoVariant, i);
|
||||
int len2 = Array.getLength(e1);
|
||||
if (max < len2) {
|
||||
max = len2;
|
||||
}
|
||||
}
|
||||
sa = new SafeArray(Variant.VariantVariant, len1, max);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
Object e1 = Array.get(objectToBeMadeIntoVariant, i);
|
||||
for (int j = 0; j < Array.getLength(e1); j++) {
|
||||
sa.setVariant(i, j, objectToVariant(Array.get(e1, j)));
|
||||
}
|
||||
}
|
||||
} else if (byte.class.equals(componentType)) {
|
||||
byte[] arr = (byte[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantByte, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setByte(i, arr[i]);
|
||||
}
|
||||
} else if (int.class.equals(componentType)) {
|
||||
int[] arr = (int[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantInt, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setInt(i, arr[i]);
|
||||
}
|
||||
} else if (double.class.equals(componentType)) {
|
||||
double[] arr = (double[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantDouble, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setDouble(i, arr[i]);
|
||||
}
|
||||
} else if (long.class.equals(componentType)) {
|
||||
long[] arr = (long[]) objectToBeMadeIntoVariant;
|
||||
sa = new SafeArray(Variant.VariantLongInt, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setLong(i, arr[i]);
|
||||
}
|
||||
} else {
|
||||
// array of object
|
||||
sa = new SafeArray(Variant.VariantVariant, len1);
|
||||
for (int i = 0; i < len1; i++) {
|
||||
sa.setVariant(i, objectToVariant(Array.get(
|
||||
objectToBeMadeIntoVariant, i)));
|
||||
}
|
||||
}
|
||||
Variant returnVariant = new Variant();
|
||||
populateVariant(returnVariant, sa, false);
|
||||
return returnVariant;
|
||||
} else {
|
||||
// rely on populateVariant to throw an exception if its an
|
||||
// invalid type
|
||||
Variant returnVariant = new Variant();
|
||||
populateVariant(returnVariant, objectToBeMadeIntoVariant, false);
|
||||
return returnVariant;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* converts an array of objects into an array of Variants by repeatedly
|
||||
* calling obj2Variant(Object)
|
||||
*
|
||||
* @param arrayOfObjectsToBeConverted
|
||||
* @return Variant[]
|
||||
*/
|
||||
protected static Variant[] objectsToVariants(
|
||||
Object[] arrayOfObjectsToBeConverted) {
|
||||
Variant vArg[] = new Variant[arrayOfObjectsToBeConverted.length];
|
||||
for (int i = 0; i < arrayOfObjectsToBeConverted.length; i++) {
|
||||
vArg[i] = objectToVariant(arrayOfObjectsToBeConverted[i]);
|
||||
}
|
||||
return vArg;
|
||||
}
|
||||
/**
|
||||
* converts an array of objects into an array of Variants by repeatedly
|
||||
* calling obj2Variant(Object)
|
||||
*
|
||||
* @param arrayOfObjectsToBeConverted
|
||||
* @return Variant[]
|
||||
*/
|
||||
protected static Variant[] objectsToVariants(
|
||||
Object[] arrayOfObjectsToBeConverted) {
|
||||
Variant vArg[] = new Variant[arrayOfObjectsToBeConverted.length];
|
||||
for (int i = 0; i < arrayOfObjectsToBeConverted.length; i++) {
|
||||
vArg[i] = objectToVariant(arrayOfObjectsToBeConverted[i]);
|
||||
}
|
||||
return vArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JACOB Variant value to a Java object (type conversions).
|
||||
* provided in Sourceforge feature request 959381. A fix was done to handle
|
||||
* byRef bug report 1607878.
|
||||
* <p>
|
||||
* Unlike other toXXX() methods, it does not do a type conversion except for
|
||||
* special data types (it shouldn't do any!)
|
||||
* <p>
|
||||
* Converts Variant.VariantArray types to SafeArrays
|
||||
*
|
||||
* @return Corresponding Java object of the type matching the Variant type.
|
||||
* @throws IllegalStateException
|
||||
* if no underlying windows data structure
|
||||
* @throws NotImplementedException
|
||||
* if unsupported conversion is requested
|
||||
* @throws JacobException
|
||||
* if the calculated result was a JacobObject usually as a
|
||||
* result of error
|
||||
*/
|
||||
protected static Object variantToObject(Variant sourceData) {
|
||||
Object result = null;
|
||||
/**
|
||||
* Convert a JACOB Variant value to a Java object (type conversions).
|
||||
* provided in Sourceforge feature request 959381. A fix was done to handle
|
||||
* byRef bug report 1607878.
|
||||
* <p>
|
||||
* Unlike other toXXX() methods, it does not do a type conversion except for
|
||||
* special data types (it shouldn't do any!)
|
||||
* <p>
|
||||
* Converts Variant.VariantArray types to SafeArrays
|
||||
*
|
||||
* @return Corresponding Java object of the type matching the Variant type.
|
||||
* @throws IllegalStateException
|
||||
* if no underlying windows data structure
|
||||
* @throws NotImplementedException
|
||||
* if unsupported conversion is requested
|
||||
* @throws JacobException
|
||||
* if the calculated result was a JacobObject usually as a
|
||||
* result of error
|
||||
*/
|
||||
protected static Object variantToObject(Variant sourceData) {
|
||||
Object result = null;
|
||||
|
||||
short type = sourceData.getvt(); // variant type
|
||||
short type = sourceData.getvt(); // variant type
|
||||
|
||||
if ((type & Variant.VariantArray) == Variant.VariantArray) { // array
|
||||
// returned?
|
||||
SafeArray array = null;
|
||||
type = (short) (type - Variant.VariantArray);
|
||||
// From SF Bug 1840487
|
||||
// This did call toSafeArray(false) but that meant
|
||||
// this was the only variantToObject() that didn't have its own
|
||||
// copy of the data so you would end up with weird run time
|
||||
// errors after some GC. So now we just get stupid about it and
|
||||
// always make a copy just like toSafeArray() does.
|
||||
array = sourceData.toSafeArray();
|
||||
result = array;
|
||||
} else { // non-array object returned
|
||||
switch (type) {
|
||||
case Variant.VariantEmpty: // 0
|
||||
case Variant.VariantNull: // 1
|
||||
break;
|
||||
case Variant.VariantShort: // 2
|
||||
result = new Short(sourceData.getShort());
|
||||
break;
|
||||
case Variant.VariantShort | Variant.VariantByref: // 2
|
||||
result = new Short(sourceData.getShortRef());
|
||||
break;
|
||||
case Variant.VariantInt: // 3
|
||||
result = new Integer(sourceData.getInt());
|
||||
break;
|
||||
case Variant.VariantInt | Variant.VariantByref: // 3
|
||||
result = new Integer(sourceData.getIntRef());
|
||||
break;
|
||||
case Variant.VariantFloat: // 4
|
||||
result = new Float(sourceData.getFloat());
|
||||
break;
|
||||
case Variant.VariantFloat | Variant.VariantByref: // 4
|
||||
result = new Float(sourceData.getFloatRef());
|
||||
break;
|
||||
case Variant.VariantDouble: // 5
|
||||
result = new Double(sourceData.getDouble());
|
||||
break;
|
||||
case Variant.VariantDouble | Variant.VariantByref: // 5
|
||||
result = new Double(sourceData.getDoubleRef());
|
||||
break;
|
||||
case Variant.VariantCurrency: // 6
|
||||
result = sourceData.getCurrency();
|
||||
break;
|
||||
case Variant.VariantCurrency | Variant.VariantByref: // 6
|
||||
result = sourceData.getCurrencyRef();
|
||||
break;
|
||||
case Variant.VariantDate: // 7
|
||||
result = sourceData.getJavaDate();
|
||||
break;
|
||||
case Variant.VariantDate | Variant.VariantByref: // 7
|
||||
result = sourceData.getJavaDateRef();
|
||||
break;
|
||||
case Variant.VariantString: // 8
|
||||
result = sourceData.getString();
|
||||
break;
|
||||
case Variant.VariantString | Variant.VariantByref: // 8
|
||||
result = sourceData.getStringRef();
|
||||
break;
|
||||
case Variant.VariantDispatch: // 9
|
||||
result = sourceData.getDispatch();
|
||||
break;
|
||||
case Variant.VariantDispatch | Variant.VariantByref: // 9
|
||||
result = sourceData.getDispatchRef(); // Can dispatches even
|
||||
// be byRef?
|
||||
break;
|
||||
case Variant.VariantError: // 10
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantError");
|
||||
break;
|
||||
case Variant.VariantBoolean: // 11
|
||||
result = new Boolean(sourceData.getBoolean());
|
||||
break;
|
||||
case Variant.VariantBoolean | Variant.VariantByref: // 11
|
||||
result = new Boolean(sourceData.getBooleanRef());
|
||||
break;
|
||||
case Variant.VariantVariant: // 12 they are always by ref
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantVariant without ByRef");
|
||||
break;
|
||||
case Variant.VariantVariant | Variant.VariantByref: // 12
|
||||
result = sourceData.getVariant();
|
||||
break;
|
||||
case Variant.VariantObject: // 13
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantObject");
|
||||
break;
|
||||
case Variant.VariantDecimal: // 14
|
||||
result = sourceData.getDecimal();
|
||||
break;
|
||||
case Variant.VariantDecimal | Variant.VariantByref: // 14
|
||||
result = sourceData.getDecimalRef();
|
||||
break;
|
||||
case Variant.VariantByte: // 17
|
||||
result = new Byte(sourceData.getByte());
|
||||
break;
|
||||
case Variant.VariantByte | Variant.VariantByref: // 17
|
||||
result = new Byte(sourceData.getByteRef());
|
||||
break;
|
||||
case Variant.VariantLongInt: // 20
|
||||
result = new Long(sourceData.getLong());
|
||||
break;
|
||||
case Variant.VariantLongInt | Variant.VariantByref: // 20
|
||||
result = new Long(sourceData.getLongRef());
|
||||
break;
|
||||
case Variant.VariantTypeMask: // 4095
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantTypeMask");
|
||||
break;
|
||||
case Variant.VariantArray: // 8192
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantArray");
|
||||
break;
|
||||
case Variant.VariantByref: // 16384
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantByref");
|
||||
break;
|
||||
default:
|
||||
result = new NotImplementedException("Unknown return type: "
|
||||
+ type);
|
||||
// there was a "return result" here that caused defect 1602118
|
||||
// so it was removed
|
||||
break;
|
||||
}// switch (type)
|
||||
if ((type & Variant.VariantArray) == Variant.VariantArray) { // array
|
||||
// returned?
|
||||
SafeArray array = null;
|
||||
type = (short) (type - Variant.VariantArray);
|
||||
// From SF Bug 1840487
|
||||
// This did call toSafeArray(false) but that meant
|
||||
// this was the only variantToObject() that didn't have its own
|
||||
// copy of the data so you would end up with weird run time
|
||||
// errors after some GC. So now we just get stupid about it and
|
||||
// always make a copy just like toSafeArray() does.
|
||||
array = sourceData.toSafeArray();
|
||||
result = array;
|
||||
} else { // non-array object returned
|
||||
switch (type) {
|
||||
case Variant.VariantEmpty: // 0
|
||||
case Variant.VariantNull: // 1
|
||||
break;
|
||||
case Variant.VariantShort: // 2
|
||||
result = new Short(sourceData.getShort());
|
||||
break;
|
||||
case Variant.VariantShort | Variant.VariantByref: // 2
|
||||
result = new Short(sourceData.getShortRef());
|
||||
break;
|
||||
case Variant.VariantInt: // 3
|
||||
result = new Integer(sourceData.getInt());
|
||||
break;
|
||||
case Variant.VariantInt | Variant.VariantByref: // 3
|
||||
result = new Integer(sourceData.getIntRef());
|
||||
break;
|
||||
case Variant.VariantFloat: // 4
|
||||
result = new Float(sourceData.getFloat());
|
||||
break;
|
||||
case Variant.VariantFloat | Variant.VariantByref: // 4
|
||||
result = new Float(sourceData.getFloatRef());
|
||||
break;
|
||||
case Variant.VariantDouble: // 5
|
||||
result = new Double(sourceData.getDouble());
|
||||
break;
|
||||
case Variant.VariantDouble | Variant.VariantByref: // 5
|
||||
result = new Double(sourceData.getDoubleRef());
|
||||
break;
|
||||
case Variant.VariantCurrency: // 6
|
||||
result = sourceData.getCurrency();
|
||||
break;
|
||||
case Variant.VariantCurrency | Variant.VariantByref: // 6
|
||||
result = sourceData.getCurrencyRef();
|
||||
break;
|
||||
case Variant.VariantDate: // 7
|
||||
result = sourceData.getJavaDate();
|
||||
break;
|
||||
case Variant.VariantDate | Variant.VariantByref: // 7
|
||||
result = sourceData.getJavaDateRef();
|
||||
break;
|
||||
case Variant.VariantString: // 8
|
||||
result = sourceData.getString();
|
||||
break;
|
||||
case Variant.VariantString | Variant.VariantByref: // 8
|
||||
result = sourceData.getStringRef();
|
||||
break;
|
||||
case Variant.VariantDispatch: // 9
|
||||
result = sourceData.getDispatch();
|
||||
break;
|
||||
case Variant.VariantDispatch | Variant.VariantByref: // 9
|
||||
result = sourceData.getDispatchRef(); // Can dispatches even
|
||||
// be byRef?
|
||||
break;
|
||||
case Variant.VariantError: // 10
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantError");
|
||||
break;
|
||||
case Variant.VariantBoolean: // 11
|
||||
result = new Boolean(sourceData.getBoolean());
|
||||
break;
|
||||
case Variant.VariantBoolean | Variant.VariantByref: // 11
|
||||
result = new Boolean(sourceData.getBooleanRef());
|
||||
break;
|
||||
case Variant.VariantVariant: // 12 they are always by ref
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantVariant without ByRef");
|
||||
break;
|
||||
case Variant.VariantVariant | Variant.VariantByref: // 12
|
||||
result = sourceData.getVariant();
|
||||
break;
|
||||
case Variant.VariantObject: // 13
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantObject");
|
||||
break;
|
||||
case Variant.VariantDecimal: // 14
|
||||
result = sourceData.getDecimal();
|
||||
break;
|
||||
case Variant.VariantDecimal | Variant.VariantByref: // 14
|
||||
result = sourceData.getDecimalRef();
|
||||
break;
|
||||
case Variant.VariantByte: // 17
|
||||
result = new Byte(sourceData.getByte());
|
||||
break;
|
||||
case Variant.VariantByte | Variant.VariantByref: // 17
|
||||
result = new Byte(sourceData.getByteRef());
|
||||
break;
|
||||
case Variant.VariantLongInt: // 20
|
||||
result = new Long(sourceData.getLong());
|
||||
break;
|
||||
case Variant.VariantLongInt | Variant.VariantByref: // 20
|
||||
result = new Long(sourceData.getLongRef());
|
||||
break;
|
||||
case Variant.VariantTypeMask: // 4095
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantTypeMask");
|
||||
break;
|
||||
case Variant.VariantArray: // 8192
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantArray");
|
||||
break;
|
||||
case Variant.VariantByref: // 16384
|
||||
result = new NotImplementedException(
|
||||
"toJavaObject() Not implemented for VariantByref");
|
||||
break;
|
||||
default:
|
||||
result = new NotImplementedException("Unknown return type: "
|
||||
+ type);
|
||||
// there was a "return result" here that caused defect 1602118
|
||||
// so it was removed
|
||||
break;
|
||||
}// switch (type)
|
||||
|
||||
if (result instanceof JacobException) {
|
||||
throw (JacobException) result;
|
||||
}
|
||||
}
|
||||
if (result instanceof JacobException) {
|
||||
throw (JacobException) result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}// toJava()
|
||||
return result;
|
||||
}// toJava()
|
||||
|
||||
/**
|
||||
* Verifies that we have a scale 0 <= x <= 28 and now more than 96 bits of
|
||||
* data. The roundToMSDecimal method will attempt to adjust a BigDecimal to
|
||||
* pass this set of tests
|
||||
*
|
||||
* @param in
|
||||
* @throws IllegalArgumentException
|
||||
* if out of bounds
|
||||
*/
|
||||
protected static void validateDecimalScaleAndBits(BigDecimal in) {
|
||||
BigInteger allWordBigInt = in.unscaledValue();
|
||||
if (in.scale() > 28) {
|
||||
// should this cast to a string and call putStringRef()?
|
||||
throw new IllegalArgumentException(
|
||||
"VT_DECIMAL only supports a maximum scale of 28 and the passed"
|
||||
+ " in value has a scale of " + in.scale());
|
||||
} else if (in.scale() < 0) {
|
||||
// should this cast to a string and call putStringRef()?
|
||||
throw new IllegalArgumentException(
|
||||
"VT_DECIMAL only supports a minimum scale of 0 and the passed"
|
||||
+ " in value has a scale of " + in.scale());
|
||||
} else if (allWordBigInt.bitLength() > 12 * 8) {
|
||||
throw new IllegalArgumentException(
|
||||
"VT_DECIMAL supports a maximum of "
|
||||
+ 12
|
||||
* 8
|
||||
+ " bits not counting scale and the number passed in has "
|
||||
+ allWordBigInt.bitLength());
|
||||
/**
|
||||
* Verifies that we have a scale 0 <= x <= 28 and now more than 96 bits of
|
||||
* data. The roundToMSDecimal method will attempt to adjust a BigDecimal to
|
||||
* pass this set of tests
|
||||
*
|
||||
* @param in
|
||||
* @throws IllegalArgumentException
|
||||
* if out of bounds
|
||||
*/
|
||||
protected static void validateDecimalScaleAndBits(BigDecimal in) {
|
||||
BigInteger allWordBigInt = in.unscaledValue();
|
||||
if (in.scale() > 28) {
|
||||
// should this cast to a string and call putStringRef()?
|
||||
throw new IllegalArgumentException(
|
||||
"VT_DECIMAL only supports a maximum scale of 28 and the passed"
|
||||
+ " in value has a scale of " + in.scale());
|
||||
} else if (in.scale() < 0) {
|
||||
// should this cast to a string and call putStringRef()?
|
||||
throw new IllegalArgumentException(
|
||||
"VT_DECIMAL only supports a minimum scale of 0 and the passed"
|
||||
+ " in value has a scale of " + in.scale());
|
||||
} else if (allWordBigInt.bitLength() > 12 * 8) {
|
||||
throw new IllegalArgumentException(
|
||||
"VT_DECIMAL supports a maximum of "
|
||||
+ 12
|
||||
* 8
|
||||
+ " bits not counting scale and the number passed in has "
|
||||
+ allWordBigInt.bitLength());
|
||||
|
||||
} else {
|
||||
// no bounds problem to be handled
|
||||
}
|
||||
} else {
|
||||
// no bounds problem to be handled
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Largest possible number with scale set to 0
|
||||
*/
|
||||
private static final BigDecimal LARGEST_DECIMAL = new BigDecimal(
|
||||
new BigInteger("ffffffffffffffffffffffff", 16));
|
||||
/**
|
||||
* Smallest possible number with scale set to 0. MS doesn't support negative
|
||||
* scales like BigDecimal.
|
||||
*/
|
||||
private static final BigDecimal SMALLEST_DECIMAL = new BigDecimal(
|
||||
new BigInteger("ffffffffffffffffffffffff", 16).negate());
|
||||
/**
|
||||
* Largest possible number with scale set to 0
|
||||
*/
|
||||
private static final BigDecimal LARGEST_DECIMAL = new BigDecimal(
|
||||
new BigInteger("ffffffffffffffffffffffff", 16));
|
||||
/**
|
||||
* Smallest possible number with scale set to 0. MS doesn't support negative
|
||||
* scales like BigDecimal.
|
||||
*/
|
||||
private static final BigDecimal SMALLEST_DECIMAL = new BigDecimal(
|
||||
new BigInteger("ffffffffffffffffffffffff", 16).negate());
|
||||
|
||||
/**
|
||||
* Does any validation that couldn't have been fixed by rounding or scale
|
||||
* modification.
|
||||
*
|
||||
* @param in
|
||||
* The BigDecimal to be validated
|
||||
* @throws IllegalArgumentException
|
||||
* if the number is too large or too small or null
|
||||
*/
|
||||
protected static void validateDecimalMinMax(BigDecimal in) {
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"null is not a supported Decimal value.");
|
||||
} else if (LARGEST_DECIMAL.compareTo(in) < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value too large for VT_DECIMAL data type:" + in.toString()
|
||||
+ " integer: " + in.toBigInteger().toString(16)
|
||||
+ " scale: " + in.scale());
|
||||
} else if (SMALLEST_DECIMAL.compareTo(in) > 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value too small for VT_DECIMAL data type:" + in.toString()
|
||||
+ " integer: " + in.toBigInteger().toString(16)
|
||||
+ " scale: " + in.scale());
|
||||
}
|
||||
/**
|
||||
* Does any validation that couldn't have been fixed by rounding or scale
|
||||
* modification.
|
||||
*
|
||||
* @param in
|
||||
* The BigDecimal to be validated
|
||||
* @throws IllegalArgumentException
|
||||
* if the number is too large or too small or null
|
||||
*/
|
||||
protected static void validateDecimalMinMax(BigDecimal in) {
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"null is not a supported Decimal value.");
|
||||
} else if (LARGEST_DECIMAL.compareTo(in) < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value too large for VT_DECIMAL data type:" + in.toString()
|
||||
+ " integer: " + in.toBigInteger().toString(16)
|
||||
+ " scale: " + in.scale());
|
||||
} else if (SMALLEST_DECIMAL.compareTo(in) > 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value too small for VT_DECIMAL data type:" + in.toString()
|
||||
+ " integer: " + in.toBigInteger().toString(16)
|
||||
+ " scale: " + in.scale());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds the scale and bit length so that it will pass
|
||||
* validateDecimalScaleBits(). Developers should call this method if they
|
||||
* really want MS Decimal and don't want to lose precision.
|
||||
* <p>
|
||||
* Changing the scale on a number that can fit in an MS Decimal can change
|
||||
* the number's representation enough that it will round to a number too
|
||||
* large to be represented by an MS VT_DECIMAL
|
||||
*
|
||||
* @param sourceDecimal
|
||||
* @return BigDecimal a new big decimal that was rounded to fit in an MS
|
||||
* VT_DECIMAL
|
||||
*/
|
||||
public static BigDecimal roundToMSDecimal(BigDecimal sourceDecimal) {
|
||||
BigInteger sourceDecimalIntComponent = sourceDecimal.unscaledValue();
|
||||
BigDecimal destinationDecimal = new BigDecimal(
|
||||
sourceDecimalIntComponent, sourceDecimal.scale());
|
||||
int roundingModel = BigDecimal.ROUND_HALF_UP;
|
||||
validateDecimalMinMax(destinationDecimal);
|
||||
// First limit the number of digits and then the precision.
|
||||
// Try and round to 29 digits because we can sometimes do that
|
||||
BigInteger allWordBigInt;
|
||||
allWordBigInt = destinationDecimal.unscaledValue();
|
||||
if (allWordBigInt.bitLength() > 96) {
|
||||
destinationDecimal = destinationDecimal.round(new MathContext(29));
|
||||
// see if 29 digits uses more than 96 bits
|
||||
if (allWordBigInt.bitLength() > 96) {
|
||||
// Dang. It was over 97 bits so shorten it one more digit to
|
||||
// stay <= 96 bits
|
||||
destinationDecimal = destinationDecimal.round(new MathContext(
|
||||
28));
|
||||
}
|
||||
}
|
||||
// the bit manipulations above may change the scale so do it afterwards
|
||||
// round the scale to the max MS can support
|
||||
if (destinationDecimal.scale() > 28) {
|
||||
destinationDecimal = destinationDecimal.setScale(28, roundingModel);
|
||||
}
|
||||
if (destinationDecimal.scale() < 0) {
|
||||
destinationDecimal = destinationDecimal.setScale(0, roundingModel);
|
||||
}
|
||||
return destinationDecimal;
|
||||
}
|
||||
/**
|
||||
* Rounds the scale and bit length so that it will pass
|
||||
* validateDecimalScaleBits(). Developers should call this method if they
|
||||
* really want MS Decimal and don't want to lose precision.
|
||||
* <p>
|
||||
* Changing the scale on a number that can fit in an MS Decimal can change
|
||||
* the number's representation enough that it will round to a number too
|
||||
* large to be represented by an MS VT_DECIMAL
|
||||
*
|
||||
* @param sourceDecimal
|
||||
* @return BigDecimal a new big decimal that was rounded to fit in an MS
|
||||
* VT_DECIMAL
|
||||
*/
|
||||
public static BigDecimal roundToMSDecimal(BigDecimal sourceDecimal) {
|
||||
BigInteger sourceDecimalIntComponent = sourceDecimal.unscaledValue();
|
||||
BigDecimal destinationDecimal = new BigDecimal(
|
||||
sourceDecimalIntComponent, sourceDecimal.scale());
|
||||
int roundingModel = BigDecimal.ROUND_HALF_UP;
|
||||
validateDecimalMinMax(destinationDecimal);
|
||||
// First limit the number of digits and then the precision.
|
||||
// Try and round to 29 digits because we can sometimes do that
|
||||
BigInteger allWordBigInt;
|
||||
allWordBigInt = destinationDecimal.unscaledValue();
|
||||
if (allWordBigInt.bitLength() > 96) {
|
||||
destinationDecimal = destinationDecimal.round(new MathContext(29));
|
||||
// see if 29 digits uses more than 96 bits
|
||||
if (allWordBigInt.bitLength() > 96) {
|
||||
// Dang. It was over 97 bits so shorten it one more digit to
|
||||
// stay <= 96 bits
|
||||
destinationDecimal = destinationDecimal.round(new MathContext(
|
||||
28));
|
||||
}
|
||||
}
|
||||
// the bit manipulations above may change the scale so do it afterwards
|
||||
// round the scale to the max MS can support
|
||||
if (destinationDecimal.scale() > 28) {
|
||||
destinationDecimal = destinationDecimal.setScale(28, roundingModel);
|
||||
}
|
||||
if (destinationDecimal.scale() < 0) {
|
||||
destinationDecimal = destinationDecimal.setScale(0, roundingModel);
|
||||
}
|
||||
return destinationDecimal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -44,10 +44,10 @@ package com.jacob.com;
|
||||
*/
|
||||
public class VariantViaEvent extends Variant {
|
||||
|
||||
/**
|
||||
* Standard constructor used by JNI event handling layer
|
||||
*/
|
||||
public VariantViaEvent() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Standard constructor used by JNI event handling layer
|
||||
*/
|
||||
public VariantViaEvent() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -42,25 +42,25 @@ package com.jacob.com;
|
||||
* thrown in util.cpp
|
||||
*/
|
||||
public class WrongThreadException extends JacobException {
|
||||
/**
|
||||
* identifier generated by Eclipse
|
||||
*/
|
||||
private static final long serialVersionUID = 6308780364980228692L;
|
||||
/**
|
||||
* identifier generated by Eclipse
|
||||
*/
|
||||
private static final long serialVersionUID = 6308780364980228692L;
|
||||
|
||||
/**
|
||||
* standard 0 arg constructor with no message
|
||||
*
|
||||
*/
|
||||
public WrongThreadException() {
|
||||
super("No Message Provided.");
|
||||
}
|
||||
/**
|
||||
* standard 0 arg constructor with no message
|
||||
*
|
||||
*/
|
||||
public WrongThreadException() {
|
||||
super("No Message Provided.");
|
||||
}
|
||||
|
||||
/**
|
||||
* standard constructor with a string message
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
public WrongThreadException(String s) {
|
||||
super(s);
|
||||
}
|
||||
/**
|
||||
* standard constructor with a string message
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
public WrongThreadException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@@ -13,71 +13,71 @@ import com.jacob.com.Variant;
|
||||
* options.
|
||||
*/
|
||||
class MathTest {
|
||||
/**
|
||||
* standard main program to run the sample
|
||||
*
|
||||
* @param args
|
||||
* command line parameters
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MathTest me = new MathTest();
|
||||
me.runTest();
|
||||
}
|
||||
/**
|
||||
* standard main program to run the sample
|
||||
*
|
||||
* @param args
|
||||
* command line parameters
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MathTest me = new MathTest();
|
||||
me.runTest();
|
||||
}
|
||||
|
||||
/** default constructor */
|
||||
public MathTest() {
|
||||
}
|
||||
/** default constructor */
|
||||
public MathTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* not clear why we need a class and run method but that's the way it was
|
||||
* written
|
||||
*/
|
||||
public void runTest() {
|
||||
// deprecated
|
||||
// System.runFinalizersOnExit(true);
|
||||
Dispatch test = new ActiveXComponent("MathTest.Math");
|
||||
TestEvents te = new TestEvents();
|
||||
DispatchEvents de = new DispatchEvents(test, te);
|
||||
if (de == null) {
|
||||
System.out
|
||||
.println("null returned when trying to create DispatchEvents");
|
||||
}
|
||||
System.out.println(Dispatch.call(test, "Add", new Variant(1),
|
||||
new Variant(2)));
|
||||
System.out.println(Dispatch.call(test, "Mult", new Variant(2),
|
||||
new Variant(2)));
|
||||
Variant v = Dispatch.call(test, "Mult", new Variant(2), new Variant(2));
|
||||
// this should return false
|
||||
System.out.println("v.isNull=" + v.isNull());
|
||||
v = Dispatch.call(test, "getNothing");
|
||||
// these should return nothing
|
||||
System.out.println("v.isNull=" + v.isNull());
|
||||
System.out.println("v.toDispatch=" + v.toDispatch());
|
||||
}
|
||||
/**
|
||||
* not clear why we need a class and run method but that's the way it was
|
||||
* written
|
||||
*/
|
||||
public void runTest() {
|
||||
// deprecated
|
||||
// System.runFinalizersOnExit(true);
|
||||
Dispatch test = new ActiveXComponent("MathTest.Math");
|
||||
TestEvents te = new TestEvents();
|
||||
DispatchEvents de = new DispatchEvents(test, te);
|
||||
if (de == null) {
|
||||
System.out
|
||||
.println("null returned when trying to create DispatchEvents");
|
||||
}
|
||||
System.out.println(Dispatch.call(test, "Add", new Variant(1),
|
||||
new Variant(2)));
|
||||
System.out.println(Dispatch.call(test, "Mult", new Variant(2),
|
||||
new Variant(2)));
|
||||
Variant v = Dispatch.call(test, "Mult", new Variant(2), new Variant(2));
|
||||
// this should return false
|
||||
System.out.println("v.isNull=" + v.isNull());
|
||||
v = Dispatch.call(test, "getNothing");
|
||||
// these should return nothing
|
||||
System.out.println("v.isNull=" + v.isNull());
|
||||
System.out.println("v.toDispatch=" + v.toDispatch());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* sample class to catch the events
|
||||
*
|
||||
*/
|
||||
public class TestEvents {
|
||||
/**
|
||||
* catches the DoneAdd event
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void DoneAdd(Variant[] args) {
|
||||
System.out.println("DoneAdd called in java");
|
||||
}
|
||||
/**
|
||||
*
|
||||
* sample class to catch the events
|
||||
*
|
||||
*/
|
||||
public class TestEvents {
|
||||
/**
|
||||
* catches the DoneAdd event
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void DoneAdd(Variant[] args) {
|
||||
System.out.println("DoneAdd called in java");
|
||||
}
|
||||
|
||||
/**
|
||||
* catches the DoneMult event
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void DoneMult(Variant[] args) {
|
||||
System.out.println("DoneMult called in java");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* catches the DoneMult event
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void DoneMult(Variant[] args) {
|
||||
System.out.println("DoneMult called in java");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,114 +31,114 @@ import com.jacob.com.Variant;
|
||||
*
|
||||
*/
|
||||
class Access {
|
||||
/**
|
||||
* the main loop for the test
|
||||
*
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
ComThread.InitSTA();
|
||||
// original test used this
|
||||
// ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
|
||||
// my xp box with a later release of access needed this
|
||||
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine.35");
|
||||
// this only works for access files pre-access-2000
|
||||
// this line doesn't work on my xp box in Eclipse
|
||||
// Dispatch db = open(ax, ".\\sample2.mdb");
|
||||
// this works when running in eclipse because the test cases run pwd
|
||||
// project root
|
||||
Dispatch db = open(ax, "samples/com/jacob/samples/access/sample2.mdb");
|
||||
String sql = "select * from MainTable";
|
||||
// make a temporary querydef
|
||||
Dispatch qd = Dispatch.call(db, "CreateQueryDef", "").toDispatch();
|
||||
// set the SQL string on it
|
||||
Dispatch.put(qd, "SQL", sql);
|
||||
Variant result = getByQueryDef(qd);
|
||||
// the 2-d safearray is transposed from what you might expect
|
||||
System.out.println("resulting array is " + result.toSafeArray());
|
||||
close(db);
|
||||
System.out.println("about to call ComThread.Release()");
|
||||
ComThread.Release();
|
||||
}
|
||||
/**
|
||||
* the main loop for the test
|
||||
*
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
ComThread.InitSTA();
|
||||
// original test used this
|
||||
// ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
|
||||
// my xp box with a later release of access needed this
|
||||
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine.35");
|
||||
// this only works for access files pre-access-2000
|
||||
// this line doesn't work on my xp box in Eclipse
|
||||
// Dispatch db = open(ax, ".\\sample2.mdb");
|
||||
// this works when running in eclipse because the test cases run pwd
|
||||
// project root
|
||||
Dispatch db = open(ax, "samples/com/jacob/samples/access/sample2.mdb");
|
||||
String sql = "select * from MainTable";
|
||||
// make a temporary querydef
|
||||
Dispatch qd = Dispatch.call(db, "CreateQueryDef", "").toDispatch();
|
||||
// set the SQL string on it
|
||||
Dispatch.put(qd, "SQL", sql);
|
||||
Variant result = getByQueryDef(qd);
|
||||
// the 2-d safearray is transposed from what you might expect
|
||||
System.out.println("resulting array is " + result.toSafeArray());
|
||||
close(db);
|
||||
System.out.println("about to call ComThread.Release()");
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a database
|
||||
*
|
||||
* @param ax
|
||||
* @param fileName
|
||||
* @return dispatch object that was opened
|
||||
*/
|
||||
public static Dispatch open(ActiveXComponent ax, String fileName) {
|
||||
Variant f = new Variant(false);
|
||||
// open the file in read-only mode
|
||||
Variant[] args = new Variant[] { new Variant(fileName), f, f };
|
||||
Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch();
|
||||
return openDB;
|
||||
}
|
||||
/**
|
||||
* Open a database
|
||||
*
|
||||
* @param ax
|
||||
* @param fileName
|
||||
* @return dispatch object that was opened
|
||||
*/
|
||||
public static Dispatch open(ActiveXComponent ax, String fileName) {
|
||||
Variant f = new Variant(false);
|
||||
// open the file in read-only mode
|
||||
Variant[] args = new Variant[] { new Variant(fileName), f, f };
|
||||
Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch();
|
||||
return openDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a database
|
||||
*
|
||||
* @param openDB
|
||||
* db to be closed
|
||||
*/
|
||||
public static void close(Dispatch openDB) {
|
||||
Dispatch.call(openDB, "Close");
|
||||
}
|
||||
/**
|
||||
* Close a database
|
||||
*
|
||||
* @param openDB
|
||||
* db to be closed
|
||||
*/
|
||||
public static void close(Dispatch openDB) {
|
||||
Dispatch.call(openDB, "Close");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the values from the recordset
|
||||
*
|
||||
* @param recset
|
||||
* @return Variant that is the returned values
|
||||
*/
|
||||
public static Variant getValues(Dispatch recset) {
|
||||
Dispatch.callSub(recset, "moveFirst");
|
||||
Variant vi = new Variant(4096);
|
||||
Variant v = Dispatch.call(recset, "GetRows", vi);
|
||||
return v;
|
||||
}
|
||||
/**
|
||||
* Extract the values from the recordset
|
||||
*
|
||||
* @param recset
|
||||
* @return Variant that is the returned values
|
||||
*/
|
||||
public static Variant getValues(Dispatch recset) {
|
||||
Dispatch.callSub(recset, "moveFirst");
|
||||
Variant vi = new Variant(4096);
|
||||
Variant v = Dispatch.call(recset, "GetRows", vi);
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* should return ?? for the passed in ??
|
||||
*
|
||||
* @param qd
|
||||
* @return Variant results of query?
|
||||
*/
|
||||
public static Variant getByQueryDef(Dispatch qd) {
|
||||
// get a reference to the recordset
|
||||
Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch();
|
||||
// get the values as a safe array
|
||||
String[] cols = getColumns(recset);
|
||||
for (int i = 0; i < cols.length; i++) {
|
||||
System.out.print(cols[i] + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
Variant vals = getValues(recset);
|
||||
return vals;
|
||||
}
|
||||
/**
|
||||
* should return ?? for the passed in ??
|
||||
*
|
||||
* @param qd
|
||||
* @return Variant results of query?
|
||||
*/
|
||||
public static Variant getByQueryDef(Dispatch qd) {
|
||||
// get a reference to the recordset
|
||||
Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch();
|
||||
// get the values as a safe array
|
||||
String[] cols = getColumns(recset);
|
||||
for (int i = 0; i < cols.length; i++) {
|
||||
System.out.print(cols[i] + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
Variant vals = getValues(recset);
|
||||
return vals;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the columns form the rec set
|
||||
*
|
||||
* @param recset
|
||||
* @return list of column names
|
||||
*/
|
||||
public static String[] getColumns(Dispatch recset) {
|
||||
Dispatch flds = Dispatch.get(recset, "Fields").toDispatch();
|
||||
int n_flds = Dispatch.get(flds, "Count").getInt();
|
||||
String[] s = new String[n_flds];
|
||||
Variant vi = new Variant();
|
||||
for (int i = 0; i < n_flds; i++) {
|
||||
vi.putInt(i);
|
||||
// must use the invoke method because this is a method call
|
||||
// that wants to have a Dispatch.Get flag...
|
||||
Dispatch fld = Dispatch.invoke(recset, "Fields", Dispatch.Get,
|
||||
new Object[] { vi }, new int[1]).toDispatch();
|
||||
Variant name = Dispatch.get(fld, "Name");
|
||||
s[i] = name.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
/**
|
||||
* gets the columns form the rec set
|
||||
*
|
||||
* @param recset
|
||||
* @return list of column names
|
||||
*/
|
||||
public static String[] getColumns(Dispatch recset) {
|
||||
Dispatch flds = Dispatch.get(recset, "Fields").toDispatch();
|
||||
int n_flds = Dispatch.get(flds, "Count").getInt();
|
||||
String[] s = new String[n_flds];
|
||||
Variant vi = new Variant();
|
||||
for (int i = 0; i < n_flds; i++) {
|
||||
vi.putInt(i);
|
||||
// must use the invoke method because this is a method call
|
||||
// that wants to have a Dispatch.Get flag...
|
||||
Dispatch fld = Dispatch.invoke(recset, "Fields", Dispatch.Get,
|
||||
new Object[] { vi }, new int[1]).toDispatch();
|
||||
Variant name = Dispatch.get(fld, "Name");
|
||||
s[i] = name.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,199 +9,199 @@ import com.jacob.com.Variant;
|
||||
*
|
||||
*/
|
||||
public class Command extends Dispatch {
|
||||
/**
|
||||
* standard constructor
|
||||
*/
|
||||
public Command() {
|
||||
super("ADODB.Command");
|
||||
}
|
||||
/**
|
||||
* standard constructor
|
||||
*/
|
||||
public Command() {
|
||||
super("ADODB.Command");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*
|
||||
* @param dispatchTarget
|
||||
*/
|
||||
public Command(Dispatch dispatchTarget) {
|
||||
super(dispatchTarget);
|
||||
}
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*
|
||||
* @param dispatchTarget
|
||||
*/
|
||||
public Command(Dispatch dispatchTarget) {
|
||||
super(dispatchTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* runs the "Properties" command
|
||||
*
|
||||
* @return the properties
|
||||
*/
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
/**
|
||||
* runs the "Properties" command
|
||||
*
|
||||
* @return the properties
|
||||
*/
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
/**
|
||||
* runs the "ActiveConnection" command
|
||||
*
|
||||
* @return a Connection object
|
||||
*/
|
||||
public Connection getActiveConnection() {
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection")
|
||||
.toDispatch());
|
||||
}
|
||||
/**
|
||||
* runs the "ActiveConnection" command
|
||||
*
|
||||
* @return a Connection object
|
||||
*/
|
||||
public Connection getActiveConnection() {
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection")
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "ActiveConnection" object
|
||||
*
|
||||
* @param ppvObject
|
||||
* the new connection
|
||||
*/
|
||||
public void setActiveConnection(Connection ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
/**
|
||||
* Sets the "ActiveConnection" object
|
||||
*
|
||||
* @param ppvObject
|
||||
* the new connection
|
||||
*/
|
||||
public void setActiveConnection(Connection ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the results from "CommandText"
|
||||
*/
|
||||
public String getCommandText() {
|
||||
return Dispatch.get(this, "CommandText").toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return the results from "CommandText"
|
||||
*/
|
||||
public String getCommandText() {
|
||||
return Dispatch.get(this, "CommandText").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pbstr
|
||||
* the new "CommandText"
|
||||
*/
|
||||
public void setCommandText(String pbstr) {
|
||||
Dispatch.put(this, "CommandText", pbstr);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pbstr
|
||||
* the new "CommandText"
|
||||
*/
|
||||
public void setCommandText(String pbstr) {
|
||||
Dispatch.put(this, "CommandText", pbstr);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the results of "CommandTimeout"
|
||||
*/
|
||||
public int getCommandTimeout() {
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return the results of "CommandTimeout"
|
||||
*/
|
||||
public int getCommandTimeout() {
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plTimeout
|
||||
* the new "CommandTimeout"
|
||||
*/
|
||||
public void setCommandTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param plTimeout
|
||||
* the new "CommandTimeout"
|
||||
*/
|
||||
public void setCommandTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return results from "Prepared"
|
||||
*/
|
||||
public boolean getPrepared() {
|
||||
return Dispatch.get(this, "Prepared").getBoolean();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return results from "Prepared"
|
||||
*/
|
||||
public boolean getPrepared() {
|
||||
return Dispatch.get(this, "Prepared").getBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pfPrepared
|
||||
* the new value for "Prepared"
|
||||
*/
|
||||
public void setPrepared(boolean pfPrepared) {
|
||||
Dispatch.put(this, "Prepared", new Variant(pfPrepared));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pfPrepared
|
||||
* the new value for "Prepared"
|
||||
*/
|
||||
public void setPrepared(boolean pfPrepared) {
|
||||
Dispatch.put(this, "Prepared", new Variant(pfPrepared));
|
||||
}
|
||||
|
||||
/**
|
||||
* "Execute"s a command
|
||||
*
|
||||
* @param RecordsAffected
|
||||
* @param Parameters
|
||||
* @param Options
|
||||
* @return
|
||||
*/
|
||||
public Recordset Execute(Variant RecordsAffected, Variant Parameters,
|
||||
int Options) {
|
||||
return (Recordset) Dispatch.call(this, "Execute", RecordsAffected,
|
||||
Parameters, new Variant(Options)).toDispatch();
|
||||
}
|
||||
/**
|
||||
* "Execute"s a command
|
||||
*
|
||||
* @param RecordsAffected
|
||||
* @param Parameters
|
||||
* @param Options
|
||||
* @return
|
||||
*/
|
||||
public Recordset Execute(Variant RecordsAffected, Variant Parameters,
|
||||
int Options) {
|
||||
return (Recordset) Dispatch.call(this, "Execute", RecordsAffected,
|
||||
Parameters, new Variant(Options)).toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* "Execute"s a command
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Recordset Execute() {
|
||||
Variant dummy = new Variant();
|
||||
return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch());
|
||||
}
|
||||
/**
|
||||
* "Execute"s a command
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Recordset Execute() {
|
||||
Variant dummy = new Variant();
|
||||
return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch());
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a parameter
|
||||
*
|
||||
* @param Name
|
||||
* @param Type
|
||||
* @param Direction
|
||||
* @param Size
|
||||
* @param Value
|
||||
* @return
|
||||
*/
|
||||
public Variant CreateParameter(String Name, int Type, int Direction,
|
||||
int Size, Variant Value) {
|
||||
return Dispatch.call(this, "CreateParameter", Name, new Variant(Type),
|
||||
new Variant(Direction), new Variant(Size), Value);
|
||||
}
|
||||
/**
|
||||
* creates a parameter
|
||||
*
|
||||
* @param Name
|
||||
* @param Type
|
||||
* @param Direction
|
||||
* @param Size
|
||||
* @param Value
|
||||
* @return
|
||||
*/
|
||||
public Variant CreateParameter(String Name, int Type, int Direction,
|
||||
int Size, Variant Value) {
|
||||
return Dispatch.call(this, "CreateParameter", Name, new Variant(Type),
|
||||
new Variant(Direction), new Variant(Size), Value);
|
||||
}
|
||||
|
||||
// need to wrap Parameters
|
||||
/**
|
||||
* @return "Parameters"
|
||||
*/
|
||||
public Variant getParameters() {
|
||||
return Dispatch.get(this, "Parameters");
|
||||
}
|
||||
// need to wrap Parameters
|
||||
/**
|
||||
* @return "Parameters"
|
||||
*/
|
||||
public Variant getParameters() {
|
||||
return Dispatch.get(this, "Parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plCmdType
|
||||
* new "CommandType"
|
||||
*/
|
||||
public void setCommandType(int plCmdType) {
|
||||
Dispatch.put(this, "CommandType", new Variant(plCmdType));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param plCmdType
|
||||
* new "CommandType"
|
||||
*/
|
||||
public void setCommandType(int plCmdType) {
|
||||
Dispatch.put(this, "CommandType", new Variant(plCmdType));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return current "CommandType"
|
||||
*/
|
||||
public int getCommandType() {
|
||||
return Dispatch.get(this, "CommandType").getInt();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return current "CommandType"
|
||||
*/
|
||||
public int getCommandType() {
|
||||
return Dispatch.get(this, "CommandType").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return "Name"
|
||||
*/
|
||||
public String getName() {
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return "Name"
|
||||
*/
|
||||
public String getName() {
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pbstrName
|
||||
* new "Name"
|
||||
*/
|
||||
public void setName(String pbstrName) {
|
||||
Dispatch.put(this, "Name", pbstrName);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pbstrName
|
||||
* new "Name"
|
||||
*/
|
||||
public void setName(String pbstrName) {
|
||||
Dispatch.put(this, "Name", pbstrName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return curent "State"
|
||||
*/
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return curent "State"
|
||||
*/
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* cancel whatever it is we're doing
|
||||
*/
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
/**
|
||||
* cancel whatever it is we're doing
|
||||
*/
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package com.jacob.samples.ado;
|
||||
// Enum: CommandTypeEnum
|
||||
|
||||
public interface CommandTypeEnum {
|
||||
public static final int adCmdUnspecified = -1;
|
||||
public static final int adCmdUnknown = 8;
|
||||
public static final int adCmdText = 1;
|
||||
public static final int adCmdTable = 2;
|
||||
public static final int adCmdStoredProc = 4;
|
||||
public static final int adCmdFile = 256;
|
||||
public static final int adCmdTableDirect = 512;
|
||||
public static final int adCmdUnspecified = -1;
|
||||
public static final int adCmdUnknown = 8;
|
||||
public static final int adCmdText = 1;
|
||||
public static final int adCmdTable = 2;
|
||||
public static final int adCmdStoredProc = 4;
|
||||
public static final int adCmdFile = 256;
|
||||
public static final int adCmdTableDirect = 512;
|
||||
}
|
||||
|
||||
@@ -4,148 +4,148 @@ import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Connection extends Dispatch {
|
||||
public Connection() {
|
||||
super("ADODB.Connection");
|
||||
}
|
||||
public Connection() {
|
||||
super("ADODB.Connection");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Connection(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Connection(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
// need to wrap Properties
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
// need to wrap Properties
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public String getConnectionString() {
|
||||
return Dispatch.get(this, "ConnectionString").toString();
|
||||
}
|
||||
public String getConnectionString() {
|
||||
return Dispatch.get(this, "ConnectionString").toString();
|
||||
}
|
||||
|
||||
public void setConnectionString(String pbstr) {
|
||||
Dispatch.put(this, "ConnectionString", pbstr);
|
||||
}
|
||||
public void setConnectionString(String pbstr) {
|
||||
Dispatch.put(this, "ConnectionString", pbstr);
|
||||
}
|
||||
|
||||
public int getCommandTimeout() {
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
public int getCommandTimeout() {
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
|
||||
public void setCommandTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
|
||||
}
|
||||
public void setCommandTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
return Dispatch.get(this, "ConnectionTimeout").getInt();
|
||||
}
|
||||
public int getConnectionTimeout() {
|
||||
return Dispatch.get(this, "ConnectionTimeout").getInt();
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout));
|
||||
}
|
||||
public void setConnectionTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout));
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return Dispatch.get(this, "Version").toString();
|
||||
}
|
||||
public String getVersion() {
|
||||
return Dispatch.get(this, "Version").toString();
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
Dispatch.call(this, "Close");
|
||||
}
|
||||
public void Close() {
|
||||
Dispatch.call(this, "Close");
|
||||
}
|
||||
|
||||
// how to deal with RecordsAffected being output?
|
||||
public Variant Execute(String CommandText, Variant RecordsAffected,
|
||||
int Options) {
|
||||
return Dispatch.call(this, CommandText, RecordsAffected, new Variant(
|
||||
Options));
|
||||
}
|
||||
// how to deal with RecordsAffected being output?
|
||||
public Variant Execute(String CommandText, Variant RecordsAffected,
|
||||
int Options) {
|
||||
return Dispatch.call(this, CommandText, RecordsAffected, new Variant(
|
||||
Options));
|
||||
}
|
||||
|
||||
public int BeginTrans() {
|
||||
return Dispatch.call(this, "BeginTrans").getInt();
|
||||
}
|
||||
public int BeginTrans() {
|
||||
return Dispatch.call(this, "BeginTrans").getInt();
|
||||
}
|
||||
|
||||
public void CommitTrans() {
|
||||
Dispatch.call(this, "CommitTrans");
|
||||
}
|
||||
public void CommitTrans() {
|
||||
Dispatch.call(this, "CommitTrans");
|
||||
}
|
||||
|
||||
public void RollbackTrans() {
|
||||
Dispatch.call(this, "RollbackTrans");
|
||||
}
|
||||
public void RollbackTrans() {
|
||||
Dispatch.call(this, "RollbackTrans");
|
||||
}
|
||||
|
||||
public void Open(String ConnectionString, String UserID, String Password,
|
||||
int Options) {
|
||||
Dispatch.call(this, "Open", ConnectionString, UserID, Password,
|
||||
new Variant(Options));
|
||||
}
|
||||
public void Open(String ConnectionString, String UserID, String Password,
|
||||
int Options) {
|
||||
Dispatch.call(this, "Open", ConnectionString, UserID, Password,
|
||||
new Variant(Options));
|
||||
}
|
||||
|
||||
public void Open() {
|
||||
Dispatch.call(this, "Open");
|
||||
}
|
||||
public void Open() {
|
||||
Dispatch.call(this, "Open");
|
||||
}
|
||||
|
||||
public Variant getErrors() {
|
||||
return Dispatch.get(this, "Errors");
|
||||
}
|
||||
public Variant getErrors() {
|
||||
return Dispatch.get(this, "Errors");
|
||||
}
|
||||
|
||||
public String getDefaultDatabase() {
|
||||
return Dispatch.get(this, "DefaultDatabase").toString();
|
||||
}
|
||||
public String getDefaultDatabase() {
|
||||
return Dispatch.get(this, "DefaultDatabase").toString();
|
||||
}
|
||||
|
||||
public void setDefaultDatabase(String pbstr) {
|
||||
Dispatch.put(this, "DefaultDatabase", pbstr);
|
||||
}
|
||||
public void setDefaultDatabase(String pbstr) {
|
||||
Dispatch.put(this, "DefaultDatabase", pbstr);
|
||||
}
|
||||
|
||||
public int getIsolationLevel() {
|
||||
return Dispatch.get(this, "IsolationLevel").getInt();
|
||||
}
|
||||
public int getIsolationLevel() {
|
||||
return Dispatch.get(this, "IsolationLevel").getInt();
|
||||
}
|
||||
|
||||
public void setIsolationLevel(int Level) {
|
||||
Dispatch.put(this, "IsolationLevel", new Variant(Level));
|
||||
}
|
||||
public void setIsolationLevel(int Level) {
|
||||
Dispatch.put(this, "IsolationLevel", new Variant(Level));
|
||||
}
|
||||
|
||||
public int getAttributes() {
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
}
|
||||
public int getAttributes() {
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
}
|
||||
|
||||
public void setAttributes(int plAttr) {
|
||||
Dispatch.put(this, "Attributes", new Variant(plAttr));
|
||||
}
|
||||
public void setAttributes(int plAttr) {
|
||||
Dispatch.put(this, "Attributes", new Variant(plAttr));
|
||||
}
|
||||
|
||||
public int getCursorLocation() {
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
}
|
||||
public int getCursorLocation() {
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
}
|
||||
|
||||
public void setCursorLocation(int plCursorLoc) {
|
||||
Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc));
|
||||
}
|
||||
public void setCursorLocation(int plCursorLoc) {
|
||||
Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc));
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return Dispatch.get(this, "Mode").getInt();
|
||||
}
|
||||
public int getMode() {
|
||||
return Dispatch.get(this, "Mode").getInt();
|
||||
}
|
||||
|
||||
public void setMode(int plMode) {
|
||||
Dispatch.put(this, "Mode", new Variant(plMode));
|
||||
}
|
||||
public void setMode(int plMode) {
|
||||
Dispatch.put(this, "Mode", new Variant(plMode));
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return Dispatch.get(this, "Provider").toString();
|
||||
}
|
||||
public String getProvider() {
|
||||
return Dispatch.get(this, "Provider").toString();
|
||||
}
|
||||
|
||||
public void setProvider(String pbstr) {
|
||||
Dispatch.put(this, "Provider", pbstr);
|
||||
}
|
||||
public void setProvider(String pbstr) {
|
||||
Dispatch.put(this, "Provider", pbstr);
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
public Variant OpenSchema(int Schema, Variant Restrictions, Variant SchemaID) {
|
||||
return Dispatch.call(this, "OpenSchema", new Variant(Schema),
|
||||
Restrictions, SchemaID);
|
||||
}
|
||||
public Variant OpenSchema(int Schema, Variant Restrictions, Variant SchemaID) {
|
||||
return Dispatch.call(this, "OpenSchema", new Variant(Schema),
|
||||
Restrictions, SchemaID);
|
||||
}
|
||||
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,98 +4,98 @@ import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Field extends Dispatch {
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Field(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Field(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public int getActualSize() {
|
||||
return Dispatch.get(this, "ActualSize").getInt();
|
||||
}
|
||||
public int getActualSize() {
|
||||
return Dispatch.get(this, "ActualSize").getInt();
|
||||
}
|
||||
|
||||
public int getAttributes() {
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
}
|
||||
public int getAttributes() {
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
}
|
||||
|
||||
public int getDefinedSize() {
|
||||
return Dispatch.get(this, "DefinedSize").getInt();
|
||||
}
|
||||
public int getDefinedSize() {
|
||||
return Dispatch.get(this, "DefinedSize").getInt();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
public String getName() {
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return Dispatch.get(this, "Type").getInt();
|
||||
}
|
||||
public int getType() {
|
||||
return Dispatch.get(this, "Type").getInt();
|
||||
}
|
||||
|
||||
public Variant getValue() {
|
||||
return Dispatch.get(this, "Value");
|
||||
}
|
||||
public Variant getValue() {
|
||||
return Dispatch.get(this, "Value");
|
||||
}
|
||||
|
||||
public void setValue(Variant pvar) {
|
||||
Dispatch.put(this, "Value", pvar);
|
||||
}
|
||||
public void setValue(Variant pvar) {
|
||||
Dispatch.put(this, "Value", pvar);
|
||||
}
|
||||
|
||||
public byte getPrecision() {
|
||||
return Dispatch.get(this, "Precision").getByte();
|
||||
}
|
||||
public byte getPrecision() {
|
||||
return Dispatch.get(this, "Precision").getByte();
|
||||
}
|
||||
|
||||
public byte getNumericScale() {
|
||||
return Dispatch.get(this, "NumericScale").getByte();
|
||||
}
|
||||
public byte getNumericScale() {
|
||||
return Dispatch.get(this, "NumericScale").getByte();
|
||||
}
|
||||
|
||||
public void AppendChunk(Variant Data) {
|
||||
Dispatch.call(this, "AppendChunk", Data);
|
||||
}
|
||||
public void AppendChunk(Variant Data) {
|
||||
Dispatch.call(this, "AppendChunk", Data);
|
||||
}
|
||||
|
||||
public Variant GetChunk(int Length) {
|
||||
return Dispatch.call(this, "GetChunk", new Variant(Length));
|
||||
}
|
||||
public Variant GetChunk(int Length) {
|
||||
return Dispatch.call(this, "GetChunk", new Variant(Length));
|
||||
}
|
||||
|
||||
public Variant getOriginalValue() {
|
||||
return Dispatch.get(this, "OriginalValue");
|
||||
}
|
||||
public Variant getOriginalValue() {
|
||||
return Dispatch.get(this, "OriginalValue");
|
||||
}
|
||||
|
||||
public Variant getUnderlyingValue() {
|
||||
return Dispatch.get(this, "UnderlyingValue");
|
||||
}
|
||||
public Variant getUnderlyingValue() {
|
||||
return Dispatch.get(this, "UnderlyingValue");
|
||||
}
|
||||
|
||||
public Variant getDataFormat() {
|
||||
return Dispatch.get(this, "DataFormat");
|
||||
}
|
||||
public Variant getDataFormat() {
|
||||
return Dispatch.get(this, "DataFormat");
|
||||
}
|
||||
|
||||
public void setDataFormat(Variant ppiDF) {
|
||||
Dispatch.put(this, "DataFormat", ppiDF);
|
||||
}
|
||||
public void setDataFormat(Variant ppiDF) {
|
||||
Dispatch.put(this, "DataFormat", ppiDF);
|
||||
}
|
||||
|
||||
public void setPrecision(byte pb) {
|
||||
Dispatch.put(this, "Precision", new Variant(pb));
|
||||
}
|
||||
public void setPrecision(byte pb) {
|
||||
Dispatch.put(this, "Precision", new Variant(pb));
|
||||
}
|
||||
|
||||
public void setNumericScale(byte pb) {
|
||||
Dispatch.put(this, "NumericScale", new Variant(pb));
|
||||
}
|
||||
public void setNumericScale(byte pb) {
|
||||
Dispatch.put(this, "NumericScale", new Variant(pb));
|
||||
}
|
||||
|
||||
public void setType(int pDataType) {
|
||||
Dispatch.put(this, "Type", new Variant(pDataType));
|
||||
}
|
||||
public void setType(int pDataType) {
|
||||
Dispatch.put(this, "Type", new Variant(pDataType));
|
||||
}
|
||||
|
||||
public void setDefinedSize(int pl) {
|
||||
Dispatch.put(this, "DefinedSize", new Variant(pl));
|
||||
}
|
||||
public void setDefinedSize(int pl) {
|
||||
Dispatch.put(this, "DefinedSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public void setAttributes(int pl) {
|
||||
Dispatch.put(this, "Attributes", new Variant(pl));
|
||||
}
|
||||
public void setAttributes(int pl) {
|
||||
Dispatch.put(this, "Attributes", new Variant(pl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,40 +4,40 @@ import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Fields extends Dispatch {
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Fields(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Fields(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return Dispatch.get(this, "Count").getInt();
|
||||
}
|
||||
public int getCount() {
|
||||
return Dispatch.get(this, "Count").getInt();
|
||||
}
|
||||
|
||||
public Variant _NewEnum() {
|
||||
return Dispatch.call(this, "_NewEnum");
|
||||
}
|
||||
public Variant _NewEnum() {
|
||||
return Dispatch.call(this, "_NewEnum");
|
||||
}
|
||||
|
||||
public void Refresh() {
|
||||
Dispatch.call(this, "Refresh");
|
||||
}
|
||||
public void Refresh() {
|
||||
Dispatch.call(this, "Refresh");
|
||||
}
|
||||
|
||||
public Field getItem(int Index) {
|
||||
return new Field(Dispatch.call(this, "Item", new Variant(Index))
|
||||
.toDispatch());
|
||||
}
|
||||
public Field getItem(int Index) {
|
||||
return new Field(Dispatch.call(this, "Item", new Variant(Index))
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
public void Append(String Name, int Type, int DefinedSize, int Attrib) {
|
||||
Dispatch.call(this, "Append", Name, new Variant(Type), new Variant(
|
||||
DefinedSize), new Variant(Attrib));
|
||||
}
|
||||
public void Append(String Name, int Type, int DefinedSize, int Attrib) {
|
||||
Dispatch.call(this, "Append", Name, new Variant(Type), new Variant(
|
||||
DefinedSize), new Variant(Attrib));
|
||||
}
|
||||
|
||||
public void Delete(Variant Index) {
|
||||
Dispatch.call(this, "Delete", Index);
|
||||
}
|
||||
public void Delete(Variant Index) {
|
||||
Dispatch.call(this, "Delete", Index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,339 +4,339 @@ import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Recordset extends Dispatch {
|
||||
public Recordset() {
|
||||
super("ADODB.Recordset");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Recordset(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public int getAbsolutePosition() {
|
||||
return Dispatch.get(this, "AbsolutePosition").getInt();
|
||||
}
|
||||
|
||||
public void setAbsolutePosition(int pl) {
|
||||
Dispatch.put(this, "AbsolutePosition", new Variant(pl));
|
||||
}
|
||||
|
||||
public Connection getActiveConnection() {
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection")
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
public void setActiveConnection(Connection ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public void setActiveConnection(Variant ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public boolean getBOF() {
|
||||
return Dispatch.get(this, "BOF").getBoolean();
|
||||
}
|
||||
|
||||
public Variant getBookmark() {
|
||||
return Dispatch.get(this, "Bookmark");
|
||||
}
|
||||
|
||||
public void setBookmark(Variant pvBookmark) {
|
||||
Dispatch.put(this, "Bookmark", pvBookmark);
|
||||
}
|
||||
|
||||
public int getCacheSize() {
|
||||
return Dispatch.get(this, "CacheSize").getInt();
|
||||
}
|
||||
|
||||
public void setCacheSize(int pl) {
|
||||
Dispatch.put(this, "CacheSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getCursorType() {
|
||||
return Dispatch.get(this, "CursorType").getInt();
|
||||
}
|
||||
|
||||
public void setCursorType(int pl) {
|
||||
Dispatch.put(this, "CursorType", new Variant(pl));
|
||||
}
|
||||
|
||||
public boolean getEOF() {
|
||||
return Dispatch.get(this, "EOF").getBoolean();
|
||||
}
|
||||
|
||||
public Fields getFields() {
|
||||
return new Fields(Dispatch.get(this, "Fields").toDispatch());
|
||||
}
|
||||
|
||||
public int getLockType() {
|
||||
return Dispatch.get(this, "LockType").getInt();
|
||||
}
|
||||
|
||||
public void setLockType(int plLockType) {
|
||||
Dispatch.put(this, "LockType", new Variant(plLockType));
|
||||
}
|
||||
|
||||
public int getMaxRecords() {
|
||||
return Dispatch.get(this, "MaxRecords").getInt();
|
||||
}
|
||||
|
||||
public void setMaxRecords(int pl) {
|
||||
Dispatch.put(this, "MaxRecords", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getRecordCount() {
|
||||
return Dispatch.get(this, "RecordCount").getInt();
|
||||
}
|
||||
|
||||
public void setSource(Object pvSource) {
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
}
|
||||
|
||||
public void setSource(String pvSource) {
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
}
|
||||
|
||||
public Variant getSource() {
|
||||
return Dispatch.get(this, "Source");
|
||||
}
|
||||
|
||||
public void AddNew(Variant FieldList, Variant Values) {
|
||||
Dispatch.call(this, "AddNew", FieldList, Values);
|
||||
}
|
||||
|
||||
public void CancelUpdate() {
|
||||
Dispatch.call(this, "CancelUpdate");
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
Dispatch.call(this, "Close");
|
||||
}
|
||||
|
||||
public void Delete(int AffectRecords) {
|
||||
Dispatch.call(this, "Delete", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public Variant GetRows(int Rows, Variant Start, Variant Fields) {
|
||||
return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields);
|
||||
}
|
||||
|
||||
// get all rows
|
||||
public Variant GetRows() {
|
||||
return Dispatch.call(this, "GetRows");
|
||||
}
|
||||
|
||||
public void Move(int NumRecords, Variant Start) {
|
||||
Dispatch.call(this, "Move", new Variant(NumRecords), Start);
|
||||
}
|
||||
|
||||
public void MoveNext() {
|
||||
Dispatch.call(this, "MoveNext");
|
||||
}
|
||||
|
||||
public void MovePrevious() {
|
||||
Dispatch.call(this, "MovePrevious");
|
||||
}
|
||||
|
||||
public void MoveFirst() {
|
||||
Dispatch.call(this, "MoveFirst");
|
||||
}
|
||||
|
||||
public void MoveLast() {
|
||||
Dispatch.call(this, "MoveLast");
|
||||
}
|
||||
|
||||
public void Open(Variant Source, Variant ActiveConnection, int CursorType,
|
||||
int LockType, int Options) {
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(
|
||||
CursorType), new Variant(LockType), new Variant(Options));
|
||||
}
|
||||
|
||||
public void Open(Variant Source, Variant ActiveConnection) {
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection);
|
||||
}
|
||||
|
||||
public void Requery(int Options) {
|
||||
Dispatch.call(this, "Requery", new Variant(Options));
|
||||
}
|
||||
|
||||
public void Update(Variant Fields, Variant Values) {
|
||||
Dispatch.call(this, "Update", Fields, Values);
|
||||
}
|
||||
|
||||
public int getAbsolutePage() {
|
||||
return Dispatch.get(this, "AbsolutePage").getInt();
|
||||
}
|
||||
|
||||
public void setAbsolutePage(int pl) {
|
||||
Dispatch.put(this, "AbsolutePage", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getEditMode() {
|
||||
return Dispatch.get(this, "EditMode").getInt();
|
||||
}
|
||||
|
||||
public Variant getFilter() {
|
||||
return Dispatch.get(this, "Filter");
|
||||
}
|
||||
|
||||
public void setFilter(Variant Criteria) {
|
||||
Dispatch.put(this, "Filter", Criteria);
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return Dispatch.get(this, "PageCount").getInt();
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return Dispatch.get(this, "PageSize").getInt();
|
||||
}
|
||||
|
||||
public void setPageSize(int pl) {
|
||||
Dispatch.put(this, "PageSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return Dispatch.get(this, "Sort").toString();
|
||||
}
|
||||
|
||||
public void setSort(String Criteria) {
|
||||
Dispatch.put(this, "Sort", Criteria);
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return Dispatch.get(this, "Status").getInt();
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
public void UpdateBatch(int AffectRecords) {
|
||||
Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public void CancelBatch(int AffectRecords) {
|
||||
Dispatch.call(this, "CancelBatch", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public int getCursorLocation() {
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
}
|
||||
|
||||
public void setCursorLocation(int pl) {
|
||||
Dispatch.put(this, "CursorLocation", new Variant(pl));
|
||||
}
|
||||
|
||||
public Recordset NextRecordset(Variant RecordsAffected) {
|
||||
return new Recordset(Dispatch.call(this, "NextRecordset",
|
||||
RecordsAffected).toDispatch());
|
||||
}
|
||||
|
||||
public boolean Supports(int CursorOptions) {
|
||||
return Dispatch.call(this, "Supports", new Variant(CursorOptions))
|
||||
.getBoolean();
|
||||
}
|
||||
|
||||
public Variant getCollect(Variant Index) {
|
||||
return Dispatch.get(this, "Collect");
|
||||
}
|
||||
|
||||
public void setCollect(Variant Index, Variant pvar) {
|
||||
Dispatch.call(this, "Collect", Index, pvar);
|
||||
}
|
||||
|
||||
public int getMarshalOptions() {
|
||||
return Dispatch.get(this, "MarshalOptions").getInt();
|
||||
}
|
||||
|
||||
public void setMarshalOptions(int pl) {
|
||||
Dispatch.put(this, "MarshalOptions", new Variant(pl));
|
||||
}
|
||||
|
||||
public void Find(String Criteria, int SkipRecords, int SearchDirection,
|
||||
Variant Start) {
|
||||
Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords),
|
||||
new Variant(SearchDirection), Start);
|
||||
}
|
||||
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
|
||||
public Variant getDataSource() {
|
||||
return Dispatch.get(this, "DataSource");
|
||||
}
|
||||
|
||||
public void setDataSource(Variant ppunkDataSource) {
|
||||
Dispatch.put(this, "DataSource", ppunkDataSource);
|
||||
}
|
||||
|
||||
public void Save(String FileName, int PersistFormat) {
|
||||
Dispatch.call(this, "Save", FileName, new Variant(PersistFormat));
|
||||
}
|
||||
|
||||
public Variant getActiveCommand() {
|
||||
return Dispatch.get(this, "ActiveCommand");
|
||||
}
|
||||
|
||||
public void setStayInSync(boolean pb) {
|
||||
Dispatch.put(this, "StayInSync", new Variant(pb));
|
||||
}
|
||||
|
||||
public boolean getStayInSync() {
|
||||
return Dispatch.get(this, "StayInSync").getBoolean();
|
||||
}
|
||||
|
||||
public String GetString(int StringFormat, int NumRows,
|
||||
String ColumnDelimeter, String RowDelimeter, String NullExpr) {
|
||||
return Dispatch.call(this, "GetString", new Variant(StringFormat),
|
||||
new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public String getDataMember() {
|
||||
return Dispatch.get(this, "DataMember").toString();
|
||||
}
|
||||
|
||||
public void setDataMember(String pl) {
|
||||
Dispatch.put(this, "DataMember", new Variant(pl));
|
||||
}
|
||||
|
||||
public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2) {
|
||||
return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2)
|
||||
.getInt();
|
||||
}
|
||||
|
||||
public Recordset Clone(int LockType) {
|
||||
return new Recordset(Dispatch
|
||||
.call(this, "Clone", new Variant(LockType)).toDispatch());
|
||||
}
|
||||
|
||||
public void Resync(int AffectRecords, int ResyncValues) {
|
||||
Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(
|
||||
ResyncValues));
|
||||
}
|
||||
|
||||
public void Seek(Variant KeyValues, int SeekOption) {
|
||||
Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption));
|
||||
}
|
||||
|
||||
public void setIndex(String pl) {
|
||||
Dispatch.put(this, "Index", new Variant(pl));
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return Dispatch.get(this, "Index)").toString();
|
||||
}
|
||||
public Recordset() {
|
||||
super("ADODB.Recordset");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Recordset(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public int getAbsolutePosition() {
|
||||
return Dispatch.get(this, "AbsolutePosition").getInt();
|
||||
}
|
||||
|
||||
public void setAbsolutePosition(int pl) {
|
||||
Dispatch.put(this, "AbsolutePosition", new Variant(pl));
|
||||
}
|
||||
|
||||
public Connection getActiveConnection() {
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection")
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
public void setActiveConnection(Connection ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public void setActiveConnection(Variant ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public boolean getBOF() {
|
||||
return Dispatch.get(this, "BOF").getBoolean();
|
||||
}
|
||||
|
||||
public Variant getBookmark() {
|
||||
return Dispatch.get(this, "Bookmark");
|
||||
}
|
||||
|
||||
public void setBookmark(Variant pvBookmark) {
|
||||
Dispatch.put(this, "Bookmark", pvBookmark);
|
||||
}
|
||||
|
||||
public int getCacheSize() {
|
||||
return Dispatch.get(this, "CacheSize").getInt();
|
||||
}
|
||||
|
||||
public void setCacheSize(int pl) {
|
||||
Dispatch.put(this, "CacheSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getCursorType() {
|
||||
return Dispatch.get(this, "CursorType").getInt();
|
||||
}
|
||||
|
||||
public void setCursorType(int pl) {
|
||||
Dispatch.put(this, "CursorType", new Variant(pl));
|
||||
}
|
||||
|
||||
public boolean getEOF() {
|
||||
return Dispatch.get(this, "EOF").getBoolean();
|
||||
}
|
||||
|
||||
public Fields getFields() {
|
||||
return new Fields(Dispatch.get(this, "Fields").toDispatch());
|
||||
}
|
||||
|
||||
public int getLockType() {
|
||||
return Dispatch.get(this, "LockType").getInt();
|
||||
}
|
||||
|
||||
public void setLockType(int plLockType) {
|
||||
Dispatch.put(this, "LockType", new Variant(plLockType));
|
||||
}
|
||||
|
||||
public int getMaxRecords() {
|
||||
return Dispatch.get(this, "MaxRecords").getInt();
|
||||
}
|
||||
|
||||
public void setMaxRecords(int pl) {
|
||||
Dispatch.put(this, "MaxRecords", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getRecordCount() {
|
||||
return Dispatch.get(this, "RecordCount").getInt();
|
||||
}
|
||||
|
||||
public void setSource(Object pvSource) {
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
}
|
||||
|
||||
public void setSource(String pvSource) {
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
}
|
||||
|
||||
public Variant getSource() {
|
||||
return Dispatch.get(this, "Source");
|
||||
}
|
||||
|
||||
public void AddNew(Variant FieldList, Variant Values) {
|
||||
Dispatch.call(this, "AddNew", FieldList, Values);
|
||||
}
|
||||
|
||||
public void CancelUpdate() {
|
||||
Dispatch.call(this, "CancelUpdate");
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
Dispatch.call(this, "Close");
|
||||
}
|
||||
|
||||
public void Delete(int AffectRecords) {
|
||||
Dispatch.call(this, "Delete", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public Variant GetRows(int Rows, Variant Start, Variant Fields) {
|
||||
return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields);
|
||||
}
|
||||
|
||||
// get all rows
|
||||
public Variant GetRows() {
|
||||
return Dispatch.call(this, "GetRows");
|
||||
}
|
||||
|
||||
public void Move(int NumRecords, Variant Start) {
|
||||
Dispatch.call(this, "Move", new Variant(NumRecords), Start);
|
||||
}
|
||||
|
||||
public void MoveNext() {
|
||||
Dispatch.call(this, "MoveNext");
|
||||
}
|
||||
|
||||
public void MovePrevious() {
|
||||
Dispatch.call(this, "MovePrevious");
|
||||
}
|
||||
|
||||
public void MoveFirst() {
|
||||
Dispatch.call(this, "MoveFirst");
|
||||
}
|
||||
|
||||
public void MoveLast() {
|
||||
Dispatch.call(this, "MoveLast");
|
||||
}
|
||||
|
||||
public void Open(Variant Source, Variant ActiveConnection, int CursorType,
|
||||
int LockType, int Options) {
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(
|
||||
CursorType), new Variant(LockType), new Variant(Options));
|
||||
}
|
||||
|
||||
public void Open(Variant Source, Variant ActiveConnection) {
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection);
|
||||
}
|
||||
|
||||
public void Requery(int Options) {
|
||||
Dispatch.call(this, "Requery", new Variant(Options));
|
||||
}
|
||||
|
||||
public void Update(Variant Fields, Variant Values) {
|
||||
Dispatch.call(this, "Update", Fields, Values);
|
||||
}
|
||||
|
||||
public int getAbsolutePage() {
|
||||
return Dispatch.get(this, "AbsolutePage").getInt();
|
||||
}
|
||||
|
||||
public void setAbsolutePage(int pl) {
|
||||
Dispatch.put(this, "AbsolutePage", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getEditMode() {
|
||||
return Dispatch.get(this, "EditMode").getInt();
|
||||
}
|
||||
|
||||
public Variant getFilter() {
|
||||
return Dispatch.get(this, "Filter");
|
||||
}
|
||||
|
||||
public void setFilter(Variant Criteria) {
|
||||
Dispatch.put(this, "Filter", Criteria);
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return Dispatch.get(this, "PageCount").getInt();
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return Dispatch.get(this, "PageSize").getInt();
|
||||
}
|
||||
|
||||
public void setPageSize(int pl) {
|
||||
Dispatch.put(this, "PageSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return Dispatch.get(this, "Sort").toString();
|
||||
}
|
||||
|
||||
public void setSort(String Criteria) {
|
||||
Dispatch.put(this, "Sort", Criteria);
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return Dispatch.get(this, "Status").getInt();
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
public void UpdateBatch(int AffectRecords) {
|
||||
Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public void CancelBatch(int AffectRecords) {
|
||||
Dispatch.call(this, "CancelBatch", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public int getCursorLocation() {
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
}
|
||||
|
||||
public void setCursorLocation(int pl) {
|
||||
Dispatch.put(this, "CursorLocation", new Variant(pl));
|
||||
}
|
||||
|
||||
public Recordset NextRecordset(Variant RecordsAffected) {
|
||||
return new Recordset(Dispatch.call(this, "NextRecordset",
|
||||
RecordsAffected).toDispatch());
|
||||
}
|
||||
|
||||
public boolean Supports(int CursorOptions) {
|
||||
return Dispatch.call(this, "Supports", new Variant(CursorOptions))
|
||||
.getBoolean();
|
||||
}
|
||||
|
||||
public Variant getCollect(Variant Index) {
|
||||
return Dispatch.get(this, "Collect");
|
||||
}
|
||||
|
||||
public void setCollect(Variant Index, Variant pvar) {
|
||||
Dispatch.call(this, "Collect", Index, pvar);
|
||||
}
|
||||
|
||||
public int getMarshalOptions() {
|
||||
return Dispatch.get(this, "MarshalOptions").getInt();
|
||||
}
|
||||
|
||||
public void setMarshalOptions(int pl) {
|
||||
Dispatch.put(this, "MarshalOptions", new Variant(pl));
|
||||
}
|
||||
|
||||
public void Find(String Criteria, int SkipRecords, int SearchDirection,
|
||||
Variant Start) {
|
||||
Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords),
|
||||
new Variant(SearchDirection), Start);
|
||||
}
|
||||
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
|
||||
public Variant getDataSource() {
|
||||
return Dispatch.get(this, "DataSource");
|
||||
}
|
||||
|
||||
public void setDataSource(Variant ppunkDataSource) {
|
||||
Dispatch.put(this, "DataSource", ppunkDataSource);
|
||||
}
|
||||
|
||||
public void Save(String FileName, int PersistFormat) {
|
||||
Dispatch.call(this, "Save", FileName, new Variant(PersistFormat));
|
||||
}
|
||||
|
||||
public Variant getActiveCommand() {
|
||||
return Dispatch.get(this, "ActiveCommand");
|
||||
}
|
||||
|
||||
public void setStayInSync(boolean pb) {
|
||||
Dispatch.put(this, "StayInSync", new Variant(pb));
|
||||
}
|
||||
|
||||
public boolean getStayInSync() {
|
||||
return Dispatch.get(this, "StayInSync").getBoolean();
|
||||
}
|
||||
|
||||
public String GetString(int StringFormat, int NumRows,
|
||||
String ColumnDelimeter, String RowDelimeter, String NullExpr) {
|
||||
return Dispatch.call(this, "GetString", new Variant(StringFormat),
|
||||
new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public String getDataMember() {
|
||||
return Dispatch.get(this, "DataMember").toString();
|
||||
}
|
||||
|
||||
public void setDataMember(String pl) {
|
||||
Dispatch.put(this, "DataMember", new Variant(pl));
|
||||
}
|
||||
|
||||
public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2) {
|
||||
return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2)
|
||||
.getInt();
|
||||
}
|
||||
|
||||
public Recordset Clone(int LockType) {
|
||||
return new Recordset(Dispatch
|
||||
.call(this, "Clone", new Variant(LockType)).toDispatch());
|
||||
}
|
||||
|
||||
public void Resync(int AffectRecords, int ResyncValues) {
|
||||
Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(
|
||||
ResyncValues));
|
||||
}
|
||||
|
||||
public void Seek(Variant KeyValues, int SeekOption) {
|
||||
Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption));
|
||||
}
|
||||
|
||||
public void setIndex(String pl) {
|
||||
Dispatch.put(this, "Index", new Variant(pl));
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return Dispatch.get(this, "Index)").toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,54 +3,54 @@ package com.jacob.samples.ado;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class test {
|
||||
public static void printRS(Recordset rs) {
|
||||
Fields fs = rs.getFields();
|
||||
public static void printRS(Recordset rs) {
|
||||
Fields fs = rs.getFields();
|
||||
|
||||
for (int i = 0; i < fs.getCount(); i++) {
|
||||
System.out.print(fs.getItem(i).getName() + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
for (int i = 0; i < fs.getCount(); i++) {
|
||||
System.out.print(fs.getItem(i).getName() + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
rs.MoveFirst();
|
||||
while (!rs.getEOF()) {
|
||||
for (int i = 0; i < fs.getCount(); i++) {
|
||||
Field f = fs.getItem(i);
|
||||
Variant v = f.getValue();
|
||||
System.out.print(v + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
rs.MoveNext();
|
||||
}
|
||||
}
|
||||
rs.MoveFirst();
|
||||
while (!rs.getEOF()) {
|
||||
for (int i = 0; i < fs.getCount(); i++) {
|
||||
Field f = fs.getItem(i);
|
||||
Variant v = f.getValue();
|
||||
System.out.print(v + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
rs.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
// open a recordset directly
|
||||
public static void getRS(String con, String query) {
|
||||
System.out.println("Recordset Open");
|
||||
Recordset rs = new Recordset();
|
||||
rs.Open(new Variant(query), new Variant(con));
|
||||
printRS(rs);
|
||||
}
|
||||
// open a recordset directly
|
||||
public static void getRS(String con, String query) {
|
||||
System.out.println("Recordset Open");
|
||||
Recordset rs = new Recordset();
|
||||
rs.Open(new Variant(query), new Variant(con));
|
||||
printRS(rs);
|
||||
}
|
||||
|
||||
// create connection and command objects and use them
|
||||
// to get a recordset
|
||||
public static void getCommand(String con, String query) {
|
||||
System.out.println("Command+Connection -> Recordset");
|
||||
Connection c = new Connection();
|
||||
c.setConnectionString(con);
|
||||
c.Open();
|
||||
Command comm = new Command();
|
||||
comm.setActiveConnection(c);
|
||||
comm.setCommandType(CommandTypeEnum.adCmdText);
|
||||
comm.setCommandText(query);
|
||||
Recordset rs = comm.Execute();
|
||||
printRS(rs);
|
||||
c.Close();
|
||||
}
|
||||
// create connection and command objects and use them
|
||||
// to get a recordset
|
||||
public static void getCommand(String con, String query) {
|
||||
System.out.println("Command+Connection -> Recordset");
|
||||
Connection c = new Connection();
|
||||
c.setConnectionString(con);
|
||||
c.Open();
|
||||
Command comm = new Command();
|
||||
comm.setActiveConnection(c);
|
||||
comm.setCommandType(CommandTypeEnum.adCmdText);
|
||||
comm.setCommandText(query);
|
||||
Recordset rs = comm.Execute();
|
||||
printRS(rs);
|
||||
c.Close();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
|
||||
String queryStr = "select * from authors";
|
||||
getCommand(connectStr, queryStr);
|
||||
getRS(connectStr, queryStr);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
|
||||
String queryStr = "select * from authors";
|
||||
getCommand(connectStr, queryStr);
|
||||
getRS(connectStr, queryStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,63 +26,63 @@ import com.jacob.com.Variant;
|
||||
|
||||
public class JacobTestApplet extends Applet implements ActionListener {
|
||||
|
||||
private static final long serialVersionUID = 4492492907986849158L;
|
||||
private static final long serialVersionUID = 4492492907986849158L;
|
||||
|
||||
TextField in;
|
||||
TextField out;
|
||||
Button calc;
|
||||
ActiveXComponent sC = null;
|
||||
TextField in;
|
||||
TextField out;
|
||||
Button calc;
|
||||
ActiveXComponent sC = null;
|
||||
|
||||
/**
|
||||
* startup method
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
setLayout(new FlowLayout());
|
||||
add(this.in = new TextField("1+1", 16));
|
||||
add(this.out = new TextField("?", 16));
|
||||
add(this.calc = new Button("Calculate"));
|
||||
this.calc.addActionListener(this);
|
||||
/**
|
||||
* startup method
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
setLayout(new FlowLayout());
|
||||
add(this.in = new TextField("1+1", 16));
|
||||
add(this.out = new TextField("?", 16));
|
||||
add(this.calc = new Button("Calculate"));
|
||||
this.calc.addActionListener(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about this applet.
|
||||
* According to the java spec:
|
||||
* "An applet should override this method to return a String containing information about the author, version, and copyright of the applet."
|
||||
*
|
||||
* @return information about the applet.
|
||||
*/
|
||||
@Override
|
||||
public String getAppletInfo() {
|
||||
return "Jacob Test Applet. Written by ttreeck, nepatec GmbH & Co. KG.\nhttp://www.nepatec.de";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the parameters that are understood by this applet.
|
||||
* According to the java spec:
|
||||
* "An applet should override this method to return an array of Strings describing these parameters."
|
||||
*
|
||||
* @return array with a set of three Strings containing the name, the type, and a description.
|
||||
*/
|
||||
/**
|
||||
* Returns information about this applet.
|
||||
* According to the java spec:
|
||||
* "An applet should override this method to return a String containing information about the author, version, and copyright of the applet."
|
||||
*
|
||||
* @return information about the applet.
|
||||
*/
|
||||
@Override
|
||||
public String getAppletInfo() {
|
||||
return "Jacob Test Applet. Written by ttreeck, nepatec GmbH & Co. KG.\nhttp://www.nepatec.de";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the parameters that are understood by this applet.
|
||||
* According to the java spec:
|
||||
* "An applet should override this method to return an array of Strings describing these parameters."
|
||||
*
|
||||
* @return array with a set of three Strings containing the name, the type, and a description.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String[][] getParameterInfo(){
|
||||
@Override
|
||||
public String[][] getParameterInfo(){
|
||||
return new String[][]{};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* action method that receives button actions
|
||||
*
|
||||
* @param ev the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
if (this.sC == null) {
|
||||
String lang = "VBScript";
|
||||
this.sC = new ActiveXComponent("ScriptControl");
|
||||
Dispatch.put(this.sC, "Language", lang);
|
||||
}
|
||||
Variant v = Dispatch.call(this.sC, "Eval", this.in.getText());
|
||||
this.out.setText(v.toString());
|
||||
}
|
||||
/**
|
||||
* action method that receives button actions
|
||||
*
|
||||
* @param ev the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
if (this.sC == null) {
|
||||
String lang = "VBScript";
|
||||
this.sC = new ActiveXComponent("ScriptControl");
|
||||
Dispatch.put(this.sC, "Language", lang);
|
||||
}
|
||||
Variant v = Dispatch.call(this.sC, "Eval", this.in.getText());
|
||||
this.out.setText(v.toString());
|
||||
}
|
||||
}
|
||||
@@ -9,59 +9,59 @@
|
||||
|
||||
STDMETHODIMP Face::InterfaceSupportsErrorInfo(REFIID riid)
|
||||
{
|
||||
static const IID* arr[] =
|
||||
{
|
||||
&IID_IFace1,
|
||||
&IID_IFace2,
|
||||
&IID_IFace3,
|
||||
};
|
||||
static const IID* arr[] =
|
||||
{
|
||||
&IID_IFace1,
|
||||
&IID_IFace2,
|
||||
&IID_IFace3,
|
||||
};
|
||||
|
||||
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
|
||||
{
|
||||
if (InlineIsEqualGUID(*arr[i],riid))
|
||||
return S_OK;
|
||||
}
|
||||
return S_FALSE;
|
||||
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
|
||||
{
|
||||
if (InlineIsEqualGUID(*arr[i],riid))
|
||||
return S_OK;
|
||||
}
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP Face::get_Face1Name(BSTR *pVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
*pVal = name1;
|
||||
return S_OK;
|
||||
// TODO: Add your implementation code here
|
||||
*pVal = name1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Face::put_Face1Name(BSTR newVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
name1 = newVal;
|
||||
return S_OK;
|
||||
// TODO: Add your implementation code here
|
||||
name1 = newVal;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Face::get_Face2Nam(BSTR *pVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
*pVal = name2;
|
||||
return S_OK;
|
||||
// TODO: Add your implementation code here
|
||||
*pVal = name2;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Face::put_Face2Nam(BSTR newVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
name2 = newVal;
|
||||
return S_OK;
|
||||
// TODO: Add your implementation code here
|
||||
name2 = newVal;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Face::get_Face3Name(BSTR *pVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
*pVal = name3;
|
||||
return S_OK;
|
||||
// TODO: Add your implementation code here
|
||||
*pVal = name3;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Face::put_Face3Name(BSTR newVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
name3 = newVal;
|
||||
return S_OK;
|
||||
// TODO: Add your implementation code here
|
||||
name3 = newVal;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -15,31 +15,31 @@
|
||||
// Face
|
||||
|
||||
class Face :
|
||||
public IDispatchImpl<IFace1, &IID_IFace1, &LIBID_MULTIFACELib>,
|
||||
public IDispatchImpl<IFace2, &IID_IFace2, &LIBID_MULTIFACELib>,
|
||||
public IDispatchImpl<IFace3, &IID_IFace3, &LIBID_MULTIFACELib>,
|
||||
public ISupportErrorInfo,
|
||||
public CComObjectRoot,
|
||||
public CComCoClass<Face,&CLSID_Face>
|
||||
public IDispatchImpl<IFace1, &IID_IFace1, &LIBID_MULTIFACELib>,
|
||||
public IDispatchImpl<IFace2, &IID_IFace2, &LIBID_MULTIFACELib>,
|
||||
public IDispatchImpl<IFace3, &IID_IFace3, &LIBID_MULTIFACELib>,
|
||||
public ISupportErrorInfo,
|
||||
public CComObjectRoot,
|
||||
public CComCoClass<Face,&CLSID_Face>
|
||||
{
|
||||
// IFace1
|
||||
private:
|
||||
CComBSTR name1;
|
||||
|
||||
// IFace2
|
||||
CComBSTR name2;
|
||||
CComBSTR name2;
|
||||
|
||||
// IFace3
|
||||
CComBSTR name3;
|
||||
CComBSTR name3;
|
||||
|
||||
public:
|
||||
Face() {}
|
||||
Face() {}
|
||||
BEGIN_COM_MAP(Face)
|
||||
COM_INTERFACE_ENTRY2(IDispatch, IFace1)
|
||||
COM_INTERFACE_ENTRY(IFace1)
|
||||
COM_INTERFACE_ENTRY(IFace2)
|
||||
COM_INTERFACE_ENTRY(IFace3)
|
||||
COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
||||
COM_INTERFACE_ENTRY2(IDispatch, IFace1)
|
||||
COM_INTERFACE_ENTRY(IFace1)
|
||||
COM_INTERFACE_ENTRY(IFace2)
|
||||
COM_INTERFACE_ENTRY(IFace3)
|
||||
COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
||||
END_COM_MAP()
|
||||
//DECLARE_NOT_AGGREGATABLE(Face)
|
||||
// Remove the comment from the line above if you don't want your object to
|
||||
@@ -47,17 +47,17 @@ END_COM_MAP()
|
||||
|
||||
DECLARE_REGISTRY_RESOURCEID(IDR_Face)
|
||||
// ISupportsErrorInfo
|
||||
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
|
||||
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
STDMETHOD(get_Face3Name)(/*[out, retval]*/ BSTR *pVal);
|
||||
STDMETHOD(put_Face3Name)(/*[in]*/ BSTR newVal);
|
||||
STDMETHOD(get_Face2Nam)(/*[out, retval]*/ BSTR *pVal);
|
||||
STDMETHOD(put_Face2Nam)(/*[in]*/ BSTR newVal);
|
||||
STDMETHOD(get_Face1Name)(/*[out, retval]*/ BSTR *pVal);
|
||||
STDMETHOD(put_Face1Name)(/*[in]*/ BSTR newVal);
|
||||
STDMETHOD(get_Face3Name)(/*[out, retval]*/ BSTR *pVal);
|
||||
STDMETHOD(put_Face3Name)(/*[in]*/ BSTR newVal);
|
||||
STDMETHOD(get_Face2Nam)(/*[out, retval]*/ BSTR *pVal);
|
||||
STDMETHOD(put_Face2Nam)(/*[in]*/ BSTR newVal);
|
||||
STDMETHOD(get_Face1Name)(/*[out, retval]*/ BSTR *pVal);
|
||||
STDMETHOD(put_Face1Name)(/*[in]*/ BSTR newVal);
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_FACE_H__9BF24413_B2E0_11D4_A695_00104BFF3241__INCLUDED_)
|
||||
|
||||
@@ -40,19 +40,19 @@ extern "C"{
|
||||
#ifndef __IFace1_FWD_DEFINED__
|
||||
#define __IFace1_FWD_DEFINED__
|
||||
typedef interface IFace1 IFace1;
|
||||
#endif /* __IFace1_FWD_DEFINED__ */
|
||||
#endif /* __IFace1_FWD_DEFINED__ */
|
||||
|
||||
|
||||
#ifndef __IFace2_FWD_DEFINED__
|
||||
#define __IFace2_FWD_DEFINED__
|
||||
typedef interface IFace2 IFace2;
|
||||
#endif /* __IFace2_FWD_DEFINED__ */
|
||||
#endif /* __IFace2_FWD_DEFINED__ */
|
||||
|
||||
|
||||
#ifndef __IFace3_FWD_DEFINED__
|
||||
#define __IFace3_FWD_DEFINED__
|
||||
typedef interface IFace3 IFace3;
|
||||
#endif /* __IFace3_FWD_DEFINED__ */
|
||||
#endif /* __IFace3_FWD_DEFINED__ */
|
||||
|
||||
|
||||
#ifndef __Face_FWD_DEFINED__
|
||||
@@ -64,7 +64,7 @@ typedef class Face Face;
|
||||
typedef struct Face Face;
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __Face_FWD_DEFINED__ */
|
||||
#endif /* __Face_FWD_DEFINED__ */
|
||||
|
||||
|
||||
/* header files for imported files */
|
||||
@@ -97,7 +97,7 @@ EXTERN_C const IID IID_IFace1;
|
||||
|
||||
};
|
||||
|
||||
#else /* C style interface */
|
||||
#else /* C style interface */
|
||||
|
||||
typedef struct IFace1Vtbl
|
||||
{
|
||||
@@ -164,39 +164,39 @@ EXTERN_C const IID IID_IFace1;
|
||||
#ifdef COBJMACROS
|
||||
|
||||
|
||||
#define IFace1_QueryInterface(This,riid,ppvObject) \
|
||||
#define IFace1_QueryInterface(This,riid,ppvObject) \
|
||||
(This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
|
||||
|
||||
#define IFace1_AddRef(This) \
|
||||
#define IFace1_AddRef(This) \
|
||||
(This)->lpVtbl -> AddRef(This)
|
||||
|
||||
#define IFace1_Release(This) \
|
||||
#define IFace1_Release(This) \
|
||||
(This)->lpVtbl -> Release(This)
|
||||
|
||||
|
||||
#define IFace1_GetTypeInfoCount(This,pctinfo) \
|
||||
#define IFace1_GetTypeInfoCount(This,pctinfo) \
|
||||
(This)->lpVtbl -> GetTypeInfoCount(This,pctinfo)
|
||||
|
||||
#define IFace1_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
|
||||
#define IFace1_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
|
||||
(This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo)
|
||||
|
||||
#define IFace1_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
|
||||
#define IFace1_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
|
||||
(This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)
|
||||
|
||||
#define IFace1_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
|
||||
#define IFace1_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
|
||||
(This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)
|
||||
|
||||
|
||||
#define IFace1_get_Face1Name(This,pVal) \
|
||||
#define IFace1_get_Face1Name(This,pVal) \
|
||||
(This)->lpVtbl -> get_Face1Name(This,pVal)
|
||||
|
||||
#define IFace1_put_Face1Name(This,newVal) \
|
||||
#define IFace1_put_Face1Name(This,newVal) \
|
||||
(This)->lpVtbl -> put_Face1Name(This,newVal)
|
||||
|
||||
#endif /* COBJMACROS */
|
||||
|
||||
|
||||
#endif /* C style interface */
|
||||
#endif /* C style interface */
|
||||
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ void __RPC_STUB IFace1_put_Face1Name_Stub(
|
||||
|
||||
|
||||
|
||||
#endif /* __IFace1_INTERFACE_DEFINED__ */
|
||||
#endif /* __IFace1_INTERFACE_DEFINED__ */
|
||||
|
||||
|
||||
#ifndef __IFace2_INTERFACE_DEFINED__
|
||||
@@ -251,7 +251,7 @@ EXTERN_C const IID IID_IFace2;
|
||||
|
||||
};
|
||||
|
||||
#else /* C style interface */
|
||||
#else /* C style interface */
|
||||
|
||||
typedef struct IFace2Vtbl
|
||||
{
|
||||
@@ -318,39 +318,39 @@ EXTERN_C const IID IID_IFace2;
|
||||
#ifdef COBJMACROS
|
||||
|
||||
|
||||
#define IFace2_QueryInterface(This,riid,ppvObject) \
|
||||
#define IFace2_QueryInterface(This,riid,ppvObject) \
|
||||
(This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
|
||||
|
||||
#define IFace2_AddRef(This) \
|
||||
#define IFace2_AddRef(This) \
|
||||
(This)->lpVtbl -> AddRef(This)
|
||||
|
||||
#define IFace2_Release(This) \
|
||||
#define IFace2_Release(This) \
|
||||
(This)->lpVtbl -> Release(This)
|
||||
|
||||
|
||||
#define IFace2_GetTypeInfoCount(This,pctinfo) \
|
||||
#define IFace2_GetTypeInfoCount(This,pctinfo) \
|
||||
(This)->lpVtbl -> GetTypeInfoCount(This,pctinfo)
|
||||
|
||||
#define IFace2_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
|
||||
#define IFace2_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
|
||||
(This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo)
|
||||
|
||||
#define IFace2_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
|
||||
#define IFace2_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
|
||||
(This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)
|
||||
|
||||
#define IFace2_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
|
||||
#define IFace2_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
|
||||
(This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)
|
||||
|
||||
|
||||
#define IFace2_get_Face2Nam(This,pVal) \
|
||||
#define IFace2_get_Face2Nam(This,pVal) \
|
||||
(This)->lpVtbl -> get_Face2Nam(This,pVal)
|
||||
|
||||
#define IFace2_put_Face2Nam(This,newVal) \
|
||||
#define IFace2_put_Face2Nam(This,newVal) \
|
||||
(This)->lpVtbl -> put_Face2Nam(This,newVal)
|
||||
|
||||
#endif /* COBJMACROS */
|
||||
|
||||
|
||||
#endif /* C style interface */
|
||||
#endif /* C style interface */
|
||||
|
||||
|
||||
|
||||
@@ -379,7 +379,7 @@ void __RPC_STUB IFace2_put_Face2Nam_Stub(
|
||||
|
||||
|
||||
|
||||
#endif /* __IFace2_INTERFACE_DEFINED__ */
|
||||
#endif /* __IFace2_INTERFACE_DEFINED__ */
|
||||
|
||||
|
||||
#ifndef __IFace3_INTERFACE_DEFINED__
|
||||
@@ -405,7 +405,7 @@ EXTERN_C const IID IID_IFace3;
|
||||
|
||||
};
|
||||
|
||||
#else /* C style interface */
|
||||
#else /* C style interface */
|
||||
|
||||
typedef struct IFace3Vtbl
|
||||
{
|
||||
@@ -472,39 +472,39 @@ EXTERN_C const IID IID_IFace3;
|
||||
#ifdef COBJMACROS
|
||||
|
||||
|
||||
#define IFace3_QueryInterface(This,riid,ppvObject) \
|
||||
#define IFace3_QueryInterface(This,riid,ppvObject) \
|
||||
(This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
|
||||
|
||||
#define IFace3_AddRef(This) \
|
||||
#define IFace3_AddRef(This) \
|
||||
(This)->lpVtbl -> AddRef(This)
|
||||
|
||||
#define IFace3_Release(This) \
|
||||
#define IFace3_Release(This) \
|
||||
(This)->lpVtbl -> Release(This)
|
||||
|
||||
|
||||
#define IFace3_GetTypeInfoCount(This,pctinfo) \
|
||||
#define IFace3_GetTypeInfoCount(This,pctinfo) \
|
||||
(This)->lpVtbl -> GetTypeInfoCount(This,pctinfo)
|
||||
|
||||
#define IFace3_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
|
||||
#define IFace3_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
|
||||
(This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo)
|
||||
|
||||
#define IFace3_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
|
||||
#define IFace3_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
|
||||
(This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)
|
||||
|
||||
#define IFace3_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
|
||||
#define IFace3_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
|
||||
(This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)
|
||||
|
||||
|
||||
#define IFace3_get_Face3Name(This,pVal) \
|
||||
#define IFace3_get_Face3Name(This,pVal) \
|
||||
(This)->lpVtbl -> get_Face3Name(This,pVal)
|
||||
|
||||
#define IFace3_put_Face3Name(This,newVal) \
|
||||
#define IFace3_put_Face3Name(This,newVal) \
|
||||
(This)->lpVtbl -> put_Face3Name(This,newVal)
|
||||
|
||||
#endif /* COBJMACROS */
|
||||
|
||||
|
||||
#endif /* C style interface */
|
||||
#endif /* C style interface */
|
||||
|
||||
|
||||
|
||||
@@ -533,7 +533,7 @@ void __RPC_STUB IFace3_put_Face3Name_Stub(
|
||||
|
||||
|
||||
|
||||
#endif /* __IFace3_INTERFACE_DEFINED__ */
|
||||
#endif /* __IFace3_INTERFACE_DEFINED__ */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -346,117 +346,117 @@ static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =
|
||||
0,
|
||||
{
|
||||
|
||||
/* Procedure get_Face3Name */
|
||||
/* Procedure get_Face3Name */
|
||||
|
||||
|
||||
/* Procedure get_Face2Nam */
|
||||
/* Procedure get_Face2Nam */
|
||||
|
||||
|
||||
/* Procedure get_Face1Name */
|
||||
/* Procedure get_Face1Name */
|
||||
|
||||
0x33, /* FC_AUTO_HANDLE */
|
||||
0x6c, /* Old Flags: object, Oi2 */
|
||||
/* 2 */ NdrFcLong( 0x0 ), /* 0 */
|
||||
/* 6 */ NdrFcShort( 0x7 ), /* 7 */
|
||||
0x33, /* FC_AUTO_HANDLE */
|
||||
0x6c, /* Old Flags: object, Oi2 */
|
||||
/* 2 */ NdrFcLong( 0x0 ), /* 0 */
|
||||
/* 6 */ NdrFcShort( 0x7 ), /* 7 */
|
||||
#ifndef _ALPHA_
|
||||
/* 8 */ NdrFcShort( 0xc ), /* x86, MIPS, PPC Stack size/offset = 12 */
|
||||
/* 8 */ NdrFcShort( 0xc ), /* x86, MIPS, PPC Stack size/offset = 12 */
|
||||
#else
|
||||
NdrFcShort( 0x18 ), /* Alpha Stack size/offset = 24 */
|
||||
NdrFcShort( 0x18 ), /* Alpha Stack size/offset = 24 */
|
||||
#endif
|
||||
/* 10 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 12 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 14 */ 0x5, /* Oi2 Flags: srv must size, has return, */
|
||||
0x2, /* 2 */
|
||||
/* 10 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 12 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 14 */ 0x5, /* Oi2 Flags: srv must size, has return, */
|
||||
0x2, /* 2 */
|
||||
|
||||
/* Parameter pVal */
|
||||
/* Parameter pVal */
|
||||
|
||||
|
||||
/* Parameter pVal */
|
||||
/* Parameter pVal */
|
||||
|
||||
|
||||
/* Parameter pVal */
|
||||
/* Parameter pVal */
|
||||
|
||||
/* 16 */ NdrFcShort( 0x2113 ), /* Flags: must size, must free, out, simple ref, srv alloc size=8 */
|
||||
/* 16 */ NdrFcShort( 0x2113 ), /* Flags: must size, must free, out, simple ref, srv alloc size=8 */
|
||||
#ifndef _ALPHA_
|
||||
/* 18 */ NdrFcShort( 0x4 ), /* x86, MIPS, PPC Stack size/offset = 4 */
|
||||
/* 18 */ NdrFcShort( 0x4 ), /* x86, MIPS, PPC Stack size/offset = 4 */
|
||||
#else
|
||||
NdrFcShort( 0x8 ), /* Alpha Stack size/offset = 8 */
|
||||
NdrFcShort( 0x8 ), /* Alpha Stack size/offset = 8 */
|
||||
#endif
|
||||
/* 20 */ NdrFcShort( 0x1e ), /* Type Offset=30 */
|
||||
/* 20 */ NdrFcShort( 0x1e ), /* Type Offset=30 */
|
||||
|
||||
/* Return value */
|
||||
/* Return value */
|
||||
|
||||
|
||||
/* Return value */
|
||||
/* Return value */
|
||||
|
||||
|
||||
/* Return value */
|
||||
/* Return value */
|
||||
|
||||
/* 22 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
|
||||
/* 22 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
|
||||
#ifndef _ALPHA_
|
||||
/* 24 */ NdrFcShort( 0x8 ), /* x86, MIPS, PPC Stack size/offset = 8 */
|
||||
/* 24 */ NdrFcShort( 0x8 ), /* x86, MIPS, PPC Stack size/offset = 8 */
|
||||
#else
|
||||
NdrFcShort( 0x10 ), /* Alpha Stack size/offset = 16 */
|
||||
NdrFcShort( 0x10 ), /* Alpha Stack size/offset = 16 */
|
||||
#endif
|
||||
/* 26 */ 0x8, /* FC_LONG */
|
||||
0x0, /* 0 */
|
||||
/* 26 */ 0x8, /* FC_LONG */
|
||||
0x0, /* 0 */
|
||||
|
||||
/* Procedure put_Face3Name */
|
||||
/* Procedure put_Face3Name */
|
||||
|
||||
|
||||
/* Procedure put_Face2Nam */
|
||||
/* Procedure put_Face2Nam */
|
||||
|
||||
|
||||
/* Procedure put_Face1Name */
|
||||
/* Procedure put_Face1Name */
|
||||
|
||||
/* 28 */ 0x33, /* FC_AUTO_HANDLE */
|
||||
0x6c, /* Old Flags: object, Oi2 */
|
||||
/* 30 */ NdrFcLong( 0x0 ), /* 0 */
|
||||
/* 34 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 28 */ 0x33, /* FC_AUTO_HANDLE */
|
||||
0x6c, /* Old Flags: object, Oi2 */
|
||||
/* 30 */ NdrFcLong( 0x0 ), /* 0 */
|
||||
/* 34 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
#ifndef _ALPHA_
|
||||
/* 36 */ NdrFcShort( 0xc ), /* x86, MIPS, PPC Stack size/offset = 12 */
|
||||
/* 36 */ NdrFcShort( 0xc ), /* x86, MIPS, PPC Stack size/offset = 12 */
|
||||
#else
|
||||
NdrFcShort( 0x18 ), /* Alpha Stack size/offset = 24 */
|
||||
NdrFcShort( 0x18 ), /* Alpha Stack size/offset = 24 */
|
||||
#endif
|
||||
/* 38 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 40 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 42 */ 0x6, /* Oi2 Flags: clt must size, has return, */
|
||||
0x2, /* 2 */
|
||||
/* 38 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 40 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 42 */ 0x6, /* Oi2 Flags: clt must size, has return, */
|
||||
0x2, /* 2 */
|
||||
|
||||
/* Parameter newVal */
|
||||
/* Parameter newVal */
|
||||
|
||||
|
||||
/* Parameter newVal */
|
||||
/* Parameter newVal */
|
||||
|
||||
|
||||
/* Parameter newVal */
|
||||
/* Parameter newVal */
|
||||
|
||||
/* 44 */ NdrFcShort( 0x8b ), /* Flags: must size, must free, in, by val, */
|
||||
/* 44 */ NdrFcShort( 0x8b ), /* Flags: must size, must free, in, by val, */
|
||||
#ifndef _ALPHA_
|
||||
/* 46 */ NdrFcShort( 0x4 ), /* x86, MIPS, PPC Stack size/offset = 4 */
|
||||
/* 46 */ NdrFcShort( 0x4 ), /* x86, MIPS, PPC Stack size/offset = 4 */
|
||||
#else
|
||||
NdrFcShort( 0x8 ), /* Alpha Stack size/offset = 8 */
|
||||
NdrFcShort( 0x8 ), /* Alpha Stack size/offset = 8 */
|
||||
#endif
|
||||
/* 48 */ NdrFcShort( 0x2c ), /* Type Offset=44 */
|
||||
/* 48 */ NdrFcShort( 0x2c ), /* Type Offset=44 */
|
||||
|
||||
/* Return value */
|
||||
/* Return value */
|
||||
|
||||
|
||||
/* Return value */
|
||||
/* Return value */
|
||||
|
||||
|
||||
/* Return value */
|
||||
/* Return value */
|
||||
|
||||
/* 50 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
|
||||
/* 50 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
|
||||
#ifndef _ALPHA_
|
||||
/* 52 */ NdrFcShort( 0x8 ), /* x86, MIPS, PPC Stack size/offset = 8 */
|
||||
/* 52 */ NdrFcShort( 0x8 ), /* x86, MIPS, PPC Stack size/offset = 8 */
|
||||
#else
|
||||
NdrFcShort( 0x10 ), /* Alpha Stack size/offset = 16 */
|
||||
NdrFcShort( 0x10 ), /* Alpha Stack size/offset = 16 */
|
||||
#endif
|
||||
/* 54 */ 0x8, /* FC_LONG */
|
||||
0x0, /* 0 */
|
||||
/* 54 */ 0x8, /* FC_LONG */
|
||||
0x0, /* 0 */
|
||||
|
||||
0x0
|
||||
0x0
|
||||
}
|
||||
};
|
||||
|
||||
@@ -464,48 +464,48 @@ static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =
|
||||
{
|
||||
0,
|
||||
{
|
||||
NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 2 */
|
||||
0x11, 0x4, /* FC_RP [alloced_on_stack] */
|
||||
/* 4 */ NdrFcShort( 0x1a ), /* Offset= 26 (30) */
|
||||
/* 6 */
|
||||
0x13, 0x0, /* FC_OP */
|
||||
/* 8 */ NdrFcShort( 0xc ), /* Offset= 12 (20) */
|
||||
/* 10 */
|
||||
0x1b, /* FC_CARRAY */
|
||||
0x1, /* 1 */
|
||||
/* 12 */ NdrFcShort( 0x2 ), /* 2 */
|
||||
/* 14 */ 0x9, /* Corr desc: FC_ULONG */
|
||||
0x0, /* */
|
||||
/* 16 */ NdrFcShort( 0xfffc ), /* -4 */
|
||||
/* 18 */ 0x6, /* FC_SHORT */
|
||||
0x5b, /* FC_END */
|
||||
/* 20 */
|
||||
0x17, /* FC_CSTRUCT */
|
||||
0x3, /* 3 */
|
||||
/* 22 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 24 */ NdrFcShort( 0xfffffff2 ), /* Offset= -14 (10) */
|
||||
/* 26 */ 0x8, /* FC_LONG */
|
||||
0x8, /* FC_LONG */
|
||||
/* 28 */ 0x5c, /* FC_PAD */
|
||||
0x5b, /* FC_END */
|
||||
/* 30 */ 0xb4, /* FC_USER_MARSHAL */
|
||||
0x83, /* 131 */
|
||||
/* 32 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 34 */ NdrFcShort( 0x4 ), /* 4 */
|
||||
/* 36 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 38 */ NdrFcShort( 0xffffffe0 ), /* Offset= -32 (6) */
|
||||
/* 40 */
|
||||
0x12, 0x0, /* FC_UP */
|
||||
/* 42 */ NdrFcShort( 0xffffffea ), /* Offset= -22 (20) */
|
||||
/* 44 */ 0xb4, /* FC_USER_MARSHAL */
|
||||
0x83, /* 131 */
|
||||
/* 46 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 48 */ NdrFcShort( 0x4 ), /* 4 */
|
||||
/* 50 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 52 */ NdrFcShort( 0xfffffff4 ), /* Offset= -12 (40) */
|
||||
NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 2 */
|
||||
0x11, 0x4, /* FC_RP [alloced_on_stack] */
|
||||
/* 4 */ NdrFcShort( 0x1a ), /* Offset= 26 (30) */
|
||||
/* 6 */
|
||||
0x13, 0x0, /* FC_OP */
|
||||
/* 8 */ NdrFcShort( 0xc ), /* Offset= 12 (20) */
|
||||
/* 10 */
|
||||
0x1b, /* FC_CARRAY */
|
||||
0x1, /* 1 */
|
||||
/* 12 */ NdrFcShort( 0x2 ), /* 2 */
|
||||
/* 14 */ 0x9, /* Corr desc: FC_ULONG */
|
||||
0x0, /* */
|
||||
/* 16 */ NdrFcShort( 0xfffc ), /* -4 */
|
||||
/* 18 */ 0x6, /* FC_SHORT */
|
||||
0x5b, /* FC_END */
|
||||
/* 20 */
|
||||
0x17, /* FC_CSTRUCT */
|
||||
0x3, /* 3 */
|
||||
/* 22 */ NdrFcShort( 0x8 ), /* 8 */
|
||||
/* 24 */ NdrFcShort( 0xfffffff2 ), /* Offset= -14 (10) */
|
||||
/* 26 */ 0x8, /* FC_LONG */
|
||||
0x8, /* FC_LONG */
|
||||
/* 28 */ 0x5c, /* FC_PAD */
|
||||
0x5b, /* FC_END */
|
||||
/* 30 */ 0xb4, /* FC_USER_MARSHAL */
|
||||
0x83, /* 131 */
|
||||
/* 32 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 34 */ NdrFcShort( 0x4 ), /* 4 */
|
||||
/* 36 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 38 */ NdrFcShort( 0xffffffe0 ), /* Offset= -32 (6) */
|
||||
/* 40 */
|
||||
0x12, 0x0, /* FC_UP */
|
||||
/* 42 */ NdrFcShort( 0xffffffea ), /* Offset= -22 (20) */
|
||||
/* 44 */ 0xb4, /* FC_USER_MARSHAL */
|
||||
0x83, /* 131 */
|
||||
/* 46 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 48 */ NdrFcShort( 0x4 ), /* 4 */
|
||||
/* 50 */ NdrFcShort( 0x0 ), /* 0 */
|
||||
/* 52 */ NdrFcShort( 0xfffffff4 ), /* Offset= -12 (40) */
|
||||
|
||||
0x0
|
||||
0x0
|
||||
}
|
||||
};
|
||||
|
||||
@@ -542,7 +542,7 @@ const IID * _MultiFace_BaseIIDList[] =
|
||||
};
|
||||
|
||||
|
||||
#define _MultiFace_CHECK_IID(n) IID_GENERIC_CHECK_IID( _MultiFace, pIID, n)
|
||||
#define _MultiFace_CHECK_IID(n) IID_GENERIC_CHECK_IID( _MultiFace, pIID, n)
|
||||
|
||||
int __stdcall _MultiFace_IID_Lookup( const IID * pIID, int * pIndex )
|
||||
{
|
||||
|
||||
@@ -6,41 +6,41 @@ import com.jacob.com.Variant;
|
||||
|
||||
class MultiFaceTest {
|
||||
|
||||
/**
|
||||
* standard main() test program
|
||||
*
|
||||
* @param args
|
||||
* the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// this method has been deprecated as being unreliable.
|
||||
// shutdown should be done through other means
|
||||
// whoever wrote this example should explain what this was intended to
|
||||
// do
|
||||
// System.runFinalizersOnExit(true);
|
||||
/**
|
||||
* standard main() test program
|
||||
*
|
||||
* @param args
|
||||
* the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// this method has been deprecated as being unreliable.
|
||||
// shutdown should be done through other means
|
||||
// whoever wrote this example should explain what this was intended to
|
||||
// do
|
||||
// System.runFinalizersOnExit(true);
|
||||
|
||||
ActiveXComponent mf = new ActiveXComponent("MultiFace.Face");
|
||||
try {
|
||||
// I am now dealing with the default interface (IFace1)
|
||||
Dispatch.put(mf, "Face1Name", new Variant("Hello Face1"));
|
||||
System.out.println(Dispatch.get(mf, "Face1Name"));
|
||||
ActiveXComponent mf = new ActiveXComponent("MultiFace.Face");
|
||||
try {
|
||||
// I am now dealing with the default interface (IFace1)
|
||||
Dispatch.put(mf, "Face1Name", new Variant("Hello Face1"));
|
||||
System.out.println(Dispatch.get(mf, "Face1Name"));
|
||||
|
||||
// get to IFace2 through the IID
|
||||
Dispatch f2 = mf
|
||||
.QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace2
|
||||
Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2"));
|
||||
System.out.println(Dispatch.get(f2, "Face2Nam"));
|
||||
// get to IFace2 through the IID
|
||||
Dispatch f2 = mf
|
||||
.QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace2
|
||||
Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2"));
|
||||
System.out.println(Dispatch.get(f2, "Face2Nam"));
|
||||
|
||||
// get to IFace3 through the IID
|
||||
Dispatch f3 = mf
|
||||
.QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace3
|
||||
Dispatch.put(f3, "Face3Name", new Variant("Hello Face3"));
|
||||
System.out.println(Dispatch.get(f3, "Face3Name"));
|
||||
// get to IFace3 through the IID
|
||||
Dispatch f3 = mf
|
||||
.QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
|
||||
// I am now dealing with IFace3
|
||||
Dispatch.put(f3, "Face3Name", new Variant("Hello Face3"));
|
||||
System.out.println(Dispatch.get(f3, "Face3Name"));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,39 +14,39 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class ExcelDispatchTest {
|
||||
|
||||
/**
|
||||
* main run loop for test program
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ComThread.InitSTA();
|
||||
/**
|
||||
* main run loop for test program
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ComThread.InitSTA();
|
||||
|
||||
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
|
||||
try {
|
||||
System.out.println("version=" + xl.getProperty("Version"));
|
||||
System.out.println("version=" + Dispatch.get(xl, "Version"));
|
||||
Dispatch.put(xl, "Visible", new Variant(true));
|
||||
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||
Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A1" }, new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A2" }, new int[1]).toDispatch();
|
||||
Dispatch.put(a1, "Value", "123.456");
|
||||
Dispatch.put(a2, "Formula", "=A1*2");
|
||||
System.out.println("a1 from excel:" + Dispatch.get(a1, "Value"));
|
||||
System.out.println("a2 from excel:" + Dispatch.get(a2, "Value"));
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
xl.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
|
||||
try {
|
||||
System.out.println("version=" + xl.getProperty("Version"));
|
||||
System.out.println("version=" + Dispatch.get(xl, "Version"));
|
||||
Dispatch.put(xl, "Visible", new Variant(true));
|
||||
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||
Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A1" }, new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A2" }, new int[1]).toDispatch();
|
||||
Dispatch.put(a1, "Value", "123.456");
|
||||
Dispatch.put(a2, "Formula", "=A1*2");
|
||||
System.out.println("a1 from excel:" + Dispatch.get(a1, "Value"));
|
||||
System.out.println("a2 from excel:" + Dispatch.get(a2, "Value"));
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
xl.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,35 +14,35 @@ import com.jacob.com.Dispatch;
|
||||
*/
|
||||
public class VisioPrintTest {
|
||||
|
||||
/**
|
||||
* Runs the print ant lets the user say ok or cancel. Note the funky Visio
|
||||
* behavior if someone hits the cancel button
|
||||
*
|
||||
*/
|
||||
public void testPrintDialog() {
|
||||
ActiveXComponent oActiveX = new ActiveXComponent("Visio.Application");
|
||||
Dispatch oDocuments = oActiveX.getProperty("Documents").toDispatch();
|
||||
// create a blank document
|
||||
Dispatch.call(oDocuments, "Add", "");
|
||||
try {
|
||||
Dispatch.call(oActiveX, "DoCmd", new Integer(1010)).getInt();
|
||||
System.out.println("User hit the ok button.");
|
||||
} catch (ComFailException e) {
|
||||
System.out.println("User hit the cancel button: " + e);
|
||||
} finally {
|
||||
oActiveX.invoke("Quit");
|
||||
}
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Runs the print ant lets the user say ok or cancel. Note the funky Visio
|
||||
* behavior if someone hits the cancel button
|
||||
*
|
||||
*/
|
||||
public void testPrintDialog() {
|
||||
ActiveXComponent oActiveX = new ActiveXComponent("Visio.Application");
|
||||
Dispatch oDocuments = oActiveX.getProperty("Documents").toDispatch();
|
||||
// create a blank document
|
||||
Dispatch.call(oDocuments, "Add", "");
|
||||
try {
|
||||
Dispatch.call(oActiveX, "DoCmd", new Integer(1010)).getInt();
|
||||
System.out.println("User hit the ok button.");
|
||||
} catch (ComFailException e) {
|
||||
System.out.println("User hit the cancel button: " + e);
|
||||
} finally {
|
||||
oActiveX.invoke("Quit");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* quick main() to test this
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
VisioPrintTest testObject = new VisioPrintTest();
|
||||
testObject.testPrintDialog();
|
||||
}
|
||||
/**
|
||||
* quick main() to test this
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
VisioPrintTest testObject = new VisioPrintTest();
|
||||
testObject.testPrintDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,154 +18,154 @@ import com.jacob.com.Variant;
|
||||
* are sections that could be enhanced
|
||||
*/
|
||||
public class WordDocumentProperties {
|
||||
// Declare word object
|
||||
private ActiveXComponent objWord;
|
||||
// Declare word object
|
||||
private ActiveXComponent objWord;
|
||||
|
||||
// Declare Word Properties
|
||||
private Dispatch custDocprops;
|
||||
// Declare Word Properties
|
||||
private Dispatch custDocprops;
|
||||
|
||||
private Dispatch builtInDocProps;
|
||||
private Dispatch builtInDocProps;
|
||||
|
||||
// the doucments object is important in any real app but this demo doesn't
|
||||
// use it
|
||||
// private Dispatch documents;
|
||||
// the doucments object is important in any real app but this demo doesn't
|
||||
// use it
|
||||
// private Dispatch documents;
|
||||
|
||||
private Dispatch document;
|
||||
private Dispatch document;
|
||||
|
||||
private Dispatch wordObject;
|
||||
private Dispatch wordObject;
|
||||
|
||||
/**
|
||||
* Empty Constructor
|
||||
*
|
||||
*/
|
||||
public WordDocumentProperties() {
|
||||
}
|
||||
/**
|
||||
* Empty Constructor
|
||||
*
|
||||
*/
|
||||
public WordDocumentProperties() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a document
|
||||
*
|
||||
* @param filename
|
||||
*/
|
||||
public void open(String filename) {
|
||||
// Instantiate objWord
|
||||
objWord = new ActiveXComponent("Word.Application");
|
||||
/**
|
||||
* Opens a document
|
||||
*
|
||||
* @param filename
|
||||
*/
|
||||
public void open(String filename) {
|
||||
// Instantiate objWord
|
||||
objWord = new ActiveXComponent("Word.Application");
|
||||
|
||||
// Assign a local word object
|
||||
wordObject = objWord.getObject();
|
||||
// Assign a local word object
|
||||
wordObject = objWord.getObject();
|
||||
|
||||
// Create a Dispatch Parameter to hide the document that is opened
|
||||
Dispatch.put(wordObject, "Visible", new Variant(false));
|
||||
// Create a Dispatch Parameter to hide the document that is opened
|
||||
Dispatch.put(wordObject, "Visible", new Variant(false));
|
||||
|
||||
// Instantiate the Documents Property
|
||||
Dispatch documents = objWord.getProperty("Documents").toDispatch();
|
||||
// Instantiate the Documents Property
|
||||
Dispatch documents = objWord.getProperty("Documents").toDispatch();
|
||||
|
||||
// Open a word document, Current Active Document
|
||||
document = Dispatch.call(documents, "Open", filename).toDispatch();
|
||||
}
|
||||
// Open a word document, Current Active Document
|
||||
document = Dispatch.call(documents, "Open", filename).toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the VBA CustomDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectCustomDocumentProperitiesMode() {
|
||||
// Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
custDocprops = Dispatch.get(document, "CustomDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
/**
|
||||
* Creates an instance of the VBA CustomDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectCustomDocumentProperitiesMode() {
|
||||
// Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
custDocprops = Dispatch.get(document, "CustomDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the VBA BuiltInDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectBuiltinPropertiesMode() {
|
||||
// Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
/**
|
||||
* Creates an instance of the VBA BuiltInDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectBuiltinPropertiesMode() {
|
||||
// Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a document
|
||||
*
|
||||
*/
|
||||
public void close() {
|
||||
// Close object
|
||||
Dispatch.call(document, "Close");
|
||||
}
|
||||
/**
|
||||
* Closes a document
|
||||
*
|
||||
*/
|
||||
public void close() {
|
||||
// Close object
|
||||
Dispatch.call(document, "Close");
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Property Name is passed in
|
||||
*
|
||||
* @param cusPropName
|
||||
* @return String - Custom property value
|
||||
*/
|
||||
public String getCustomProperty(String cusPropName) {
|
||||
try {
|
||||
cusPropName = Dispatch.call(custDocprops, "Item", cusPropName)
|
||||
.toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
cusPropName = null;
|
||||
}
|
||||
/**
|
||||
* Custom Property Name is passed in
|
||||
*
|
||||
* @param cusPropName
|
||||
* @return String - Custom property value
|
||||
*/
|
||||
public String getCustomProperty(String cusPropName) {
|
||||
try {
|
||||
cusPropName = Dispatch.call(custDocprops, "Item", cusPropName)
|
||||
.toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
cusPropName = null;
|
||||
}
|
||||
|
||||
return cusPropName;
|
||||
}
|
||||
return cusPropName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Built In Property Name is passed in
|
||||
*
|
||||
* @param builtInPropName
|
||||
* @return String - Built in property value
|
||||
*/
|
||||
public String getBuiltInProperty(String builtInPropName) {
|
||||
try {
|
||||
builtInPropName = Dispatch.call(builtInDocProps, "Item",
|
||||
builtInPropName).toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
builtInPropName = null;
|
||||
}
|
||||
/**
|
||||
* Built In Property Name is passed in
|
||||
*
|
||||
* @param builtInPropName
|
||||
* @return String - Built in property value
|
||||
*/
|
||||
public String getBuiltInProperty(String builtInPropName) {
|
||||
try {
|
||||
builtInPropName = Dispatch.call(builtInDocProps, "Item",
|
||||
builtInPropName).toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
builtInPropName = null;
|
||||
}
|
||||
|
||||
return builtInPropName;
|
||||
}
|
||||
return builtInPropName;
|
||||
}
|
||||
|
||||
/**
|
||||
* simple main program that gets some properties and prints them out
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Instantiate the class
|
||||
WordDocumentProperties jacTest = new WordDocumentProperties();
|
||||
/**
|
||||
* simple main program that gets some properties and prints them out
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Instantiate the class
|
||||
WordDocumentProperties jacTest = new WordDocumentProperties();
|
||||
|
||||
// Open the word doc
|
||||
File doc = new File(
|
||||
"samples/com/jacob/samples/office/TestDocument.doc");
|
||||
jacTest.open(doc.getAbsolutePath());
|
||||
// Open the word doc
|
||||
File doc = new File(
|
||||
"samples/com/jacob/samples/office/TestDocument.doc");
|
||||
jacTest.open(doc.getAbsolutePath());
|
||||
|
||||
// Set Custom Properties
|
||||
jacTest.selectCustomDocumentProperitiesMode();
|
||||
// Set Custom Properties
|
||||
jacTest.selectCustomDocumentProperitiesMode();
|
||||
|
||||
// Set Built In Properties
|
||||
jacTest.selectBuiltinPropertiesMode();
|
||||
// Set Built In Properties
|
||||
jacTest.selectBuiltinPropertiesMode();
|
||||
|
||||
// Get custom Property Value
|
||||
String custValue = jacTest.getCustomProperty("Information Source");
|
||||
// Get custom Property Value
|
||||
String custValue = jacTest.getCustomProperty("Information Source");
|
||||
|
||||
// Get built in prroperty Property Value
|
||||
String builtInValue = jacTest.getBuiltInProperty("Author");
|
||||
// Get built in prroperty Property Value
|
||||
String builtInValue = jacTest.getBuiltInProperty("Author");
|
||||
|
||||
// Close Word Doc
|
||||
jacTest.close();
|
||||
// Close Word Doc
|
||||
jacTest.close();
|
||||
|
||||
// Output data
|
||||
System.out.println("Document Val One: " + custValue);
|
||||
System.out.println("Document Author: " + builtInValue);
|
||||
// Output data
|
||||
System.out.println("Document Val One: " + custValue);
|
||||
System.out.println("Document Author: " + builtInValue);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,67 +14,67 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class Outlook {
|
||||
|
||||
private static String pad(int i) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
private static String pad(int i) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while (sb.length() < i) {
|
||||
sb.append(' ');
|
||||
}
|
||||
while (sb.length() < i) {
|
||||
sb.append(' ');
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void recurseFolders(int iIndent, Dispatch o) {
|
||||
private static void recurseFolders(int iIndent, Dispatch o) {
|
||||
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
Dispatch oFolders = Dispatch.get(o, "Folders").toDispatch();
|
||||
// System.out.println("oFolders=" + oFolders);
|
||||
if (oFolders == null) {
|
||||
return;
|
||||
}
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
Dispatch oFolders = Dispatch.get(o, "Folders").toDispatch();
|
||||
// System.out.println("oFolders=" + oFolders);
|
||||
if (oFolders == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatch oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
|
||||
do {
|
||||
Object oFolderName = Dispatch.get(oFolder, "Name");
|
||||
if (null == oFolderName) {
|
||||
break;
|
||||
}
|
||||
Dispatch oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
|
||||
do {
|
||||
Object oFolderName = Dispatch.get(oFolder, "Name");
|
||||
if (null == oFolderName) {
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println(pad(iIndent) + oFolderName);
|
||||
recurseFolders(iIndent + 3, oFolder);
|
||||
System.out.println(pad(iIndent) + oFolderName);
|
||||
recurseFolders(iIndent + 3, oFolder);
|
||||
|
||||
oFolder = Dispatch.get(oFolders, "GetNext").toDispatch();
|
||||
} while (true);
|
||||
oFolder = Dispatch.get(oFolders, "GetNext").toDispatch();
|
||||
} while (true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* standard run loop
|
||||
*
|
||||
* @param asArgs
|
||||
* command line arguments
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String asArgs[]) throws Exception {
|
||||
System.out.println("Outlook: IN");
|
||||
/**
|
||||
* standard run loop
|
||||
*
|
||||
* @param asArgs
|
||||
* command line arguments
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String asArgs[]) throws Exception {
|
||||
System.out.println("Outlook: IN");
|
||||
|
||||
ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
|
||||
try {
|
||||
System.out.println("version=" + axOutlook.getProperty("Version"));
|
||||
ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
|
||||
try {
|
||||
System.out.println("version=" + axOutlook.getProperty("Version"));
|
||||
|
||||
Dispatch oOutlook = axOutlook.getObject();
|
||||
System.out.println("version=" + Dispatch.get(oOutlook, "Version"));
|
||||
Dispatch oOutlook = axOutlook.getObject();
|
||||
System.out.println("version=" + Dispatch.get(oOutlook, "Version"));
|
||||
|
||||
Dispatch oNameSpace = axOutlook.getProperty("Session").toDispatch();
|
||||
System.out.println("oNameSpace=" + oNameSpace);
|
||||
Dispatch oNameSpace = axOutlook.getProperty("Session").toDispatch();
|
||||
System.out.println("oNameSpace=" + oNameSpace);
|
||||
|
||||
recurseFolders(0, oNameSpace);
|
||||
recurseFolders(0, oNameSpace);
|
||||
|
||||
} finally {
|
||||
axOutlook.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
axOutlook.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,132 +21,132 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class DiskUtils {
|
||||
|
||||
/** formatters aren't thread safe but the sample only has one thread */
|
||||
private static DecimalFormat sizeFormatter = new DecimalFormat(
|
||||
"###,###,###,###");
|
||||
/** formatters aren't thread safe but the sample only has one thread */
|
||||
private static DecimalFormat sizeFormatter = new DecimalFormat(
|
||||
"###,###,###,###");
|
||||
|
||||
/** a pointer to the scripting file system object */
|
||||
private ActiveXComponent fileSystemApp = null;
|
||||
/** a pointer to the scripting file system object */
|
||||
private ActiveXComponent fileSystemApp = null;
|
||||
|
||||
/** the dispatch that points at the drive this DiskUtil operates against */
|
||||
private Dispatch myDrive = null;
|
||||
/** the dispatch that points at the drive this DiskUtil operates against */
|
||||
private Dispatch myDrive = null;
|
||||
|
||||
/**
|
||||
* Standard constructor
|
||||
*
|
||||
* @param drive
|
||||
* the drive to run the test against.
|
||||
*/
|
||||
public DiskUtils(String drive) {
|
||||
setUp(drive);
|
||||
}
|
||||
/**
|
||||
* Standard constructor
|
||||
*
|
||||
* @param drive
|
||||
* the drive to run the test against.
|
||||
*/
|
||||
public DiskUtils(String drive) {
|
||||
setUp(drive);
|
||||
}
|
||||
|
||||
/**
|
||||
* open the connection to the scripting object
|
||||
*
|
||||
* @param drive
|
||||
* the drive to run the test against
|
||||
*/
|
||||
public void setUp(String drive) {
|
||||
if (fileSystemApp == null) {
|
||||
ComThread.InitSTA();
|
||||
fileSystemApp = new ActiveXComponent("Scripting.FileSystemObject");
|
||||
myDrive = Dispatch.call(fileSystemApp, "GetDrive", drive)
|
||||
.toDispatch();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* open the connection to the scripting object
|
||||
*
|
||||
* @param drive
|
||||
* the drive to run the test against
|
||||
*/
|
||||
public void setUp(String drive) {
|
||||
if (fileSystemApp == null) {
|
||||
ComThread.InitSTA();
|
||||
fileSystemApp = new ActiveXComponent("Scripting.FileSystemObject");
|
||||
myDrive = Dispatch.call(fileSystemApp, "GetDrive", drive)
|
||||
.toDispatch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do any needed cleanup
|
||||
*/
|
||||
public void tearDown() {
|
||||
ComThread.Release();
|
||||
}
|
||||
/**
|
||||
* Do any needed cleanup
|
||||
*/
|
||||
public void tearDown() {
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience method
|
||||
*
|
||||
* @return driver serial number
|
||||
*/
|
||||
public int getSerialNumber() {
|
||||
return Dispatch.get(myDrive, "SerialNumber").getInt();
|
||||
}
|
||||
/**
|
||||
* convenience method
|
||||
*
|
||||
* @return driver serial number
|
||||
*/
|
||||
public int getSerialNumber() {
|
||||
return Dispatch.get(myDrive, "SerialNumber").getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. We go through these formatting hoops so we can make
|
||||
* the size string pretty. We wouldn't have to do that if we didn't mind
|
||||
* long strings with Exxx at the end or the fact that the value returned can
|
||||
* vary in size based on the size of the disk.
|
||||
*
|
||||
* @return driver total size of the disk
|
||||
*/
|
||||
public String getTotalSize() {
|
||||
Variant returnValue = Dispatch.get(myDrive, "TotalSize");
|
||||
if (returnValue.getvt() == Variant.VariantDouble) {
|
||||
return sizeFormatter.format(returnValue.getDouble());
|
||||
} else if (returnValue.getvt() == Variant.VariantInt) {
|
||||
return sizeFormatter.format(returnValue.getInt());
|
||||
} else {
|
||||
return "Don't know type: " + returnValue.getvt();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Convenience method. We go through these formatting hoops so we can make
|
||||
* the size string pretty. We wouldn't have to do that if we didn't mind
|
||||
* long strings with Exxx at the end or the fact that the value returned can
|
||||
* vary in size based on the size of the disk.
|
||||
*
|
||||
* @return driver total size of the disk
|
||||
*/
|
||||
public String getTotalSize() {
|
||||
Variant returnValue = Dispatch.get(myDrive, "TotalSize");
|
||||
if (returnValue.getvt() == Variant.VariantDouble) {
|
||||
return sizeFormatter.format(returnValue.getDouble());
|
||||
} else if (returnValue.getvt() == Variant.VariantInt) {
|
||||
return sizeFormatter.format(returnValue.getInt());
|
||||
} else {
|
||||
return "Don't know type: " + returnValue.getvt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. We wouldn't have to do that if we didn't mind long
|
||||
* strings with Exxx at the end or the fact that the value returned can vary
|
||||
* in size based on the size of the disk.
|
||||
*
|
||||
* @return driver free size of the disk
|
||||
*/
|
||||
public String getFreeSpace() {
|
||||
Variant returnValue = Dispatch.get(myDrive, "FreeSpace");
|
||||
if (returnValue.getvt() == Variant.VariantDouble) {
|
||||
return sizeFormatter.format(returnValue.getDouble());
|
||||
} else if (returnValue.getvt() == Variant.VariantInt) {
|
||||
return sizeFormatter.format(returnValue.getInt());
|
||||
} else {
|
||||
return "Don't know type: " + returnValue.getvt();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Convenience method. We wouldn't have to do that if we didn't mind long
|
||||
* strings with Exxx at the end or the fact that the value returned can vary
|
||||
* in size based on the size of the disk.
|
||||
*
|
||||
* @return driver free size of the disk
|
||||
*/
|
||||
public String getFreeSpace() {
|
||||
Variant returnValue = Dispatch.get(myDrive, "FreeSpace");
|
||||
if (returnValue.getvt() == Variant.VariantDouble) {
|
||||
return sizeFormatter.format(returnValue.getDouble());
|
||||
} else if (returnValue.getvt() == Variant.VariantInt) {
|
||||
return sizeFormatter.format(returnValue.getInt());
|
||||
} else {
|
||||
return "Don't know type: " + returnValue.getvt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return file system on the drive
|
||||
*/
|
||||
public String getFileSystemType() {
|
||||
// figure ot the actual variant type
|
||||
// Variant returnValue = Dispatch.get(myDrive, "FileSystem");
|
||||
// System.out.println(returnValue.getvt());
|
||||
return Dispatch.get(myDrive, "FileSystem").getString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return file system on the drive
|
||||
*/
|
||||
public String getFileSystemType() {
|
||||
// figure ot the actual variant type
|
||||
// Variant returnValue = Dispatch.get(myDrive, "FileSystem");
|
||||
// System.out.println(returnValue.getvt());
|
||||
return Dispatch.get(myDrive, "FileSystem").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return volume name
|
||||
*/
|
||||
public String getVolumeName() {
|
||||
return Dispatch.get(myDrive, "VolumeName").getString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return volume name
|
||||
*/
|
||||
public String getVolumeName() {
|
||||
return Dispatch.get(myDrive, "VolumeName").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple main program that creates a DiskUtils object and queries for the
|
||||
* C: drive
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// DiskUtils utilConnection = new DiskUtils("F");
|
||||
DiskUtils utilConnection = new DiskUtils("C");
|
||||
System.out.println("Disk serial number is: "
|
||||
+ utilConnection.getSerialNumber());
|
||||
System.out.println("FileSystem is: "
|
||||
+ utilConnection.getFileSystemType());
|
||||
System.out.println("Volume Name is: " + utilConnection.getVolumeName());
|
||||
System.out.println("Disk total size is: "
|
||||
+ utilConnection.getTotalSize());
|
||||
System.out.println("Disk free space is: "
|
||||
+ utilConnection.getFreeSpace());
|
||||
utilConnection.tearDown();
|
||||
}
|
||||
/**
|
||||
* Simple main program that creates a DiskUtils object and queries for the
|
||||
* C: drive
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// DiskUtils utilConnection = new DiskUtils("F");
|
||||
DiskUtils utilConnection = new DiskUtils("C");
|
||||
System.out.println("Disk serial number is: "
|
||||
+ utilConnection.getSerialNumber());
|
||||
System.out.println("FileSystem is: "
|
||||
+ utilConnection.getFileSystemType());
|
||||
System.out.println("Volume Name is: " + utilConnection.getVolumeName());
|
||||
System.out.println("Disk total size is: "
|
||||
+ utilConnection.getTotalSize());
|
||||
System.out.println("Disk free space is: "
|
||||
+ utilConnection.getFreeSpace());
|
||||
utilConnection.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,59 +17,59 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class SystemMonitor {
|
||||
|
||||
/**
|
||||
* example run loop method called by main()
|
||||
*/
|
||||
public void runMonitor() {
|
||||
/**
|
||||
* example run loop method called by main()
|
||||
*/
|
||||
public void runMonitor() {
|
||||
|
||||
ActiveXComponent wmi = null;
|
||||
wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
|
||||
// no connection parameters means to connect to the local machine
|
||||
Variant conRet = wmi.invoke("ConnectServer");
|
||||
// the author liked the ActiveXComponent api style over the Dispatch
|
||||
// style
|
||||
ActiveXComponent wmiconnect = new ActiveXComponent(conRet.toDispatch());
|
||||
ActiveXComponent wmi = null;
|
||||
wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
|
||||
// no connection parameters means to connect to the local machine
|
||||
Variant conRet = wmi.invoke("ConnectServer");
|
||||
// the author liked the ActiveXComponent api style over the Dispatch
|
||||
// style
|
||||
ActiveXComponent wmiconnect = new ActiveXComponent(conRet.toDispatch());
|
||||
|
||||
// the WMI supports a query language.
|
||||
String query = "select CategoryString, Message, TimeGenerated, User, Type "
|
||||
+ "from Win32_NtLogEvent "
|
||||
+ "where Logfile = 'Application' and TimeGenerated > '20070915000000.000000-***'";
|
||||
Variant vCollection = wmiconnect
|
||||
.invoke("ExecQuery", new Variant(query));
|
||||
// the WMI supports a query language.
|
||||
String query = "select CategoryString, Message, TimeGenerated, User, Type "
|
||||
+ "from Win32_NtLogEvent "
|
||||
+ "where Logfile = 'Application' and TimeGenerated > '20070915000000.000000-***'";
|
||||
Variant vCollection = wmiconnect
|
||||
.invoke("ExecQuery", new Variant(query));
|
||||
|
||||
EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
|
||||
EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
|
||||
|
||||
String resultString = "";
|
||||
Dispatch item = null;
|
||||
String resultString = "";
|
||||
Dispatch item = null;
|
||||
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
resultString = "";
|
||||
item = enumVariant.nextElement().toDispatch();
|
||||
String categoryString = Dispatch.call(item, "CategoryString")
|
||||
.toString();
|
||||
String messageString = Dispatch.call(item, "Message").toString();
|
||||
String timeGenerated = Dispatch.call(item, "TimeGenerated")
|
||||
.toString();
|
||||
String eventUser = Dispatch.call(item, "User").toString();
|
||||
String eventType = Dispatch.call(item, "Type").toString();
|
||||
resultString += "TimeGenerated: " + timeGenerated + " Category: "
|
||||
+ categoryString + " User: " + eventUser + " EventType: "
|
||||
+ eventType + " Message:" + messageString;
|
||||
System.out.println(resultString);
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
resultString = "";
|
||||
item = enumVariant.nextElement().toDispatch();
|
||||
String categoryString = Dispatch.call(item, "CategoryString")
|
||||
.toString();
|
||||
String messageString = Dispatch.call(item, "Message").toString();
|
||||
String timeGenerated = Dispatch.call(item, "TimeGenerated")
|
||||
.toString();
|
||||
String eventUser = Dispatch.call(item, "User").toString();
|
||||
String eventType = Dispatch.call(item, "Type").toString();
|
||||
resultString += "TimeGenerated: " + timeGenerated + " Category: "
|
||||
+ categoryString + " User: " + eventUser + " EventType: "
|
||||
+ eventType + " Message:" + messageString;
|
||||
System.out.println(resultString);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sample's main program
|
||||
*
|
||||
* @param args
|
||||
* command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SystemMonitor utilConnection = new SystemMonitor();
|
||||
utilConnection.runMonitor();
|
||||
}
|
||||
/**
|
||||
* sample's main program
|
||||
*
|
||||
* @param args
|
||||
* command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SystemMonitor utilConnection = new SystemMonitor();
|
||||
utilConnection.runMonitor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,106 +16,106 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class VisioApp extends ActiveXComponent {
|
||||
|
||||
/**
|
||||
* constructor that spins up Visio
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
public VisioApp() throws VisioException {
|
||||
super("Visio.Application");
|
||||
setVisible(false);
|
||||
}
|
||||
/**
|
||||
* constructor that spins up Visio
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
public VisioApp() throws VisioException {
|
||||
super("Visio.Application");
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a DispatchEvents object to register o as a listener
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
public void addEventListener(VisioEventListener o) {
|
||||
DispatchEvents events = new DispatchEvents(this, o);
|
||||
if (events == null) {
|
||||
System.out
|
||||
.println("You should never get null back when creating a DispatchEvents object");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* creates a DispatchEvents object to register o as a listener
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
public void addEventListener(VisioEventListener o) {
|
||||
DispatchEvents events = new DispatchEvents(this, o);
|
||||
if (events == null) {
|
||||
System.out
|
||||
.println("You should never get null back when creating a DispatchEvents object");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* opens the passed in file in Visio
|
||||
*
|
||||
* @param f
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void open(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent documents = new ActiveXComponent(getProperty(
|
||||
"Documents").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
documents.invoke("Open", args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* opens the passed in file in Visio
|
||||
*
|
||||
* @param f
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void open(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent documents = new ActiveXComponent(getProperty(
|
||||
"Documents").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
documents.invoke("Open", args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* tells Visio to save the drawing
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void save() throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActiveDocument").toDispatch());
|
||||
document.invoke("Save");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* tells Visio to save the drawing
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void save() throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActiveDocument").toDispatch());
|
||||
document.invoke("Save");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* terminates Visio
|
||||
*/
|
||||
public void quit() {
|
||||
System.out.println("Received quit()");
|
||||
// there can't be any open documents for this to work
|
||||
// you'll get a visio error if you don't close them
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActiveDocument").toDispatch());
|
||||
document.invoke("Close");
|
||||
invoke("Quit");
|
||||
}
|
||||
/**
|
||||
* terminates Visio
|
||||
*/
|
||||
public void quit() {
|
||||
System.out.println("Received quit()");
|
||||
// there can't be any open documents for this to work
|
||||
// you'll get a visio error if you don't close them
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActiveDocument").toDispatch());
|
||||
document.invoke("Close");
|
||||
invoke("Quit");
|
||||
}
|
||||
|
||||
/**
|
||||
* runs the Visio export command
|
||||
*
|
||||
* @param f
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void export(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActivePage").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
document.invoke("Export", args);
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* runs the Visio export command
|
||||
*
|
||||
* @param f
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void export(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActivePage").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
document.invoke("Export", args);
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* makes Visio visible so the user can watch
|
||||
*
|
||||
* @param b
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void setVisible(boolean b) throws VisioException {
|
||||
try {
|
||||
setProperty("Visible", new Variant(b));
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* makes Visio visible so the user can watch
|
||||
*
|
||||
* @param b
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void setVisible(boolean b) throws VisioException {
|
||||
try {
|
||||
setProperty("Visible", new Variant(b));
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,159 +22,159 @@ import java.io.OutputStream;
|
||||
*/
|
||||
public class VisioAppFacade {
|
||||
|
||||
private VisioApp app;
|
||||
private static VisioAppFacade instance;
|
||||
private VisioApp app;
|
||||
private static VisioAppFacade instance;
|
||||
|
||||
/** extension for image files */
|
||||
public static final String IMAGE_EXT = ".jpg";
|
||||
/** extension for visio files */
|
||||
public static final String VISIO_EXT = ".vsd";
|
||||
/** the buffer size when we want to read stuff in */
|
||||
public static final int BUFFER_SIZE = 2048;
|
||||
/** extension for image files */
|
||||
public static final String IMAGE_EXT = ".jpg";
|
||||
/** extension for visio files */
|
||||
public static final String VISIO_EXT = ".vsd";
|
||||
/** the buffer size when we want to read stuff in */
|
||||
public static final int BUFFER_SIZE = 2048;
|
||||
|
||||
/**
|
||||
* Wrapper around Visio
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
private VisioAppFacade() throws VisioException {
|
||||
this.app = new VisioApp();
|
||||
app.addEventListener(new VisioEventAdapter(app));
|
||||
}
|
||||
/**
|
||||
* Wrapper around Visio
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
private VisioAppFacade() throws VisioException {
|
||||
this.app = new VisioApp();
|
||||
app.addEventListener(new VisioEventAdapter(app));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the singleton instance of Visio
|
||||
* @throws VisioException
|
||||
*/
|
||||
public static VisioAppFacade getInstance() throws VisioException {
|
||||
if (instance == null) {
|
||||
instance = new VisioAppFacade();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* @return the singleton instance of Visio
|
||||
* @throws VisioException
|
||||
*/
|
||||
public static VisioAppFacade getInstance() throws VisioException {
|
||||
if (instance == null) {
|
||||
instance = new VisioAppFacade();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a preview in a temp file and returns the raw data.
|
||||
*
|
||||
* @param visioData
|
||||
* @return raw preview data
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(byte[] visioData) throws VisioException {
|
||||
byte[] preview;
|
||||
File tmpFile;
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
OutputStream out = new FileOutputStream(tmpFile);
|
||||
out.write(visioData);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
/**
|
||||
* creates a preview in a temp file and returns the raw data.
|
||||
*
|
||||
* @param visioData
|
||||
* @return raw preview data
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(byte[] visioData) throws VisioException {
|
||||
byte[] preview;
|
||||
File tmpFile;
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
OutputStream out = new FileOutputStream(tmpFile);
|
||||
out.write(visioData);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a preview from a saved file
|
||||
*
|
||||
* @param visioFile
|
||||
* @return raw preview data
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(File visioFile) throws VisioException {
|
||||
try {
|
||||
File imageFile;
|
||||
imageFile = getTempImageFile();
|
||||
app.open(visioFile);
|
||||
app.export(imageFile);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
FileInputStream fin = new FileInputStream(imageFile);
|
||||
copy(fin, bout);
|
||||
fin.close();
|
||||
imageFile.delete();
|
||||
bout.close();
|
||||
return bout.toByteArray();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* reads a preview from a saved file
|
||||
*
|
||||
* @param visioFile
|
||||
* @return raw preview data
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(File visioFile) throws VisioException {
|
||||
try {
|
||||
File imageFile;
|
||||
imageFile = getTempImageFile();
|
||||
app.open(visioFile);
|
||||
app.export(imageFile);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
FileInputStream fin = new FileInputStream(imageFile);
|
||||
copy(fin, bout);
|
||||
fin.close();
|
||||
imageFile.delete();
|
||||
bout.close();
|
||||
return bout.toByteArray();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
private void copy(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buff = new byte[BUFFER_SIZE];
|
||||
int read;
|
||||
do {
|
||||
read = in.read(buff);
|
||||
if (read > 0) {
|
||||
out.write(buff, 0, read);
|
||||
}
|
||||
} while (read > 0);
|
||||
}
|
||||
private void copy(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buff = new byte[BUFFER_SIZE];
|
||||
int read;
|
||||
do {
|
||||
read = in.read(buff);
|
||||
if (read > 0) {
|
||||
out.write(buff, 0, read);
|
||||
}
|
||||
} while (read > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a preview from an input stream
|
||||
*
|
||||
* @param in
|
||||
* @return byte contents of the preview stream
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(InputStream in) throws VisioException {
|
||||
byte[] preview;
|
||||
// byte[] buff = new byte[2048];
|
||||
// int read = 0;
|
||||
OutputStream out;
|
||||
File tmpFile;
|
||||
/**
|
||||
* creates a preview from an input stream
|
||||
*
|
||||
* @param in
|
||||
* @return byte contents of the preview stream
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(InputStream in) throws VisioException {
|
||||
byte[] preview;
|
||||
// byte[] buff = new byte[2048];
|
||||
// int read = 0;
|
||||
OutputStream out;
|
||||
File tmpFile;
|
||||
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
out = new FileOutputStream(tmpFile);
|
||||
copy(in, out);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
out = new FileOutputStream(tmpFile);
|
||||
copy(in, out);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* opens the file in Visio and makes the editor visible
|
||||
*
|
||||
* @param f
|
||||
* the reference to the Visio file to be opened
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void editDiagram(File f) throws VisioException {
|
||||
app.open(f);
|
||||
app.setVisible(true);
|
||||
}
|
||||
/**
|
||||
* opens the file in Visio and makes the editor visible
|
||||
*
|
||||
* @param f
|
||||
* the reference to the Visio file to be opened
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void editDiagram(File f) throws VisioException {
|
||||
app.open(f);
|
||||
app.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a temporary viso file
|
||||
*
|
||||
* @return created visio temporary file
|
||||
* @throws IOException
|
||||
*/
|
||||
private File getTempVisioFile() throws IOException {
|
||||
return File.createTempFile("java", VISIO_EXT);
|
||||
}
|
||||
/**
|
||||
* creates a temporary viso file
|
||||
*
|
||||
* @return created visio temporary file
|
||||
* @throws IOException
|
||||
*/
|
||||
private File getTempVisioFile() throws IOException {
|
||||
return File.createTempFile("java", VISIO_EXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a temporary image file and returns the File object
|
||||
*
|
||||
* @return the created image file object
|
||||
* @throws IOException
|
||||
*/
|
||||
private File getTempImageFile() throws IOException {
|
||||
return File.createTempFile("java", IMAGE_EXT);
|
||||
}
|
||||
/**
|
||||
* creates a temporary image file and returns the File object
|
||||
*
|
||||
* @return the created image file object
|
||||
* @throws IOException
|
||||
*/
|
||||
private File getTempImageFile() throws IOException {
|
||||
return File.createTempFile("java", IMAGE_EXT);
|
||||
}
|
||||
|
||||
/** exit visio */
|
||||
public void quit() {
|
||||
app.quit();
|
||||
instance = null;
|
||||
}
|
||||
/** exit visio */
|
||||
public void quit() {
|
||||
app.quit();
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,166 +32,166 @@ import com.jacob.com.ComThread;
|
||||
*/
|
||||
public class VisioDemo extends JFrame implements ActionListener, WindowListener {
|
||||
|
||||
/**
|
||||
* Totally dummy value to make Eclipse quit complaining
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* Totally dummy value to make Eclipse quit complaining
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
JButton chooseButton;
|
||||
JButton openButton;
|
||||
JPanel buttons;
|
||||
JButton chooseButton;
|
||||
JButton openButton;
|
||||
JPanel buttons;
|
||||
|
||||
ImageIcon theImage;
|
||||
JLabel theLabel; // the icon on the page is actually this button's icon
|
||||
ImageIcon theImage;
|
||||
JLabel theLabel; // the icon on the page is actually this button's icon
|
||||
|
||||
File selectedFile;
|
||||
/** everyone should get this through getVisio() */
|
||||
private VisioAppFacade visioProxy = null;
|
||||
File selectedFile;
|
||||
/** everyone should get this through getVisio() */
|
||||
private VisioAppFacade visioProxy = null;
|
||||
|
||||
// put this up here so it remembers where we were on the last choose
|
||||
JFileChooser chooser = null;
|
||||
// put this up here so it remembers where we were on the last choose
|
||||
JFileChooser chooser = null;
|
||||
|
||||
public class VisioFileFilter extends FileFilter {
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
} else {
|
||||
return (f.getName().toUpperCase().endsWith(".VSD"));
|
||||
}
|
||||
}
|
||||
public class VisioFileFilter extends FileFilter {
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
} else {
|
||||
return (f.getName().toUpperCase().endsWith(".VSD"));
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "Visio Drawings";
|
||||
}
|
||||
}
|
||||
public String getDescription() {
|
||||
return "Visio Drawings";
|
||||
}
|
||||
}
|
||||
|
||||
public VisioDemo() {
|
||||
super("Visio in Swing POC");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
buttons = new JPanel();
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
chooseButton = new JButton("Choose file to display");
|
||||
openButton = new JButton("Open file chosen file in Visio");
|
||||
chooseButton.addActionListener(this);
|
||||
openButton.addActionListener(this);
|
||||
buttons.add(chooseButton);
|
||||
buttons.add(openButton);
|
||||
getContentPane().add(buttons, BorderLayout.SOUTH);
|
||||
theLabel = new JLabel("");
|
||||
getContentPane().add(theLabel, BorderLayout.CENTER);
|
||||
addWindowListener(this);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setSize(640, 480);
|
||||
this.setVisible(true);
|
||||
}
|
||||
public VisioDemo() {
|
||||
super("Visio in Swing POC");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
buttons = new JPanel();
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
chooseButton = new JButton("Choose file to display");
|
||||
openButton = new JButton("Open file chosen file in Visio");
|
||||
chooseButton.addActionListener(this);
|
||||
openButton.addActionListener(this);
|
||||
buttons.add(chooseButton);
|
||||
buttons.add(openButton);
|
||||
getContentPane().add(buttons, BorderLayout.SOUTH);
|
||||
theLabel = new JLabel("");
|
||||
getContentPane().add(theLabel, BorderLayout.CENTER);
|
||||
addWindowListener(this);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setSize(640, 480);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
ComThread.InitSTA();
|
||||
VisioDemo poc = new VisioDemo();
|
||||
ComThread.Release();
|
||||
if (poc == null) {
|
||||
System.out.println("poc== null? That should never happen!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void main(String args[]) throws Exception {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
ComThread.InitSTA();
|
||||
VisioDemo poc = new VisioDemo();
|
||||
ComThread.Release();
|
||||
if (poc == null) {
|
||||
System.out.println("poc== null? That should never happen!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == chooseButton) {
|
||||
pickFile();
|
||||
} else if (e.getSource() == openButton) {
|
||||
try {
|
||||
openFile();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Awesome!");
|
||||
}
|
||||
}
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == chooseButton) {
|
||||
pickFile();
|
||||
} else if (e.getSource() == openButton) {
|
||||
try {
|
||||
openFile();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Awesome!");
|
||||
}
|
||||
}
|
||||
|
||||
private void pickFile() {
|
||||
try {
|
||||
chooser = new JFileChooser();
|
||||
// comment this out if you want it to always go to myDocuments
|
||||
chooser
|
||||
.setCurrentDirectory(new File(System
|
||||
.getProperty("user.dir")));
|
||||
chooser.setFileFilter(new VisioFileFilter());
|
||||
int returnVal = chooser.showOpenDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
selectedFile = chooser.getSelectedFile();
|
||||
showSelectedFilePreview();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void pickFile() {
|
||||
try {
|
||||
chooser = new JFileChooser();
|
||||
// comment this out if you want it to always go to myDocuments
|
||||
chooser
|
||||
.setCurrentDirectory(new File(System
|
||||
.getProperty("user.dir")));
|
||||
chooser.setFileFilter(new VisioFileFilter());
|
||||
int returnVal = chooser.showOpenDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
selectedFile = chooser.getSelectedFile();
|
||||
showSelectedFilePreview();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* use this private method instead of initializing on boot up so that
|
||||
* instance and all listeners are created in this thread (event thread)
|
||||
* rather than root thread
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private VisioAppFacade getVisio() {
|
||||
if (visioProxy == null) {
|
||||
try {
|
||||
visioProxy = VisioAppFacade.getInstance();
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
}
|
||||
return visioProxy;
|
||||
}
|
||||
/**
|
||||
* use this private method instead of initializing on boot up so that
|
||||
* instance and all listeners are created in this thread (event thread)
|
||||
* rather than root thread
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private VisioAppFacade getVisio() {
|
||||
if (visioProxy == null) {
|
||||
try {
|
||||
visioProxy = VisioAppFacade.getInstance();
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
}
|
||||
return visioProxy;
|
||||
}
|
||||
|
||||
private void showSelectedFilePreview() throws VisioException {
|
||||
if (selectedFile != null) {
|
||||
byte[] image = getVisio().createPreview(selectedFile);
|
||||
theImage = new ImageIcon(image);
|
||||
theLabel.setIcon(theImage);
|
||||
}
|
||||
}
|
||||
private void showSelectedFilePreview() throws VisioException {
|
||||
if (selectedFile != null) {
|
||||
byte[] image = getVisio().createPreview(selectedFile);
|
||||
theImage = new ImageIcon(image);
|
||||
theLabel.setIcon(theImage);
|
||||
}
|
||||
}
|
||||
|
||||
private void openFile() throws VisioException {
|
||||
try {
|
||||
getVisio().editDiagram(selectedFile);
|
||||
showSelectedFilePreview();
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
private void openFile() throws VisioException {
|
||||
try {
|
||||
getVisio().editDiagram(selectedFile);
|
||||
showSelectedFilePreview();
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent e) {
|
||||
}
|
||||
public void windowActivated(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.out.println("WINDOW CLOSED");
|
||||
if (visioProxy != null) {
|
||||
visioProxy.quit();
|
||||
}
|
||||
}
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.out.println("WINDOW CLOSED");
|
||||
if (visioProxy != null) {
|
||||
visioProxy.quit();
|
||||
}
|
||||
}
|
||||
|
||||
public void windowClosing(WindowEvent e) {
|
||||
}
|
||||
public void windowClosing(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
}
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
}
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowIconified(WindowEvent e) {
|
||||
System.out.println("Fooboo");
|
||||
}
|
||||
public void windowIconified(WindowEvent e) {
|
||||
System.out.println("Fooboo");
|
||||
}
|
||||
|
||||
public void windowOpened(WindowEvent e) {
|
||||
}
|
||||
public void windowOpened(WindowEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,56 +13,56 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public class VisioEventAdapter implements VisioEventListener {
|
||||
|
||||
VisioApp app = null;
|
||||
VisioApp app = null;
|
||||
|
||||
public VisioEventAdapter(VisioApp pApp) {
|
||||
app = pApp;
|
||||
System.out.println("Event listener constructed");
|
||||
}
|
||||
public VisioEventAdapter(VisioApp pApp) {
|
||||
app = pApp;
|
||||
System.out.println("Event listener constructed");
|
||||
}
|
||||
|
||||
public void BeforeQuit(Variant[] args) {
|
||||
}
|
||||
public void BeforeQuit(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentChanged(Variant[] args) {
|
||||
System.out.println("documentChanged()");
|
||||
}
|
||||
public void DocumentChanged(Variant[] args) {
|
||||
System.out.println("documentChanged()");
|
||||
}
|
||||
|
||||
public void DocumentCloseCanceled(Variant[] args) {
|
||||
}
|
||||
public void DocumentCloseCanceled(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentCreated(Variant[] args) {
|
||||
}
|
||||
public void DocumentCreated(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentOpened(Variant[] args) {
|
||||
System.out.println("DocumentOpened()");
|
||||
}
|
||||
public void DocumentOpened(Variant[] args) {
|
||||
System.out.println("DocumentOpened()");
|
||||
}
|
||||
|
||||
public void DocumentSaved(Variant[] args) {
|
||||
}
|
||||
public void DocumentSaved(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentSavedAs(Variant[] args) {
|
||||
}
|
||||
public void DocumentSavedAs(Variant[] args) {
|
||||
}
|
||||
|
||||
public Variant QueryCancelDocumentClose(Variant[] args) {
|
||||
System.out.println("QueryCancelDocumentClose()");
|
||||
return new Variant(false);
|
||||
}
|
||||
public Variant QueryCancelDocumentClose(Variant[] args) {
|
||||
System.out.println("QueryCancelDocumentClose()");
|
||||
return new Variant(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* we don't actually let it quit. We block it so that we don't have to
|
||||
* relaunch when we look at a new document
|
||||
*/
|
||||
public Variant QueryCancelQuit(Variant[] args) {
|
||||
// these may throw VisioException
|
||||
System.out
|
||||
.println("Saving document, hiding and telling visio not to quit");
|
||||
try {
|
||||
app.save();
|
||||
app.setVisible(false);
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
return new Variant(true);
|
||||
}
|
||||
/**
|
||||
* we don't actually let it quit. We block it so that we don't have to
|
||||
* relaunch when we look at a new document
|
||||
*/
|
||||
public Variant QueryCancelQuit(Variant[] args) {
|
||||
// these may throw VisioException
|
||||
System.out
|
||||
.println("Saving document, hiding and telling visio not to quit");
|
||||
try {
|
||||
app.save();
|
||||
app.setVisible(false);
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
return new Variant(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,19 +15,19 @@ import com.jacob.com.Variant;
|
||||
*/
|
||||
public interface VisioEventListener {
|
||||
|
||||
public void BeforeQuit(Variant[] args);
|
||||
public void BeforeQuit(Variant[] args);
|
||||
|
||||
public void DocumentChanged(Variant[] args);
|
||||
public void DocumentChanged(Variant[] args);
|
||||
|
||||
public void DocumentCloseCanceled(Variant[] args);
|
||||
public void DocumentCloseCanceled(Variant[] args);
|
||||
|
||||
public void DocumentCreated(Variant[] args);
|
||||
public void DocumentCreated(Variant[] args);
|
||||
|
||||
public void DocumentOpened(Variant[] args);
|
||||
public void DocumentOpened(Variant[] args);
|
||||
|
||||
public void DocumentSaved(Variant[] args);
|
||||
public void DocumentSaved(Variant[] args);
|
||||
|
||||
public void DocumentSavedAs(Variant[] args);
|
||||
public void DocumentSavedAs(Variant[] args);
|
||||
|
||||
public Variant QueryCancelQuit(Variant[] args);
|
||||
public Variant QueryCancelQuit(Variant[] args);
|
||||
}
|
||||
|
||||
@@ -10,16 +10,16 @@ package com.jacob.samples.visio;
|
||||
* blocks everywhere
|
||||
*/
|
||||
public class VisioException extends Exception {
|
||||
/**
|
||||
* Totally dummy value to make Eclipse quit complaining
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* Totally dummy value to make Eclipse quit complaining
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public VisioException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
public VisioException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public VisioException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public VisioException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -51,105 +51,105 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class ActiveXComponentFactoryTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* This test is supposed to verify we get multiple instances when we mean
|
||||
* too. Unfortunately, it requires that the runner of the test verify via
|
||||
* the "Windows Task Manager"
|
||||
*/
|
||||
public void testMultipleInstances() {
|
||||
ComThread.InitMTA();
|
||||
String mApplicationId = "Word.Application";
|
||||
ActiveXComponent instance1 = ActiveXComponent
|
||||
.createNewInstance(mApplicationId);
|
||||
ActiveXComponent instance2 = ActiveXComponent
|
||||
.createNewInstance(mApplicationId);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
instance1.invoke("Quit", new Variant[] {});
|
||||
instance2.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
/**
|
||||
* This test is supposed to verify we get multiple instances when we mean
|
||||
* too. Unfortunately, it requires that the runner of the test verify via
|
||||
* the "Windows Task Manager"
|
||||
*/
|
||||
public void testMultipleInstances() {
|
||||
ComThread.InitMTA();
|
||||
String mApplicationId = "Word.Application";
|
||||
ActiveXComponent instance1 = ActiveXComponent
|
||||
.createNewInstance(mApplicationId);
|
||||
ActiveXComponent instance2 = ActiveXComponent
|
||||
.createNewInstance(mApplicationId);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
instance1.invoke("Quit", new Variant[] {});
|
||||
instance2.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test is supposed to verify we can force multiple items through a
|
||||
* single running instance. It requires that a user physically watch the
|
||||
* "Windows Task Manager" to verify only one copy of MS Word is executing
|
||||
*/
|
||||
public void testOnlyOneInstance() {
|
||||
ComThread.InitMTA();
|
||||
String mApplicationId = "Word.Application";
|
||||
ActiveXComponent instance1 = new ActiveXComponent(mApplicationId);
|
||||
ActiveXComponent instance2 = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
assertNotNull(instance2);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
instance1.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
/**
|
||||
* This test is supposed to verify we can force multiple items through a
|
||||
* single running instance. It requires that a user physically watch the
|
||||
* "Windows Task Manager" to verify only one copy of MS Word is executing
|
||||
*/
|
||||
public void testOnlyOneInstance() {
|
||||
ComThread.InitMTA();
|
||||
String mApplicationId = "Word.Application";
|
||||
ActiveXComponent instance1 = new ActiveXComponent(mApplicationId);
|
||||
ActiveXComponent instance2 = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
assertNotNull(instance2);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
instance1.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that verifies function of the ActiveXComponentFactory
|
||||
*/
|
||||
public void testActiveXComponentFactory() {
|
||||
ComThread.InitSTA(true);
|
||||
try {
|
||||
System.out
|
||||
.println("This test only works if MS Word is NOT already running");
|
||||
String mApplicationId = "Word.Application";
|
||||
ActiveXComponent mTryConnectingFirst = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
if (mTryConnectingFirst != null) {
|
||||
mTryConnectingFirst.invoke("Quit", new Variant[] {});
|
||||
System.out
|
||||
.println("Was able to connect to MSWord when hadn't started it");
|
||||
} else {
|
||||
System.out
|
||||
.println("Correctly could not connect to running MSWord");
|
||||
}
|
||||
System.out.println(" Word Starting");
|
||||
ActiveXComponent mTryStartingSecond = ActiveXComponent
|
||||
.createNewInstance(mApplicationId);
|
||||
if (mTryStartingSecond == null) {
|
||||
System.out.println("was unable to start up MSWord ");
|
||||
} else {
|
||||
System.out.println("Correctly could start MSWord");
|
||||
}
|
||||
ActiveXComponent mTryConnectingThird = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
if (mTryConnectingThird == null) {
|
||||
fail("Was unable able to connect to MSWord after previous startup");
|
||||
} else {
|
||||
System.out.println("Stopping MSWord");
|
||||
// stop it so we can fail trying to connect to a running
|
||||
mTryConnectingThird.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
ActiveXComponent mTryConnectingFourth = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
if (mTryConnectingFourth != null) {
|
||||
mTryConnectingFourth.invoke("Quit", new Variant[] {});
|
||||
fail("Was able to connect to MSWord that was stopped");
|
||||
} else {
|
||||
System.out
|
||||
.println("Correctly could not connect to running MSWord");
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
} catch (ComException e) {
|
||||
e.printStackTrace();
|
||||
fail("Caught COM exception");
|
||||
} finally {
|
||||
// System.out.println("About to sleep for 2 seconds so we can bask
|
||||
// in the glory of this success");
|
||||
// Thread.sleep(2000);
|
||||
ComThread.Release();
|
||||
ComThread.quitMainSTA();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test that verifies function of the ActiveXComponentFactory
|
||||
*/
|
||||
public void testActiveXComponentFactory() {
|
||||
ComThread.InitSTA(true);
|
||||
try {
|
||||
System.out
|
||||
.println("This test only works if MS Word is NOT already running");
|
||||
String mApplicationId = "Word.Application";
|
||||
ActiveXComponent mTryConnectingFirst = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
if (mTryConnectingFirst != null) {
|
||||
mTryConnectingFirst.invoke("Quit", new Variant[] {});
|
||||
System.out
|
||||
.println("Was able to connect to MSWord when hadn't started it");
|
||||
} else {
|
||||
System.out
|
||||
.println("Correctly could not connect to running MSWord");
|
||||
}
|
||||
System.out.println(" Word Starting");
|
||||
ActiveXComponent mTryStartingSecond = ActiveXComponent
|
||||
.createNewInstance(mApplicationId);
|
||||
if (mTryStartingSecond == null) {
|
||||
System.out.println("was unable to start up MSWord ");
|
||||
} else {
|
||||
System.out.println("Correctly could start MSWord");
|
||||
}
|
||||
ActiveXComponent mTryConnectingThird = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
if (mTryConnectingThird == null) {
|
||||
fail("Was unable able to connect to MSWord after previous startup");
|
||||
} else {
|
||||
System.out.println("Stopping MSWord");
|
||||
// stop it so we can fail trying to connect to a running
|
||||
mTryConnectingThird.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
ActiveXComponent mTryConnectingFourth = ActiveXComponent
|
||||
.connectToActiveInstance(mApplicationId);
|
||||
if (mTryConnectingFourth != null) {
|
||||
mTryConnectingFourth.invoke("Quit", new Variant[] {});
|
||||
fail("Was able to connect to MSWord that was stopped");
|
||||
} else {
|
||||
System.out
|
||||
.println("Correctly could not connect to running MSWord");
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
} catch (ComException e) {
|
||||
e.printStackTrace();
|
||||
fail("Caught COM exception");
|
||||
} finally {
|
||||
// System.out.println("About to sleep for 2 seconds so we can bask
|
||||
// in the glory of this success");
|
||||
// Thread.sleep(2000);
|
||||
ComThread.Release();
|
||||
ComThread.quitMainSTA();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -53,39 +53,39 @@ import junit.framework.TestCase;
|
||||
|
||||
public class DateUtilitiesTest extends TestCase {
|
||||
|
||||
/**
|
||||
* verify date conversion to and from java
|
||||
*/
|
||||
public void testDateUtilities() {
|
||||
Date now = new Date();
|
||||
double comTimeForNow = DateUtilities.convertDateToWindowsTime(now);
|
||||
Date retrievedNow = DateUtilities
|
||||
.convertWindowsTimeToDate(comTimeForNow);
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("DateUtilities Date Test failed " + now + " != "
|
||||
+ retrievedNow);
|
||||
} else {
|
||||
System.out.println("DateUtilities Date Test passed");
|
||||
}
|
||||
/**
|
||||
* verify date conversion to and from java
|
||||
*/
|
||||
public void testDateUtilities() {
|
||||
Date now = new Date();
|
||||
double comTimeForNow = DateUtilities.convertDateToWindowsTime(now);
|
||||
Date retrievedNow = DateUtilities
|
||||
.convertWindowsTimeToDate(comTimeForNow);
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("DateUtilities Date Test failed " + now + " != "
|
||||
+ retrievedNow);
|
||||
} else {
|
||||
System.out.println("DateUtilities Date Test passed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the start of time is when we think it is.
|
||||
*/
|
||||
public void testBeginningOfWindowsTime() {
|
||||
// this is a magic time in the windows world
|
||||
Date beginningOfWindowsTime = new GregorianCalendar(1899,
|
||||
Calendar.DECEMBER, 30).getTime();
|
||||
double comTimeForBeginningOfWindowsTime = DateUtilities
|
||||
.convertDateToWindowsTime(beginningOfWindowsTime);
|
||||
if (comTimeForBeginningOfWindowsTime > 0) {
|
||||
fail("Beginning of windows time test failed "
|
||||
+ comTimeForBeginningOfWindowsTime);
|
||||
} else {
|
||||
System.out.println("Beginning of windows time test passed");
|
||||
}
|
||||
/**
|
||||
* Verify that the start of time is when we think it is.
|
||||
*/
|
||||
public void testBeginningOfWindowsTime() {
|
||||
// this is a magic time in the windows world
|
||||
Date beginningOfWindowsTime = new GregorianCalendar(1899,
|
||||
Calendar.DECEMBER, 30).getTime();
|
||||
double comTimeForBeginningOfWindowsTime = DateUtilities
|
||||
.convertDateToWindowsTime(beginningOfWindowsTime);
|
||||
if (comTimeForBeginningOfWindowsTime > 0) {
|
||||
fail("Beginning of windows time test failed "
|
||||
+ comTimeForBeginningOfWindowsTime);
|
||||
} else {
|
||||
System.out.println("Beginning of windows time test passed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -51,25 +51,25 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class DispatchNullProgramId extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Verify that dispatch constructors are protected from null program ids.
|
||||
*/
|
||||
public void testNullProgramId() {
|
||||
try {
|
||||
String nullParam = null;
|
||||
new Dispatch(nullParam);
|
||||
fail("the dispatch failed to protect itself from null program ids");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out
|
||||
.println("the dispatch protected itself from null program ids");
|
||||
}
|
||||
try {
|
||||
String nullParam = "";
|
||||
new Dispatch(nullParam);
|
||||
fail("the dispatch failed to protect itself from empty string program ids");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out
|
||||
.println("the dispatch protected itself from empty string program ids");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Verify that dispatch constructors are protected from null program ids.
|
||||
*/
|
||||
public void testNullProgramId() {
|
||||
try {
|
||||
String nullParam = null;
|
||||
new Dispatch(nullParam);
|
||||
fail("the dispatch failed to protect itself from null program ids");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out
|
||||
.println("the dispatch protected itself from null program ids");
|
||||
}
|
||||
try {
|
||||
String nullParam = "";
|
||||
new Dispatch(nullParam);
|
||||
fail("the dispatch failed to protect itself from empty string program ids");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out
|
||||
.println("the dispatch protected itself from empty string program ids");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -50,22 +50,22 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class DispatchTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Verify this detects word's exit
|
||||
*/
|
||||
public void testDispatchHasExited() {
|
||||
String pid = "Word.Application";
|
||||
ActiveXComponent axc = new ActiveXComponent(pid);
|
||||
assertEquals(0, Dispatch.hasExited(axc));
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
// should take some amount of time for Word to Quit so should = !exited
|
||||
assertEquals(0, Dispatch.hasExited(axc));
|
||||
try {
|
||||
// sleep some reasonable amount of time waiting for it to quit
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
fail("should not have been interrupted");
|
||||
}
|
||||
assertEquals(1, Dispatch.hasExited(axc));
|
||||
}
|
||||
/**
|
||||
* Verify this detects word's exit
|
||||
*/
|
||||
public void testDispatchHasExited() {
|
||||
String pid = "Word.Application";
|
||||
ActiveXComponent axc = new ActiveXComponent(pid);
|
||||
assertEquals(0, Dispatch.hasExited(axc));
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
// should take some amount of time for Word to Quit so should = !exited
|
||||
assertEquals(0, Dispatch.hasExited(axc));
|
||||
try {
|
||||
// sleep some reasonable amount of time waiting for it to quit
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
fail("should not have been interrupted");
|
||||
}
|
||||
assertEquals(1, Dispatch.hasExited(axc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -49,31 +49,31 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class DispatchValidDispatchTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* force an IllegalArgumentException to verify the utility method throws
|
||||
* correctly.
|
||||
*/
|
||||
public void testThrowIllegalArgumentException() {
|
||||
try {
|
||||
Dispatch.call(null, 0);
|
||||
fail("Failed to throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out.println("Caught correct IllegalArgumentException: "
|
||||
+ iae);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* force an IllegalArgumentException to verify the utility method throws
|
||||
* correctly.
|
||||
*/
|
||||
public void testThrowIllegalArgumentException() {
|
||||
try {
|
||||
Dispatch.call(null, 0);
|
||||
fail("Failed to throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.out.println("Caught correct IllegalArgumentException: "
|
||||
+ iae);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* force an IllegalStateException to verify the utility method throws
|
||||
* correctly.
|
||||
*/
|
||||
public void testThrowIllegalStateException() {
|
||||
try {
|
||||
Dispatch foo = new Dispatch();
|
||||
Dispatch.call(foo, 0);
|
||||
fail("Failed to throw IllegalStateException");
|
||||
} catch (IllegalStateException ise) {
|
||||
System.out.println("Caught correct IllegalStateException " + ise);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* force an IllegalStateException to verify the utility method throws
|
||||
* correctly.
|
||||
*/
|
||||
public void testThrowIllegalStateException() {
|
||||
try {
|
||||
Dispatch foo = new Dispatch();
|
||||
Dispatch.call(foo, 0);
|
||||
fail("Failed to throw IllegalStateException");
|
||||
} catch (IllegalStateException ise) {
|
||||
System.out.println("Caught correct IllegalStateException " + ise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -60,99 +60,99 @@ import com.jacob.test.BaseTestCase;
|
||||
*
|
||||
*/
|
||||
public class JacobDeadlockTest extends BaseTestCase {
|
||||
private static final long TIMEOUT = 5000l;
|
||||
private static final long TIMEOUT = 5000l;
|
||||
|
||||
/** Thread component */
|
||||
public static class TestThread extends Thread {
|
||||
private final int id;
|
||||
private final boolean initCOM;
|
||||
private final boolean writeOutput;
|
||||
/** Thread component */
|
||||
public static class TestThread extends Thread {
|
||||
private final int id;
|
||||
private final boolean initCOM;
|
||||
private final boolean writeOutput;
|
||||
|
||||
/**
|
||||
* constructor for ThestThread
|
||||
*
|
||||
* @param id
|
||||
* @param initCOM
|
||||
* @param writeOutput
|
||||
*
|
||||
*/
|
||||
public TestThread(int id, boolean initCOM, boolean writeOutput) {
|
||||
this.id = id;
|
||||
this.initCOM = initCOM;
|
||||
this.writeOutput = writeOutput;
|
||||
}
|
||||
/**
|
||||
* constructor for ThestThread
|
||||
*
|
||||
* @param id
|
||||
* @param initCOM
|
||||
* @param writeOutput
|
||||
*
|
||||
*/
|
||||
public TestThread(int id, boolean initCOM, boolean writeOutput) {
|
||||
this.id = id;
|
||||
this.initCOM = initCOM;
|
||||
this.writeOutput = writeOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
log("iteration " + i);
|
||||
if (initCOM) {
|
||||
log("Initializing COM thread");
|
||||
ComThread.InitMTA(false);
|
||||
}
|
||||
log("Creating JacobObject");
|
||||
new JacobObject();
|
||||
log("Releasing COM thread");
|
||||
ComThread.Release();
|
||||
}
|
||||
log("Exiting Java Thread");
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
log("iteration " + i);
|
||||
if (initCOM) {
|
||||
log("Initializing COM thread");
|
||||
ComThread.InitMTA(false);
|
||||
}
|
||||
log("Creating JacobObject");
|
||||
new JacobObject();
|
||||
log("Releasing COM thread");
|
||||
ComThread.Release();
|
||||
}
|
||||
log("Exiting Java Thread");
|
||||
}
|
||||
|
||||
private void log(String message) {
|
||||
if (writeOutput) {
|
||||
System.out.println(Thread.currentThread().getName()
|
||||
+ ": TestThread[" + id + "] " + " " + " - " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void log(String message) {
|
||||
if (writeOutput) {
|
||||
System.out.println(Thread.currentThread().getName()
|
||||
+ ": TestThread[" + id + "] " + " " + " - " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test shows that if ComThread.Init() is called explicitly, no problem
|
||||
* occurs.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testShowNoProblemIfCOMIsInitialized()
|
||||
throws InterruptedException {
|
||||
runTest(2, true, false);
|
||||
runTest(100, true, false);
|
||||
}
|
||||
/**
|
||||
* This test shows that if ComThread.Init() is called explicitly, no problem
|
||||
* occurs.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testShowNoProblemIfCOMIsInitialized()
|
||||
throws InterruptedException {
|
||||
runTest(2, true, false);
|
||||
runTest(100, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test shows that if only one thread is creating COM objects, no
|
||||
* problem occurs.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testShowNoProblemIfSingleThreaded() throws InterruptedException {
|
||||
runTest(1, false, false);
|
||||
runTest(1, true, false);
|
||||
}
|
||||
/**
|
||||
* This test shows that if only one thread is creating COM objects, no
|
||||
* problem occurs.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testShowNoProblemIfSingleThreaded() throws InterruptedException {
|
||||
runTest(1, false, false);
|
||||
runTest(1, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the test with two threads, which don't initialize the COM thread.
|
||||
*
|
||||
* This test will always fail.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testShowDeadlockProblem() throws InterruptedException {
|
||||
runTest(2, false, true);
|
||||
}
|
||||
/**
|
||||
* Runs the test with two threads, which don't initialize the COM thread.
|
||||
*
|
||||
* This test will always fail.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testShowDeadlockProblem() throws InterruptedException {
|
||||
runTest(2, false, true);
|
||||
}
|
||||
|
||||
private void runTest(int numberOfThreads, boolean initCOM,
|
||||
boolean writeOutput) throws InterruptedException {
|
||||
Thread[] threads = new Thread[numberOfThreads];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new TestThread(i, initCOM, writeOutput);
|
||||
threads[i].start();
|
||||
}
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i].join(TIMEOUT);
|
||||
if (threads[i].isAlive()) {
|
||||
fail("thread " + i + " failed to finish in " + TIMEOUT
|
||||
+ " milliseconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void runTest(int numberOfThreads, boolean initCOM,
|
||||
boolean writeOutput) throws InterruptedException {
|
||||
Thread[] threads = new Thread[numberOfThreads];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new TestThread(i, initCOM, writeOutput);
|
||||
threads[i].start();
|
||||
}
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i].join(TIMEOUT);
|
||||
if (threads[i].isAlive()) {
|
||||
fail("thread " + i + " failed to finish in " + TIMEOUT
|
||||
+ " milliseconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -49,12 +49,12 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class JacobObjectTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* verify the build version and date functions work correctly
|
||||
*/
|
||||
public void testBuildVersion() {
|
||||
System.out.println("build version is " + JacobReleaseInfo.getBuildVersion());
|
||||
System.out.println("build date is " + JacobReleaseInfo.getBuildDate());
|
||||
}
|
||||
/**
|
||||
* verify the build version and date functions work correctly
|
||||
*/
|
||||
public void testBuildVersion() {
|
||||
System.out.println("build version is " + JacobReleaseInfo.getBuildVersion());
|
||||
System.out.println("build date is " + JacobReleaseInfo.getBuildDate());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -52,109 +52,109 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class ROT2Test extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* runs a multi-threaded test
|
||||
*/
|
||||
public void testDoesNotBlowUp() {
|
||||
ROT2TestThread threads[] = new ROT2TestThread[4];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new ROT2TestThread("thread-" + i, 3000);
|
||||
}
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i].start();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* runs a multi-threaded test
|
||||
*/
|
||||
public void testDoesNotBlowUp() {
|
||||
ROT2TestThread threads[] = new ROT2TestThread[4];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new ROT2TestThread("thread-" + i, 3000);
|
||||
}
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i].start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This will try and exercise the thread support in the ROT
|
||||
*/
|
||||
/**
|
||||
* This will try and exercise the thread support in the ROT
|
||||
*/
|
||||
|
||||
public class ROT2TestThread extends Thread {
|
||||
private java.util.List<Variant> ThreadObjects;
|
||||
public class ROT2TestThread extends Thread {
|
||||
private java.util.List<Variant> ThreadObjects;
|
||||
|
||||
private int initialRunSize = 0;
|
||||
private int initialRunSize = 0;
|
||||
|
||||
/**
|
||||
* @param arg0
|
||||
* @param iStartCount
|
||||
* the initial number of threads
|
||||
*/
|
||||
public ROT2TestThread(String arg0, int iStartCount) {
|
||||
super(arg0);
|
||||
initialRunSize = iStartCount;
|
||||
/**
|
||||
* @param arg0
|
||||
* @param iStartCount
|
||||
* the initial number of threads
|
||||
*/
|
||||
public ROT2TestThread(String arg0, int iStartCount) {
|
||||
super(arg0);
|
||||
initialRunSize = iStartCount;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A semi-complex series of steps to put the ROT under stress. 1)
|
||||
* discard half the objects we've created 2) if size is greater than 1
|
||||
* but not a even number, add 1 new object 3) stop when size is 1.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run() {
|
||||
// something that keeps object references around
|
||||
// so the gc can't collect them
|
||||
// we need to create these in the thread so they end up in the right
|
||||
// ROT table
|
||||
ThreadObjects = new java.util.ArrayList<Variant>(initialRunSize);
|
||||
for (int i = 0; i < initialRunSize; i++) {
|
||||
// create the object
|
||||
Variant aNewVariant = new Variant(getName() + "_" + i);
|
||||
/**
|
||||
* A semi-complex series of steps to put the ROT under stress. 1)
|
||||
* discard half the objects we've created 2) if size is greater than 1
|
||||
* but not a even number, add 1 new object 3) stop when size is 1.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run() {
|
||||
// something that keeps object references around
|
||||
// so the gc can't collect them
|
||||
// we need to create these in the thread so they end up in the right
|
||||
// ROT table
|
||||
ThreadObjects = new java.util.ArrayList<Variant>(initialRunSize);
|
||||
for (int i = 0; i < initialRunSize; i++) {
|
||||
// create the object
|
||||
Variant aNewVariant = new Variant(getName() + "_" + i);
|
||||
|
||||
// create a hard reference to it
|
||||
ThreadObjects.add(aNewVariant);
|
||||
}
|
||||
// create a hard reference to it
|
||||
ThreadObjects.add(aNewVariant);
|
||||
}
|
||||
|
||||
while (ThreadObjects.size() > 1) {
|
||||
String message = "";
|
||||
message = getName() + " Workingset=" + ThreadObjects.size()
|
||||
+ " ROT: ";
|
||||
message += "(before additions and gc "
|
||||
+ ROT.getThreadObjects(false).size() + ")";
|
||||
// if there is an odd number of objects greater than 2
|
||||
if (ThreadObjects.size() > 2 && ThreadObjects.size() % 2 != 0) {
|
||||
// add a new object
|
||||
Variant aNewVariant = new Variant(getName() + "_*"
|
||||
+ ThreadObjects.size());
|
||||
ThreadObjects.add(aNewVariant);
|
||||
}
|
||||
// now iterate across all the objects in our list
|
||||
for (int i = ThreadObjects.size(); i > 0; i--) {
|
||||
// removing every other one?
|
||||
if (i % 2 == 0) {
|
||||
// remove the reference so gc can get it
|
||||
ThreadObjects.remove(i - 1);
|
||||
}
|
||||
while (ThreadObjects.size() > 1) {
|
||||
String message = "";
|
||||
message = getName() + " Workingset=" + ThreadObjects.size()
|
||||
+ " ROT: ";
|
||||
message += "(before additions and gc "
|
||||
+ ROT.getThreadObjects(false).size() + ")";
|
||||
// if there is an odd number of objects greater than 2
|
||||
if (ThreadObjects.size() > 2 && ThreadObjects.size() % 2 != 0) {
|
||||
// add a new object
|
||||
Variant aNewVariant = new Variant(getName() + "_*"
|
||||
+ ThreadObjects.size());
|
||||
ThreadObjects.add(aNewVariant);
|
||||
}
|
||||
// now iterate across all the objects in our list
|
||||
for (int i = ThreadObjects.size(); i > 0; i--) {
|
||||
// removing every other one?
|
||||
if (i % 2 == 0) {
|
||||
// remove the reference so gc can get it
|
||||
ThreadObjects.remove(i - 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// simulate the system under load and run the GC
|
||||
// should end up with weak references with no objects
|
||||
// attached
|
||||
Thread.sleep(9);
|
||||
} catch (InterruptedException e) {
|
||||
// the VM doesn't want us to sleep anymore,
|
||||
// so get back to work
|
||||
}
|
||||
message += " (before gc, after additions "
|
||||
+ ROT.getThreadObjects(false).size() + ")";
|
||||
System.gc();
|
||||
message += " (after System.gc "
|
||||
+ ROT.getThreadObjects(false).size() + ")";
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
try {
|
||||
// simulate the system under load and run the GC
|
||||
// should end up with weak references with no objects
|
||||
// attached
|
||||
Thread.sleep(9);
|
||||
} catch (InterruptedException e) {
|
||||
// the VM doesn't want us to sleep anymore,
|
||||
// so get back to work
|
||||
}
|
||||
message += " (before gc, after additions "
|
||||
+ ROT.getThreadObjects(false).size() + ")";
|
||||
System.gc();
|
||||
message += " (after System.gc "
|
||||
+ ROT.getThreadObjects(false).size() + ")";
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Another test would be to override this to always return the same
|
||||
* name. That would really screw the ROT!
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Another test would be to override this to always return the same
|
||||
* name. That would really screw the ROT!
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -54,126 +54,126 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class ROT3Test extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* runs a multi-threaded test
|
||||
*/
|
||||
public void testROTVersion3() {
|
||||
ROT3TestThread threads[] = new ROT3TestThread[4];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new ROT3TestThread("thread-" + i, 3000 + i * 10);
|
||||
}
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i].start();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* runs a multi-threaded test
|
||||
*/
|
||||
public void testROTVersion3() {
|
||||
ROT3TestThread threads[] = new ROT3TestThread[4];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i] = new ROT3TestThread("thread-" + i, 3000 + i * 10);
|
||||
}
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
threads[i].start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This will try and exercise the thread support in the ROT
|
||||
*/
|
||||
/**
|
||||
* This will try and exercise the thread support in the ROT
|
||||
*/
|
||||
|
||||
public class ROT3TestThread extends Thread {
|
||||
private java.util.List<Variant> variansCreatedInThisThread;
|
||||
public class ROT3TestThread extends Thread {
|
||||
private java.util.List<Variant> variansCreatedInThisThread;
|
||||
|
||||
private int initialRunSize = 0;
|
||||
private int initialRunSize = 0;
|
||||
|
||||
/**
|
||||
* @param arg0
|
||||
* @param iStartCount
|
||||
* the number of initial threads
|
||||
*/
|
||||
public ROT3TestThread(String arg0, int iStartCount) {
|
||||
super(arg0);
|
||||
initialRunSize = iStartCount;
|
||||
/**
|
||||
* @param arg0
|
||||
* @param iStartCount
|
||||
* the number of initial threads
|
||||
*/
|
||||
public ROT3TestThread(String arg0, int iStartCount) {
|
||||
super(arg0);
|
||||
initialRunSize = iStartCount;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A semi-complex series of steps to put the ROT under stress. 1)
|
||||
* discard half the objects we've created 2) if size is greater than 1
|
||||
* but not a even number, add 1 new object 3) stop when size is 1.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() {
|
||||
// something that keeps object references around
|
||||
// so the gc can't collect them
|
||||
// we need to create these in the thread so they end up in the right
|
||||
// ROT table
|
||||
variansCreatedInThisThread = new java.util.ArrayList<Variant>(
|
||||
initialRunSize);
|
||||
for (int i = 0; i < initialRunSize; i++) {
|
||||
// create the object
|
||||
Variant aNewVariant = new Variant(getName() + "_" + i);
|
||||
// create a hard reference to it
|
||||
variansCreatedInThisThread.add(aNewVariant);
|
||||
}
|
||||
/**
|
||||
* A semi-complex series of steps to put the ROT under stress. 1)
|
||||
* discard half the objects we've created 2) if size is greater than 1
|
||||
* but not a even number, add 1 new object 3) stop when size is 1.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() {
|
||||
// something that keeps object references around
|
||||
// so the gc can't collect them
|
||||
// we need to create these in the thread so they end up in the right
|
||||
// ROT table
|
||||
variansCreatedInThisThread = new java.util.ArrayList<Variant>(
|
||||
initialRunSize);
|
||||
for (int i = 0; i < initialRunSize; i++) {
|
||||
// create the object
|
||||
Variant aNewVariant = new Variant(getName() + "_" + i);
|
||||
// create a hard reference to it
|
||||
variansCreatedInThisThread.add(aNewVariant);
|
||||
}
|
||||
|
||||
while (variansCreatedInThisThread.size() > 1) {
|
||||
String message = "";
|
||||
message = getName() + " Workingset="
|
||||
+ variansCreatedInThisThread.size()
|
||||
+ " ROT threadObject hashCode: "
|
||||
+ ROT.getThreadObjects(true).hashCode();
|
||||
message += " size before mods and gc "
|
||||
+ ROT.getThreadObjects(true).size() + ")";
|
||||
// If there are more than 10 objects in our cache then add 1/4
|
||||
// of that again
|
||||
if (variansCreatedInThisThread.size() > 10) {
|
||||
message += " (adding) ";
|
||||
// add an additional 1/4 of our current number
|
||||
for (int i = 0; i < variansCreatedInThisThread.size() / 4; i++) {
|
||||
// add a new object
|
||||
Variant aNewVariant = new Variant(getName() + "_*"
|
||||
+ variansCreatedInThisThread.size());
|
||||
variansCreatedInThisThread.add(aNewVariant);
|
||||
}
|
||||
}
|
||||
// now iterate across 1/2 the objects in our list
|
||||
message += " (removing) ";
|
||||
for (int i = variansCreatedInThisThread.size(); i > 0; i--) {
|
||||
// removing every other one?
|
||||
if (i % 2 == 0) {
|
||||
// remove the reference so gc can get it
|
||||
if (!ROT.USE_AUTOMATIC_GARBAGE_COLLECTION) {
|
||||
// uses deprecated API to set up a special situation
|
||||
// because this is an ROT test
|
||||
ROT.removeObject(variansCreatedInThisThread
|
||||
.get(i - 1));
|
||||
}
|
||||
variansCreatedInThisThread.remove(i - 1);
|
||||
}
|
||||
while (variansCreatedInThisThread.size() > 1) {
|
||||
String message = "";
|
||||
message = getName() + " Workingset="
|
||||
+ variansCreatedInThisThread.size()
|
||||
+ " ROT threadObject hashCode: "
|
||||
+ ROT.getThreadObjects(true).hashCode();
|
||||
message += " size before mods and gc "
|
||||
+ ROT.getThreadObjects(true).size() + ")";
|
||||
// If there are more than 10 objects in our cache then add 1/4
|
||||
// of that again
|
||||
if (variansCreatedInThisThread.size() > 10) {
|
||||
message += " (adding) ";
|
||||
// add an additional 1/4 of our current number
|
||||
for (int i = 0; i < variansCreatedInThisThread.size() / 4; i++) {
|
||||
// add a new object
|
||||
Variant aNewVariant = new Variant(getName() + "_*"
|
||||
+ variansCreatedInThisThread.size());
|
||||
variansCreatedInThisThread.add(aNewVariant);
|
||||
}
|
||||
}
|
||||
// now iterate across 1/2 the objects in our list
|
||||
message += " (removing) ";
|
||||
for (int i = variansCreatedInThisThread.size(); i > 0; i--) {
|
||||
// removing every other one?
|
||||
if (i % 2 == 0) {
|
||||
// remove the reference so gc can get it
|
||||
if (!ROT.USE_AUTOMATIC_GARBAGE_COLLECTION) {
|
||||
// uses deprecated API to set up a special situation
|
||||
// because this is an ROT test
|
||||
ROT.removeObject(variansCreatedInThisThread
|
||||
.get(i - 1));
|
||||
}
|
||||
variansCreatedInThisThread.remove(i - 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
message += " (after mods " + ROT.getThreadObjects(true).size()
|
||||
+ ")";
|
||||
// comm
|
||||
if (!ROT.USE_AUTOMATIC_GARBAGE_COLLECTION) {
|
||||
ROT.clearObjects();
|
||||
}
|
||||
System.gc();
|
||||
try {
|
||||
// vain attempt at letting the gc run
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException ie) {
|
||||
message += " (after mods " + ROT.getThreadObjects(true).size()
|
||||
+ ")";
|
||||
// comm
|
||||
if (!ROT.USE_AUTOMATIC_GARBAGE_COLLECTION) {
|
||||
ROT.clearObjects();
|
||||
}
|
||||
System.gc();
|
||||
try {
|
||||
// vain attempt at letting the gc run
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException ie) {
|
||||
|
||||
}
|
||||
message += " (after gc " + ROT.getThreadObjects(true).size()
|
||||
+ ")";
|
||||
message += " Should see GC if debug turned on...";
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
message += " (after gc " + ROT.getThreadObjects(true).size()
|
||||
+ ")";
|
||||
message += " Should see GC if debug turned on...";
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Another test would be to overide this to always return the same name.
|
||||
* That would really screw the ROT!
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Another test would be to overide this to always return the same name.
|
||||
* That would really screw the ROT!
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -51,121 +51,121 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class ROTTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* verify the SystemProperty (classname).PutInROT functions as expected. A
|
||||
* value of false means instances of the class are not put in the ROT Any o
|
||||
* ther value means they are
|
||||
*/
|
||||
public void testDontFillROTSystemProperty() {
|
||||
debug("testDontFillROTSystemProperty: started");
|
||||
// Make sure the class is loaded before running any of the tests
|
||||
// class to load and any pre-defined Variants (FALSE and TRUE) to be
|
||||
// created immediately
|
||||
VariantViaEvent.class.getName();
|
||||
if (ROT.getThreadObjects(true).entrySet().size() < 1) {
|
||||
debug("Failure: ROT should have objects in it as soon as Variant class loaded.");
|
||||
}
|
||||
/**
|
||||
* verify the SystemProperty (classname).PutInROT functions as expected. A
|
||||
* value of false means instances of the class are not put in the ROT Any o
|
||||
* ther value means they are
|
||||
*/
|
||||
public void testDontFillROTSystemProperty() {
|
||||
debug("testDontFillROTSystemProperty: started");
|
||||
// Make sure the class is loaded before running any of the tests
|
||||
// class to load and any pre-defined Variants (FALSE and TRUE) to be
|
||||
// created immediately
|
||||
VariantViaEvent.class.getName();
|
||||
if (ROT.getThreadObjects(true).entrySet().size() < 1) {
|
||||
debug("Failure: ROT should have objects in it as soon as Variant class loaded.");
|
||||
}
|
||||
|
||||
System.setProperty(VariantViaEvent.class.getName()
|
||||
+ ROT.PUT_IN_ROT_SUFFIX, "false");
|
||||
int countPriorToTest = ROT.getThreadObjects(true).entrySet().size();
|
||||
new VariantViaEvent();
|
||||
int countAfterAddWithoutROT = ROT.getThreadObjects(true).entrySet()
|
||||
.size();
|
||||
if (countAfterAddWithoutROT != countPriorToTest) {
|
||||
debug("Failure: count prior: " + countPriorToTest
|
||||
+ " and count after without ROT was: "
|
||||
+ countAfterAddWithoutROT);
|
||||
}
|
||||
System.setProperty(VariantViaEvent.class.getName()
|
||||
+ ROT.PUT_IN_ROT_SUFFIX, "false");
|
||||
int countPriorToTest = ROT.getThreadObjects(true).entrySet().size();
|
||||
new VariantViaEvent();
|
||||
int countAfterAddWithoutROT = ROT.getThreadObjects(true).entrySet()
|
||||
.size();
|
||||
if (countAfterAddWithoutROT != countPriorToTest) {
|
||||
debug("Failure: count prior: " + countPriorToTest
|
||||
+ " and count after without ROT was: "
|
||||
+ countAfterAddWithoutROT);
|
||||
}
|
||||
|
||||
System.setProperty(VariantViaEvent.class.getName()
|
||||
+ ROT.PUT_IN_ROT_SUFFIX, "true");
|
||||
new VariantViaEvent();
|
||||
int countAfterAddWithROT = ROT.getThreadObjects(true).entrySet().size();
|
||||
if (countAfterAddWithROT != (countPriorToTest + 1)) {
|
||||
debug("Failure: count prior: " + countPriorToTest
|
||||
+ " and count after with ROT was: " + countAfterAddWithROT);
|
||||
}
|
||||
debug("testDontFillROTSystemProperty: completed");
|
||||
}
|
||||
System.setProperty(VariantViaEvent.class.getName()
|
||||
+ ROT.PUT_IN_ROT_SUFFIX, "true");
|
||||
new VariantViaEvent();
|
||||
int countAfterAddWithROT = ROT.getThreadObjects(true).entrySet().size();
|
||||
if (countAfterAddWithROT != (countPriorToTest + 1)) {
|
||||
debug("Failure: count prior: " + countPriorToTest
|
||||
+ " and count after with ROT was: " + countAfterAddWithROT);
|
||||
}
|
||||
debug("testDontFillROTSystemProperty: completed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs documentation. This test looks broken
|
||||
*
|
||||
*/
|
||||
public void testGCBehavior() {
|
||||
int sizeBeforeBuild = 0;
|
||||
int sizeAfterBuild = 0;
|
||||
int sizeBeforeGC = 0;
|
||||
int sizeAfterGC = 0;
|
||||
int loopSize = 10000;
|
||||
int sizeExpectedAfterBuild = 0;
|
||||
/**
|
||||
* Needs documentation. This test looks broken
|
||||
*
|
||||
*/
|
||||
public void testGCBehavior() {
|
||||
int sizeBeforeBuild = 0;
|
||||
int sizeAfterBuild = 0;
|
||||
int sizeBeforeGC = 0;
|
||||
int sizeAfterGC = 0;
|
||||
int loopSize = 10000;
|
||||
int sizeExpectedAfterBuild = 0;
|
||||
|
||||
debug("testGCBehavior: started");
|
||||
debug("creating 10,000 object sets");
|
||||
// cause classes to get loaded and any static instances to be created
|
||||
SafeArray.class.getName();
|
||||
Variant.class.getName();
|
||||
sizeBeforeBuild = ROT.getThreadObjects(false).size();
|
||||
sizeExpectedAfterBuild = ((loopSize * 3) + sizeBeforeBuild);
|
||||
for (int i = 0; i < loopSize; i++) {
|
||||
SafeArray a1 = new SafeArray(Variant.VariantVariant, 2);
|
||||
a1.setVariant(0, new Variant("foo"));
|
||||
a1.setVariant(1, new Variant("bar"));
|
||||
}
|
||||
sizeAfterBuild = ROT.getThreadObjects(false).size();
|
||||
if (sizeAfterBuild < sizeExpectedAfterBuild) {
|
||||
debug("Something got GC'd: " + sizeAfterBuild);
|
||||
} else if (sizeAfterBuild > sizeExpectedAfterBuild) {
|
||||
debug("More: " + sizeAfterBuild + " than expected: "
|
||||
+ sizeExpectedAfterBuild);
|
||||
} else {
|
||||
debug("They're all there");
|
||||
}
|
||||
// add more to the VM
|
||||
debug("Flooding Memory to force GC");
|
||||
for (int i = 0; i <= loopSize * 2; i++) {
|
||||
new String("this is just some text to see if we can force gc " + i);
|
||||
}
|
||||
// storage will hold weak references until the next JacobObject is
|
||||
// created
|
||||
System.gc();
|
||||
sizeBeforeGC = ROT.getThreadObjects(false).size();
|
||||
debug("Objects left after flood and gc but before adding a new object that clean's up weak references: "
|
||||
+ sizeBeforeGC);
|
||||
debug("Creating single object. This adds one and causes ROT to clean up GC'd");
|
||||
new JacobObject();
|
||||
sizeAfterGC = ROT.getThreadObjects(false).size();
|
||||
debug("Objects left after adding one (caused weak ref objects to be removed): "
|
||||
+ sizeAfterGC);
|
||||
new JacobObject();
|
||||
if (ROT.getThreadObjects(false).size() != sizeAfterGC + 1) {
|
||||
debug("Unexpected number of objects after adding only one more "
|
||||
+ ROT.getThreadObjects(false).size());
|
||||
} else {
|
||||
debug("Found number expected after adding one more "
|
||||
+ (sizeAfterGC + 1));
|
||||
}
|
||||
ROT.clearObjects();
|
||||
if (ROT.getThreadObjects(false) == null) {
|
||||
debug("ROT pool was destroyed as expected after clearObjects called.");
|
||||
} else {
|
||||
debug("ROT pool for thread still exists when it shouldn't");
|
||||
}
|
||||
debug("testGCBehavior: started");
|
||||
debug("creating 10,000 object sets");
|
||||
// cause classes to get loaded and any static instances to be created
|
||||
SafeArray.class.getName();
|
||||
Variant.class.getName();
|
||||
sizeBeforeBuild = ROT.getThreadObjects(false).size();
|
||||
sizeExpectedAfterBuild = ((loopSize * 3) + sizeBeforeBuild);
|
||||
for (int i = 0; i < loopSize; i++) {
|
||||
SafeArray a1 = new SafeArray(Variant.VariantVariant, 2);
|
||||
a1.setVariant(0, new Variant("foo"));
|
||||
a1.setVariant(1, new Variant("bar"));
|
||||
}
|
||||
sizeAfterBuild = ROT.getThreadObjects(false).size();
|
||||
if (sizeAfterBuild < sizeExpectedAfterBuild) {
|
||||
debug("Something got GC'd: " + sizeAfterBuild);
|
||||
} else if (sizeAfterBuild > sizeExpectedAfterBuild) {
|
||||
debug("More: " + sizeAfterBuild + " than expected: "
|
||||
+ sizeExpectedAfterBuild);
|
||||
} else {
|
||||
debug("They're all there");
|
||||
}
|
||||
// add more to the VM
|
||||
debug("Flooding Memory to force GC");
|
||||
for (int i = 0; i <= loopSize * 2; i++) {
|
||||
new String("this is just some text to see if we can force gc " + i);
|
||||
}
|
||||
// storage will hold weak references until the next JacobObject is
|
||||
// created
|
||||
System.gc();
|
||||
sizeBeforeGC = ROT.getThreadObjects(false).size();
|
||||
debug("Objects left after flood and gc but before adding a new object that clean's up weak references: "
|
||||
+ sizeBeforeGC);
|
||||
debug("Creating single object. This adds one and causes ROT to clean up GC'd");
|
||||
new JacobObject();
|
||||
sizeAfterGC = ROT.getThreadObjects(false).size();
|
||||
debug("Objects left after adding one (caused weak ref objects to be removed): "
|
||||
+ sizeAfterGC);
|
||||
new JacobObject();
|
||||
if (ROT.getThreadObjects(false).size() != sizeAfterGC + 1) {
|
||||
debug("Unexpected number of objects after adding only one more "
|
||||
+ ROT.getThreadObjects(false).size());
|
||||
} else {
|
||||
debug("Found number expected after adding one more "
|
||||
+ (sizeAfterGC + 1));
|
||||
}
|
||||
ROT.clearObjects();
|
||||
if (ROT.getThreadObjects(false) == null) {
|
||||
debug("ROT pool was destroyed as expected after clearObjects called.");
|
||||
} else {
|
||||
debug("ROT pool for thread still exists when it shouldn't");
|
||||
}
|
||||
|
||||
// ========= part two ================================
|
||||
debug("Verifying doesn't blow up with double release");
|
||||
for (int i = 0; i <= 10000; i++) {
|
||||
new JacobObject();
|
||||
}
|
||||
// force safeRelease call on all objects
|
||||
ROT.clearObjects();
|
||||
// now force the gc to go collect them, running safeRelease again
|
||||
System.gc();
|
||||
debug("testGCBehavior: finished");
|
||||
}
|
||||
// ========= part two ================================
|
||||
debug("Verifying doesn't blow up with double release");
|
||||
for (int i = 0; i <= 10000; i++) {
|
||||
new JacobObject();
|
||||
}
|
||||
// force safeRelease call on all objects
|
||||
ROT.clearObjects();
|
||||
// now force the gc to go collect them, running safeRelease again
|
||||
System.gc();
|
||||
debug("testGCBehavior: finished");
|
||||
}
|
||||
|
||||
private static void debug(String message) {
|
||||
System.out.println(Thread.currentThread().getName() + " " + message);
|
||||
}
|
||||
private static void debug(String message) {
|
||||
System.out.println(Thread.currentThread().getName() + " " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -51,58 +51,58 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class VariantDateTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* verify the conversion of Variants into java dates
|
||||
*/
|
||||
public void testVariantDate() {
|
||||
Date now = new Date();
|
||||
Variant holder = new Variant();
|
||||
holder.putDate(now);
|
||||
Date retrievedNow = holder.getJavaDate();
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("Variant Date Test failed " + now + " != " + retrievedNow);
|
||||
} else {
|
||||
System.out.println("Variant Date Test passed");
|
||||
}
|
||||
/**
|
||||
* verify the conversion of Variants into java dates
|
||||
*/
|
||||
public void testVariantDate() {
|
||||
Date now = new Date();
|
||||
Variant holder = new Variant();
|
||||
holder.putDate(now);
|
||||
Date retrievedNow = holder.getJavaDate();
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("Variant Date Test failed " + now + " != " + retrievedNow);
|
||||
} else {
|
||||
System.out.println("Variant Date Test passed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* verify that the Variant constructor accepts Java dates and converts them
|
||||
* correctly
|
||||
*/
|
||||
public void testVariantDateToJavaObject() {
|
||||
Date now = new Date();
|
||||
Variant holder = new Variant(now);
|
||||
for (int i = 0; i < 30000; i++) {
|
||||
Variant dateVariant = new Variant(now);
|
||||
Date retrievedNow = holder.getJavaDate();
|
||||
retrievedNow = dateVariant.getJavaDate();
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("Variant Date Test (1) failed " + now + " != "
|
||||
+ retrievedNow);
|
||||
} else {
|
||||
// System.out.println("Variant Date Test (1) passed");
|
||||
}
|
||||
// verify auto typecasting works
|
||||
retrievedNow = (Date) dateVariant.toJavaObject();
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("Variant Date Test (2) failed " + now + " != "
|
||||
+ retrievedNow);
|
||||
} else {
|
||||
// System.out.println("Variant Date Test (2) passed
|
||||
// "+retrievedNow);
|
||||
}
|
||||
/**
|
||||
* verify that the Variant constructor accepts Java dates and converts them
|
||||
* correctly
|
||||
*/
|
||||
public void testVariantDateToJavaObject() {
|
||||
Date now = new Date();
|
||||
Variant holder = new Variant(now);
|
||||
for (int i = 0; i < 30000; i++) {
|
||||
Variant dateVariant = new Variant(now);
|
||||
Date retrievedNow = holder.getJavaDate();
|
||||
retrievedNow = dateVariant.getJavaDate();
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("Variant Date Test (1) failed " + now + " != "
|
||||
+ retrievedNow);
|
||||
} else {
|
||||
// System.out.println("Variant Date Test (1) passed");
|
||||
}
|
||||
// verify auto typecasting works
|
||||
retrievedNow = (Date) dateVariant.toJavaObject();
|
||||
if (!now.equals(retrievedNow)) {
|
||||
fail("Variant Date Test (2) failed " + now + " != "
|
||||
+ retrievedNow);
|
||||
} else {
|
||||
// System.out.println("Variant Date Test (2) passed
|
||||
// "+retrievedNow);
|
||||
}
|
||||
|
||||
Variant intVariant = new Variant(4);
|
||||
Object variantReturn = intVariant.toJavaObject();
|
||||
// degenerate test to make sure date isn't always returned
|
||||
if (variantReturn instanceof Date) {
|
||||
System.out.println("int variant returned date");
|
||||
}
|
||||
}
|
||||
System.out.print("Test finished. All tests passed.");
|
||||
Variant intVariant = new Variant(4);
|
||||
Object variantReturn = intVariant.toJavaObject();
|
||||
// degenerate test to make sure date isn't always returned
|
||||
if (variantReturn instanceof Date) {
|
||||
System.out.println("int variant returned date");
|
||||
}
|
||||
}
|
||||
System.out.print("Test finished. All tests passed.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.com;
|
||||
|
||||
@@ -49,122 +49,122 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class VariantUtilitiesTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* verifies our unpacking stuff
|
||||
*/
|
||||
public void testObjectsToVariants() {
|
||||
Object testArray[] = new Object[] { Integer.valueOf(1),
|
||||
Integer.valueOf(2) };
|
||||
Variant resultArray[] = VariantUtilities.objectsToVariants(testArray);
|
||||
assertEquals(2, resultArray.length);
|
||||
/**
|
||||
* verifies our unpacking stuff
|
||||
*/
|
||||
public void testObjectsToVariants() {
|
||||
Object testArray[] = new Object[] { Integer.valueOf(1),
|
||||
Integer.valueOf(2) };
|
||||
Variant resultArray[] = VariantUtilities.objectsToVariants(testArray);
|
||||
assertEquals(2, resultArray.length);
|
||||
|
||||
Variant resultArray2[] = VariantUtilities
|
||||
.objectsToVariants(resultArray);
|
||||
assertEquals(2, resultArray2.length);
|
||||
assertSame(resultArray[0], resultArray2[0]);
|
||||
assertSame(resultArray[1], resultArray2[1]);
|
||||
}
|
||||
Variant resultArray2[] = VariantUtilities
|
||||
.objectsToVariants(resultArray);
|
||||
assertEquals(2, resultArray2.length);
|
||||
assertSame(resultArray[0], resultArray2[0]);
|
||||
assertSame(resultArray[1], resultArray2[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test nested arrays
|
||||
*/
|
||||
public void testObjectsToVariantNestedArray() {
|
||||
Object testArray[] = new Object[] { Integer.valueOf(1),
|
||||
Integer.valueOf(2) };
|
||||
Object testArrayOuter[] = new Object[] { testArray };
|
||||
Variant resultArray[] = VariantUtilities
|
||||
.objectsToVariants(testArrayOuter);
|
||||
// should be a SafeArray
|
||||
assertEquals(1, resultArray.length);
|
||||
}
|
||||
/**
|
||||
* test nested arrays
|
||||
*/
|
||||
public void testObjectsToVariantNestedArray() {
|
||||
Object testArray[] = new Object[] { Integer.valueOf(1),
|
||||
Integer.valueOf(2) };
|
||||
Object testArrayOuter[] = new Object[] { testArray };
|
||||
Variant resultArray[] = VariantUtilities
|
||||
.objectsToVariants(testArrayOuter);
|
||||
// should be a SafeArray
|
||||
assertEquals(1, resultArray.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* verify that dispatch can convert from object to variant and that the
|
||||
* variant holds the right value
|
||||
*/
|
||||
public void testConverters() {
|
||||
Date testDate = new Date();
|
||||
Variant fromDate = VariantUtilities.objectToVariant(testDate);
|
||||
Date returnedDate = fromDate.getJavaDate();
|
||||
// System.out.println("test date is "+testDate);
|
||||
// System.out.println("VariantDate is "+fromDate.getJavaDate());
|
||||
assertTrue("Could not call obj2variant(Date) and get it to work",
|
||||
testDate.equals(returnedDate));
|
||||
Currency someMoney = new Currency(12349876L);
|
||||
Variant fromMoney = VariantUtilities.objectToVariant(someMoney);
|
||||
Currency someMoneyConverted = fromMoney.getCurrency();
|
||||
assertTrue("Could not call obj2variant(Long) and get it to work",
|
||||
someMoney.equals(someMoneyConverted));
|
||||
System.out.println("currency returned was: " + someMoneyConverted);
|
||||
/**
|
||||
* verify that dispatch can convert from object to variant and that the
|
||||
* variant holds the right value
|
||||
*/
|
||||
public void testConverters() {
|
||||
Date testDate = new Date();
|
||||
Variant fromDate = VariantUtilities.objectToVariant(testDate);
|
||||
Date returnedDate = fromDate.getJavaDate();
|
||||
// System.out.println("test date is "+testDate);
|
||||
// System.out.println("VariantDate is "+fromDate.getJavaDate());
|
||||
assertTrue("Could not call obj2variant(Date) and get it to work",
|
||||
testDate.equals(returnedDate));
|
||||
Currency someMoney = new Currency(12349876L);
|
||||
Variant fromMoney = VariantUtilities.objectToVariant(someMoney);
|
||||
Currency someMoneyConverted = fromMoney.getCurrency();
|
||||
assertTrue("Could not call obj2variant(Long) and get it to work",
|
||||
someMoney.equals(someMoneyConverted));
|
||||
System.out.println("currency returned was: " + someMoneyConverted);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testPrimitiveByteArray() {
|
||||
byte[] arr = new byte[] { 1, 2, 3 };
|
||||
public void testPrimitiveByteArray() {
|
||||
byte[] arr = new byte[] { 1, 2, 3 };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantByte, sa.getvt());
|
||||
assertEquals(Variant.VariantByte, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
byte[] bytes = sa.toByteArray();
|
||||
assertTrue(Arrays.equals(bytes, arr));
|
||||
}
|
||||
byte[] bytes = sa.toByteArray();
|
||||
assertTrue(Arrays.equals(bytes, arr));
|
||||
}
|
||||
|
||||
public void testPrimitiveIntArray() {
|
||||
int[] arr = new int[] { 1000, 2000, 3 };
|
||||
public void testPrimitiveIntArray() {
|
||||
int[] arr = new int[] { 1000, 2000, 3 };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantInt, sa.getvt());
|
||||
assertEquals(Variant.VariantInt, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
int[] ints = sa.toIntArray();
|
||||
assertTrue(Arrays.equals(ints, arr));
|
||||
}
|
||||
int[] ints = sa.toIntArray();
|
||||
assertTrue(Arrays.equals(ints, arr));
|
||||
}
|
||||
|
||||
public void testPrimitiveDoubleArray() {
|
||||
double[] arr = new double[] { 1000, 2000, 3 };
|
||||
public void testPrimitiveDoubleArray() {
|
||||
double[] arr = new double[] { 1000, 2000, 3 };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantDouble, sa.getvt());
|
||||
assertEquals(Variant.VariantDouble, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
double[] doubles = sa.toDoubleArray();
|
||||
assertTrue(Arrays.equals(doubles, arr));
|
||||
}
|
||||
double[] doubles = sa.toDoubleArray();
|
||||
assertTrue(Arrays.equals(doubles, arr));
|
||||
}
|
||||
|
||||
public void testPrimitiveLongArray() {
|
||||
long[] arr = new long[] { 0xcafebabecafebabeL, 42, 0xbabecafebabeL };
|
||||
public void testPrimitiveLongArray() {
|
||||
long[] arr = new long[] { 0xcafebabecafebabeL, 42, 0xbabecafebabeL };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantLongInt, sa.getvt());
|
||||
assertEquals(Variant.VariantLongInt, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
long[] longs = sa.toLongArray();
|
||||
assertTrue(Arrays.equals(longs, arr));
|
||||
}
|
||||
long[] longs = sa.toLongArray();
|
||||
assertTrue(Arrays.equals(longs, arr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test;
|
||||
|
||||
@@ -61,152 +61,152 @@ import com.jacob.com.JacobObject;
|
||||
*/
|
||||
public class BaseTestCase extends TestCase {
|
||||
|
||||
protected void setUp() {
|
||||
// verify we have run with the dll in the lib path
|
||||
try {
|
||||
JacobObject foo = new JacobObject();
|
||||
if (foo == null) {
|
||||
fail("Failed basic sanity test: Can't create JacobObject (-D<java.library.path=xxx>)");
|
||||
}
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
fail("Did you remember to run with the jacob.dll in the libpath ?");
|
||||
}
|
||||
}
|
||||
protected void setUp() {
|
||||
// verify we have run with the dll in the lib path
|
||||
try {
|
||||
JacobObject foo = new JacobObject();
|
||||
if (foo == null) {
|
||||
fail("Failed basic sanity test: Can't create JacobObject (-D<java.library.path=xxx>)");
|
||||
}
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
fail("Did you remember to run with the jacob.dll in the libpath ?");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this test exists just to test the setup.
|
||||
*/
|
||||
public void testSetup() {
|
||||
JacobObject foo = new JacobObject();
|
||||
assertNotNull(foo);
|
||||
}
|
||||
/**
|
||||
* this test exists just to test the setup.
|
||||
*/
|
||||
public void testSetup() {
|
||||
JacobObject foo = new JacobObject();
|
||||
assertNotNull(foo);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a simple VB script that generates the result "3"
|
||||
*/
|
||||
public String getSampleVPScriptForEval() {
|
||||
return "1+(2*4)-3";
|
||||
/**
|
||||
*
|
||||
* @return a simple VB script that generates the result "3"
|
||||
*/
|
||||
public String getSampleVPScriptForEval() {
|
||||
return "1+(2*4)-3";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the class name into a path and appends the resource name. Used
|
||||
* to derive the path to a resource in the file system where the resource is
|
||||
* co-located with the referenced class.
|
||||
*
|
||||
* @param resourceName
|
||||
* @param classInSamePackageAsResource
|
||||
* @return a class loader compatible fully qualified file system path to a
|
||||
* resource
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private String getJavaFilePathToPackageResource(String resourceName,
|
||||
Class classInSamePackageAsResource) {
|
||||
/**
|
||||
* Converts the class name into a path and appends the resource name. Used
|
||||
* to derive the path to a resource in the file system where the resource is
|
||||
* co-located with the referenced class.
|
||||
*
|
||||
* @param resourceName
|
||||
* @param classInSamePackageAsResource
|
||||
* @return a class loader compatible fully qualified file system path to a
|
||||
* resource
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private String getJavaFilePathToPackageResource(String resourceName,
|
||||
Class classInSamePackageAsResource) {
|
||||
|
||||
String classPackageName = classInSamePackageAsResource.getName();
|
||||
int i = classPackageName.lastIndexOf('.');
|
||||
if (i == -1) {
|
||||
classPackageName = "";
|
||||
} else {
|
||||
classPackageName = classPackageName.substring(0, i);
|
||||
}
|
||||
String classPackageName = classInSamePackageAsResource.getName();
|
||||
int i = classPackageName.lastIndexOf('.');
|
||||
if (i == -1) {
|
||||
classPackageName = "";
|
||||
} else {
|
||||
classPackageName = classPackageName.substring(0, i);
|
||||
}
|
||||
|
||||
// change all "." to ^ for later conversion to "/" so we can append
|
||||
// resource names with "."
|
||||
classPackageName = classPackageName.replace('.', '^');
|
||||
System.out.println("classPackageName: " + classPackageName);
|
||||
String fullPathToResource;
|
||||
if (classPackageName.length() > 0) {
|
||||
fullPathToResource = classPackageName + "^" + resourceName;
|
||||
} else {
|
||||
fullPathToResource = resourceName;
|
||||
}
|
||||
// change all "." to ^ for later conversion to "/" so we can append
|
||||
// resource names with "."
|
||||
classPackageName = classPackageName.replace('.', '^');
|
||||
System.out.println("classPackageName: " + classPackageName);
|
||||
String fullPathToResource;
|
||||
if (classPackageName.length() > 0) {
|
||||
fullPathToResource = classPackageName + "^" + resourceName;
|
||||
} else {
|
||||
fullPathToResource = resourceName;
|
||||
}
|
||||
|
||||
fullPathToResource = fullPathToResource.replace('^', '/');
|
||||
System.out.println("fullPathToResource: " + fullPathToResource);
|
||||
fullPathToResource = fullPathToResource.replace('^', '/');
|
||||
System.out.println("fullPathToResource: " + fullPathToResource);
|
||||
|
||||
URL urlToLibrary = classInSamePackageAsResource.getClassLoader()
|
||||
.getResource(fullPathToResource);
|
||||
assertNotNull("URL to resource " + resourceName
|
||||
+ " should not be null."
|
||||
+ " You probably need to add 'unittest' to the"
|
||||
+ " classpath so the tests can find resources", urlToLibrary);
|
||||
String fullPathToResourceAsFile = urlToLibrary.getFile();
|
||||
System.out.println("url to library: " + urlToLibrary);
|
||||
System.out.println("fullPathToResourceAsFile: "
|
||||
+ fullPathToResourceAsFile);
|
||||
URL urlToLibrary = classInSamePackageAsResource.getClassLoader()
|
||||
.getResource(fullPathToResource);
|
||||
assertNotNull("URL to resource " + resourceName
|
||||
+ " should not be null."
|
||||
+ " You probably need to add 'unittest' to the"
|
||||
+ " classpath so the tests can find resources", urlToLibrary);
|
||||
String fullPathToResourceAsFile = urlToLibrary.getFile();
|
||||
System.out.println("url to library: " + urlToLibrary);
|
||||
System.out.println("fullPathToResourceAsFile: "
|
||||
+ fullPathToResourceAsFile);
|
||||
|
||||
return fullPathToResourceAsFile;
|
||||
}
|
||||
return fullPathToResourceAsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the class name into a path and appends the resource name. Used
|
||||
* to derive the path to a resource in the file system where the resource is
|
||||
* co-located with the referenced class.
|
||||
*
|
||||
* @param resourceName
|
||||
* @param classInSamePackageAsResource
|
||||
* @return returns the path in the file system of the requested resource in
|
||||
* windows c compatible format
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getWindowsFilePathToPackageResource(String resourceName,
|
||||
Class classInSamePackageAsResource) {
|
||||
String javaFilePath = getJavaFilePathToPackageResource(resourceName,
|
||||
classInSamePackageAsResource);
|
||||
javaFilePath = javaFilePath.replace('/', '\\');
|
||||
return javaFilePath.substring(1);
|
||||
}
|
||||
/**
|
||||
* Converts the class name into a path and appends the resource name. Used
|
||||
* to derive the path to a resource in the file system where the resource is
|
||||
* co-located with the referenced class.
|
||||
*
|
||||
* @param resourceName
|
||||
* @param classInSamePackageAsResource
|
||||
* @return returns the path in the file system of the requested resource in
|
||||
* windows c compatible format
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getWindowsFilePathToPackageResource(String resourceName,
|
||||
Class classInSamePackageAsResource) {
|
||||
String javaFilePath = getJavaFilePathToPackageResource(resourceName,
|
||||
classInSamePackageAsResource);
|
||||
javaFilePath = javaFilePath.replace('/', '\\');
|
||||
return javaFilePath.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param resourceName
|
||||
* @param classInSamePackageAsResource
|
||||
* @return a resource located in the same package as the passed in class
|
||||
*/
|
||||
@SuppressWarnings( { "unused", "unchecked" })
|
||||
private Object getPackageResource(String resourceName,
|
||||
Class classInSamePackageAsResource) {
|
||||
String fullPathToResource = getJavaFilePathToPackageResource(
|
||||
resourceName, classInSamePackageAsResource);
|
||||
ClassLoader localClassLoader = classInSamePackageAsResource
|
||||
.getClassLoader();
|
||||
if (null == localClassLoader) {
|
||||
return ClassLoader.getSystemResource(fullPathToResource);
|
||||
} else {
|
||||
return localClassLoader.getResource(fullPathToResource);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param resourceName
|
||||
* @param classInSamePackageAsResource
|
||||
* @return a resource located in the same package as the passed in class
|
||||
*/
|
||||
@SuppressWarnings( { "unused", "unchecked" })
|
||||
private Object getPackageResource(String resourceName,
|
||||
Class classInSamePackageAsResource) {
|
||||
String fullPathToResource = getJavaFilePathToPackageResource(
|
||||
resourceName, classInSamePackageAsResource);
|
||||
ClassLoader localClassLoader = classInSamePackageAsResource
|
||||
.getClassLoader();
|
||||
if (null == localClassLoader) {
|
||||
return ClassLoader.getSystemResource(fullPathToResource);
|
||||
} else {
|
||||
return localClassLoader.getResource(fullPathToResource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load a library from same place in the file system that the class was
|
||||
* loaded from.
|
||||
* <p>
|
||||
* This is an attempt to let unit tests run without having to run regsvr32.
|
||||
*
|
||||
* @param libraryName
|
||||
* @param classInSamePackageAsResource
|
||||
*/
|
||||
@SuppressWarnings( { "unchecked", "unused" })
|
||||
private void loadLibraryFromClassPackage(String libraryName,
|
||||
Class classInSamePackageAsResource) {
|
||||
String libraryNameWithSuffix = "";
|
||||
String fullLibraryNameWithPath = "";
|
||||
if (libraryName != null && libraryName.endsWith("dll")) {
|
||||
libraryNameWithSuffix = libraryName;
|
||||
} else if (libraryName != null) {
|
||||
libraryNameWithSuffix = libraryName + ".dll";
|
||||
} else {
|
||||
fail("can't create full library name " + libraryName);
|
||||
}
|
||||
// generate the path the classloader would use to find this on the
|
||||
// classpath
|
||||
fullLibraryNameWithPath = getJavaFilePathToPackageResource(
|
||||
libraryNameWithSuffix, classInSamePackageAsResource);
|
||||
System.load(fullLibraryNameWithPath);
|
||||
// requires that the dll be on the library path
|
||||
// System.loadLibrary(fullLibraryNameWithPath);
|
||||
}
|
||||
/**
|
||||
* load a library from same place in the file system that the class was
|
||||
* loaded from.
|
||||
* <p>
|
||||
* This is an attempt to let unit tests run without having to run regsvr32.
|
||||
*
|
||||
* @param libraryName
|
||||
* @param classInSamePackageAsResource
|
||||
*/
|
||||
@SuppressWarnings( { "unchecked", "unused" })
|
||||
private void loadLibraryFromClassPackage(String libraryName,
|
||||
Class classInSamePackageAsResource) {
|
||||
String libraryNameWithSuffix = "";
|
||||
String fullLibraryNameWithPath = "";
|
||||
if (libraryName != null && libraryName.endsWith("dll")) {
|
||||
libraryNameWithSuffix = libraryName;
|
||||
} else if (libraryName != null) {
|
||||
libraryNameWithSuffix = libraryName + ".dll";
|
||||
} else {
|
||||
fail("can't create full library name " + libraryName);
|
||||
}
|
||||
// generate the path the classloader would use to find this on the
|
||||
// classpath
|
||||
fullLibraryNameWithPath = getJavaFilePathToPackageResource(
|
||||
libraryNameWithSuffix, classInSamePackageAsResource);
|
||||
System.load(fullLibraryNameWithPath);
|
||||
// requires that the dll be on the library path
|
||||
// System.loadLibrary(fullLibraryNameWithPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.errors;
|
||||
|
||||
@@ -51,22 +51,22 @@ import com.jacob.com.ComException;
|
||||
*/
|
||||
public class UnicodeErrorTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* verifies that messages can now have unicode in them like when the file
|
||||
* names have unicode characters
|
||||
*/
|
||||
public void testUnicodeCharactersInErrorMessage() {
|
||||
ActiveXComponent application = new ActiveXComponent("Word.Application");
|
||||
ActiveXComponent documents = application
|
||||
.getPropertyAsComponent("Documents");
|
||||
String fileName = "abc\u0411\u0412\u0413\u0414def";
|
||||
try {
|
||||
documents.invoke("Open", fileName);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (ComException e) {
|
||||
assertTrue("Error message should contain file name with unicode "
|
||||
+ "characters in it. " + e.getMessage(), e.getMessage()
|
||||
.indexOf(fileName) > 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* verifies that messages can now have unicode in them like when the file
|
||||
* names have unicode characters
|
||||
*/
|
||||
public void testUnicodeCharactersInErrorMessage() {
|
||||
ActiveXComponent application = new ActiveXComponent("Word.Application");
|
||||
ActiveXComponent documents = application
|
||||
.getPropertyAsComponent("Documents");
|
||||
String fileName = "abc\u0411\u0412\u0413\u0414def";
|
||||
try {
|
||||
documents.invoke("Open", fileName);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (ComException e) {
|
||||
assertTrue("Error message should contain file name with unicode "
|
||||
+ "characters in it. " + e.getMessage(), e.getMessage()
|
||||
.indexOf(fileName) > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.events;
|
||||
|
||||
@@ -59,132 +59,132 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class ExcelEventTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* load up excel, register for events and make stuff happen
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void testExcelWithInvocationProxy() {
|
||||
ComThread.InitSTA();
|
||||
// we are going to listen to events on Application.
|
||||
// You can probably also listen Excel.Sheet and Excel.Chart
|
||||
String excelApplicationProgramId = "Excel.Application";
|
||||
String excelSheetProgramId = "Excel.Sheet";
|
||||
String typeLibLocation;
|
||||
// office 2003
|
||||
typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";
|
||||
// office 2007
|
||||
typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE12\\EXCEL.EXE";
|
||||
// office 2013 322 bit
|
||||
typeLibLocation = "C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE";
|
||||
/**
|
||||
* load up excel, register for events and make stuff happen
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void testExcelWithInvocationProxy() {
|
||||
ComThread.InitSTA();
|
||||
// we are going to listen to events on Application.
|
||||
// You can probably also listen Excel.Sheet and Excel.Chart
|
||||
String excelApplicationProgramId = "Excel.Application";
|
||||
String excelSheetProgramId = "Excel.Sheet";
|
||||
String typeLibLocation;
|
||||
// office 2003
|
||||
typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";
|
||||
// office 2007
|
||||
typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE12\\EXCEL.EXE";
|
||||
// office 2013 322 bit
|
||||
typeLibLocation = "C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE";
|
||||
|
||||
// Grab The Component.
|
||||
ActiveXComponent axc = new ActiveXComponent(excelApplicationProgramId);
|
||||
hookupListener(axc, excelApplicationProgramId, typeLibLocation);
|
||||
// Grab The Component.
|
||||
ActiveXComponent axc = new ActiveXComponent(excelApplicationProgramId);
|
||||
hookupListener(axc, excelApplicationProgramId, typeLibLocation);
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
System.out.println("version=" + axc.getProperty("Version"));
|
||||
System.out.println("version=" + Dispatch.get(axc, "Version"));
|
||||
axc.setProperty("Visible", true);
|
||||
Dispatch workbooks = axc.getPropertyAsComponent("Workbooks");
|
||||
Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
System.out.println("Workbook: " + workbook);
|
||||
System.out.println("Sheet: " + sheet);
|
||||
if (typeLibLocation.contains("OFFICE11")) {
|
||||
// office 2007 throws crashes the VM
|
||||
System.out.println("Hooking up sheet listener");
|
||||
hookupListener(sheet, excelSheetProgramId, typeLibLocation);
|
||||
}
|
||||
System.out.println("Retrieving cells");
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A1" }, new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A2" }, new int[1]).toDispatch();
|
||||
System.out.println("Inserting value into A1");
|
||||
System.out.println("Inserting calculation 2xA1 into A2");
|
||||
Dispatch.put(a1, "Value", "123.456");
|
||||
Dispatch.put(a2, "Formula", "=A1*2");
|
||||
System.out.println("Retrieved a1 from excel:"
|
||||
+ Dispatch.get(a1, "Value"));
|
||||
System.out.println("Retrieved a2 from excel:"
|
||||
+ Dispatch.get(a2, "Value"));
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
System.out.println("version=" + axc.getProperty("Version"));
|
||||
System.out.println("version=" + Dispatch.get(axc, "Version"));
|
||||
axc.setProperty("Visible", true);
|
||||
Dispatch workbooks = axc.getPropertyAsComponent("Workbooks");
|
||||
Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
System.out.println("Workbook: " + workbook);
|
||||
System.out.println("Sheet: " + sheet);
|
||||
if (typeLibLocation.contains("OFFICE11")) {
|
||||
// office 2007 throws crashes the VM
|
||||
System.out.println("Hooking up sheet listener");
|
||||
hookupListener(sheet, excelSheetProgramId, typeLibLocation);
|
||||
}
|
||||
System.out.println("Retrieving cells");
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A1" }, new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A2" }, new int[1]).toDispatch();
|
||||
System.out.println("Inserting value into A1");
|
||||
System.out.println("Inserting calculation 2xA1 into A2");
|
||||
Dispatch.put(a1, "Value", "123.456");
|
||||
Dispatch.put(a2, "Formula", "=A1*2");
|
||||
System.out.println("Retrieved a1 from excel:"
|
||||
+ Dispatch.get(a1, "Value"));
|
||||
System.out.println("Retrieved a2 from excel:"
|
||||
+ Dispatch.get(a2, "Value"));
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
|
||||
} catch (ComException cfe) {
|
||||
cfe.printStackTrace();
|
||||
fail("Failed to attach to " + excelApplicationProgramId + ": "
|
||||
+ cfe.getMessage());
|
||||
}
|
||||
try {
|
||||
// the sleep is required to let everything clear out after the quit
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
ComThread.Release();
|
||||
}
|
||||
} catch (ComException cfe) {
|
||||
cfe.printStackTrace();
|
||||
fail("Failed to attach to " + excelApplicationProgramId + ": "
|
||||
+ cfe.getMessage());
|
||||
}
|
||||
try {
|
||||
// the sleep is required to let everything clear out after the quit
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* extracted the listener hookup so we could try multiple listeners.
|
||||
*
|
||||
* @param axc
|
||||
* @param programId
|
||||
* @param typeLibLocation
|
||||
*/
|
||||
private void hookupListener(Dispatch axc, String programId,
|
||||
String typeLibLocation) {
|
||||
// Add a listener (doesn't matter what it is).
|
||||
DispatchEvents applicationEvents;
|
||||
if (typeLibLocation == null) {
|
||||
applicationEvents = new DispatchEvents(axc, new ExcelEvents(
|
||||
programId));
|
||||
} else {
|
||||
applicationEvents = new DispatchEvents(axc, new ExcelEvents(
|
||||
programId), programId, typeLibLocation);
|
||||
}
|
||||
if (applicationEvents == null) {
|
||||
System.out
|
||||
.println("No exception thrown but no dispatch returned for Excel events");
|
||||
} else {
|
||||
// Yea!
|
||||
System.out
|
||||
.println("Successfully attached listener to " + programId);
|
||||
/**
|
||||
* extracted the listener hookup so we could try multiple listeners.
|
||||
*
|
||||
* @param axc
|
||||
* @param programId
|
||||
* @param typeLibLocation
|
||||
*/
|
||||
private void hookupListener(Dispatch axc, String programId,
|
||||
String typeLibLocation) {
|
||||
// Add a listener (doesn't matter what it is).
|
||||
DispatchEvents applicationEvents;
|
||||
if (typeLibLocation == null) {
|
||||
applicationEvents = new DispatchEvents(axc, new ExcelEvents(
|
||||
programId));
|
||||
} else {
|
||||
applicationEvents = new DispatchEvents(axc, new ExcelEvents(
|
||||
programId), programId, typeLibLocation);
|
||||
}
|
||||
if (applicationEvents == null) {
|
||||
System.out
|
||||
.println("No exception thrown but no dispatch returned for Excel events");
|
||||
} else {
|
||||
// Yea!
|
||||
System.out
|
||||
.println("Successfully attached listener to " + programId);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy class to verify we receive expected events
|
||||
*/
|
||||
public class ExcelEvents extends InvocationProxy {
|
||||
/**
|
||||
* Proxy class to verify we receive expected events
|
||||
*/
|
||||
public class ExcelEvents extends InvocationProxy {
|
||||
|
||||
private String listenerPrefix = "-";
|
||||
private String listenerPrefix = "-";
|
||||
|
||||
/**
|
||||
* Constructor so we can create an instance that implements invoke()
|
||||
*
|
||||
* @param interfaceIdentifier
|
||||
* a string that identifies which listener is speaking
|
||||
*/
|
||||
public ExcelEvents(String interfaceIdentifier) {
|
||||
listenerPrefix = interfaceIdentifier;
|
||||
}
|
||||
/**
|
||||
* Constructor so we can create an instance that implements invoke()
|
||||
*
|
||||
* @param interfaceIdentifier
|
||||
* a string that identifies which listener is speaking
|
||||
*/
|
||||
public ExcelEvents(String interfaceIdentifier) {
|
||||
listenerPrefix = interfaceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the invoke method to log all the events so that we don't
|
||||
* have to implement all of the specific events.
|
||||
*/
|
||||
@Override
|
||||
public Variant invoke(String methodName, Variant targetParameter[]) {
|
||||
System.out.println("Received event from " + listenerPrefix + ": "
|
||||
+ methodName);
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Override the invoke method to log all the events so that we don't
|
||||
* have to implement all of the specific events.
|
||||
*/
|
||||
@Override
|
||||
public Variant invoke(String methodName, Variant targetParameter[]) {
|
||||
System.out.println("Received event from " + listenerPrefix + ": "
|
||||
+ methodName);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.events;
|
||||
|
||||
@@ -60,418 +60,418 @@ import com.jacob.test.BaseTestCase;
|
||||
|
||||
public class IETest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* well known address we can navigate to
|
||||
*/
|
||||
private final String testUrls[] = {
|
||||
"http://sourceforge.net/projects/jacob-project",
|
||||
"http://www.google.com" };
|
||||
/**
|
||||
* well known address we can navigate to
|
||||
*/
|
||||
private final String testUrls[] = {
|
||||
"http://sourceforge.net/projects/jacob-project",
|
||||
"http://www.google.com" };
|
||||
|
||||
/**
|
||||
* runs the IE test and feeds it commands
|
||||
*/
|
||||
public void testRunIECleanly() {
|
||||
runTheTest(true, testUrls);
|
||||
}
|
||||
/**
|
||||
* runs the IE test and feeds it commands
|
||||
*/
|
||||
public void testRunIECleanly() {
|
||||
runTheTest(true, testUrls);
|
||||
}
|
||||
|
||||
/**
|
||||
* runs the IE test and feeds it commands
|
||||
*/
|
||||
public void testRunIETerminateWithoutWait() {
|
||||
runTheTest(false, testUrls);
|
||||
}
|
||||
/**
|
||||
* runs the IE test and feeds it commands
|
||||
*/
|
||||
public void testRunIETerminateWithoutWait() {
|
||||
runTheTest(false, testUrls);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual work of running the test.
|
||||
*
|
||||
* @param waitForQuit
|
||||
* @param urls
|
||||
*/
|
||||
private void runTheTest(boolean waitForQuit, String[] urls) {
|
||||
// this line starts the pump but it runs fine without it
|
||||
ComThread.startMainSTA();
|
||||
// Run the test in a thread. Lets us test running out of "main" thread
|
||||
IETestThread aThread = new IETestThread(waitForQuit, urls);
|
||||
aThread.start();
|
||||
while (aThread.isAlive()) {
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException e) {
|
||||
// done with the sleep
|
||||
}
|
||||
}
|
||||
System.out.println("Main: Thread quit, about to quitMainSTA in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
// this line only does something if startMainSTA() was called
|
||||
ComThread.quitMainSTA();
|
||||
System.out.println("Main: did quit main sta in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
/**
|
||||
* The actual work of running the test.
|
||||
*
|
||||
* @param waitForQuit
|
||||
* @param urls
|
||||
*/
|
||||
private void runTheTest(boolean waitForQuit, String[] urls) {
|
||||
// this line starts the pump but it runs fine without it
|
||||
ComThread.startMainSTA();
|
||||
// Run the test in a thread. Lets us test running out of "main" thread
|
||||
IETestThread aThread = new IETestThread(waitForQuit, urls);
|
||||
aThread.start();
|
||||
while (aThread.isAlive()) {
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException e) {
|
||||
// done with the sleep
|
||||
}
|
||||
}
|
||||
System.out.println("Main: Thread quit, about to quitMainSTA in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
// this line only does something if startMainSTA() was called
|
||||
ComThread.quitMainSTA();
|
||||
System.out.println("Main: did quit main sta in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
|
||||
if (aThread.threadFailedWithException != null) {
|
||||
aThread.threadFailedWithException.printStackTrace();
|
||||
fail("caught an unexpected exception "
|
||||
+ aThread.threadFailedWithException);
|
||||
}
|
||||
}
|
||||
if (aThread.threadFailedWithException != null) {
|
||||
aThread.threadFailedWithException.printStackTrace();
|
||||
fail("caught an unexpected exception "
|
||||
+ aThread.threadFailedWithException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IETestThread extends Thread {
|
||||
/** flag that says we got a quit message from IE */
|
||||
public static boolean quitHandled = false;
|
||||
/** flag that says we got a quit message from IE */
|
||||
public static boolean quitHandled = false;
|
||||
|
||||
/**
|
||||
* determines if we wait until last quit call back received before
|
||||
* terminating
|
||||
*/
|
||||
private static boolean waitUntilReceivedQuitCallback = true;
|
||||
/**
|
||||
* determines if we wait until last quit call back received before
|
||||
* terminating
|
||||
*/
|
||||
private static boolean waitUntilReceivedQuitCallback = true;
|
||||
|
||||
/**
|
||||
* the places we should navigate to
|
||||
*/
|
||||
private static String[] targets = null;
|
||||
/**
|
||||
* the places we should navigate to
|
||||
*/
|
||||
private static String[] targets = null;
|
||||
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
|
||||
/**
|
||||
* constructor for the test thread
|
||||
*
|
||||
* @param beNeat
|
||||
* should we wait until quit received
|
||||
* @param urls
|
||||
* the web pages we will navigate to
|
||||
*/
|
||||
public IETestThread(boolean beNeat, String urls[]) {
|
||||
super();
|
||||
waitUntilReceivedQuitCallback = beNeat;
|
||||
targets = urls;
|
||||
}
|
||||
/**
|
||||
* constructor for the test thread
|
||||
*
|
||||
* @param beNeat
|
||||
* should we wait until quit received
|
||||
* @param urls
|
||||
* the web pages we will navigate to
|
||||
*/
|
||||
public IETestThread(boolean beNeat, String urls[]) {
|
||||
super();
|
||||
waitUntilReceivedQuitCallback = beNeat;
|
||||
targets = urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run through the addresses passed in via the constructor
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
// pick a time that lets sourceforge respond (in msec)
|
||||
int delay = 3000;
|
||||
// pre-1.14 paired with statement below that blows up
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent ie = new ActiveXComponent(
|
||||
"InternetExplorer.Application");
|
||||
try {
|
||||
Dispatch.put(ie, "Visible", new Variant(true));
|
||||
Dispatch.put(ie, "AddressBar", new Variant(true));
|
||||
System.out.println("IETestThread: " + Dispatch.get(ie, "Path"));
|
||||
// Some version of IE broke this. Not sure which one
|
||||
// Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
|
||||
/**
|
||||
* Run through the addresses passed in via the constructor
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
// pick a time that lets sourceforge respond (in msec)
|
||||
int delay = 3000;
|
||||
// pre-1.14 paired with statement below that blows up
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent ie = new ActiveXComponent(
|
||||
"InternetExplorer.Application");
|
||||
try {
|
||||
Dispatch.put(ie, "Visible", new Variant(true));
|
||||
Dispatch.put(ie, "AddressBar", new Variant(true));
|
||||
System.out.println("IETestThread: " + Dispatch.get(ie, "Path"));
|
||||
// Some version of IE broke this. Not sure which one
|
||||
// Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
|
||||
|
||||
System.out.println("IETestThread: About to hookup event listener");
|
||||
IEEvents ieE = new IEEvents();
|
||||
new DispatchEvents(ie, ieE, "InternetExplorer.Application.1");
|
||||
System.out.println("IETestThread: Did hookup event listener");
|
||||
System.out.println("IETestThread: About to hookup event listener");
|
||||
IEEvents ieE = new IEEvents();
|
||||
new DispatchEvents(ie, ieE, "InternetExplorer.Application.1");
|
||||
System.out.println("IETestThread: Did hookup event listener");
|
||||
|
||||
for (String url : targets) {
|
||||
System.out.println("IETestThread: About to call navigate to "
|
||||
+ url);
|
||||
Dispatch.call(ie, "Navigate", new Variant(url));
|
||||
System.out.println("IETestThread: Did call navigate to " + url);
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
e.printStackTrace();
|
||||
} catch (Throwable re) {
|
||||
threadFailedWithException = re;
|
||||
re.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("IETestThread: About to send Quit");
|
||||
ie.invoke("Quit", new Variant[] {});
|
||||
System.out.println("IETestThread: Did send Quit");
|
||||
}
|
||||
// a value is set to false if we try to crash VM by leaving before
|
||||
// callbacks all received
|
||||
if (waitUntilReceivedQuitCallback) {
|
||||
System.out
|
||||
.println("IETestThread: Waiting until we've received quit callback");
|
||||
// wait a little while for it to end
|
||||
while (!quitHandled) {
|
||||
try {
|
||||
Thread.sleep(delay / 10);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
System.out.println("IETestThread: Received the OnQuit callback");
|
||||
} else {
|
||||
System.out.println("IETestThread: Not waiting for OnQuit callback");
|
||||
}
|
||||
System.out.println("IETestThread: Calling ComThread.Release in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
ComThread.Release();
|
||||
}
|
||||
for (String url : targets) {
|
||||
System.out.println("IETestThread: About to call navigate to "
|
||||
+ url);
|
||||
Dispatch.call(ie, "Navigate", new Variant(url));
|
||||
System.out.println("IETestThread: Did call navigate to " + url);
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
e.printStackTrace();
|
||||
} catch (Throwable re) {
|
||||
threadFailedWithException = re;
|
||||
re.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("IETestThread: About to send Quit");
|
||||
ie.invoke("Quit", new Variant[] {});
|
||||
System.out.println("IETestThread: Did send Quit");
|
||||
}
|
||||
// a value is set to false if we try to crash VM by leaving before
|
||||
// callbacks all received
|
||||
if (waitUntilReceivedQuitCallback) {
|
||||
System.out
|
||||
.println("IETestThread: Waiting until we've received quit callback");
|
||||
// wait a little while for it to end
|
||||
while (!quitHandled) {
|
||||
try {
|
||||
Thread.sleep(delay / 10);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
System.out.println("IETestThread: Received the OnQuit callback");
|
||||
} else {
|
||||
System.out.println("IETestThread: Not waiting for OnQuit callback");
|
||||
}
|
||||
System.out.println("IETestThread: Calling ComThread.Release in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* The events class must be publicly accessible for reflection to work. The
|
||||
* list of available events is located at
|
||||
* http://msdn2.microsoft.com/en-us/library/aa768280.aspx
|
||||
*/
|
||||
public class IEEvents {
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void BeforeNavigate2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): BeforeNavigate2 "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* The events class must be publicly accessible for reflection to work. The
|
||||
* list of available events is located at
|
||||
* http://msdn2.microsoft.com/en-us/library/aa768280.aspx
|
||||
*/
|
||||
public class IEEvents {
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void BeforeNavigate2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): BeforeNavigate2 "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void CommandStateChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): CommandStateChange " + args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void CommandStateChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): CommandStateChange " + args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void DocumentComplete(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): DocumentComplete "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void DocumentComplete(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): DocumentComplete "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void DownloadBegin(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): DownloadBegin "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void DownloadBegin(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): DownloadBegin "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void DownloadComplete(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): DownloadComplete "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void DownloadComplete(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): DownloadComplete "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void NavigateError(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateError "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void NavigateError(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateError "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void NavigateComplete2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateComplete "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void NavigateComplete2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateComplete "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void NewWindow2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NewWindow2 "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void NewWindow2(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NewWindow2 "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnFullScreen(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnFullScreen "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnFullScreen(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnFullScreen "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnMenuBar(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnMenuBar "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnMenuBar(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnMenuBar "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnQuit(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnQuit "
|
||||
+ args.length + " parameters");
|
||||
IETestThread.quitHandled = true;
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnQuit(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnQuit "
|
||||
+ args.length + " parameters");
|
||||
IETestThread.quitHandled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnStatusBar(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnStatusBar "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnStatusBar(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnStatusBar "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnTheaterMode(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnTheaterMode "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnTheaterMode(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnTheaterMode "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnToolBar(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnToolBar "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnToolBar(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnToolBar "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnVisible(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnVisible "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void OnVisible(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): OnVisible "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void ProgressChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): ProgressChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void ProgressChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): ProgressChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void PropertyChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): PropertyChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void PropertyChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): PropertyChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void SetSecureLockIcon(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): setSecureLockIcon " + args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void SetSecureLockIcon(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): setSecureLockIcon " + args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void StatusTextChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): StatusTextChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void StatusTextChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): StatusTextChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void TitleChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): TitleChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void TitleChange(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): TitleChange "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void WindowClosing(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): WindowClosing "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Internet explorer event this proxy can receive
|
||||
*
|
||||
* @param args
|
||||
* the COM Variant objects that this event passes in.
|
||||
*/
|
||||
public void WindowClosing(Variant[] args) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): WindowClosing "
|
||||
+ args.length + " parameters");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.events;
|
||||
|
||||
@@ -60,268 +60,268 @@ import com.jacob.test.BaseTestCase;
|
||||
|
||||
public class IETestActiveXProxy extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* the main test method that builds up the connection and runs the test
|
||||
*/
|
||||
public void testIEActiveProxyCallback() {
|
||||
// this line starts the pump but it runs fine without it
|
||||
ComThread.startMainSTA();
|
||||
// remove this line and it dies
|
||||
// /ComThread.InitMTA(true);
|
||||
IETestActiveProxyThread aThread = new IETestActiveProxyThread();
|
||||
aThread.start();
|
||||
while (aThread.isAlive()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// doen with the sleep
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out
|
||||
.println("Main: Thread quit, about to quit main sta in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
// this line only does someting if startMainSTA() was called
|
||||
ComThread.quitMainSTA();
|
||||
System.out.println("Main: did quit main sta in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
if (aThread.threadFailedWithException != null) {
|
||||
fail("caught an unexpected exception "
|
||||
+ aThread.threadFailedWithException);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* the main test method that builds up the connection and runs the test
|
||||
*/
|
||||
public void testIEActiveProxyCallback() {
|
||||
// this line starts the pump but it runs fine without it
|
||||
ComThread.startMainSTA();
|
||||
// remove this line and it dies
|
||||
// /ComThread.InitMTA(true);
|
||||
IETestActiveProxyThread aThread = new IETestActiveProxyThread();
|
||||
aThread.start();
|
||||
while (aThread.isAlive()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// doen with the sleep
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out
|
||||
.println("Main: Thread quit, about to quit main sta in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
// this line only does someting if startMainSTA() was called
|
||||
ComThread.quitMainSTA();
|
||||
System.out.println("Main: did quit main sta in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
if (aThread.threadFailedWithException != null) {
|
||||
fail("caught an unexpected exception "
|
||||
+ aThread.threadFailedWithException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IETestActiveProxyThread extends Thread {
|
||||
/** says that the quit message has been received from the target application */
|
||||
public static boolean quitHandled = false;
|
||||
/** says that the quit message has been received from the target application */
|
||||
public static boolean quitHandled = false;
|
||||
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
|
||||
/** the thread's constructor */
|
||||
public IETestActiveProxyThread() {
|
||||
super();
|
||||
}
|
||||
/** the thread's constructor */
|
||||
public IETestActiveProxyThread() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// this used to be 5 seconds but sourceforge is slow
|
||||
int delay = 5000; // msec
|
||||
// paired with statement below that blows up
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent ie = new ActiveXComponent(
|
||||
"InternetExplorer.Application");
|
||||
try {
|
||||
Dispatch.put(ie, "Visible", new Variant(true));
|
||||
Dispatch.put(ie, "AddressBar", new Variant(true));
|
||||
System.out.println("IETestActiveProxyThread: "
|
||||
+ Dispatch.get(ie, "Path"));
|
||||
Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
|
||||
public void run() {
|
||||
// this used to be 5 seconds but sourceforge is slow
|
||||
int delay = 5000; // msec
|
||||
// paired with statement below that blows up
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent ie = new ActiveXComponent(
|
||||
"InternetExplorer.Application");
|
||||
try {
|
||||
Dispatch.put(ie, "Visible", new Variant(true));
|
||||
Dispatch.put(ie, "AddressBar", new Variant(true));
|
||||
System.out.println("IETestActiveProxyThread: "
|
||||
+ Dispatch.get(ie, "Path"));
|
||||
Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
|
||||
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: About to hookup event listener");
|
||||
IEEventsActiveProxy ieE = new IEEventsActiveProxy();
|
||||
new ActiveXDispatchEvents(ie, ieE, "InternetExplorer.Application.1");
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Did hookup event listener");
|
||||
// / why is this here? Was there some other code here in the past?
|
||||
Variant optional = new Variant();
|
||||
optional.putNoParam();
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: About to hookup event listener");
|
||||
IEEventsActiveProxy ieE = new IEEventsActiveProxy();
|
||||
new ActiveXDispatchEvents(ie, ieE, "InternetExplorer.Application.1");
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Did hookup event listener");
|
||||
// / why is this here? Was there some other code here in the past?
|
||||
Variant optional = new Variant();
|
||||
optional.putNoParam();
|
||||
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: About to call navigate to sourceforge");
|
||||
Dispatch.call(ie, "Navigate", new Variant(
|
||||
"http://sourceforge.net/projects/jacob-project"));
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Did call navigate to sourceforge");
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: About to call navigate to yahoo");
|
||||
Dispatch.call(ie, "Navigate", new Variant(
|
||||
"http://groups.yahoo.com/group/jacob-project"));
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Did call navigate to yahoo");
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
e.printStackTrace();
|
||||
} catch (Throwable re) {
|
||||
threadFailedWithException = re;
|
||||
re.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("IETestActiveProxyThread: About to send Quit");
|
||||
ie.invoke("Quit", new Variant[] {});
|
||||
System.out.println("IETestActiveProxyThread: Did send Quit");
|
||||
}
|
||||
// this blows up when it tries to release a DispatchEvents object
|
||||
// I think this is because there is still one event we should get back
|
||||
// "OnQuit" that will came after we have released the thread pool
|
||||
// this is probably messed up because DispatchEvent object will have
|
||||
// been
|
||||
// freed before the callback
|
||||
// commenting out ie.invoke(quit...) causes this to work without error
|
||||
// this code tries to wait until the quit has been handled but that
|
||||
// doesn't work
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Waiting until we've received the quit callback");
|
||||
while (!quitHandled) {
|
||||
try {
|
||||
Thread.sleep(delay / 5);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Received the quit callback");
|
||||
// wait a little while for it to end
|
||||
// try {Thread.sleep(delay); } catch (InterruptedException e) {}
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: about to call ComThread.Release in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: About to call navigate to sourceforge");
|
||||
Dispatch.call(ie, "Navigate", new Variant(
|
||||
"http://sourceforge.net/projects/jacob-project"));
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Did call navigate to sourceforge");
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: About to call navigate to yahoo");
|
||||
Dispatch.call(ie, "Navigate", new Variant(
|
||||
"http://groups.yahoo.com/group/jacob-project"));
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Did call navigate to yahoo");
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
e.printStackTrace();
|
||||
} catch (Throwable re) {
|
||||
threadFailedWithException = re;
|
||||
re.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("IETestActiveProxyThread: About to send Quit");
|
||||
ie.invoke("Quit", new Variant[] {});
|
||||
System.out.println("IETestActiveProxyThread: Did send Quit");
|
||||
}
|
||||
// this blows up when it tries to release a DispatchEvents object
|
||||
// I think this is because there is still one event we should get back
|
||||
// "OnQuit" that will came after we have released the thread pool
|
||||
// this is probably messed up because DispatchEvent object will have
|
||||
// been
|
||||
// freed before the callback
|
||||
// commenting out ie.invoke(quit...) causes this to work without error
|
||||
// this code tries to wait until the quit has been handled but that
|
||||
// doesn't work
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Waiting until we've received the quit callback");
|
||||
while (!quitHandled) {
|
||||
try {
|
||||
Thread.sleep(delay / 5);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: Received the quit callback");
|
||||
// wait a little while for it to end
|
||||
// try {Thread.sleep(delay); } catch (InterruptedException e) {}
|
||||
System.out
|
||||
.println("IETestActiveProxyThread: about to call ComThread.Release in thread "
|
||||
+ Thread.currentThread().getName());
|
||||
|
||||
ComThread.Release();
|
||||
}
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* The events class must be publicly accessable for reflection to work. The
|
||||
* list of available events is located at
|
||||
* http://msdn2.microsoft.com/en-us/library/aa768280.aspx
|
||||
*/
|
||||
public class IEEventsActiveProxy {
|
||||
/**
|
||||
* The events class must be publicly accessable for reflection to work. The
|
||||
* list of available events is located at
|
||||
* http://msdn2.microsoft.com/en-us/library/aa768280.aspx
|
||||
*/
|
||||
public class IEEventsActiveProxy {
|
||||
|
||||
public void BeforeNavigate2(Dispatch pDisp, String url, Integer flags,
|
||||
String targetFrameName, Variant postData, String headers,
|
||||
Boolean cancel) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): BeforeNavigate2 "
|
||||
+ url);
|
||||
}
|
||||
public void BeforeNavigate2(Dispatch pDisp, String url, Integer flags,
|
||||
String targetFrameName, Variant postData, String headers,
|
||||
Boolean cancel) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): BeforeNavigate2 "
|
||||
+ url);
|
||||
}
|
||||
|
||||
public void CommandStateChange(Integer command, Boolean enable) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): CommandStateChange " + command);
|
||||
}
|
||||
public void CommandStateChange(Integer command, Boolean enable) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): CommandStateChange " + command);
|
||||
}
|
||||
|
||||
public void DocumentComplete(Dispatch pDisp, String url) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): DocumentComplete "
|
||||
+ url);
|
||||
}
|
||||
public void DocumentComplete(Dispatch pDisp, String url) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): DocumentComplete "
|
||||
+ url);
|
||||
}
|
||||
|
||||
public void DownloadBegin() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): DownloadBegin ");
|
||||
}
|
||||
public void DownloadBegin() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): DownloadBegin ");
|
||||
}
|
||||
|
||||
public void DownloadComplete() {
|
||||
System.out
|
||||
.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): DownloadComplete ");
|
||||
}
|
||||
public void DownloadComplete() {
|
||||
System.out
|
||||
.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): DownloadComplete ");
|
||||
}
|
||||
|
||||
public void NavigateComplete2(Dispatch pDisp, String url) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateComplete "
|
||||
+ url);
|
||||
}
|
||||
public void NavigateComplete2(Dispatch pDisp, String url) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateComplete "
|
||||
+ url);
|
||||
}
|
||||
|
||||
public void NavigateError(Dispatch pDispatch, String url,
|
||||
String targetFrameName, Integer statusCode, Boolean Cancel) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateError "
|
||||
+ statusCode);
|
||||
}
|
||||
public void NavigateError(Dispatch pDispatch, String url,
|
||||
String targetFrameName, Integer statusCode, Boolean Cancel) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): NavigateError "
|
||||
+ statusCode);
|
||||
}
|
||||
|
||||
public void NewWindow2(Dispatch pDisp, Boolean cancel) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): NewWindow2 "
|
||||
+ pDisp);
|
||||
}
|
||||
public void NewWindow2(Dispatch pDisp, Boolean cancel) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): NewWindow2 "
|
||||
+ pDisp);
|
||||
}
|
||||
|
||||
public void OnFullScreen(Boolean fullScreen) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnFullScreen "
|
||||
+ fullScreen);
|
||||
}
|
||||
public void OnFullScreen(Boolean fullScreen) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnFullScreen "
|
||||
+ fullScreen);
|
||||
}
|
||||
|
||||
public void OnMenuBar(Boolean menuBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnMenuBar "
|
||||
+ menuBar);
|
||||
}
|
||||
public void OnMenuBar(Boolean menuBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnMenuBar "
|
||||
+ menuBar);
|
||||
}
|
||||
|
||||
public void OnQuit() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnQuit ");
|
||||
IETestActiveProxyThread.quitHandled = true;
|
||||
}
|
||||
public void OnQuit() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnQuit ");
|
||||
IETestActiveProxyThread.quitHandled = true;
|
||||
}
|
||||
|
||||
public void OnStatusBar(Boolean statusBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnStatusBar "
|
||||
+ statusBar);
|
||||
}
|
||||
public void OnStatusBar(Boolean statusBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnStatusBar "
|
||||
+ statusBar);
|
||||
}
|
||||
|
||||
public void OnTheaterMode(Boolean theaterMode) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnTheaterMode "
|
||||
+ theaterMode);
|
||||
}
|
||||
public void OnTheaterMode(Boolean theaterMode) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnTheaterMode "
|
||||
+ theaterMode);
|
||||
}
|
||||
|
||||
public void OnToolBar(Boolean onToolBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnToolBar "
|
||||
+ onToolBar);
|
||||
}
|
||||
public void OnToolBar(Boolean onToolBar) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): OnToolBar "
|
||||
+ onToolBar);
|
||||
}
|
||||
|
||||
public void OnVisible(Boolean onVisible) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): onVisible "
|
||||
+ onVisible);
|
||||
}
|
||||
public void OnVisible(Boolean onVisible) {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): onVisible "
|
||||
+ onVisible);
|
||||
}
|
||||
|
||||
public void ProgressChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): ProgressChange ");
|
||||
}
|
||||
public void ProgressChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): ProgressChange ");
|
||||
}
|
||||
|
||||
public void PropertyChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): PropertyChange ");
|
||||
}
|
||||
public void PropertyChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): PropertyChange ");
|
||||
}
|
||||
|
||||
public void SetSecureLockIcon(Integer secureLockIcon) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): setSecureLockIcon " + secureLockIcon);
|
||||
}
|
||||
public void SetSecureLockIcon(Integer secureLockIcon) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): setSecureLockIcon " + secureLockIcon);
|
||||
}
|
||||
|
||||
public void StatusTextChange() {
|
||||
System.out
|
||||
.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): StatusTextChange ");
|
||||
}
|
||||
public void StatusTextChange() {
|
||||
System.out
|
||||
.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName()
|
||||
+ "): StatusTextChange ");
|
||||
}
|
||||
|
||||
public void TitleChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): TitleChange ");
|
||||
}
|
||||
public void TitleChange() {
|
||||
System.out.println("IEEventsActiveProxy Received ("
|
||||
+ Thread.currentThread().getName() + "): TitleChange ");
|
||||
}
|
||||
|
||||
public void WindowClosing(Boolean isChildWindow) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): WindowClosing "
|
||||
+ isChildWindow);
|
||||
}
|
||||
}
|
||||
public void WindowClosing(Boolean isChildWindow) {
|
||||
System.out.println("IEEvents Received ("
|
||||
+ Thread.currentThread().getName() + "): WindowClosing "
|
||||
+ isChildWindow);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.events;
|
||||
|
||||
@@ -58,74 +58,74 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class WordEventTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* load up word, register for events and make stuff happen
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void testCaptureWordEvents() {
|
||||
String pid = "Word.Application";
|
||||
String typeLibLocation = null;
|
||||
/**
|
||||
* load up word, register for events and make stuff happen
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void testCaptureWordEvents() {
|
||||
String pid = "Word.Application";
|
||||
String typeLibLocation = null;
|
||||
|
||||
// Grab The Component.
|
||||
ActiveXComponent axc = new ActiveXComponent(pid);
|
||||
try {
|
||||
// Add a listener (doesn't matter what it is).
|
||||
DispatchEvents de;
|
||||
if (typeLibLocation == null) {
|
||||
de = new DispatchEvents(axc, new WordEventTest());
|
||||
} else {
|
||||
de = new DispatchEvents(axc, new WordEventTest(), pid,
|
||||
typeLibLocation);
|
||||
}
|
||||
if (de == null) {
|
||||
fail("No exception thrown but no dispatch returned for Word events");
|
||||
} else {
|
||||
// Yea!
|
||||
System.out.println("Successfully attached to " + pid);
|
||||
// Grab The Component.
|
||||
ActiveXComponent axc = new ActiveXComponent(pid);
|
||||
try {
|
||||
// Add a listener (doesn't matter what it is).
|
||||
DispatchEvents de;
|
||||
if (typeLibLocation == null) {
|
||||
de = new DispatchEvents(axc, new WordEventTest());
|
||||
} else {
|
||||
de = new DispatchEvents(axc, new WordEventTest(), pid,
|
||||
typeLibLocation);
|
||||
}
|
||||
if (de == null) {
|
||||
fail("No exception thrown but no dispatch returned for Word events");
|
||||
} else {
|
||||
// Yea!
|
||||
System.out.println("Successfully attached to " + pid);
|
||||
|
||||
}
|
||||
// this is different from the ExcelEventTest because it uses
|
||||
// the jacob active X api instead of the Dispatch api
|
||||
System.out.println("version=" + axc.getPropertyAsString("Version"));
|
||||
axc.setProperty("Visible", true);
|
||||
ActiveXComponent documents = axc
|
||||
.getPropertyAsComponent("Documents");
|
||||
if (documents == null) {
|
||||
fail("unable to get documents");
|
||||
}
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
// this is different from the ExcelEventTest because it uses
|
||||
// the jacob active X api instead of the Dispatch api
|
||||
System.out.println("version=" + axc.getPropertyAsString("Version"));
|
||||
axc.setProperty("Visible", true);
|
||||
ActiveXComponent documents = axc
|
||||
.getPropertyAsComponent("Documents");
|
||||
if (documents == null) {
|
||||
fail("unable to get documents");
|
||||
}
|
||||
axc.invoke("Quit", new Variant[] {});
|
||||
|
||||
} catch (ComException cfe) {
|
||||
cfe.printStackTrace();
|
||||
fail("Failed to attach to " + pid + ": " + cfe.getMessage());
|
||||
} catch (ComException cfe) {
|
||||
cfe.printStackTrace();
|
||||
fail("Failed to attach to " + pid + ": " + cfe.getMessage());
|
||||
|
||||
}
|
||||
System.out
|
||||
.println("Someone needs to add some MSWord commands to this to "
|
||||
+ "make some on screen stuff happens so the tester "
|
||||
+ "thinks we tested something");
|
||||
}
|
||||
}
|
||||
System.out
|
||||
.println("Someone needs to add some MSWord commands to this to "
|
||||
+ "make some on screen stuff happens so the tester "
|
||||
+ "thinks we tested something");
|
||||
}
|
||||
|
||||
/**
|
||||
* a class that receives messages from word
|
||||
*/
|
||||
public class WordEvents extends InvocationProxy {
|
||||
/**
|
||||
* Constructor so we can create an instance that implements invoke()
|
||||
*/
|
||||
public WordEvents() {
|
||||
}
|
||||
/**
|
||||
* a class that receives messages from word
|
||||
*/
|
||||
public class WordEvents extends InvocationProxy {
|
||||
/**
|
||||
* Constructor so we can create an instance that implements invoke()
|
||||
*/
|
||||
public WordEvents() {
|
||||
}
|
||||
|
||||
/**
|
||||
* override the invoke() method to log all the events without writing a
|
||||
* bunch of code
|
||||
*/
|
||||
public Variant invoke(String methodName, Variant targetParameter[]) {
|
||||
System.out.println("Received event from Windows program"
|
||||
+ methodName);
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* override the invoke() method to log all the events without writing a
|
||||
* bunch of code
|
||||
*/
|
||||
public Variant invoke(String methodName, Variant targetParameter[]) {
|
||||
System.out.println("Received event from Windows program"
|
||||
+ methodName);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.excel;
|
||||
|
||||
@@ -56,219 +56,219 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class ControllerTest extends BaseTestCase {
|
||||
|
||||
private Controller controller;
|
||||
private Controller controller;
|
||||
|
||||
protected void setUp() {
|
||||
controller = new Controller();
|
||||
}
|
||||
protected void setUp() {
|
||||
controller = new Controller();
|
||||
}
|
||||
|
||||
public void testGetColumnA() {
|
||||
List<String> list = controller.getColumnA(super
|
||||
.getWindowsFilePathToPackageResource("teste.xls", this
|
||||
.getClass()));
|
||||
assertEquals(50, list.size());
|
||||
}
|
||||
public void testGetColumnA() {
|
||||
List<String> list = controller.getColumnA(super
|
||||
.getWindowsFilePathToPackageResource("teste.xls", this
|
||||
.getClass()));
|
||||
assertEquals(50, list.size());
|
||||
}
|
||||
|
||||
public void testGetColumnB() {
|
||||
List<String> list = controller.getColumnB(super
|
||||
.getWindowsFilePathToPackageResource("teste.xls", this
|
||||
.getClass()));
|
||||
assertEquals(40, list.size());
|
||||
}
|
||||
public void testGetColumnB() {
|
||||
List<String> list = controller.getColumnB(super
|
||||
.getWindowsFilePathToPackageResource("teste.xls", this
|
||||
.getClass()));
|
||||
assertEquals(40, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* This class looks bad because it is a compressed version that was
|
||||
* originally in 3 different files as part of a bug submission. I didn't
|
||||
* want to simplify it because it might no longer demonstrate the problem we
|
||||
* were trying to fix
|
||||
*/
|
||||
public class Controller {
|
||||
/**
|
||||
* This class looks bad because it is a compressed version that was
|
||||
* originally in 3 different files as part of a bug submission. I didn't
|
||||
* want to simplify it because it might no longer demonstrate the problem we
|
||||
* were trying to fix
|
||||
*/
|
||||
public class Controller {
|
||||
|
||||
private List<String> columnA;
|
||||
private List<String> columnA;
|
||||
|
||||
private List<String> columnB;
|
||||
private List<String> columnB;
|
||||
|
||||
public List<String> getColumnA(String pathToTest) {
|
||||
load(pathToTest);
|
||||
return columnA;
|
||||
}
|
||||
public List<String> getColumnA(String pathToTest) {
|
||||
load(pathToTest);
|
||||
return columnA;
|
||||
}
|
||||
|
||||
public List<String> getColumnB(String pathToTest) {
|
||||
load(pathToTest);
|
||||
return columnB;
|
||||
}
|
||||
public List<String> getColumnB(String pathToTest) {
|
||||
load(pathToTest);
|
||||
return columnB;
|
||||
}
|
||||
|
||||
public void load(String pathToTest) {
|
||||
if (columnA == null || columnB == null) {
|
||||
File excelFile = new File(pathToTest);
|
||||
executaExcelCallBack(excelFile.getAbsolutePath(), "password");
|
||||
}
|
||||
}
|
||||
public void load(String pathToTest) {
|
||||
if (columnA == null || columnB == null) {
|
||||
File excelFile = new File(pathToTest);
|
||||
executaExcelCallBack(excelFile.getAbsolutePath(), "password");
|
||||
}
|
||||
}
|
||||
|
||||
public void executaExcelCallBack(String path, String password) {
|
||||
// ComThread.InitSTA();
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent excel = new ActiveXComponent("Excel.Application");
|
||||
public void executaExcelCallBack(String path, String password) {
|
||||
// ComThread.InitSTA();
|
||||
ComThread.InitMTA();
|
||||
ActiveXComponent excel = new ActiveXComponent("Excel.Application");
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
excel.setProperty("Visible", false);
|
||||
Dispatch workbooks = excel.getProperty("Workbooks")
|
||||
.toDispatch();
|
||||
excel.setProperty("Visible", false);
|
||||
Dispatch workbooks = excel.getProperty("Workbooks")
|
||||
.toDispatch();
|
||||
|
||||
Dispatch workbook = Dispatch.call(workbooks, "Open", path, // FileName
|
||||
3, // UpdateLinks
|
||||
false, // Readonly
|
||||
5, // Format
|
||||
password // Password
|
||||
).toDispatch();
|
||||
Dispatch workbook = Dispatch.call(workbooks, "Open", path, // FileName
|
||||
3, // UpdateLinks
|
||||
false, // Readonly
|
||||
5, // Format
|
||||
password // Password
|
||||
).toDispatch();
|
||||
|
||||
Dispatch sheets = Dispatch.call(workbook, "Worksheets")
|
||||
.toDispatch();
|
||||
System.out.println("Before executa");
|
||||
executa(excel, sheets);
|
||||
System.out.println("After executa");
|
||||
Dispatch sheets = Dispatch.call(workbook, "Worksheets")
|
||||
.toDispatch();
|
||||
System.out.println("Before executa");
|
||||
executa(excel, sheets);
|
||||
System.out.println("After executa");
|
||||
|
||||
Dispatch.call(workbook, "Close", new Variant(false));
|
||||
Dispatch.call(workbooks, "Close");
|
||||
System.out.println("After Close");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Before Quit");
|
||||
excel.invoke("Quit", new Variant[] {});
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("After Quit, Before Release()");
|
||||
ComThread.Release();
|
||||
System.out.println("After Release()");
|
||||
}
|
||||
}
|
||||
Dispatch.call(workbook, "Close", new Variant(false));
|
||||
Dispatch.call(workbooks, "Close");
|
||||
System.out.println("After Close");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Before Quit");
|
||||
excel.invoke("Quit", new Variant[] {});
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("After Quit, Before Release()");
|
||||
ComThread.Release();
|
||||
System.out.println("After Release()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constante para configurar a planilha em modo "Calculation" autom<6F>tico
|
||||
*/
|
||||
public static final int CALC_AUTOMATICO = -4105;
|
||||
/**
|
||||
* Constante para configurar a planilha em modo "Calculation" autom<6F>tico
|
||||
*/
|
||||
public static final int CALC_AUTOMATICO = -4105;
|
||||
|
||||
/**
|
||||
* Constante para configurar a planilha em modo "Calculation" manual
|
||||
*/
|
||||
public static final int CALC_MANUAL = -4135;
|
||||
/**
|
||||
* Constante para configurar a planilha em modo "Calculation" manual
|
||||
*/
|
||||
public static final int CALC_MANUAL = -4135;
|
||||
|
||||
/**
|
||||
* Escreve um determinado valor em uma c<>lula da pasta em quest<73>o. O
|
||||
* valor <20> escrito configurando a propriedade Value da c<>lula
|
||||
*
|
||||
* @param celula -
|
||||
* c<>lula para escrever novo valor
|
||||
* @param sheet -
|
||||
* pasta da planilha em quest<73>o
|
||||
* @param valor -
|
||||
* valor a ser escrito na celula
|
||||
*/
|
||||
public void informarValorCelula(String celula, Dispatch sheet,
|
||||
String valor) {
|
||||
System.out.println("Entered informarValorCelula");
|
||||
Dispatch cel = obterCelula(celula, sheet);
|
||||
Dispatch.put(cel, "Value", valor);
|
||||
System.out.println("Exiting informarValorCelula");
|
||||
}
|
||||
/**
|
||||
* Escreve um determinado valor em uma c<>lula da pasta em quest<73>o. O
|
||||
* valor <20> escrito configurando a propriedade Value da c<>lula
|
||||
*
|
||||
* @param celula -
|
||||
* c<>lula para escrever novo valor
|
||||
* @param sheet -
|
||||
* pasta da planilha em quest<73>o
|
||||
* @param valor -
|
||||
* valor a ser escrito na celula
|
||||
*/
|
||||
public void informarValorCelula(String celula, Dispatch sheet,
|
||||
String valor) {
|
||||
System.out.println("Entered informarValorCelula");
|
||||
Dispatch cel = obterCelula(celula, sheet);
|
||||
Dispatch.put(cel, "Value", valor);
|
||||
System.out.println("Exiting informarValorCelula");
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtem o valor de contido em uma c<>lula. O valor representa o conte<74>do
|
||||
* da propriedade Value da c<>lula
|
||||
*
|
||||
* @param celula -
|
||||
* c<>lula a ser lida
|
||||
* @param sheet -
|
||||
* pasta da planilha que cont<6E>m a c<>lula
|
||||
* @return - conte<74>do da propriedade Value
|
||||
*/
|
||||
public Variant obterValorCelula(String celula, Dispatch sheet) {
|
||||
System.out.println("Entered obterValorCelula");
|
||||
Dispatch d = obterCelula(celula, sheet);
|
||||
Variant returnedValue = Dispatch.get(d, "Value");
|
||||
System.out.println("Exiting obterValorCelula");
|
||||
return returnedValue;
|
||||
}
|
||||
/**
|
||||
* Obtem o valor de contido em uma c<>lula. O valor representa o conte<74>do
|
||||
* da propriedade Value da c<>lula
|
||||
*
|
||||
* @param celula -
|
||||
* c<>lula a ser lida
|
||||
* @param sheet -
|
||||
* pasta da planilha que cont<6E>m a c<>lula
|
||||
* @return - conte<74>do da propriedade Value
|
||||
*/
|
||||
public Variant obterValorCelula(String celula, Dispatch sheet) {
|
||||
System.out.println("Entered obterValorCelula");
|
||||
Dispatch d = obterCelula(celula, sheet);
|
||||
Variant returnedValue = Dispatch.get(d, "Value");
|
||||
System.out.println("Exiting obterValorCelula");
|
||||
return returnedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtem refer<65>ncia para a c<>lua ou conjunto de c<>lulas especificado no
|
||||
* parametro
|
||||
*
|
||||
* @param celula -
|
||||
* Refer<65>ncia para c<>lula ou conjunto de c<>lulas. A String
|
||||
* "A1" referencia a coluna A e linha 1. A Sting "A1:A10"
|
||||
* referencia as c<>lulas compreendidas no intervalo entre a
|
||||
* c<>lua A1 e a c<>lula A10
|
||||
* @param sheet -
|
||||
* pasta da planilha qye cont<6E>m as c<>lulas
|
||||
* @return - referencia para um c<>lula ou conjunto de c<>lulas,
|
||||
* dependendo do par<61>metro passado
|
||||
*/
|
||||
public Dispatch obterCelula(String celula, Dispatch sheet) {
|
||||
System.out.println("Entered obterCelula");
|
||||
Dispatch d = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { celula }, new int[1]).toDispatch();
|
||||
System.out.println("Exiting obterCelula");
|
||||
return d;
|
||||
}
|
||||
/**
|
||||
* Obtem refer<65>ncia para a c<>lua ou conjunto de c<>lulas especificado no
|
||||
* parametro
|
||||
*
|
||||
* @param celula -
|
||||
* Refer<65>ncia para c<>lula ou conjunto de c<>lulas. A String
|
||||
* "A1" referencia a coluna A e linha 1. A Sting "A1:A10"
|
||||
* referencia as c<>lulas compreendidas no intervalo entre a
|
||||
* c<>lua A1 e a c<>lula A10
|
||||
* @param sheet -
|
||||
* pasta da planilha qye cont<6E>m as c<>lulas
|
||||
* @return - referencia para um c<>lula ou conjunto de c<>lulas,
|
||||
* dependendo do par<61>metro passado
|
||||
*/
|
||||
public Dispatch obterCelula(String celula, Dispatch sheet) {
|
||||
System.out.println("Entered obterCelula");
|
||||
Dispatch d = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { celula }, new int[1]).toDispatch();
|
||||
System.out.println("Exiting obterCelula");
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtem os valores de um conjunto de c<>lulas
|
||||
*
|
||||
* @param celulas -
|
||||
* Refer<65>ncia para conjunto de c<>lulas
|
||||
* @param sheet -
|
||||
* Pasta que cont<6E>m as c<>lulas referenciadas
|
||||
* @return - Lista onde cada elemento <20> o valor de uma c<>lula
|
||||
* referenciada na conjunto
|
||||
*/
|
||||
public List<String> obterValoresRange(String celulas, Dispatch sheet) {
|
||||
List<String> valores = new LinkedList<String>();
|
||||
/**
|
||||
* Obtem os valores de um conjunto de c<>lulas
|
||||
*
|
||||
* @param celulas -
|
||||
* Refer<65>ncia para conjunto de c<>lulas
|
||||
* @param sheet -
|
||||
* Pasta que cont<6E>m as c<>lulas referenciadas
|
||||
* @return - Lista onde cada elemento <20> o valor de uma c<>lula
|
||||
* referenciada na conjunto
|
||||
*/
|
||||
public List<String> obterValoresRange(String celulas, Dispatch sheet) {
|
||||
List<String> valores = new LinkedList<String>();
|
||||
|
||||
// obtem valor das celulas como um Variant
|
||||
Variant var = obterValorCelula(celulas, sheet);
|
||||
// obtem valor das celulas como um Variant
|
||||
Variant var = obterValorCelula(celulas, sheet);
|
||||
|
||||
// toString da Variant <20> interpretado por um StringTokenizer e os
|
||||
// tokens
|
||||
// inseridos na lista de retorno
|
||||
String arrayAsString = null;
|
||||
System.out
|
||||
.println("Calling toString() on the Variant that is an array will blow up "
|
||||
+ var.getvt() + " --> " + arrayAsString);
|
||||
arrayAsString = var.toString();
|
||||
StringTokenizer st = new StringTokenizer(arrayAsString, "\n");
|
||||
while (st.hasMoreTokens()) {
|
||||
valores.add(st.nextToken().trim());
|
||||
}
|
||||
return valores;
|
||||
}
|
||||
// toString da Variant <20> interpretado por um StringTokenizer e os
|
||||
// tokens
|
||||
// inseridos na lista de retorno
|
||||
String arrayAsString = null;
|
||||
System.out
|
||||
.println("Calling toString() on the Variant that is an array will blow up "
|
||||
+ var.getvt() + " --> " + arrayAsString);
|
||||
arrayAsString = var.toString();
|
||||
StringTokenizer st = new StringTokenizer(arrayAsString, "\n");
|
||||
while (st.hasMoreTokens()) {
|
||||
valores.add(st.nextToken().trim());
|
||||
}
|
||||
return valores;
|
||||
}
|
||||
|
||||
/**
|
||||
* M<>todo para execu<63><75>o de a<><61>o a ser executada em planilha excel.
|
||||
*
|
||||
* @param xl -
|
||||
* Referencia para aplica<63><61>o excel
|
||||
* @param sheets -
|
||||
* Referencia para conjunto de pastas da planilha
|
||||
*/
|
||||
public void executa(ActiveXComponent xl, Dispatch sheets) {
|
||||
/**
|
||||
* M<>todo para execu<63><75>o de a<><61>o a ser executada em planilha excel.
|
||||
*
|
||||
* @param xl -
|
||||
* Referencia para aplica<63><61>o excel
|
||||
* @param sheets -
|
||||
* Referencia para conjunto de pastas da planilha
|
||||
*/
|
||||
public void executa(ActiveXComponent xl, Dispatch sheets) {
|
||||
|
||||
System.out.println("Entered private ExcellCallBack executa()");
|
||||
Dispatch sheet = Dispatch.call(sheets, "Item", "Plan1")
|
||||
.toDispatch();
|
||||
columnA = obterValoresRange("A1:A50", sheet);
|
||||
columnB = obterValoresRange("B1:B40", sheet);
|
||||
System.out.println("Exiting private ExcellCallBack executa()");
|
||||
}
|
||||
}
|
||||
System.out.println("Entered private ExcellCallBack executa()");
|
||||
Dispatch sheet = Dispatch.call(sheets, "Item", "Plan1")
|
||||
.toDispatch();
|
||||
columnA = obterValoresRange("A1:A50", sheet);
|
||||
columnB = obterValoresRange("B1:B40", sheet);
|
||||
System.out.println("Exiting private ExcellCallBack executa()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.powerpoint;
|
||||
|
||||
@@ -69,131 +69,131 @@ import com.jacob.test.BaseTestCase;
|
||||
* options.
|
||||
*/
|
||||
public class PowerpointTest extends BaseTestCase {
|
||||
private static final int NUM_THREADS = 5;
|
||||
protected static final int NUM_ITERATIONS = 50;
|
||||
private static final int NUM_THREADS = 5;
|
||||
protected static final int NUM_ITERATIONS = 50;
|
||||
|
||||
/**
|
||||
* main program that lets us run this as a test
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void testPowerpoint() {
|
||||
ComThread.InitMTA();
|
||||
/**
|
||||
* main program that lets us run this as a test
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void testPowerpoint() {
|
||||
ComThread.InitMTA();
|
||||
|
||||
ActiveXComponent component = new ActiveXComponent(
|
||||
"Powerpoint.Application");
|
||||
Dispatch comPowerpoint = component.getObject();
|
||||
ActiveXComponent component = new ActiveXComponent(
|
||||
"Powerpoint.Application");
|
||||
Dispatch comPowerpoint = component.getObject();
|
||||
|
||||
try {
|
||||
PowerpointTestThread[] threads = new PowerpointTestThread[NUM_THREADS];
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
threads[i] = new PowerpointTestThread(i + 1, comPowerpoint);
|
||||
threads[i].start();
|
||||
}
|
||||
try {
|
||||
PowerpointTestThread[] threads = new PowerpointTestThread[NUM_THREADS];
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
threads[i] = new PowerpointTestThread(i + 1, comPowerpoint);
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
boolean allThreadsFinished = false;
|
||||
while (!allThreadsFinished) {
|
||||
allThreadsFinished = true;
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
if (threads[i].isAlive()) {
|
||||
allThreadsFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!allThreadsFinished) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
// no op
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean allThreadsFinished = false;
|
||||
while (!allThreadsFinished) {
|
||||
allThreadsFinished = true;
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
if (threads[i].isAlive()) {
|
||||
allThreadsFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!allThreadsFinished) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
// no op
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dispatch.call(comPowerpoint, "Quit");
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
if (threads[i].threadFailedWithException != null) {
|
||||
fail("caught unexpected exception in thread "
|
||||
+ threads[i].threadFailedWithException);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
}
|
||||
Dispatch.call(comPowerpoint, "Quit");
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
if (threads[i].threadFailedWithException != null) {
|
||||
fail("caught unexpected exception in thread "
|
||||
+ threads[i].threadFailedWithException);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the thread class that runs power point
|
||||
*/
|
||||
public class PowerpointTestThread extends Thread {
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
/**
|
||||
* the thread class that runs power point
|
||||
*/
|
||||
public class PowerpointTestThread extends Thread {
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
|
||||
private int threadID;
|
||||
private Dispatch comPowerpoint;
|
||||
private int threadID;
|
||||
private Dispatch comPowerpoint;
|
||||
|
||||
/**
|
||||
* thread constructor
|
||||
*
|
||||
* @param threadID
|
||||
* @param comPowerpoint
|
||||
*/
|
||||
public PowerpointTestThread(int threadID, Dispatch comPowerpoint) {
|
||||
super("TestThread " + threadID);
|
||||
this.threadID = threadID;
|
||||
this.comPowerpoint = comPowerpoint;
|
||||
}
|
||||
/**
|
||||
* thread constructor
|
||||
*
|
||||
* @param threadID
|
||||
* @param comPowerpoint
|
||||
*/
|
||||
public PowerpointTestThread(int threadID, Dispatch comPowerpoint) {
|
||||
super("TestThread " + threadID);
|
||||
this.threadID = threadID;
|
||||
this.comPowerpoint = comPowerpoint;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("Thread \"" + Thread.currentThread().getName()
|
||||
+ "\" started");
|
||||
System.out.flush();
|
||||
ComThread.InitMTA();
|
||||
try {
|
||||
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
||||
if (i % 10 == 0) {
|
||||
System.out.println(Thread.currentThread().getName()
|
||||
+ ": Iteration " + i);
|
||||
System.out.flush();
|
||||
}
|
||||
// office 2003 seems to have been able to handle more
|
||||
// multi-threaded requests than office 2007
|
||||
// office 2003 could handle 5 threads @ 50 iterations
|
||||
// office 2007 can only handle 1 thread at a time
|
||||
synchronized(comPowerpoint){
|
||||
Dispatch comPresentations = Dispatch.get(comPowerpoint,
|
||||
"Presentations").toDispatch();
|
||||
Dispatch comPresentation = Dispatch.call(
|
||||
comPresentations,
|
||||
"Open",
|
||||
getWindowsFilePathToPackageResource("test"
|
||||
+ threadID + ".ppt", this.getClass()),
|
||||
new Integer(0), new Integer(0), new Integer(0))
|
||||
.toDispatch();
|
||||
Dispatch.call(comPresentation, "Close");
|
||||
}
|
||||
}
|
||||
} catch (ComFailException cfe) {
|
||||
threadFailedWithException = cfe;
|
||||
System.err.println(Thread.currentThread().getName()
|
||||
+ "\" while working on: "
|
||||
+ getWindowsFilePathToPackageResource("test" + threadID
|
||||
+ ".ppt", this.getClass()));
|
||||
cfe.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
System.err.println("Error in Thread \""
|
||||
+ Thread.currentThread().getName() + "\":");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
System.out.println("Thread \""
|
||||
+ Thread.currentThread().getName() + "\" finished");
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
System.out.println("Thread \"" + Thread.currentThread().getName()
|
||||
+ "\" started");
|
||||
System.out.flush();
|
||||
ComThread.InitMTA();
|
||||
try {
|
||||
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
||||
if (i % 10 == 0) {
|
||||
System.out.println(Thread.currentThread().getName()
|
||||
+ ": Iteration " + i);
|
||||
System.out.flush();
|
||||
}
|
||||
// office 2003 seems to have been able to handle more
|
||||
// multi-threaded requests than office 2007
|
||||
// office 2003 could handle 5 threads @ 50 iterations
|
||||
// office 2007 can only handle 1 thread at a time
|
||||
synchronized(comPowerpoint){
|
||||
Dispatch comPresentations = Dispatch.get(comPowerpoint,
|
||||
"Presentations").toDispatch();
|
||||
Dispatch comPresentation = Dispatch.call(
|
||||
comPresentations,
|
||||
"Open",
|
||||
getWindowsFilePathToPackageResource("test"
|
||||
+ threadID + ".ppt", this.getClass()),
|
||||
new Integer(0), new Integer(0), new Integer(0))
|
||||
.toDispatch();
|
||||
Dispatch.call(comPresentation, "Close");
|
||||
}
|
||||
}
|
||||
} catch (ComFailException cfe) {
|
||||
threadFailedWithException = cfe;
|
||||
System.err.println(Thread.currentThread().getName()
|
||||
+ "\" while working on: "
|
||||
+ getWindowsFilePathToPackageResource("test" + threadID
|
||||
+ ".ppt", this.getClass()));
|
||||
cfe.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
System.err.println("Error in Thread \""
|
||||
+ Thread.currentThread().getName() + "\":");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
System.out.println("Thread \""
|
||||
+ Thread.currentThread().getName() + "\" finished");
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.safearray;
|
||||
|
||||
@@ -57,297 +57,297 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class SafeArrayBasicTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testShortSafeArray() {
|
||||
short sourceData[] = new short[] { 1, 2, 3 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testShortSafeArray() {
|
||||
short sourceData[] = new short[] { 1, 2, 3 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
|
||||
saUnderTest.fromShortArray(sourceData);
|
||||
short[] extractedFromSafeArray = saUnderTest.toShortArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
saUnderTest.fromShortArray(sourceData);
|
||||
short[] extractedFromSafeArray = saUnderTest.toShortArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getShort(2));
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getShort(2));
|
||||
|
||||
// test conversion
|
||||
int[] extractedFromSafeArrayInt = saUnderTest.toIntArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArrayInt[i]);
|
||||
}
|
||||
// test conversion
|
||||
double[] extractedFromSafeArrayDouble = saUnderTest.toDoubleArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayDouble.length; i++) {
|
||||
assertEquals("" + i, new Double(sourceData[i]).doubleValue(),
|
||||
extractedFromSafeArrayDouble[i]);
|
||||
}
|
||||
// test conversion
|
||||
Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
|
||||
assertEquals("" + i, sourceData[i],
|
||||
extractedFromSafeArrayVariant[i].getShort());
|
||||
}
|
||||
}
|
||||
// test conversion
|
||||
int[] extractedFromSafeArrayInt = saUnderTest.toIntArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArrayInt[i]);
|
||||
}
|
||||
// test conversion
|
||||
double[] extractedFromSafeArrayDouble = saUnderTest.toDoubleArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayDouble.length; i++) {
|
||||
assertEquals("" + i, new Double(sourceData[i]).doubleValue(),
|
||||
extractedFromSafeArrayDouble[i]);
|
||||
}
|
||||
// test conversion
|
||||
Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
|
||||
assertEquals("" + i, sourceData[i],
|
||||
extractedFromSafeArrayVariant[i].getShort());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testIntSafeArray() {
|
||||
int sourceData[] = new int[] { 100000, 200000, 300000 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromIntArray(sourceData);
|
||||
int[] extractedFromSafeArray = saUnderTest.toIntArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getInt(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testIntSafeArray() {
|
||||
int sourceData[] = new int[] { 100000, 200000, 300000 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromIntArray(sourceData);
|
||||
int[] extractedFromSafeArray = saUnderTest.toIntArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getInt(2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testLongSafeArrayVariantVariant() {
|
||||
long sourceData[] = new long[] { 2L << 40, 3L << 41, 4L << 42 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant,
|
||||
sourceData.length);
|
||||
saUnderTest.fromLongArray(sourceData);
|
||||
long[] extractedFromSafeArray = saUnderTest.toLongArray();
|
||||
assertEquals(sourceData.length, extractedFromSafeArray.length);
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("failed on index " + i, sourceData[i],
|
||||
extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getLong(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testLongSafeArrayVariantVariant() {
|
||||
long sourceData[] = new long[] { 2L << 40, 3L << 41, 4L << 42 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant,
|
||||
sourceData.length);
|
||||
saUnderTest.fromLongArray(sourceData);
|
||||
long[] extractedFromSafeArray = saUnderTest.toLongArray();
|
||||
assertEquals(sourceData.length, extractedFromSafeArray.length);
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("failed on index " + i, sourceData[i],
|
||||
extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getLong(2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testLongSafeArrayVariantLongInt() {
|
||||
long sourceData[] = new long[] { 2L << 40, 3L << 41, 4L << 42 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantLongInt,
|
||||
sourceData.length);
|
||||
saUnderTest.fromLongArray(sourceData);
|
||||
long[] extractedFromSafeArray = saUnderTest.toLongArray();
|
||||
assertEquals(sourceData.length, extractedFromSafeArray.length);
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("failed on index " + i, sourceData[i],
|
||||
extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getLong(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testLongSafeArrayVariantLongInt() {
|
||||
long sourceData[] = new long[] { 2L << 40, 3L << 41, 4L << 42 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantLongInt,
|
||||
sourceData.length);
|
||||
saUnderTest.fromLongArray(sourceData);
|
||||
long[] extractedFromSafeArray = saUnderTest.toLongArray();
|
||||
assertEquals(sourceData.length, extractedFromSafeArray.length);
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("failed on index " + i, sourceData[i],
|
||||
extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getLong(2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testDoubleSafeArrayVariantVariant() {
|
||||
double sourceData[] = new double[] { 1.5, 2.5, 3.5 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant,
|
||||
sourceData.length);
|
||||
saUnderTest.fromDoubleArray(sourceData);
|
||||
double[] extractedFromSafeArray = saUnderTest.toDoubleArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getDouble(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testDoubleSafeArrayVariantVariant() {
|
||||
double sourceData[] = new double[] { 1.5, 2.5, 3.5 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant,
|
||||
sourceData.length);
|
||||
saUnderTest.fromDoubleArray(sourceData);
|
||||
double[] extractedFromSafeArray = saUnderTest.toDoubleArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getDouble(2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testDoubleSafeArrayVariantDouble() {
|
||||
double sourceData[] = new double[] { 1.5, 2.5, 3.5 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantDouble,
|
||||
sourceData.length);
|
||||
saUnderTest.fromDoubleArray(sourceData);
|
||||
double[] extractedFromSafeArray = saUnderTest.toDoubleArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getDouble(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testDoubleSafeArrayVariantDouble() {
|
||||
double sourceData[] = new double[] { 1.5, 2.5, 3.5 };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantDouble,
|
||||
sourceData.length);
|
||||
saUnderTest.fromDoubleArray(sourceData);
|
||||
double[] extractedFromSafeArray = saUnderTest.toDoubleArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getDouble(2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testFloatSafeArray() {
|
||||
float sourceData[] = new float[] { 1.5F, 2.5F, 3.5F };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromFloatArray(sourceData);
|
||||
float[] extractedFromSafeArray = saUnderTest.toFloatArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testFloatSafeArray() {
|
||||
float sourceData[] = new float[] { 1.5F, 2.5F, 3.5F };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromFloatArray(sourceData);
|
||||
float[] extractedFromSafeArray = saUnderTest.toFloatArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testBooleanSafeArray() {
|
||||
boolean sourceData[] = new boolean[] { true, false, true, false };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromBooleanArray(sourceData);
|
||||
boolean[] extractedFromSafeArray = saUnderTest.toBooleanArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getBoolean(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testBooleanSafeArray() {
|
||||
boolean sourceData[] = new boolean[] { true, false, true, false };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromBooleanArray(sourceData);
|
||||
boolean[] extractedFromSafeArray = saUnderTest.toBooleanArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getBoolean(2));
|
||||
|
||||
// test conversion
|
||||
Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
|
||||
assertEquals("" + i, sourceData[i],
|
||||
extractedFromSafeArrayVariant[i].getBoolean());
|
||||
}
|
||||
}
|
||||
// test conversion
|
||||
Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
|
||||
assertEquals("" + i, sourceData[i],
|
||||
extractedFromSafeArrayVariant[i].getBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testCharSafeArray() {
|
||||
char sourceData[] = new char[] { 'a', 'b', 'c', 'd' };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromCharArray(sourceData);
|
||||
char[] extractedFromSafeArray = saUnderTest.toCharArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getChar(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testCharSafeArray() {
|
||||
char sourceData[] = new char[] { 'a', 'b', 'c', 'd' };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromCharArray(sourceData);
|
||||
char[] extractedFromSafeArray = saUnderTest.toCharArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getChar(2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testStringSafeArray() {
|
||||
String sourceData[] = new String[] { "hello", "from", "java", "com" };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromStringArray(sourceData);
|
||||
String[] extractedFromSafeArray = saUnderTest.toStringArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getString(2));
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testStringSafeArray() {
|
||||
String sourceData[] = new String[] { "hello", "from", "java", "com" };
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromStringArray(sourceData);
|
||||
String[] extractedFromSafeArray = saUnderTest.toStringArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i], extractedFromSafeArray[i]);
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2], saUnderTest
|
||||
.getString(2));
|
||||
|
||||
// test conversion
|
||||
Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
|
||||
assertEquals("" + i, sourceData[i],
|
||||
extractedFromSafeArrayVariant[i].getString());
|
||||
}
|
||||
}
|
||||
// test conversion
|
||||
Variant extractedFromSafeArrayVariant[] = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArrayVariant.length; i++) {
|
||||
assertEquals("" + i, sourceData[i],
|
||||
extractedFromSafeArrayVariant[i].getString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify we get expected unicode this test forces this file to UTF-16 :-(
|
||||
* SF 2847577
|
||||
*
|
||||
* <pre>
|
||||
* The console output will be the following without unicode support:
|
||||
* Russian: <20>? уÑ<C692>?Ñ<>?<3F>?º<>?¸<>?¹
|
||||
*
|
||||
* Expected:
|
||||
* Russian: Ру<D0A0>?<3F>?кий
|
||||
*</pre>
|
||||
*/
|
||||
public void testStringUnicode() {
|
||||
SafeArray sa = new SafeArray(Variant.VariantString, 1);
|
||||
sa.setString(0, "Russian: \u0420\u0443\u0441\u0441\u043A\u0438\u0439");
|
||||
String result = sa.getString(0);
|
||||
Assert.assertEquals("Russian: Ру<D0A0>?<3F>?кий", result);
|
||||
// System.out.println(sa.getString(0));
|
||||
}
|
||||
/**
|
||||
* Verify we get expected unicode this test forces this file to UTF-16 :-(
|
||||
* SF 2847577
|
||||
*
|
||||
* <pre>
|
||||
* The console output will be the following without unicode support:
|
||||
* Russian: <20>? уÑ<C692>?Ñ<>?<3F>?º<>?¸<>?¹
|
||||
*
|
||||
* Expected:
|
||||
* Russian: Ру<D0A0>?<3F>?кий
|
||||
*</pre>
|
||||
*/
|
||||
public void testStringUnicode() {
|
||||
SafeArray sa = new SafeArray(Variant.VariantString, 1);
|
||||
sa.setString(0, "Russian: \u0420\u0443\u0441\u0441\u043A\u0438\u0439");
|
||||
String result = sa.getString(0);
|
||||
Assert.assertEquals("Russian: Ру<D0A0>?<3F>?кий", result);
|
||||
// System.out.println(sa.getString(0));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testVariantSafeArray() {
|
||||
Variant sourceData[] = new Variant[] { new Variant(1),
|
||||
new Variant(2.3), new Variant("hi") };
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void testVariantSafeArray() {
|
||||
Variant sourceData[] = new Variant[] { new Variant(1),
|
||||
new Variant(2.3), new Variant("hi") };
|
||||
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromVariantArray(sourceData);
|
||||
Variant[] extractedFromSafeArray = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i].toString(),
|
||||
extractedFromSafeArray[i].toString());
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2].toString(),
|
||||
saUnderTest.getVariant(2).toString());
|
||||
SafeArray saUnderTest = new SafeArray(Variant.VariantVariant, 3);
|
||||
saUnderTest.fromVariantArray(sourceData);
|
||||
Variant[] extractedFromSafeArray = saUnderTest.toVariantArray();
|
||||
for (int i = 0; i < extractedFromSafeArray.length; i++) {
|
||||
assertEquals("" + i, sourceData[i].toString(),
|
||||
extractedFromSafeArray[i].toString());
|
||||
}
|
||||
assertEquals("single get failed: ", sourceData[2].toString(),
|
||||
saUnderTest.getVariant(2).toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test method that verifies setting of bounds in multi-dimensional arrays
|
||||
*/
|
||||
public void testSafeArrayNumDimensions() {
|
||||
int[] lowerBounds = new int[] { 0, 0, 0 };
|
||||
int[] dimensionSizes = new int[] { 3, 3, 3 };
|
||||
/**
|
||||
* test method that verifies setting of bounds in multi-dimensional arrays
|
||||
*/
|
||||
public void testSafeArrayNumDimensions() {
|
||||
int[] lowerBounds = new int[] { 0, 0, 0 };
|
||||
int[] dimensionSizes = new int[] { 3, 3, 3 };
|
||||
|
||||
SafeArray sa3x3 = new SafeArray(Variant.VariantVariant, lowerBounds,
|
||||
dimensionSizes);
|
||||
SafeArray sa3x3 = new SafeArray(Variant.VariantVariant, lowerBounds,
|
||||
dimensionSizes);
|
||||
|
||||
Assert.assertEquals(3, sa3x3.getNumDim());
|
||||
// System.out.println("Num Dimensions = " + sa3x3.getNumDim());
|
||||
for (int safeArrayDimension = 1; safeArrayDimension <= sa3x3
|
||||
.getNumDim(); safeArrayDimension++) {
|
||||
int configArrayIndex = safeArrayDimension - 1;
|
||||
assertEquals("unexpected lower bound value ",
|
||||
lowerBounds[configArrayIndex], sa3x3
|
||||
.getLBound(safeArrayDimension));
|
||||
assertEquals("unexpeced upper bound value ",
|
||||
(dimensionSizes[configArrayIndex] - 1)
|
||||
+ lowerBounds[configArrayIndex], sa3x3
|
||||
.getUBound(safeArrayDimension));
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(3, sa3x3.getNumDim());
|
||||
// System.out.println("Num Dimensions = " + sa3x3.getNumDim());
|
||||
for (int safeArrayDimension = 1; safeArrayDimension <= sa3x3
|
||||
.getNumDim(); safeArrayDimension++) {
|
||||
int configArrayIndex = safeArrayDimension - 1;
|
||||
assertEquals("unexpected lower bound value ",
|
||||
lowerBounds[configArrayIndex], sa3x3
|
||||
.getLBound(safeArrayDimension));
|
||||
assertEquals("unexpeced upper bound value ",
|
||||
(dimensionSizes[configArrayIndex] - 1)
|
||||
+ lowerBounds[configArrayIndex], sa3x3
|
||||
.getUBound(safeArrayDimension));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test the set and get method on multi-dimensional arrays
|
||||
*/
|
||||
public void testSafeArrayMultiDimension() {
|
||||
/**
|
||||
* test the set and get method on multi-dimensional arrays
|
||||
*/
|
||||
public void testSafeArrayMultiDimension() {
|
||||
|
||||
int[] lowerBounds = new int[] { 0, 0, 0 };
|
||||
int[] dimensionSizes = new int[] { 3, 3, 3 };
|
||||
int[] lowerBounds = new int[] { 0, 0, 0 };
|
||||
int[] dimensionSizes = new int[] { 3, 3, 3 };
|
||||
|
||||
SafeArray sa3x3 = new SafeArray(Variant.VariantVariant, lowerBounds,
|
||||
dimensionSizes);
|
||||
int[] indices = new int[] { 0, 0, 0 };
|
||||
SafeArray sa3x3 = new SafeArray(Variant.VariantVariant, lowerBounds,
|
||||
dimensionSizes);
|
||||
int[] indices = new int[] { 0, 0, 0 };
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
indices[0] = i;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
indices[1] = j;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
indices[2] = k;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
indices[0] = i;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
indices[1] = j;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
indices[2] = k;
|
||||
|
||||
int fill = 0;
|
||||
fill = i * 100 + j * 10 + k;
|
||||
sa3x3.setInt(indices, fill);
|
||||
assertEquals(fill, sa3x3.getInt(indices));
|
||||
int fill = 0;
|
||||
fill = i * 100 + j * 10 + k;
|
||||
sa3x3.setInt(indices, fill);
|
||||
assertEquals(fill, sa3x3.getInt(indices));
|
||||
|
||||
long fillLong = 0L;
|
||||
// Pick a number bigger than 2^31
|
||||
fillLong = 100000000000000L * fill;
|
||||
sa3x3.setLong(indices, fillLong);
|
||||
assertEquals(fillLong, sa3x3.getLong(indices));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
long fillLong = 0L;
|
||||
// Pick a number bigger than 2^31
|
||||
fillLong = 100000000000000L * fill;
|
||||
sa3x3.setLong(indices, fillLong);
|
||||
assertEquals(fillLong, sa3x3.getLong(indices));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.safearray;
|
||||
|
||||
@@ -53,259 +53,259 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class SafeArrayContents extends BaseTestCase {
|
||||
|
||||
public static void printArray(boolean a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(boolean a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(int a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(int a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(short a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(short a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(byte a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(byte a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(double a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(double a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(float a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(float a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(String a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(String a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(Variant a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(Variant a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public static void printArray(char a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
public static void printArray(char a[]) {
|
||||
System.out.print("[");
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.print(" " + a[i] + " ");
|
||||
}
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
public void testSafeArrayContents() {
|
||||
// int
|
||||
System.out.println("Int");
|
||||
SafeArray ia = new SafeArray(Variant.VariantInt, 4);
|
||||
System.out.println("elem size:" + ia.getElemSize());
|
||||
int iack[] = new int[] { 100000, 200000, 300000, 400000 };
|
||||
printArray(iack);
|
||||
ia.fromIntArray(iack);
|
||||
iack = ia.toIntArray();
|
||||
printArray(iack);
|
||||
public void testSafeArrayContents() {
|
||||
// int
|
||||
System.out.println("Int");
|
||||
SafeArray ia = new SafeArray(Variant.VariantInt, 4);
|
||||
System.out.println("elem size:" + ia.getElemSize());
|
||||
int iack[] = new int[] { 100000, 200000, 300000, 400000 };
|
||||
printArray(iack);
|
||||
ia.fromIntArray(iack);
|
||||
iack = ia.toIntArray();
|
||||
printArray(iack);
|
||||
|
||||
int i4[] = new int[4];
|
||||
ia.getInts(0, 4, i4, 0);
|
||||
printArray(i4);
|
||||
int i4[] = new int[4];
|
||||
ia.getInts(0, 4, i4, 0);
|
||||
printArray(i4);
|
||||
|
||||
SafeArray ia2 = new SafeArray(Variant.VariantInt, 4);
|
||||
ia2.setInts(0, 4, i4, 0);
|
||||
iack = ia2.toIntArray();
|
||||
printArray(iack);
|
||||
SafeArray ia2 = new SafeArray(Variant.VariantInt, 4);
|
||||
ia2.setInts(0, 4, i4, 0);
|
||||
iack = ia2.toIntArray();
|
||||
printArray(iack);
|
||||
|
||||
// double
|
||||
System.out.println("Double");
|
||||
SafeArray da = new SafeArray(Variant.VariantDouble, 4);
|
||||
System.out.println("elem size:" + da.getElemSize());
|
||||
double dack[] = new double[] { 123.456, 456.123, 1234567.89, 12.3456789 };
|
||||
printArray(dack);
|
||||
da.fromDoubleArray(dack);
|
||||
dack = da.toDoubleArray();
|
||||
printArray(dack);
|
||||
// double
|
||||
System.out.println("Double");
|
||||
SafeArray da = new SafeArray(Variant.VariantDouble, 4);
|
||||
System.out.println("elem size:" + da.getElemSize());
|
||||
double dack[] = new double[] { 123.456, 456.123, 1234567.89, 12.3456789 };
|
||||
printArray(dack);
|
||||
da.fromDoubleArray(dack);
|
||||
dack = da.toDoubleArray();
|
||||
printArray(dack);
|
||||
|
||||
double d4[] = new double[4];
|
||||
da.getDoubles(0, 4, d4, 0);
|
||||
printArray(d4);
|
||||
double d4[] = new double[4];
|
||||
da.getDoubles(0, 4, d4, 0);
|
||||
printArray(d4);
|
||||
|
||||
SafeArray da2 = new SafeArray(Variant.VariantDouble, 4);
|
||||
da2.setDoubles(0, 4, d4, 0);
|
||||
dack = da2.toDoubleArray();
|
||||
printArray(dack);
|
||||
SafeArray da2 = new SafeArray(Variant.VariantDouble, 4);
|
||||
da2.setDoubles(0, 4, d4, 0);
|
||||
dack = da2.toDoubleArray();
|
||||
printArray(dack);
|
||||
|
||||
// float
|
||||
System.out.println("Float");
|
||||
SafeArray fa = new SafeArray(Variant.VariantFloat, 4);
|
||||
System.out.println("elem size:" + fa.getElemSize());
|
||||
float fack[] = new float[] { 123.456F, 456.123F, 1234567.89F,
|
||||
12.3456789F };
|
||||
printArray(fack);
|
||||
fa.fromFloatArray(fack);
|
||||
fack = fa.toFloatArray();
|
||||
printArray(fack);
|
||||
// float
|
||||
System.out.println("Float");
|
||||
SafeArray fa = new SafeArray(Variant.VariantFloat, 4);
|
||||
System.out.println("elem size:" + fa.getElemSize());
|
||||
float fack[] = new float[] { 123.456F, 456.123F, 1234567.89F,
|
||||
12.3456789F };
|
||||
printArray(fack);
|
||||
fa.fromFloatArray(fack);
|
||||
fack = fa.toFloatArray();
|
||||
printArray(fack);
|
||||
|
||||
float f4[] = new float[4];
|
||||
fa.getFloats(0, 4, f4, 0);
|
||||
printArray(f4);
|
||||
float f4[] = new float[4];
|
||||
fa.getFloats(0, 4, f4, 0);
|
||||
printArray(f4);
|
||||
|
||||
SafeArray fa2 = new SafeArray(Variant.VariantFloat, 4);
|
||||
fa2.setFloats(0, 4, f4, 0);
|
||||
fack = fa2.toFloatArray();
|
||||
printArray(fack);
|
||||
SafeArray fa2 = new SafeArray(Variant.VariantFloat, 4);
|
||||
fa2.setFloats(0, 4, f4, 0);
|
||||
fack = fa2.toFloatArray();
|
||||
printArray(fack);
|
||||
|
||||
// boolean
|
||||
System.out.println("Boolean");
|
||||
SafeArray ba = new SafeArray(Variant.VariantBoolean, 4);
|
||||
System.out.println("elem size:" + ba.getElemSize());
|
||||
boolean back[] = new boolean[] { true, false, true, false };
|
||||
printArray(back);
|
||||
ba.fromBooleanArray(back);
|
||||
back = ba.toBooleanArray();
|
||||
printArray(back);
|
||||
// boolean
|
||||
System.out.println("Boolean");
|
||||
SafeArray ba = new SafeArray(Variant.VariantBoolean, 4);
|
||||
System.out.println("elem size:" + ba.getElemSize());
|
||||
boolean back[] = new boolean[] { true, false, true, false };
|
||||
printArray(back);
|
||||
ba.fromBooleanArray(back);
|
||||
back = ba.toBooleanArray();
|
||||
printArray(back);
|
||||
|
||||
boolean b4[] = new boolean[4];
|
||||
ba.getBooleans(0, 4, b4, 0);
|
||||
printArray(b4);
|
||||
boolean b4[] = new boolean[4];
|
||||
ba.getBooleans(0, 4, b4, 0);
|
||||
printArray(b4);
|
||||
|
||||
SafeArray ba2 = new SafeArray(Variant.VariantBoolean, 4);
|
||||
ba2.setBooleans(0, 4, b4, 0);
|
||||
back = ba2.toBooleanArray();
|
||||
printArray(back);
|
||||
SafeArray ba2 = new SafeArray(Variant.VariantBoolean, 4);
|
||||
ba2.setBooleans(0, 4, b4, 0);
|
||||
back = ba2.toBooleanArray();
|
||||
printArray(back);
|
||||
|
||||
// char
|
||||
System.out.println("Char");
|
||||
SafeArray ca = new SafeArray(Variant.VariantShort, 4);
|
||||
System.out.println("elem size:" + ca.getElemSize());
|
||||
char cack[] = new char[] { 'a', 'b', 'c', 'd' };
|
||||
printArray(cack);
|
||||
ca.fromCharArray(cack);
|
||||
cack = ca.toCharArray();
|
||||
printArray(cack);
|
||||
// char
|
||||
System.out.println("Char");
|
||||
SafeArray ca = new SafeArray(Variant.VariantShort, 4);
|
||||
System.out.println("elem size:" + ca.getElemSize());
|
||||
char cack[] = new char[] { 'a', 'b', 'c', 'd' };
|
||||
printArray(cack);
|
||||
ca.fromCharArray(cack);
|
||||
cack = ca.toCharArray();
|
||||
printArray(cack);
|
||||
|
||||
char c4[] = new char[4];
|
||||
ca.getChars(0, 4, c4, 0);
|
||||
printArray(c4);
|
||||
char c4[] = new char[4];
|
||||
ca.getChars(0, 4, c4, 0);
|
||||
printArray(c4);
|
||||
|
||||
SafeArray ca2 = new SafeArray(Variant.VariantShort, 4);
|
||||
ca2.setChars(0, 4, c4, 0);
|
||||
cack = ca2.toCharArray();
|
||||
printArray(cack);
|
||||
SafeArray ca2 = new SafeArray(Variant.VariantShort, 4);
|
||||
ca2.setChars(0, 4, c4, 0);
|
||||
cack = ca2.toCharArray();
|
||||
printArray(cack);
|
||||
|
||||
// short
|
||||
System.out.println("Short");
|
||||
SafeArray sha = new SafeArray(Variant.VariantShort, 4);
|
||||
System.out.println("elem size:" + sha.getElemSize());
|
||||
short shack[] = new short[] { 1000, 2000, 3000, 4000 };
|
||||
printArray(shack);
|
||||
sha.fromShortArray(shack);
|
||||
shack = sha.toShortArray();
|
||||
printArray(shack);
|
||||
// short
|
||||
System.out.println("Short");
|
||||
SafeArray sha = new SafeArray(Variant.VariantShort, 4);
|
||||
System.out.println("elem size:" + sha.getElemSize());
|
||||
short shack[] = new short[] { 1000, 2000, 3000, 4000 };
|
||||
printArray(shack);
|
||||
sha.fromShortArray(shack);
|
||||
shack = sha.toShortArray();
|
||||
printArray(shack);
|
||||
|
||||
short sh4[] = new short[4];
|
||||
sha.getShorts(0, 4, sh4, 0);
|
||||
printArray(sh4);
|
||||
short sh4[] = new short[4];
|
||||
sha.getShorts(0, 4, sh4, 0);
|
||||
printArray(sh4);
|
||||
|
||||
SafeArray sha2 = new SafeArray(Variant.VariantShort, 4);
|
||||
sha2.setShorts(0, 4, sh4, 0);
|
||||
shack = sha2.toShortArray();
|
||||
printArray(shack);
|
||||
SafeArray sha2 = new SafeArray(Variant.VariantShort, 4);
|
||||
sha2.setShorts(0, 4, sh4, 0);
|
||||
shack = sha2.toShortArray();
|
||||
printArray(shack);
|
||||
|
||||
// string
|
||||
System.out.println("String");
|
||||
SafeArray sa = new SafeArray(Variant.VariantString, 4);
|
||||
System.out.println("elem size:" + sa.getElemSize());
|
||||
String sack[] = new String[] { "aa", "bb", "cc", "dd" };
|
||||
printArray(sack);
|
||||
sa.fromStringArray(sack);
|
||||
sack = sa.toStringArray();
|
||||
printArray(sack);
|
||||
// string
|
||||
System.out.println("String");
|
||||
SafeArray sa = new SafeArray(Variant.VariantString, 4);
|
||||
System.out.println("elem size:" + sa.getElemSize());
|
||||
String sack[] = new String[] { "aa", "bb", "cc", "dd" };
|
||||
printArray(sack);
|
||||
sa.fromStringArray(sack);
|
||||
sack = sa.toStringArray();
|
||||
printArray(sack);
|
||||
|
||||
String s4[] = new String[4];
|
||||
sa.getStrings(0, 4, s4, 0);
|
||||
printArray(s4);
|
||||
String s4[] = new String[4];
|
||||
sa.getStrings(0, 4, s4, 0);
|
||||
printArray(s4);
|
||||
|
||||
SafeArray sa2 = new SafeArray(Variant.VariantString, 4);
|
||||
sa2.setStrings(0, 4, s4, 0);
|
||||
sack = sa2.toStringArray();
|
||||
printArray(sack);
|
||||
SafeArray sa2 = new SafeArray(Variant.VariantString, 4);
|
||||
sa2.setStrings(0, 4, s4, 0);
|
||||
sack = sa2.toStringArray();
|
||||
printArray(sack);
|
||||
|
||||
// variant
|
||||
System.out.println("Variant");
|
||||
SafeArray va = new SafeArray(Variant.VariantVariant, 4);
|
||||
System.out.println("elem size:" + va.getElemSize());
|
||||
Variant vack[] = new Variant[] { new Variant(1), new Variant(2.3),
|
||||
new Variant(true), new Variant("four"), };
|
||||
printArray(vack);
|
||||
va.fromVariantArray(vack);
|
||||
vack = va.toVariantArray();
|
||||
printArray(vack);
|
||||
// variant
|
||||
System.out.println("Variant");
|
||||
SafeArray va = new SafeArray(Variant.VariantVariant, 4);
|
||||
System.out.println("elem size:" + va.getElemSize());
|
||||
Variant vack[] = new Variant[] { new Variant(1), new Variant(2.3),
|
||||
new Variant(true), new Variant("four"), };
|
||||
printArray(vack);
|
||||
va.fromVariantArray(vack);
|
||||
vack = va.toVariantArray();
|
||||
printArray(vack);
|
||||
|
||||
Variant v4[] = new Variant[4];
|
||||
va.getVariants(0, 4, v4, 0);
|
||||
printArray(v4);
|
||||
Variant v4[] = new Variant[4];
|
||||
va.getVariants(0, 4, v4, 0);
|
||||
printArray(v4);
|
||||
|
||||
SafeArray va2 = new SafeArray(Variant.VariantVariant, 4);
|
||||
va2.setVariants(0, 4, v4, 0);
|
||||
vack = va2.toVariantArray();
|
||||
printArray(vack);
|
||||
SafeArray va2 = new SafeArray(Variant.VariantVariant, 4);
|
||||
va2.setVariants(0, 4, v4, 0);
|
||||
vack = va2.toVariantArray();
|
||||
printArray(vack);
|
||||
|
||||
// byte
|
||||
System.out.println("Byte");
|
||||
SafeArray bba = new SafeArray(Variant.VariantByte, 4);
|
||||
System.out.println("elem size:" + bba.getElemSize());
|
||||
byte bback[] = new byte[] { 0x1, 0x2, 0x3, 0x4 };
|
||||
printArray(bback);
|
||||
bba.fromByteArray(bback);
|
||||
bback = bba.toByteArray();
|
||||
printArray(bback);
|
||||
// byte
|
||||
System.out.println("Byte");
|
||||
SafeArray bba = new SafeArray(Variant.VariantByte, 4);
|
||||
System.out.println("elem size:" + bba.getElemSize());
|
||||
byte bback[] = new byte[] { 0x1, 0x2, 0x3, 0x4 };
|
||||
printArray(bback);
|
||||
bba.fromByteArray(bback);
|
||||
bback = bba.toByteArray();
|
||||
printArray(bback);
|
||||
|
||||
byte bb4[] = new byte[4];
|
||||
bba.getBytes(0, 4, bb4, 0);
|
||||
printArray(bb4);
|
||||
byte bb4[] = new byte[4];
|
||||
bba.getBytes(0, 4, bb4, 0);
|
||||
printArray(bb4);
|
||||
|
||||
SafeArray bba2 = new SafeArray(Variant.VariantByte, 4);
|
||||
bba2.setBytes(0, 4, bb4, 0);
|
||||
bback = bba2.toByteArray();
|
||||
printArray(bback);
|
||||
SafeArray bba2 = new SafeArray(Variant.VariantByte, 4);
|
||||
bba2.setBytes(0, 4, bb4, 0);
|
||||
bback = bba2.toByteArray();
|
||||
printArray(bback);
|
||||
|
||||
try {
|
||||
// this should throw ComException
|
||||
bba2.fromCharArray(new char[] { 'a' });
|
||||
fail("Failed to catch expected exception");
|
||||
} catch (ComFailException cfe) {
|
||||
// do nothing
|
||||
// cfe.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
// this should throw ComException
|
||||
bba2.fromCharArray(new char[] { 'a' });
|
||||
fail("Failed to catch expected exception");
|
||||
} catch (ComFailException cfe) {
|
||||
// do nothing
|
||||
// cfe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.safearray;
|
||||
|
||||
@@ -49,35 +49,35 @@ import com.jacob.test.BaseTestCase;
|
||||
* Test class to verify dispatch with SafeArray
|
||||
*/
|
||||
public class SafeArrayDispatchTest extends BaseTestCase {
|
||||
public void testDispatchWithSafeArray() {
|
||||
try {
|
||||
String scriptCommand = "1+(2*4)-3";
|
||||
String lang = "VBScript";
|
||||
ActiveXComponent sControl = new ActiveXComponent("ScriptControl");
|
||||
Dispatch.put(sControl, "Language", lang);
|
||||
public void testDispatchWithSafeArray() {
|
||||
try {
|
||||
String scriptCommand = "1+(2*4)-3";
|
||||
String lang = "VBScript";
|
||||
ActiveXComponent sControl = new ActiveXComponent("ScriptControl");
|
||||
Dispatch.put(sControl, "Language", lang);
|
||||
|
||||
Variant result = Dispatch.call(sControl, "Eval", scriptCommand);
|
||||
assertTrue(result.toString().equals("6"));
|
||||
Variant result = Dispatch.call(sControl, "Eval", scriptCommand);
|
||||
assertTrue(result.toString().equals("6"));
|
||||
|
||||
// wrap the script control in a variant
|
||||
Variant v = new Variant(sControl);
|
||||
// wrap the script control in a variant
|
||||
Variant v = new Variant(sControl);
|
||||
|
||||
// create a safe array of type dispatch
|
||||
SafeArray sa = new SafeArray(Variant.VariantDispatch, 1);
|
||||
// create a safe array of type dispatch
|
||||
SafeArray sa = new SafeArray(Variant.VariantDispatch, 1);
|
||||
|
||||
// put the variant in the array
|
||||
sa.setVariant(0, v);
|
||||
// put the variant in the array
|
||||
sa.setVariant(0, v);
|
||||
|
||||
// take it back out
|
||||
Variant v2 = sa.getVariant(0);
|
||||
Dispatch d = v2.toDispatch();
|
||||
// take it back out
|
||||
Variant v2 = sa.getVariant(0);
|
||||
Dispatch d = v2.toDispatch();
|
||||
|
||||
// make sure you can call eval on it
|
||||
result = Dispatch.call(d, "Eval", scriptCommand);
|
||||
assertTrue(result.toString().equals("6"));
|
||||
} catch (ComException e) {
|
||||
e.printStackTrace();
|
||||
fail("script failure " + e);
|
||||
}
|
||||
}
|
||||
// make sure you can call eval on it
|
||||
result = Dispatch.call(d, "Eval", scriptCommand);
|
||||
assertTrue(result.toString().equals("6"));
|
||||
} catch (ComException e) {
|
||||
e.printStackTrace();
|
||||
fail("script failure " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.jacob.test.safearray;
|
||||
|
||||
@@ -59,157 +59,157 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class SafeArrayLeak extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* ----------------------------------------------------------------------------------------------------------------------------
|
||||
*
|
||||
* ----------------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public void testLeakWithSetString() {
|
||||
/**
|
||||
* ----------------------------------------------------------------------------------------------------------------------------
|
||||
*
|
||||
* ----------------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
public void testLeakWithSetString() {
|
||||
|
||||
ActiveXComponent xl = null;
|
||||
Dispatch workbooks = null;
|
||||
Dispatch workbook = null;
|
||||
Dispatch workSheets = null;
|
||||
Dispatch sheet = null;
|
||||
Dispatch tabCells = null;
|
||||
SafeArray sa = null;
|
||||
ActiveXComponent xl = null;
|
||||
Dispatch workbooks = null;
|
||||
Dispatch workbook = null;
|
||||
Dispatch workSheets = null;
|
||||
Dispatch sheet = null;
|
||||
Dispatch tabCells = null;
|
||||
SafeArray sa = null;
|
||||
|
||||
// -Dcom.jacob.autogc=true
|
||||
System.out.println("Jacob version: " + JacobReleaseInfo.getBuildVersion());
|
||||
// -Dcom.jacob.autogc=true
|
||||
System.out.println("Jacob version: " + JacobReleaseInfo.getBuildVersion());
|
||||
|
||||
for (int t = 0; t < 10; t++) {
|
||||
// look at a large range of cells
|
||||
String position = "A7:DM8934";
|
||||
for (int t = 0; t < 10; t++) {
|
||||
// look at a large range of cells
|
||||
String position = "A7:DM8934";
|
||||
|
||||
try {
|
||||
xl = new ActiveXComponent("Excel.Application");
|
||||
System.out
|
||||
.println("Excel version=" + xl.getProperty("Version"));
|
||||
try {
|
||||
xl = new ActiveXComponent("Excel.Application");
|
||||
System.out
|
||||
.println("Excel version=" + xl.getProperty("Version"));
|
||||
|
||||
xl.setProperty("Visible", new Variant(false));
|
||||
workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||
xl.setProperty("Visible", new Variant(false));
|
||||
workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||
|
||||
workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
|
||||
workSheets = Dispatch.get(workbook, "Worksheets").toDispatch();
|
||||
workSheets = Dispatch.get(workbook, "Worksheets").toDispatch();
|
||||
|
||||
sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
// grab the whole range specified above.
|
||||
tabCells = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { position }, new int[1]).toDispatch();
|
||||
sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
// grab the whole range specified above.
|
||||
tabCells = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { position }, new int[1]).toDispatch();
|
||||
|
||||
sa = Dispatch.get(tabCells, "Value").toSafeArray(true);
|
||||
sa = Dispatch.get(tabCells, "Value").toSafeArray(true);
|
||||
|
||||
System.out.println("Ub0=" + sa.getUBound(1)); // nbCol
|
||||
System.out.println("Ub1=" + sa.getUBound(2)); // nbLgn
|
||||
System.out.println("Ub0=" + sa.getUBound(1)); // nbCol
|
||||
System.out.println("Ub1=" + sa.getUBound(2)); // nbLgn
|
||||
|
||||
// number of rows
|
||||
int nbLgn = sa.getUBound(2);
|
||||
// number of columns
|
||||
int nbCol = sa.getUBound(1);
|
||||
// number of rows
|
||||
int nbLgn = sa.getUBound(2);
|
||||
// number of columns
|
||||
int nbCol = sa.getUBound(1);
|
||||
|
||||
int[] colLgn = new int[] { 0, 0 };
|
||||
int[] colLgn = new int[] { 0, 0 };
|
||||
|
||||
// now set a value on every cell in the range we retrieved
|
||||
for (int i = 1; i <= nbLgn; i++) {
|
||||
colLgn[1] = i;
|
||||
// now set a value on every cell in the range we retrieved
|
||||
for (int i = 1; i <= nbLgn; i++) {
|
||||
colLgn[1] = i;
|
||||
|
||||
for (int j = 1; j <= nbCol; j++) {
|
||||
colLgn[0] = j;
|
||||
// this one works with out a leak 1.13-M3
|
||||
// sa.setString(j, i, "test");
|
||||
// This one leaks with 1.13-M3 and earlier
|
||||
sa.setString(colLgn, "test");
|
||||
}
|
||||
}
|
||||
for (int j = 1; j <= nbCol; j++) {
|
||||
colLgn[0] = j;
|
||||
// this one works with out a leak 1.13-M3
|
||||
// sa.setString(j, i, "test");
|
||||
// This one leaks with 1.13-M3 and earlier
|
||||
sa.setString(colLgn, "test");
|
||||
}
|
||||
}
|
||||
|
||||
Dispatch.put(tabCells, "Value", sa);
|
||||
Dispatch.put(tabCells, "Value", sa);
|
||||
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
System.out.println("Close");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
System.out.println("Close");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
if (sa != null) {
|
||||
try {
|
||||
sa.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sa = null;
|
||||
}
|
||||
}
|
||||
if (sa != null) {
|
||||
try {
|
||||
sa.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sa = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (tabCells != null) {
|
||||
try {
|
||||
tabCells.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
tabCells = null;
|
||||
}
|
||||
}
|
||||
if (tabCells != null) {
|
||||
try {
|
||||
tabCells.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
tabCells = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (sheet != null) {
|
||||
try {
|
||||
sheet.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sheet = null;
|
||||
}
|
||||
}
|
||||
if (sheet != null) {
|
||||
try {
|
||||
sheet.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sheet = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (workSheets != null) {
|
||||
try {
|
||||
workSheets.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workSheets = null;
|
||||
}
|
||||
}
|
||||
if (workSheets != null) {
|
||||
try {
|
||||
workSheets.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workSheets = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (workbook != null) {
|
||||
try {
|
||||
workbook.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workbook = null;
|
||||
}
|
||||
}
|
||||
if (workbook != null) {
|
||||
try {
|
||||
workbook.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workbook = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (workbooks != null) {
|
||||
try {
|
||||
workbooks.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workbooks = null;
|
||||
}
|
||||
}
|
||||
if (workbooks != null) {
|
||||
try {
|
||||
workbooks.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
workbooks = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (xl != null) {
|
||||
try {
|
||||
xl.invoke("Quit", new Variant[] {});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (xl != null) {
|
||||
try {
|
||||
xl.invoke("Quit", new Variant[] {});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
xl.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
xl = null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
xl.safeRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
xl = null;
|
||||
}
|
||||
}
|
||||
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user