Skip to content

Commit e8d65ee

Browse files
committed
close #8
1 parent efeca0f commit e8d65ee

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/main/java/org/mujoco/xml/BodyarchType.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import java.beans.PropertyChangeListener;
1212
import java.beans.VetoableChangeListener;
13+
import java.lang.reflect.InvocationTargetException;
14+
import java.lang.reflect.Method;
1315
import java.math.BigDecimal;
1416
import java.util.ArrayList;
1517
import java.util.Arrays;
@@ -24,6 +26,8 @@
2426
import javax.xml.bind.annotation.XmlElementRefs;
2527
import javax.xml.bind.annotation.XmlElements;
2628
import javax.xml.bind.annotation.XmlType;
29+
import javax.xml.namespace.QName;
30+
2731
import com.kscs.util.jaxb.BoundList;
2832
import com.kscs.util.jaxb.BoundListProxy;
2933
import com.kscs.util.jaxb.Buildable;
@@ -362,12 +366,52 @@ protected<_P extends BodyarchType >_P init(final _P _product) {
362366
if (this.inertialOrJointOrFreejoint!= null) {
363367
final List<JAXBElement<?>> inertialOrJointOrFreejoint = new ArrayList<JAXBElement<?>>(this.inertialOrJointOrFreejoint.size());
364368
for (Buildable _item: this.inertialOrJointOrFreejoint) {
365-
inertialOrJointOrFreejoint.add(((JAXBElement<?> ) _item.build()));
369+
try {
370+
inertialOrJointOrFreejoint.add(buildRecoursive(_item));
371+
} catch (NoSuchMethodException | SecurityException | IllegalAccessException
372+
| IllegalArgumentException | InvocationTargetException e) {
373+
// TODO Auto-generated catch block
374+
e.printStackTrace();
375+
}
366376
}
367377
_product.inertialOrJointOrFreejoint = inertialOrJointOrFreejoint;
368378
}
369379
return super.init(_product);
370380
}
381+
private JAXBElement<?> buildRecoursive(Object o) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
382+
Class<? extends Object> class1 = o.getClass();
383+
System.out.println("Class "+class1);
384+
Method setNameMethod = class1.getMethod("build");
385+
Object product = setNameMethod.invoke(o);
386+
if(JAXBElement.class.isInstance(product))
387+
return (JAXBElement<?>)product;
388+
if (product==null)
389+
throw new NullPointerException();
390+
if(BodyarchType.class.isInstance(product)) {
391+
BodyarchType bat = (BodyarchType)product;
392+
JAXBElement<BodyarchType> element =new JAXBElement<BodyarchType>(new QName("body"),BodyarchType.class,bat);
393+
return element;
394+
}
395+
return buildRecoursive(product);
396+
}
397+
398+
/**
399+
* Returns a new builder to build an additional value of the "body" property.
400+
* Use {@link org.mujoco.xml.BodyarchType.Builder#end()} to return to the current builder.
401+
*
402+
* @return
403+
* a new builder to build an additional value of the "body" property.
404+
* Use {@link org.mujoco.xml.BodyarchType.Builder#end()} to return to the current builder.
405+
*/
406+
public BodyarchType.Builder<? extends BodyType.Builder<_B>> addBody() {
407+
if (this.inertialOrJointOrFreejoint == null) {
408+
this.inertialOrJointOrFreejoint = new ArrayList<Buildable>();
409+
}
410+
final BodyarchType.Builder<BodyType.Builder<_B>> body_Builder = new BodyarchType.Builder<BodyType.Builder<_B>>(this, null, false);
411+
//System.out.println("Builder type is "+body_Builder.getClass());
412+
this.inertialOrJointOrFreejoint.add(body_Builder);
413+
return body_Builder;
414+
}
371415

372416
/**
373417
* Adds the given items to the value of "inertialOrJointOrFreejoint"

src/main/java/org/mujoco/xml/Mujoco.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13758,11 +13758,12 @@ public Mujoco.Worldbody.Builder<_B> addBody(BodyarchType... body_) {
1375813758
* a new builder to build an additional value of the "body" property.
1375913759
* Use {@link org.mujoco.xml.BodyarchType.Builder#end()} to return to the current builder.
1376013760
*/
13761-
public BodyarchType.Builder<? extends Mujoco.Worldbody.Builder<_B>> addBody() {
13761+
public org.mujoco.xml.BodyarchType.Builder<? extends org.mujoco.xml.Mujoco.Worldbody.Builder<_B>> addBody() {
1376213762
if (this.geomOrSiteOrCamera == null) {
1376313763
this.geomOrSiteOrCamera = new ArrayList<Buildable>();
1376413764
}
13765-
final BodyarchType.Builder<Mujoco.Worldbody.Builder<_B>> body_Builder = new BodyarchType.Builder<Mujoco.Worldbody.Builder<_B>>(this, null, false);
13765+
final org.mujoco.xml.BodyarchType.Builder<org.mujoco.xml.Mujoco.Worldbody.Builder<_B>> body_Builder = new org.mujoco.xml.BodyarchType.Builder<org.mujoco.xml.Mujoco.Worldbody.Builder<_B>>(this, null, false);
13766+
System.out.println("Builder type is "+body_Builder.getClass());
1376613767
this.geomOrSiteOrCamera.add(body_Builder);
1376713768
return body_Builder;
1376813769
}

src/test/java/mujoco/java/XMLtest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public void marshal() throws JAXBException {
3535
topbody.withPos("0 0 1.282");
3636

3737
//topbody.addBody();
38-
//topbody.addBody().withName("Head");
38+
topbody.addBody().withName("Head").withPos("0 0 2.2")
39+
.addBody()
40+
.withName("mowhawk")
41+
.withPos("0 0 1.2")
42+
;
3943

4044

4145
//topbody.addBody(topbody.ge);

0 commit comments

Comments
 (0)