비즈니스 오브젝트 요소 및 속성에 고유한 이름을 지정해야 합니다.
서비스 데이터 오브젝트(SDO) 프레임워크에서 요소 및 속성은 특성으로 작성됩니다. 다음 코드 예제에서는 XSD가 foo로 이름 지정된 하나의 특성이 있는 유형을 작성합니다.
<xsd:complexType name="ElementFoo"> <xsd:sequence> <xsd:element name="foo" type="xsd:string" default="elem_value"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="AttributeFoo"> <xsd:attribute name="foo" type="xsd:string" default="attr_value"/> </xsd:complexType>
이런 경우 XML 경로 언어(XPath)를 사용하여 특성에 액세스할 수 있습니다. 그러나 다음 예제에서와 같이 유효한 스키마 유형에 동일한 이름을 가진 속성 및 요소가 있을 수 있습니다.
<xsd:complexType name="DuplicateNames"> <xsd:sequence> <xsd:element name="foo" type="xsd:string" default="elem_value"/> </xsd:sequence> <xsd:attribute name="foo" type="xsd:string" default="attr_value"/> </xsd:complexType>
XPath에서 동일한 이름이 지정된 요소를 속성과 구별할 수 있어야 합니다. 이름 중 하나를 앳 부호(@)로 시작하여 이를 구별합니다. 다음 스니펫은 동일하게 이름이 지정된 요소 및 속성에 액세스하는 방법을 보여 줍니다.
1 DataObject duplicateNames = ... 2 // Displays "elem_value" 3 System.out.println(duplicateNames.get("foo")); 4 // Displays "attr_value" 5 System.out.println(duplicateNames.get("@foo"));
SDO XPath인 문자열 값을 취하는 모든 메소드에 이 네이밍 설계를 사용하십시오.