我想在子对象和父对象之间的类中使用双向导航方法.在我的情况下,IDREF是不够的,因为我不想指定父的le id.要清楚,从这样的xsd:
<complexType name="A">
<xs:sequence>
<element name="b" type="B" minOccurs="0" maxOccurs="unbounded"></element>
</xs:sequence>
<attribute name="id" type="ID"></attribute>
</complexType>
<complexType name="B">
<attribute name="id" type="ID"></attribute>
</complexType>
Run Code Online (Sandbox Code Playgroud)
我希望课程看起来像这样:
class A {
...
public List<B> getB() { ...}
...
}
class B {
...
public A getA() {
...
}
Run Code Online (Sandbox Code Playgroud)
我的xml必须如下所示:
<a id="a1">
<b id="b1"/>
<b id="b2"/>
...
</a>
Run Code Online (Sandbox Code Playgroud)
在unmarshal之后,我希望能够将A导航到Bs并从B导航到A(通过b.getA())!! 这是一个非常基本的功能,但我找不到一种简单的方法来实现这一目标......
任何的想法 ??
提前致谢
存在的问题
如果我有一个类层次结构,如:
public class TestSuper {
public static class A {
@Override
public String toString() { return "I am A"; }
}
public static class B extends A {
@Override
public String toString() { return "I am B"; }
}
public static void main(String[] args) {
Object o = new B();
System.out.println( o ); // --> I am B
// ?????? // --> I am A
}
}
Run Code Online (Sandbox Code Playgroud)
从main方法,当实例是B类时,是否可以调用A的toString?
当然,像o.super.toString()这样的东西不能编译......
是否可以检索方法/构造函数的调用者实例?
这个问题已经发布,但每次答案都是关于调用者类(使用堆栈跟踪)而不是调用者实例.如果存在解决方案,那么构建对象图(具有公共超类型)并使用默认构造函数处理父子导航可能非常方便.
public class TestCallStack {
public static class BaseClass {
BaseClass owner;
// //ok, this is the correct way to do it
// public BaseClass(BaseClass owner) {
// this.owner = owner;
// }
public BaseClass() {
//this.owner = ???????;
}
}
public static class Parent extends BaseClass {
Child child = new Child();
}
public static class Child extends BaseClass {
}
public static void main(String[] args) {
Parent parent = new Parent();
System.out.println(parent.child.owner==parent); // must be true
} …
Run Code Online (Sandbox Code Playgroud) 我需要使用forfiles命令从windows命令提示符生成一个xml.
我不是那么远,但变量包含引号,我不想要它...
这是我当前的命令:
%FF_CMD% /c "cmd /c if @isdir==TRUE echo ^<root^>^<dir^>@fname^</dir^>^</root^>"
Run Code Online (Sandbox Code Playgroud)
结果是:
<root><dir>"DIRNAME"</dir></root>
Run Code Online (Sandbox Code Playgroud)
但我想要这个:
<root><dir>DIRNAME</dir></root>
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?
提前致谢
java ×3
callstack ×1
cmd ×1
command-line ×1
inheritance ×1
jaxb ×1
stack-trace ×1
variables ×1
windows ×1
xjc ×1