/* parse and store the IDL here */
static osrfHash* idlHash;
+static void add_std_fld( osrfHash* fields_hash, const char* field_name, unsigned pos );
osrfHash* oilsIDL(void) { return idlHash; }
osrfHash* oilsIDLInit( const char* idl_filename ) {
unsigned int array_pos = 0;
char array_pos_buf[ 7 ]; // For up to 1,000,000 fields per class
- xmlNodePtr _f = _cur->children;
+ xmlNodePtr _f = _cur->children;
while(_f) {
if (strcmp( (char*)_f->name, "field" )) {
_f = _f->next;
continue;
}
+ // Get the field name. If it's one of the three standard
+ // fields that we always generate, ignore it.
+ char* field_name = (char*)xmlGetProp(_f, BAD_CAST "name");
+ if( field_name ) {
+ osrfLogDebug(OSRF_LOG_MARK,
+ "Found field %s for class %s", field_name, current_class_name );
+ if( !strcmp( field_name, "isnew" )
+ || !strcmp( field_name, "ischanged" )
+ || !strcmp( field_name, "isdeleted" ) ) {
+ free( field_name );
+ _f = _f->next;
+ continue;
+ }
+ } else {
+ osrfLogDebug(OSRF_LOG_MARK,
+ "Found field with no name for class %s", current_class_name );
+ _f = _f->next;
+ continue;
+ }
+
osrfHash* field_def_hash = osrfNewHash();
// Insert array_position
);
}
- if( (prop_str = (char*)xmlGetProp(_f, BAD_CAST "name")) ) {
- osrfHashSet(
- field_def_hash,
- prop_str,
- "name"
- );
- osrfLogDebug(OSRF_LOG_MARK,
- "Found field %s for class %s", prop_str, current_class_name );
- } else
- osrfLogDebug(OSRF_LOG_MARK,
- "Found field with no name for class %s", current_class_name );
-
+ osrfHashSet( field_def_hash, field_name, "name" );
osrfHashSet(
current_fields_hash,
field_def_hash,
- prop_str
+ field_name
);
_f = _f->next;
}
+
+ // Create three standard, stereotyped virtual fields for every class
+ add_std_fld( current_fields_hash, "isnew", array_pos++ );
+ add_std_fld( current_fields_hash, "ischanged", array_pos++ );
+ add_std_fld( current_fields_hash, "isdeleted", array_pos );
+
}
if (!strcmp( (char*)_cur->name, "links" )) {
return idlHash;
}
+// Adds a standard virtual field to a fields hash
+static void add_std_fld( osrfHash* fields_hash, const char* field_name, unsigned pos ) {
+ char array_pos_buf[ 7 ];
+ osrfHash* std_fld_hash = osrfNewHash();
+
+ snprintf( array_pos_buf, sizeof( array_pos_buf ), "%u", pos );
+ osrfHashSet( std_fld_hash, strdup( array_pos_buf ), "array_position" );
+ osrfHashSet( std_fld_hash, "true", "virtual" );
+ osrfHashSet( std_fld_hash, strdup( field_name ), "name" );
+ osrfHashSet( fields_hash, std_fld_hash, field_name );
+}
+
+
osrfHash* oilsIDLFindPath( const char* path, ... ) {
if(!path || strlen(path) < 1) return NULL;
for my $t (@$types) {
my ($u,$v,$d,$i,$n,$o,$p) = (val($t->can_have_users),val($t->can_have_vols),$t->depth,$t->id,val($t->name),val($t->opac_label),$t->parent);
$p ||= 'null';
- $pile .= "new aout([null,null,null,null,$u,$v,$d,$i,$n,$o,$p]), ";
+ $pile .= "new aout([null,$u,$v,$d,$i,$n,$o,$p]), ";
}
$pile =~ s/, $//; # remove trailing comma
$pile .= ']; /* OU Types */';
my $attribute_list = $field->attributes();
my $name = get_attribute( $attribute_list, 'name' );
+ next if( $name eq 'isnew' || $name eq 'ischanged' || $name eq 'isdeleted' );
my $virtual = get_attribute( $attribute_list, 'oils_persist:virtual' );
if( ! defined( $virtual ) ) {
$virtual = "false";
++$array_position;
}
}
+
+ # Load the standard 3 virtual fields ------------------------
+
+ for my $vfield ( qw/isnew ischanged isdeleted/ ) {
+ $$fieldmap{$fm}{fields}{ $vfield } =
+ { position => $array_position,
+ virtual => 1
+ };
+ ++$array_position;
+ }
}
sub load_links {
use base 'Fieldmapper';
PERL
- my $pos = 0;
- for my $vfield ( qw/isnew ischanged isdeleted/ ) {
- $$fieldmap{$pkg}{fields}{$vfield} = { position => $pos, virtual => 1 };
- $pos++;
- }
-
if (exists $$fieldmap{$pkg}{proto_fields}) {
for my $pfield ( sort keys %{ $$fieldmap{$pkg}{proto_fields} } ) {
$$fieldmap{$pkg}{fields}{$pfield} = { position => $pos, virtual => $$fieldmap{$pkg}{proto_fields}{$pfield} };
def parse_IDL(self):
"""Parses the IDL file and builds class, field, and link objects"""
+ # in case we're calling parse_IDL directly
+ if not IDLParser._global_parser:
+ IDLParser._global_parser = self
+
doc = xml.dom.minidom.parse(self.idlFile)
root = doc.documentElement
fields = [f for f in child.childNodes if f.nodeName == 'fields']
links = [f for f in child.childNodes if f.nodeName == 'links']
- keys = self.parse_fields(obj, fields[0])
+ fields = self.parse_fields(obj, fields[0])
if len(links) > 0:
self.parse_links(obj, links[0])
- osrf.net_obj.register_hint(obj.name, keys, 'array')
+ osrf.net_obj.register_hint(obj.name, [f.name for f in fields], 'array')
doc.unlink()
def parse_fields(self, idlobj, fields):
"""Takes the fields node and parses the included field elements"""
- keys = []
-
idlobj.primary = self._get_attr(fields, 'oils_persist:primary', OILS_NS_PERSIST)
idlobj.sequence = self._get_attr(fields, 'oils_persist:sequence', OILS_NS_PERSIST)
- # pre-flesh the array of keys to accomodate random index insertions
- for field in fields.childNodes:
- if field.nodeType == field.ELEMENT_NODE:
- keys.append(None)
-
+ position = 0
for field in [l for l in fields.childNodes if l.nodeName == 'field']:
+ name = self._get_attr(field, 'name')
+
+ if name in ['isnew', 'ischanged', 'isdeleted']:
+ continue
+
obj = IDLField(
idlobj,
- name = self._get_attr(field, 'name'),
- position = int(self._get_attr(field, 'oils_obj:array_position', OILS_NS_OBJ)),
+ name = name,
+ position = position,
virtual = self._get_attr(field, 'oils_persist:virtual', OILS_NS_PERSIST),
label = self._get_attr(field, 'reporter:label', OILS_NS_REPORTER),
rpt_datatype = self._get_attr(field, 'reporter:datatype', OILS_NS_REPORTER),
primitive = self._get_attr(field, 'oils_persist:primitive', OILS_NS_PERSIST)
)
- try:
- keys[obj.position] = obj.name
- except Exception, e:
- osrf.log.log_error("parse_fields(): position out of range. pos=%d : key-size=%d" % (obj.position, len(keys)))
- raise e
+ idlobj.fields.append(obj)
+ position += 1
+ for name in ['isnew', 'ischanged', 'isdeleted']:
+ obj = IDLField(idlobj,
+ name = name,
+ position = position,
+ virtual = 'true'
+ )
idlobj.fields.append(obj)
+ position += 1
- return keys
+ return idlobj.fields
for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
var p = field.array_position;
- if (p <= 2) continue;
-
this._fields.push( field.name );
this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
}
this.classname = this.declaredClass;
this._fields = fmclasses[this.classname];
for( var pos = 0; pos < this._fields.length; pos++ ) {
- var p = parseInt(pos) + 3;
+ var p = parseInt(pos);
var f = this._fields[pos];
this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
}
else links = [];
+ var position = 0;
for(var i = 0; i < fields.length; i++) {
var field = fields[i];
var name = field.getAttribute('name');
+ if(name == 'isnew' || name == 'ischanged' || name == 'isdeleted')
+ continue;
+
var obj = {
field : field,
name : name,
datatype : field.getAttributeNS(this.NS_REPORTS,'datatype'),
primitive : field.getAttributeNS(this.NS_PERSIST,'primitive'),
selector : field.getAttributeNS(this.NS_REPORTS,'selector'),
- array_position : parseInt(field.getAttributeNS(this.NS_OBJ,'array_position')),
+ array_position : position++,
type : 'field',
virtual : (fields[i].getAttributeNS(this.NS_PERSIST, 'virtual') == 'true')
};
obj.label = obj.label || obj.name;
obj.datatype = obj.datatype || 'text';
- if (obj.array_position > 2)
- window.fmclasses[classname].push(obj.name);
+ window.fmclasses[classname].push(obj.name);
var link = null;
for(var l = 0; l < links.length; l++) {
map[obj.name] = obj;
}
- /*
- data = data.sort(
- function(a,b) {
- if( a.label > b.label ) return 1;
- if( a.label < b.name ) return -1;
- return 0;
+ dojo.forEach(['isnew', 'ischanged', 'isdeleted'],
+ function(name) {
+ var obj = {
+ name : name,
+ array_position : position++,
+ type : 'field',
+ virtual : true
+ };
+ data.push(obj);
+ map[obj.name] = obj;
}
);
- */
-
+
return { list : data, map : map };
}
}
return obj;
}
-Fieldmapper.prototype.isnew = function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; }
-Fieldmapper.prototype.ischanged = function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; }
-Fieldmapper.prototype.isdeleted = function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; }
+
function FMEX(message) { this.message = message; }
FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; }
string += cl + "._isfieldmapper=true;";
+ fmclasses[cl].push('isnew');
+ fmclasses[cl].push('ischanged');
+ fmclasses[cl].push('isdeleted');
+
for( var pos in fmclasses[cl] ) {
- var p = parseInt(pos) + 3;
+ var p = parseInt(pos);
var field = fmclasses[cl][pos];
string += cl + ".prototype." + field +
"=function(n){if(arguments.length == 1)this.a[" +