}
public static Object constructRubyStruct(final Constructor ctor, final String tag, final Node node) {
final Ruby runtime = ((JRubyConstructor)ctor).runtime;
RubyModule sClass = runtime.fastGetModule("Struct");
RubyClass struct_type;
String[] nms = tag.split("::");
for(int i=0,j=nms.length;i<j && sClass != null;i++) {
sClass = (RubyModule)sClass.getConstant(nms[i]);
}
Map props = new HashMap();
Map val = (Map)(ctor.constructMapping(node));
for(Iterator iter = val.entrySet().iterator();iter.hasNext();) {
Map.Entry em = (Map.Entry)iter.next();
if(em.getKey().toString().startsWith("@")) {
props.put(em.getKey(),em.getValue());
iter.remove();
}
}
// If no such struct exists...
if(sClass == null) {
IRubyObject[] params = new IRubyObject[val.size()+1];
params[0] = runtime.newString(tag);
int i = 1;
for(Iterator iter = val.entrySet().iterator();iter.hasNext();i++) {
Map.Entry em = (Map.Entry)iter.next();
params[i] = ((RubyString)em.getKey()).intern();
}
struct_type = RubyStruct.newInstance(runtime.fastGetModule("Struct"),params,Block.NULL_BLOCK);
} else {
struct_type = (RubyClass)sClass;
}
IRubyObject st = struct_type.callMethod(runtime.getCurrentContext(),"new");
RubyArray members = RubyStruct.members(struct_type,Block.NULL_BLOCK);
for(int i=0,j=members.size();i<j;i++) {
IRubyObject m = members.eltInternal(i);
st.callMethod(runtime.getCurrentContext(), m.toString() + "=", (IRubyObject)val.get(m));
}