동일한 네임 스페이스를 갖는 다중 XSD가 동일하게 이름 지정된 유형을 정의하는 경우 잘못된 유형을 우연히 참조할 수 있습니다.
Address1.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="Address"> <xsd:sequence> <xsd:element minOccurs="0" name="city" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> Address2.xsd: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="Address"> <xsd:sequence> <xsd:element minOccurs="0" name="state" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
비즈니스 오브젝트는 BOFactory.create() API를 통해 어떤 글로벌 XSD 구조(예: complexType, simpleType, 요소, 속성 등)에도 중복된 이름을 지원하지 않습니다. 다음 예제에서와 같이 올바른 API를 사용하면 다른 구조의 하위 구조로 중복 글로벌 구조를 여전히 작성할 수 있습니다.
Customer1.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://Customer1" targetNamespace="http://Customer1"> <xsd:import schemaLocation="./Address1.xsd"/> <xsd:complexType name="Customer"> <xsd:sequence> <xsd:element minOccurs="0" name="address" type="Address"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Customer2.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://Customer2" targetNamespace="http://Customer2"> <xsd:import schemaLocation="./Address2.xsd"/> <xsd:complexType name="Customer"> <xsd:sequence> <xsd:element minOccurs="0" name="address" type="Address"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
고객 주소 필드를 둘 다 채우고 BOFactory.create()를 호출하여 주소를 작성하는 경우 생성되는 하위 비즈니스 오브젝트 유형이 잘못 설정될 수 있습니다. 고객 DataObject에 대한 createDataObject("address") API를 호출하여 이를 방지할 수 있습니다. 비즈니스 오브젝트는 가져오기의 schemaLocation을 따르므로 올바른 유형의 하위 유형을 생성하도록 보장할 수 있습니다.
DataObject customer1 = ... // Incorrect way to create Address child // This may create a type of Address1.xsd Address or maybe Address2.xsd Address DataObject incorrect = boFactory.create("", "Address"); customer1.set("address", incorrect); // Correct way to create Address child // This is guaranteed to create a type of Address1.xsd Address customer1.createDataObject("address");