public String process() { if (this.type.getCanonicalName() == null) { new RuntimeException("" + this.type).printStackTrace(); } else { this.elem(Elem.mapping); if (this.abs) { this.attr("abstract", "true"); } else { this.attr("name", this.type.getSimpleName()) .attr("extends", this.type.getSuperclass().getCanonicalName()); } this.attr("class", this.type.getCanonicalName()); if (BindingGenerator.MSG_TYPE.isAssignableFrom(this.type.getSuperclass()) || BindingGenerator.DATA_TYPE.isAssignableFrom(this.type.getSuperclass())) { this.elem(Elem.structure) .attr("map-as", this.type.getSuperclass().getCanonicalName()) .end(); } for (Field f : type.getDeclaredFields()) { TypeBinding tb = getTypeBinding(f); if (!(tb instanceof NoopTypeBinding)) { System.out.printf( "BOUND: %-70s [type=%s:%s]\n", f.getDeclaringClass().getCanonicalName() + "." + f.getName(), tb.getTypeName(), f.getType().getCanonicalName()); this.append(tb.toString()); } } this.end(); } return this.toString(); }
@Override public void processClass(Class klass) { if (BindingGenerator.DATA_TYPE.isAssignableFrom(klass) || BindingGenerator.MSG_TYPE.isAssignableFrom(klass)) { String mapping = new RootObjectTypeBinding(klass).process(); out.write(mapping); out.flush(); } }
public TypeBinding getTypeBinding(Field field) { Class itsType = field.getType(); if (this.isIgnored(field)) { return new NoopTypeBinding(field); } else if (List.class.isAssignableFrom(itsType)) { Class listType = getTypeArgument(field); if (listType == null) { System.err.printf( "IGNORE: %-70s [type=%s] NO GENERIC TYPE FOR LIST\n", field.getDeclaringClass().getCanonicalName() + "." + field.getName(), listType); return new NoopTypeBinding(field); } else if (typeBindings.containsKey(listType.getCanonicalName())) { return new CollectionTypeBinding( field.getName(), typeBindings.get(listType.getCanonicalName())); } else if (BindingGenerator.DATA_TYPE.isAssignableFrom(listType)) { return new CollectionTypeBinding( field.getName(), new ObjectTypeBinding(field.getName(), listType)); } else { System.err.printf( "IGNORE: %-70s [type=%s] LIST'S GENERIC TYPE DOES NOT CONFORM TO EucalyptusData\n", field.getDeclaringClass().getCanonicalName() + "." + field.getName(), listType.getCanonicalName()); return new NoopTypeBinding(field); } } else if (typeBindings.containsKey(itsType.getCanonicalName())) { TypeBinding t = typeBindings.get(itsType.getCanonicalName()); try { t = typeBindings.get(itsType.getCanonicalName()).getClass().newInstance(); } catch (Exception e) { } return t.value(field.getName()); } else if (BindingGenerator.DATA_TYPE.isAssignableFrom(field.getType())) { return new ObjectTypeBinding(field); } else { System.err.printf( "IGNORE: %-70s [type=%s] TYPE DOES NOT CONFORM TO EucalyptusData\n", field.getDeclaringClass().getCanonicalName() + "." + field.getName(), field.getType().getCanonicalName()); return new NoopTypeBinding(field); } }