JaxB를 시작했으며 Moxy 구현을 사용 중입니다. Jaxb를 사용하여 Java Object Model로 변환 한 산업 표준 xsd가 있습니다. 문자열, 정수 및 날짜와 같은 간단한 필드에 주석을 달기까지했습니다.JAXB Moxy- 복잡한 유형의 필드 xtd에 주석을 달기위한 질문
4 개의 속성과 선택적 문자열 요소가있는 xsd 복합 유형 인 다음 필드에 주석을 달려면 올바른 방향으로 검색해야합니다. Cd.java 클래스의 수에 사용될
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "cd", propOrder = {
"originalText",
})
public class Cd {
protected Object originalText;
@XmlAttribute(name = "code")
@XmlSchemaType(name = "anySimpleType")
protected String code;
@XmlAttribute(name = "displayName")
@XmlSchemaType(name = "anySimpleType")
protected String displayName;
@XmlAttribute(name = "codeSystem")
@XmlSchemaType(name = "anySimpleType")
protected String codeSystem;
@XmlAttribute(name = "codeSystemName")
@XmlSchemaType(name = "anySimpleType")
protected String codeSystemName;
@XmlAttribute(name = "nullFlavor")
protected NullFlavorType nullFlavor;
//ommitted getters and setters
Conditions.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"condition"
})
@XmlRootElement(name = "conditions")
public class Conditions {
protected List<Conditions.Condition> condition;
public List<Conditions.Condition> getCondition() {
if (condition == null) {
condition = new ArrayList<Conditions.Condition>();
}
return this.condition;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"problemDate",
"problemType",
"problemCode",
"problemStatus",
})
public static class Condition {
protected IvlTs problemDate;
//This is the field I need to annotate (problemType)
protected Cd problemType;
//The 2 below fields (problemCode, problemStatus) will also have to be annotated but I am just focusing on problemType for now
protected Cd problemCode;
protected Ce problemStatus
public void setProblemDate(IvlTs value) {
this.problemDate = value;
}
public void setProblemType(Cd value) {
this.problemType = value;
}
public void setProblemCode(Cd value) {
this.problemCode = value;
}
public void setProblemStatus(Ce value) {
this.problemStatus = value;
}
//omitted getters
}
Cd.java을 다음과 같이 생성 된 코드의 서브 세트는 다른 클래스는 Conditions.java 클래스뿐만 아니라
제 질문은 problemType에 4 개의 속성과 하나의 선택적 요소가있는 Conditions.java의 problemType에 내 필드에 주석을 추가하는 방법입니다.
Cd.java에 직접 주석을 달 수 없습니다. 구현할 클래스 (Cd.java 클래스를 사용하는 다른 8 개의 클래스 중에서 선택)에 따라 xml 입력이 달라지기 때문에 직접 Cd.java에 주석을 추가 할 수 없습니다. 내 질문을 명확히하기 위해 필요로하는 곳에
<PROBLEM_MODULE>
<code>24434</code> //Maps to protected String code in Cd.java;
<codeName>ICD-9</codeName> //Maps to protected String codeSystem in Cd.java;
<display>Asthma</display> //Maps to protected String displayName in Cd.java;
<codeSystem>2.564.34343.222</codeSystem> // Maps to protected String codeSystemName in Cd.java;
</PROBLEM_MODULE>
가 알려 주시기 바랍니다 다음과 같이 기존의 주석 JAXB별로 자동 생성 된 위의 Conditions.java problemType의 XML 입력입니다. 궁극적으로 나는 이것을 통해 나를 도울 자원이나 튜토리얼을 요청하고있다.
** * ***UPDATE* ** * ** * 나는대로되지 않은 다른 프로젝트에 테스트로 블 레즈의 솔루션은 완벽하게 작동 복잡한. 따라서이 방법은 옳다.하지만 메타 데이터 파일에 문제가있다. 위의 Conditions.java 파일을 업데이트했는데, 메타 데이터 파일을 구현하는 데 필요한 방식에 영향을 줄 수있는 세부 사항을 생략했습니다.
내 oxm.xml 파일
<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="conditions.exec"
xml-mapping-metadata-complete="true">
<java-types>
<java-type name="Conditions" xml-accessor-type="FIELD">
<xml-root-element name="PROBLEM_MODULE"/>
</java-type>
<java-type name="Cd" xml-accessor-type="FIELD">
<java-attributes>
<xml-type prop-order="code codeSystem displayName codeSystemName"/>
<xml-element java-attribute="codeSystem" name="codeName"/>
<xml-element java-attribute="displayName" name="display"/>
<xml-element java-attribute="codeSystemName" name="codeSystem"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
* 메인 클래스 *
public static void main(String[] args) {
try {
Map<String, Object> properties = new HashMap<String, Object>(1);
properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, new File("src/conditions/exec/oxm.xml"));
JAXBContext jc = JAXBContext.newInstance(new Class[] {Conditions.class,Cd.class}, properties);
// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();
conditions.exec.Conditions InventoryInput = (conditions.exec.Conditions) u.unmarshal(
new File("src/conditions/exec/problems.xml")); //input file
// create a Marshaller and marshal to a file
Marshaller resultMarshaller = jc.createMarshaller();
resultMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
resultMarshaller.marshal(InventoryInput, System.out);
} catch (JAXBException je) {
je.printStackTrace();
}