我必须使用包含以下代码段的架构,其中名称 object 是重复的。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="param_object_type">
<xs:sequence>
<xs:element name="object" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="object" minOccurs="0" maxOccurs="unbounded">
</xs:sequence>
</xs:complexType>
</xs:sequence>
</xs:complexType>
</xs:schema>
Jaxb 最初很乐意导入它,但由于 Object 类被声明了两次而无法编译源代码。
我添加了 globalBindings 选项 localScoping="toplevel" 现在会导致以下编译时错误:
org.xml.sax.SAXParseException; systemId:具有相同名称“jaxb.Object”的类/接口(interface)已在使用中。使用类自定义来解决此冲突。
所以我尝试添加一个自定义绑定(bind)来重命名对象之一,jaxb:class 和 jaxb:property。两者都会产生相同的错误。
如果有帮助,这是我的绑定(bind)文件:
<jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true" choiceContentProperty="true" localScoping="toplevel"/>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../xsd/NodeSchema.xsd" node="/xs:schema">
<jaxb:bindings node="/xs:schema/xs:complexType[@name='param_object_type']/xs:sequence/xs:element[@name='object']">
<jaxb:class name="object2"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
我如何才能确保这些实例中的一个被重命名而另一个保持不变?
最佳答案
正确的复杂类型 .. 缺少 xs:element 的结束标记
XSD
<xs:complexType name="param_object_type">
<xs:sequence>
<xs:element name="object" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="object" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
绑定(bind)
<jxb:bindings node="//xs:schema//xs:complexType[@name='param_object_type']//xs:sequence//xs:element[@name='object']//xs:complexType//xs:sequence//xs:element[@name='object']">
<jxb:class name="object2" />
</jxb:bindings>
ParamObjectType.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "param_object_type", propOrder = {
"object"
})
public class ParamObjectType
implements Serializable
{
private final static long serialVersionUID = 2L;
protected List<ParamObjectType.Object> object;
/**
* Gets the value of the object property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the object property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getObject().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link ParamObjectType.Object }
*
*
*/
public List<ParamObjectType.Object> getObject() {
if (object == null) {
object = new ArrayList<ParamObjectType.Object>();
}
return this.object;
}
/**
* <p>Classe Java per anonymous complex type.
*
* <p>Il seguente frammento di schema specifica il contenuto previsto contenuto in questa classe.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="object" type="{http://www.w3.org/2001/XMLSchema}anyType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"object"
})
public static class Object
implements Serializable
{
private final static long serialVersionUID = 2L;
@XmlElementRef(name = "object", type = ParamObjectType.Object.Object2 .class, required = false)
protected List<ParamObjectType.Object.Object2> object;
/**
* Gets the value of the object property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the object property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getObject().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link ParamObjectType.Object.Object2 }
*
*
*/
public List<ParamObjectType.Object.Object2> getObject() {
if (object == null) {
object = new ArrayList<ParamObjectType.Object.Object2>();
}
return this.object;
}
public static class Object2
extends JAXBElement<java.lang.Object>
{
protected final static QName NAME = new QName("", "object");
public Object2(java.lang.Object value) {
super(NAME, ((Class) java.lang.Object.class), ParamObjectType.Object.class, value);
}
public Object2() {
super(NAME, ((Class) java.lang.Object.class), ParamObjectType.Object.class, null);
}
}
}
}
关于java - JaxB 重命名具有重复名称的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29016151/
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
假设我有一个FireNinja我的数据库中的对象,使用单表继承存储。后来才知道他真的是WaterNinja.将他更改为不同的子类的最干净的方法是什么?更好的是,我很想创建一个新的WaterNinja对象并替换旧的FireNinja在数据库中,保留ID。编辑我知道如何创建新的WaterNinja来self现有FireNinja的对象,我也知道我可以删除旧的并保存新的。我想做的是改变现有项目的类别。我是通过创建一个新对象并执行一些ActiveRecord魔法来替换行,还是通过对对象本身做一些疯狂的事情,或者甚至通过删除它并使用相同的ID重新插入来做到这一点,这是问题的一部分。
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我正在使用Rails3.1并在一个论坛上工作。我有一个名为Topic的模型,每个模型都有许多Post。当用户创建新主题时,他们也应该创建第一个Post。但是,我不确定如何以相同的形式执行此操作。这是我的代码:classTopic:destroyaccepts_nested_attributes_for:postsvalidates_presence_of:titleendclassPost...但这似乎不起作用。有什么想法吗?谢谢! 最佳答案 @Pablo的回答似乎有你需要的一切。但更具体地说...首先改变你View中的这一行对此#
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只