src/macosx/native/java/util/MacOSXPreferencesFile.m

Print this page




 624 
 625             if (topKey) CFRelease(topKey);
 626             if (topValue) CFRelease(topValue);
 627         }
 628     }
 629 
 630 
 631  badparent:
 632     if (constParent) CFRelease(constParent);
 633     CFRelease(childName);
 634  badchildName:
 635     CFRelease(parentName);
 636  badparentName:
 637  badparams:
 638     if (path) CFRelease(path);
 639     if (name) CFRelease(name);
 640 }
 641 
 642 
 643 // child must end with '/'
 644 JNIEXPORT void JNICALL
 645 Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
 646 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
 647  jobject jname, jlong juser, jlong jhost)
 648 {
 649     // like addNode, but can put a three-level-deep dict into the root file
 650     CFStringRef path = toCF(env, jpath);
 651     CFStringRef child = toCF(env, jchild);
 652     CFStringRef name = toCF(env, jname);
 653     CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
 654     CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
 655     CFMutableDictionaryRef parent;
 656     CFDictionaryRef node;
 657     CFStringRef topKey;
 658     CFMutableDictionaryRef topValue;

 659 
 660     if (!path  ||  !child  ||  !name) goto badparams;
 661 
 662     node = createEmptyNode();
 663     throwIfNull(node, "createEmptyNode failed");
 664 
 665     // copyMutableNode creates the node if necessary
 666     parent = copyMutableNode(path, name, user, host, &topKey, &topValue);
 667     throwIfNull(parent, "copyMutableNode failed");
 668 
 669     CFDictionaryAddValue(parent, child, node);
 670 



 671     CFPreferencesSetValue(topKey, topValue, name, user, host);
 672 
 673     CFRelease(parent);
 674     if (topKey) CFRelease(topKey);
 675     if (topValue) CFRelease(topValue);
 676  badparent:
 677     CFRelease(node);
 678  badnode:
 679  badparams:
 680     if (path) CFRelease(path);
 681     if (child) CFRelease(child);
 682     if (name) CFRelease(name);

 683 }
 684 
 685 
 686 JNIEXPORT void JNICALL
 687 Java_java_util_prefs_MacOSXPreferencesFile_removeChildFromNode
 688 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
 689  jobject jname, jlong juser, jlong jhost)
 690 {
 691     CFStringRef path = toCF(env, jpath);
 692     CFStringRef child = toCF(env, jchild);
 693     CFStringRef name = toCF(env, jname);
 694     CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
 695     CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
 696     CFDictionaryRef constParent;
 697 
 698     if (!path  ||  !child  ||  !name) goto badparams;
 699 
 700     constParent = copyNodeIfPresent(path, name, user, host);
 701     if (constParent  &&  CFDictionaryContainsKey(constParent, child)) {
 702         CFStringRef topKey;




 624 
 625             if (topKey) CFRelease(topKey);
 626             if (topValue) CFRelease(topValue);
 627         }
 628     }
 629 
 630 
 631  badparent:
 632     if (constParent) CFRelease(constParent);
 633     CFRelease(childName);
 634  badchildName:
 635     CFRelease(parentName);
 636  badparentName:
 637  badparams:
 638     if (path) CFRelease(path);
 639     if (name) CFRelease(name);
 640 }
 641 
 642 
 643 // child must end with '/'
 644 JNIEXPORT Boolean JNICALL
 645 Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode
 646 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
 647  jobject jname, jlong juser, jlong jhost)
 648 {
 649     // like addNode, but can put a three-level-deep dict into the root file
 650     CFStringRef path = toCF(env, jpath);
 651     CFStringRef child = toCF(env, jchild);
 652     CFStringRef name = toCF(env, jname);
 653     CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
 654     CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
 655     CFMutableDictionaryRef parent;
 656     CFDictionaryRef node;
 657     CFStringRef topKey;
 658     CFMutableDictionaryRef topValue;
 659     Boolean beforeAdd = false;
 660 
 661     if (!path  ||  !child  ||  !name) goto badparams;
 662 
 663     node = createEmptyNode();
 664     throwIfNull(node, "createEmptyNode failed");
 665 
 666     // copyMutableNode creates the node if necessary
 667     parent = copyMutableNode(path, name, user, host, &topKey, &topValue);
 668     throwIfNull(parent, "copyMutableNode failed");
 669     beforeAdd = CFDictionaryContainsKey(parent, child);
 670     CFDictionaryAddValue(parent, child, node);
 671     if (!beforeAdd)
 672         beforeAdd = CFDictionaryContainsKey(parent, child);
 673     else
 674         beforeAdd = false;
 675     CFPreferencesSetValue(topKey, topValue, name, user, host);
 676 
 677     CFRelease(parent);
 678     if (topKey) CFRelease(topKey);
 679     if (topValue) CFRelease(topValue);
 680  badparent:
 681     CFRelease(node);
 682  badnode:
 683  badparams:
 684     if (path) CFRelease(path);
 685     if (child) CFRelease(child);
 686     if (name) CFRelease(name);
 687     return beforeAdd;
 688 }
 689 
 690 
 691 JNIEXPORT void JNICALL
 692 Java_java_util_prefs_MacOSXPreferencesFile_removeChildFromNode
 693 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild,
 694  jobject jname, jlong juser, jlong jhost)
 695 {
 696     CFStringRef path = toCF(env, jpath);
 697     CFStringRef child = toCF(env, jchild);
 698     CFStringRef name = toCF(env, jname);
 699     CFStringRef user = (CFStringRef)jlong_to_ptr(juser);
 700     CFStringRef host = (CFStringRef)jlong_to_ptr(jhost);
 701     CFDictionaryRef constParent;
 702 
 703     if (!path  ||  !child  ||  !name) goto badparams;
 704 
 705     constParent = copyNodeIfPresent(path, name, user, host);
 706     if (constParent  &&  CFDictionaryContainsKey(constParent, child)) {
 707         CFStringRef topKey;