void AGOSEngine::synchChain(Item *i) { SubChain *c = (SubChain *)findChildOfType(i, kChainType); while (c) { setItemState(derefItem(c->chChained), i->state); c = (SubChain *)nextSub((Child *)c, kChainType); } }
void DoExchange(JNIEnv *env, jobject jobParent, DynamicXMLObject *pDXOApply, const char *pzDirection, long nDataType, const char *pzVarName,const char *pzTag, const char *pzNestedInTag, const char *pzObjectType, const char *pzContainerType,DynamicXMLObject *pDXOOwner, int Source) { jmethodID midAddElement; jmethodID midAddElement2; jobject jobCollection; jclass clazz2; jobject job; jfieldID fid; DynamicXMLObject *pDXOSubObject = 0; jboolean isCopy; if (!jobParent || !env){ logit("--------- Wasnt expecting this 1------------\n"); return; } jclass clazz; try { clazz = env->GetObjectClass(jobParent); }catch(...) { logit("--------- Wasnt expecting this 1.5------------\n"); return; } // for portable case insensitive compairs GString strStringType("Ljava/lang/String;"); GString strOn("on"); GString strTrue("true"); GString strYes("yes"); GString strOne("1"); if (pzDirection[0] == 'i' || pzDirection[0] == 'I') // direction is 'in' { if (!pDXOApply){ // this never happens return; } // Create a space delimitted list of strings GStringList lst(" ",pzNestedInTag); GStringIterator it(&lst); while (it()) { pDXOApply = pDXOApply->GetSubObject( it++ ); if (!pDXOApply) return; // member [pzVarName] has no value in the XML } // logit("Tag=["); // logit(pzTag); // TransactionTime // logit(" "); // logit(pDXOApply->GetObjectTag()); // Order // logit(" "); // logit(pDXOApply->GetVirtualType()); // Lgapp/MyOrder // The ObjectValue() of the first sub-Object matching the given xmlTag const char *pSrcValue = 0; if (Source == 1) // Element pSrcValue = pDXOApply->GetMember(pzTag); else if (Source == 2) // Attribute pSrcValue = pDXOApply->FindAttribute(pzTag); // logit("]Source=["); // logit(pSrcValue); // logit("]\n"); jdouble d = 0; jlong l = 0; jint i=0; jshort s = 0; jbyte b; jboolean z = 0; // Move data into the java object if (pSrcValue || nDataType > 6) // 7+ are objects { switch(nDataType) { /*long*/ case 0: fid = env->GetFieldID(clazz, pzVarName, "J"); l = Xatoi64(pSrcValue); env->SetLongField(jobParent, fid, l); break; /*double*/ case 1: fid = env->GetFieldID(clazz, pzVarName, "D"); d = atof(pSrcValue); env->SetDoubleField(jobParent, fid, d); break; /*short*/ case 2: fid = env->GetFieldID(clazz, pzVarName, "S"); sscanf (pSrcValue, "%d", &s); env->SetShortField(jobParent, fid, s); break; /*byte*/ case 3: fid = env->GetFieldID(clazz, pzVarName, "B"); sscanf (pSrcValue, "%c", &b); env->SetByteField(jobParent, fid, b); break; /*String*/ case 4: fid = env->GetFieldID(clazz, pzVarName, "Ljava/lang/String;"); env->SetObjectField(jobParent, fid, env->NewStringUTF(pSrcValue)); break; /*int*/ case 5: fid = env->GetFieldID(clazz, pzVarName, "I"); sscanf (pSrcValue, "%d", &i); env->SetIntField(jobParent, fid, i); break; /*boolean*/ case 6: if (pSrcValue) { if (strOn.CompareNoCase(pSrcValue) == 0 || strTrue.CompareNoCase(pSrcValue) == 0 || strYes.CompareNoCase(pSrcValue) == 0 || strOne.CompareNoCase(pSrcValue) == 0 ) { z = 1; } } fid = env->GetFieldID(clazz, pzVarName, "Z"); env->SetBooleanField(jobParent, fid, z); break; /*Object*/ case 7: pDXOSubObject = pDXOApply->GetSubObject(pzTag); logit(pDXOSubObject->ToXML()); logit("\n\n"); if (pDXOSubObject) { // update it, otherwise create,assign,then update it GString strObjSignature; strObjSignature << "L" << pzObjectType << ";"; // "Lgapp/MyOrder;" fid = env->GetFieldID(clazz, pzVarName, strObjSignature); if (fid) { // handle to the java object reference job = env->GetObjectField(jobParent, fid); // OBTAIN if (!job) { // CREATE then assign a new object into the java object reference job = MakeObjectInstance(env,pzObjectType, pDXOSubObject,pDXOOwner); env->SetObjectField(jobParent, fid, job); // ASSIGN } else { pDXOSubObject=ExchangeDataObject(env,pDXOSubObject,job); } // move from the data object into the Java object //UPDATE ExchangeMembers(env, "in", pDXOSubObject, job, pDXOOwner); } else { // variable[pzVarName], type [pzObjectType] not found in object GString strError; strError << "ERROR @<" << pzTag << ">=" << pzVarName << " type:" << strObjSignature << " Not found\n"; logit(strError); // otherwise we'll get java.lang.NoSuchFieldError: no field with name='objOrderXXX' signature='LMyOrder;' in class Lgapp/Customer1; env->ExceptionClear(); } } break; /*AbstractCollection of Objects*/ case 8: // logit(pzTag); // logit("\n"); // logit(pzContainerType); // logit(pzVarName); // logit("\n"); // The source XML may specify 0..n object(s) of type 'pzTag' GListIterator Iter(pDXOApply->GetSubObjectList()); pDXOSubObject = nextSub(Iter,pzTag); if (pDXOSubObject) { logit("adding object...\n"); // get the container object Ljava/util/Vector; fid = env->GetFieldID(clazz, pzVarName, pzContainerType); if (!fid) { // in this error the signature is wrong // java.lang.NoSuchFieldError: no field with name='vecStrings' signature='java/util/Vector' in class Lgapp/Customer1; logit("**** FAILED Here!"); } if (fid) { logit("got fid\n"); jobCollection = env->GetObjectField(jobParent, fid); logit("got collection\n"); // create the collection object if necessary if (!jobCollection) { logit("NEW collection\n"); logit(pzContainerType); logit("\n"); GString strUnSignature(&pzContainerType[1], strlen(pzContainerType) - 2); // start at the 2nd byte and drop the last byte jclass ColClazz = env->FindClass(strUnSignature); // (pzContainerType); if (ColClazz) { logit("found collection\n"); jmethodID midCtor = env->GetMethodID(ColClazz, "<init>", "()V"); // CREATE logit("create object for collection\n"); jobCollection = env->NewObject(ColClazz, midCtor); // ASSIGN logit("add object to collection\n"); env->SetObjectField(jobParent, fid, jobCollection); logit("did it\n"); } else{ GString strError; strError << "ERROR @<" << pzTag << ">=" << pzVarName << " type:" << strUnSignature << " Not found\n"; logit(strError); } } clazz2 = env->GetObjectClass(jobCollection); // add overload in Vector //@Override public void add(int location, E object); //@Override public synchronized boolean add(E object); midAddElement = env->GetMethodID(clazz2,"add","(Ljava/lang/Object;)Z"); if (midAddElement) { logit("OK midAddElement\n"); } // env->GetMethodID(clazz2,"add","(I;Ljava/lang/Object;)V"); // java.lang.NoSuchMethodError: no method with name='add' signature='(I;Ljava/lang/Object;)V' in class Ljava/util/Vector; // now add/update the object(s) in the collection. while (pDXOSubObject) { if (strStringType.CompareNoCase(pzObjectType) == 0) { logit("Pre call Bool...\n"); GString x; pDXOSubObject->ToXML(x); logit(x); logit("\n"); // add a new String object into the collection; const char *pzVal =pDXOSubObject->GetObjectValue(); logit("Post call Bool...\n"); logit(pzVal); logit("\n"); env->MonitorEnter(clazz2); // env->CallVoidMethod(jobCollection, midAddElement, env->NewStringUTF(pzVal)); env->CallBooleanMethod(jobCollection, midAddElement, env->NewStringUTF(pzVal)); logit(pzVal); logit(" Added\n"); env->MonitorExit(clazz2); logit("added done\n"); } else // it's a user defined object { // Iterate the existing collection for an instance // keyed by ObjectID. logit("add Object\n"); if (!ApplyObjectToCollection(env,jobCollection, pDXOSubObject, pDXOOwner)) { logit("add Create\n"); // No existing object with a matching ObjectID // was found. Create and Add a User defined // object into the collection job = MakeObjectInstance(env,pzObjectType,pDXOSubObject,pDXOOwner); logit("add Create 2\n"); // add object to collection // this was the old NT/Solaris code ~2002 // env->CallVoidMethod(jobCollection, midAddElement,job); // changed for Android 2015 env->CallBooleanMethod(jobCollection, midAddElement, job); ExchangeMembers(env, "in", pDXOSubObject, job,pDXOOwner); logit("add Create 3\n"); } else { logit("add Data Applied\n"); } } // check the source XML for the next // object to apply to this collection pDXOSubObject = nextSub(Iter,pzTag); } } } break; }// end of datatype switch } else { // xml tag[pzTag] declared in object[] but not found in XML. // ignore unless specifically told to do otherwise (v2) } } // direction is 'out' else if (pzDirection[0] == 'o' || pzDirection[0] == 'O') { if (nDataType < 7) pDXOApply = ApplyNesting(pDXOApply,pzNestedInTag); GString strSrcValue; GString strSignature; // Move data out of the java object switch(nDataType) { /*long*/ case 0: // 64 bit where applicable fid = env->GetFieldID(clazz, pzVarName, "J"); strSrcValue = env->GetLongField(jobParent, fid); break; /*double*/ case 1: fid = env->GetFieldID(clazz, pzVarName, "D"); strSrcValue = env->GetDoubleField(jobParent, fid); break; /*short*/ case 2: fid = env->GetFieldID(clazz, pzVarName, "S"); strSrcValue = env->GetShortField(jobParent, fid); break; /*byte*/ case 3: fid = env->GetFieldID(clazz, pzVarName, "B"); int i; i = (int) env->GetByteField(jobParent, fid); strSrcValue.Format("%d", i); break; /*String*/ case 4: logit(pzVarName); logit("\n"); fid = env->GetFieldID(clazz, pzVarName, "Ljava/lang/String;"); job = env->GetObjectField(jobParent, fid); if (job) { strSrcValue = (char *) env->GetStringUTFChars((jstring)job, &isCopy); } else{ logit("string object is NULL\n"); } break; /*int*/ case 5: fid = env->GetFieldID(clazz, pzVarName, "I"); strSrcValue.Format("%d", env->GetIntField(jobParent, fid) ); break; /*boolean*/ case 6: fid = env->GetFieldID(clazz, pzVarName, "Z"); if (env->GetBooleanField(jobParent, fid)) strSrcValue = "True"; else strSrcValue = "False"; break; /*object*/ case 7: logit("777 Where is our object?\n"); logit(pzVarName); logit("\n"); strSignature << "L" << pzObjectType << ";"; logit(strSignature); logit("\n"); clazz = env->GetObjectClass(jobParent); // "Lgapp/MyOrder;" is what is must be // pzObjectType == gapp/MyOrder fid = env->GetFieldID(clazz, pzVarName, strSignature ); // fid = env->GetFieldID(g_activityClassXXX, pzVarName, pzObjectType); // we can use a global/static clazz if (fid) // if the referenced sub object, pzObjectType, is found in the parent { logit("!!!OBJECT!!!\n"); job = env->GetObjectField(jobParent, fid); if (!job) { // the reference is null, nothing to serialize. logit("the reference is null, nothing to serialize.\n"); } else { logit("serialize object\n"); // get the already created Storage for this jobject pDXOApply = ApplyNesting(pDXOApply,pzNestedInTag); logit("serialize object A\n"); pDXOSubObject = ExchangeDataObject(env,pDXOSubObject,job); logit("serialize object B\n"); pDXOApply->AddSubObject(pDXOSubObject); logit("serialize object C\n"); ExchangeMembers(env, "out", pDXOSubObject, job, pDXOSubObject); logit("serialize object D\n"); } } else { logit("--Object NOT mapped ------------\n"); logit(pzVarName); logit("\n"); logit(pzObjectType); // java.lang.NoSuchFieldError: no field with name='objOrderXXX' signature='gapp/MyOrder' in class Lgapp/Customer1; if (env->ExceptionOccurred()) { env->ExceptionClear(); } } break; /*AbstractCollection of Objects*/ case 8: // get the container object Ljava/util/Vector; fid = env->GetFieldID(clazz, pzVarName, pzContainerType); if (fid) { jobCollection = env->GetObjectField(jobParent, fid);// OBTAIN if (!jobCollection) { // Collection is null, (nothing to iterate or serialize) } else { // locate method used to add an object to the collection clazz2 = env->GetObjectClass(jobCollection); // Iterate the collection midAddElement = env->GetMethodID(clazz2,"iterator", "()Ljava/util/Iterator;"); jobject it = env->CallObjectMethod(jobCollection,midAddElement); clazz2 = env->GetObjectClass(it); jmethodID midNext = env->GetMethodID(clazz2, "next", "()Ljava/lang/Object;"); jmethodID midMore=env->GetMethodID(clazz2,"hasNext","()Z"); jobject itjob; if( env->CallBooleanMethod(it,midMore) ) pDXOApply = ApplyNesting(pDXOApply,pzNestedInTag); while( env->CallBooleanMethod(it,midMore) ) { itjob = env->CallObjectMethod(it,midNext); if (strStringType.CompareNoCase(pzObjectType) == 0) { // it's a string object strSrcValue = (char*) env->GetStringUTFChars((jstring)itjob, &isCopy); pDXOApply->SetMemberVar( pzTag, strSrcValue, 0 ); } else { pDXOSubObject = ExchangeDataObject(env,0,itjob); pDXOOwner->addSubUserLanguageObject(pDXOSubObject->getUserLanguageObject()); pDXOApply->AddSubObject(pDXOSubObject); ExchangeMembers(env,"out",pDXOSubObject,itjob, pDXOOwner); } } } } break; } // for all native types(int byte bool etc..) if (nDataType < 7) { if (Source == 1) // Element pDXOApply->SetMemberVar( pzTag, strSrcValue, 0); else if (Source == 2) // Attribute pDXOApply->AddAttribute(pzTag, strSrcValue , 0); } } else { // invalid direction } }