[英]use fully qualified names in hyperjaxb3 generated java classes
I have generated .java classes from the hyperjax3 which are already annotated with Annotations like @Entity and @Table etc.." 我已经从hyperjax3生成了.java类,这些类已经用@Entity和@Table等注释进行了注释。”
In @Entity the class name is automatically added as follows: @Entity(name = "MyClassName")
But I want this name field to have a fully qualified class name as 在@Entity中,类名称将自动添加,如下所示:
@Entity(name = "MyClassName")
但是我希望此名称字段具有完全限定的类名称 ,如下所示:
@Entity(name = "myPackage.here.MyClassName")
I am using the hyperjaxb3-ejb-samples-po-initial-0.5.6 example and generating the annotated java classes by running mvn clean install where my XSDs schemas are present in the src\\main\\resources
folder in maven project. @Entity(name = "myPackage.here.MyClassName")
我正在使用hyperjaxb3-ejb-samples-po-initial-0.5.6示例,并通过运行mvn clean install生成带注释的Java类,其中我的XSD模式存在于Maven项目中的src\\main\\resources
文件夹。
*I have searched and found a way which states that use auto-import=false but I am not able to incorporate this as I am simply running that maven project. *我已经搜索并找到一种状态,该状态指出使用auto-import = false,但是由于我只是运行该maven项目,因此无法合并。
Disclaimer: I am the author of Hyperjaxb3 . 免责声明:我是Hyperjaxb3的作者。
Entity name is not customizable, but you can implement your own naming strategy to generate fully qualified entity names. 实体名称不可自定义,但是您可以实施自己的命名策略以生成完全限定的实体名称。
For this, you'd have to impement the org.jvnet.hyperjaxb3.ejb.strategy.naming.Naming
interface. 为此,您必须强制使用
org.jvnet.hyperjaxb3.ejb.strategy.naming.Naming
接口。 The easiest would be to subclass org.jvnet.hyperjaxb3.ejb.strategy.naming.impl.DefaultNaming
and to override the getEntityName
method: 最简单的是子类
org.jvnet.hyperjaxb3.ejb.strategy.naming.impl.DefaultNaming
并重写getEntityName
方法:
public String getEntityName(Mapping context, Outline outline, NType type) {
final JType theType = type.toType(outline, Aspect.EXPOSED);
assert theType instanceof JClass;
final JClass theClass = (JClass) theType;
return CodeModelUtils.getPackagedClassName(theClass);
}
You'll also have to include the org\\jvnet\\hyperjaxb3\\ejb\\plugin\\custom\\applicationContext.xml
resource to configure your custom naming strategy: 您还必须包括
org\\jvnet\\hyperjaxb3\\ejb\\plugin\\custom\\applicationContext.xml
资源,以配置自定义命名策略:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean name="naming" class="com.acme.foo.CustomNaming">
<property name="reservedNames" ref="reservedNames"/>
</bean>
</beans>
Finally, compile it all, pack as JAR and add to the HJ3 classpath, for instance via plugin dependencies in the Maven POM: 最后,编译所有内容,打包为JAR并添加到HJ3类路径,例如通过Maven POM中的插件依赖项:
<plugin>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<configuration>...</configuration>
<dependencies>
<dependency>
<groupId>com.acme.foo</groupId>
<artifactId>hyperjaxb3-custom-naming-extension</artifactId>
<version>...</version>
</dependency>
</dependencies>
</plugin>
Here's a test project which implements/configures a custom naming stratgy: 这是一个实现/配置自定义命名策略的测试项目:
See also: 也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.