Renamed helma.Group.Wrapper to helma.Group.GroupObject

This commit is contained in:
Tobi Schäfer 2007-04-05 15:53:09 +00:00
parent 2d278e8272
commit ab188b2a70

View file

@ -8,10 +8,10 @@
* *
* Copyright 1998-2006 Helma Software. All Rights Reserved. * Copyright 1998-2006 Helma Software. All Rights Reserved.
* *
* $RCSfile: Html.js,v $ * $RCSfile: Group.js,v $
* $Author: robert $ * $Author: tobi $
* $Revision: 1.4 $ * $Revision: 1.1 $
* $Date: 2007/01/30 14:49:57 $ * $Date: 2007/04/05 15:33:58 $
*/ */
/** /**
@ -32,7 +32,7 @@ if (!global.helma) {
*/ */
helma.Group = function(javaGroup) { helma.Group = function(javaGroup) {
// private variable containing the wrapper object // private variable containing the wrapper object
var groupRoot = new helma.Group.Wrapper(javaGroup.getRoot()); var groupRoot = new helma.Group.GroupObject(javaGroup.getRoot());
/** /**
* @returns the wrapped java object Group * @returns the wrapped java object Group
@ -67,28 +67,28 @@ helma.Group = function(javaGroup) {
}; };
/** /**
* @see helma.Group.Wrapper.listChildren * @see helma.Group.GroupObject.listChildren
*/ */
this.listChildren = function() { this.listChildren = function() {
return groupRoot.listChildren(); return groupRoot.listChildren();
}; };
/** /**
* @see helma.Group.Wrapper.listProperties * @see helma.Group.GroupObject.listProperties
*/ */
this.listProperties = function() { this.listProperties = function() {
return groupRoot.listProperties(); return groupRoot.listProperties();
}; };
/** /**
* @see helma.Group.Wrapper.countChildren * @see helma.Group.GroupObject.countChildren
*/ */
this.countChildren = function() { this.countChildren = function() {
return groupRoot.countChildren(); return groupRoot.countChildren();
}; };
/** /**
* @see helma.Group.Wrapper.countProperties * @see helma.Group.GroupObject.countProperties
*/ */
this.countProperties = function() { this.countProperties = function() {
return groupRoot.countProperties(); return groupRoot.countProperties();
@ -101,13 +101,13 @@ helma.Group = function(javaGroup) {
* is called as root.test(), stories.137.render * is called as root.test(), stories.137.render
* is called as root.stories.get("137").render() etc etc. * is called as root.stories.get("137").render() etc etc.
* @param argArr array of arguments to the remote method * @param argArr array of arguments to the remote method
* @param sendMode as defined for helma.Group.Wrapper * @param sendMode as defined for helma.Group.GroupObject
* @returns array of result objects * @returns array of result objects
*/ */
this.callFunction = function(method, argArr, sendMode) { this.callFunction = function(method, argArr, sendMode) {
groups.checkWriteAccess(javaGroup); groups.checkWriteAccess(javaGroup);
if (sendMode == null) { if (sendMode == null) {
sendMode = helma.Group.Wrapper.DEFAULT_GET; sendMode = helma.Group.GroupObject.DEFAULT_GET;
} }
var argVec = new java.util.Vector(); var argVec = new java.util.Vector();
for (var i=0; i<argArr.length; i++) { for (var i=0; i<argArr.length; i++) {
@ -130,11 +130,11 @@ helma.Group = function(javaGroup) {
}; };
/** /**
* Constructs a new helma.Group.Wrapper. This class wraps the java GroupObject * Constructs a new helma.Group.GroupObject. This class wraps the java GroupObject
* and provides several methods for retrieving and manipulating properties. * and provides several methods for retrieving and manipulating properties.
* @param {Object} Instance of helma.extensions.helmagroups.GroupObject * @param {Object} Instance of helma.extensions.helmagroups.GroupObject
*/ */
helma.Group.Wrapper = function(javaGroupObject) { helma.Group.GroupObject = function(javaGroupObject) {
var helmagroups = Packages.helma.extensions.helmagroups; var helmagroups = Packages.helma.extensions.helmagroups;
if (!javaGroupObject) { if (!javaGroupObject) {
@ -202,7 +202,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
// loop down until end of array // loop down until end of array
for (var i=0; i<key.length-1; i++) { for (var i=0; i<key.length-1; i++) {
var nextObj = obj.get(key[i]); var nextObj = obj.get(key[i]);
if (nextObj == null || !(nextObj instanceof GroupObject)) { if (nextObj == null || !(nextObj instanceof helma.Group.GroupObject)) {
return null; return null;
} }
obj = nextObj; obj = nextObj;
@ -215,7 +215,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
/** /**
* if key is a path, walks through the path and returns the lowest GroupObject. * if key is a path, walks through the path and returns the lowest GroupObject.
* if tree ends somewhere in the path, function creates the missing GroupObjects. * if tree ends somewhere in the path, function creates the missing GroupObjects.
* @returns helma.Group.Wrapper * @returns helma.Group.GroupObject
*/ */
var createPath = function(obj, key) { var createPath = function(obj, key) {
var separator = helmagroups.GroupObject.SEPARATOR; var separator = helmagroups.GroupObject.SEPARATOR;
@ -229,8 +229,8 @@ helma.Group.Wrapper = function(javaGroupObject) {
// loop down until end of array // loop down until end of array
for (var i=0; i<key.length-1; i++) { for (var i=0; i<key.length-1; i++) {
var nextObj = obj.get(key[i]); var nextObj = obj.get(key[i]);
if (nextObj == null || !(nextObj instanceof helma.Group.Wrapper)) { if (nextObj == null || !(nextObj instanceof helma.Group.GroupObject)) {
nextObj = new helma.Group.Wrapper(); nextObj = new helma.Group.GroupObject();
obj.set(key[i], nextObj); obj.set(key[i], nextObj);
} }
obj = nextObj; obj = nextObj;
@ -267,7 +267,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
*/ */
this.set = function(key, val, sendMode) { this.set = function(key, val, sendMode) {
if (!key) { if (!key) {
throw "helma.Group.Wrapper.set(): key can't be null"; throw "helma.Group.GroupObject.set(): key can't be null";
} }
checkWriteAccess(); checkWriteAccess();
// check content type of value: // check content type of value:
@ -282,13 +282,13 @@ helma.Group.Wrapper = function(javaGroupObject) {
ok = true; ok = true;
else if (val instanceof Date) else if (val instanceof Date)
ok = true; ok = true;
else if (val instanceof helma.Group.Wrapper) else if (val instanceof helma.Group.GroupObject)
ok = true; ok = true;
if (ok == false) { if (ok == false) {
throw "only primitive values, Date and helma.Group.Wrapper allowed in helma.Group.Wrapper.set()"; throw "only primitive values, Date and helma.Group.GroupObject allowed in helma.Group.GroupObject.set()";
} }
if (sendMode == null) { if (sendMode == null) {
sendMode = helma.Group.Wrapper.DEFAULT_GET; sendMode = helma.Group.GroupObject.DEFAULT_GET;
} }
if (keyIsPath(key)) { if (keyIsPath(key)) {
@ -302,12 +302,12 @@ helma.Group.Wrapper = function(javaGroupObject) {
// null values aren't permitted in the group, // null values aren't permitted in the group,
// setting a property to null is the same as deleting it // setting a property to null is the same as deleting it
this.remove(key, sendMode); this.remove(key, sendMode);
} else if (val instanceof helma.Group.Wrapper) { } else if (val instanceof helma.Group.GroupObject) {
// replicate helma.Group.Wrapper // replicate helma.Group.GroupObject
javaGroupObject.put(key, val.getJavaObject(), sendMode); javaGroupObject.put(key, val.getJavaObject(), sendMode);
} else { } else {
// put the primitive property (or maybe replicate, // put the primitive property (or maybe replicate,
// decision's up to helma.Group.Wrapper) // decision's up to helma.Group.GroupObject)
if (val instanceof Date) { if (val instanceof Date) {
// convert javascript dates to java dates // convert javascript dates to java dates
val = new java.util.Date(val.getTime()); val = new java.util.Date(val.getTime());
@ -338,7 +338,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
this.remove = function(key, sendMode) { this.remove = function(key, sendMode) {
checkWriteAccess(); checkWriteAccess();
if (sendMode == null) { if (sendMode == null) {
sendMode = helma.Group.Wrapper.DEFAULT_GET; sendMode = helma.Group.GroupObject.DEFAULT_GET;
} }
if (keyIsPath(key)) { if (keyIsPath(key)) {
var obj = walkPath(this, key); var obj = walkPath(this, key);
@ -367,7 +367,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
* <li>an Array containing String keys</li> * <li>an Array containing String keys</li>
* </ul> * </ul>
* @return Depending on the argument either the appropriate property * @return Depending on the argument either the appropriate property
* value or a helma.Group.Wrapper * value or a helma.Group.GroupObject
* @type Object * @type Object
*/ */
this.get = function(key) { this.get = function(key) {
@ -391,7 +391,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
return val; return val;
} else if (javaGroupObject.hasChild(key)) { } else if (javaGroupObject.hasChild(key)) {
// we got a child object // we got a child object
return new helma.Group.Wrapper(javaGroupObject.getChild(key)); return new helma.Group.GroupObject(javaGroupObject.getChild(key));
} }
return null; return null;
}; };
@ -435,10 +435,10 @@ helma.Group.Wrapper = function(javaGroupObject) {
this.wrap = function(newGroupObject) { this.wrap = function(newGroupObject) {
checkWriteAccess(); checkWriteAccess();
if (javaGroupObject.getState() != helmagroups.GroupObject.REPLICATED) { if (javaGroupObject.getState() != helmagroups.GroupObject.REPLICATED) {
throw "helma.Group.Wrapper.wrap() may only be called on replicated GroupObjects"; throw "helma.Group.GroupObject.wrap() may only be called on replicated GroupObjects";
} }
if (newGroupObject == null || !(newGroupObject instanceof helma.Group.Wrapper)) { if (newGroupObject == null || !(newGroupObject instanceof helma.Group.GroupObject)) {
throw "helma.Group.Wrapper.wrap() requires a helma.Group.Wrapper as an argument"; throw "helma.Group.GroupObject.wrap() requires a helma.Group.GroupObject as an argument";
} }
javaGroupObject.wrap(newGroupObject.getJavaObject()); javaGroupObject.wrap(newGroupObject.getJavaObject());
return this; return this;
@ -460,7 +460,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
javaGroupObjectClone.setChildren(new java.util.Hashtable()); javaGroupObjectClone.setChildren(new java.util.Hashtable());
javaGroupObjectClone.setState(helmagroups.GroupObject.LOCAL); javaGroupObjectClone.setState(helmagroups.GroupObject.LOCAL);
javaGroupObjectClone.setPath(null); javaGroupObjectClone.setPath(null);
return new helma.Group.Wrapper(javaGroupObjectClone); return new helma.Group.GroupObject(javaGroupObjectClone);
}; };
/** /**
@ -510,7 +510,7 @@ helma.Group.Wrapper = function(javaGroupObject) {
/** /**
* Returns the number of child GroupObjects * Returns the number of child GroupObjects
* @returns The number of child GroupObjects of this * @returns The number of child GroupObjects of this
* helma.Group.Wrapper instance * helma.Group.GroupObject instance
* @type Number * @type Number
*/ */
this.countChildren = function() { this.countChildren = function() {
@ -558,17 +558,17 @@ helma.Group.Wrapper = function(javaGroupObject) {
* for further comments see the sourcecode of that class * for further comments see the sourcecode of that class
*/ */
// wait just for the first response // wait just for the first response
helma.Group.Wrapper.GET_FIRST = 1; helma.Group.GroupObject.GET_FIRST = 1;
// wait until all members have responded // wait until all members have responded
helma.Group.Wrapper.GET_ALL = 2; helma.Group.GroupObject.GET_ALL = 2;
// wait for majority (50% + 1) to respond // wait for majority (50% + 1) to respond
helma.Group.Wrapper.GET_MAJORITY = 3; helma.Group.GroupObject.GET_MAJORITY = 3;
// wait for majority of all members (may block!) // wait for majority of all members (may block!)
helma.Group.Wrapper.GET_ABS_MAJORITY = 4; helma.Group.GroupObject.GET_ABS_MAJORITY = 4;
// don't wait for any response (fire & forget) // don't wait for any response (fire & forget)
helma.Group.Wrapper.GET_NONE = 6; helma.Group.GroupObject.GET_NONE = 6;
// default: wait for all responses // default: wait for all responses
helma.Group.Wrapper.DEFAULT_GET = helma.Group.Wrapper.GET_ALL; helma.Group.GroupObject.DEFAULT_GET = helma.Group.GroupObject.GET_ALL;
/** /**
* this is mounted as "groups". the root for all groups started in this application * this is mounted as "groups". the root for all groups started in this application