You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Kuketayev, Argyn (Contractor)" <ar...@fanniemae.com> on 2005/09/23 18:24:44 UTC

ClassCastException when calling one of the getters of the Type class, substitutionGroup element

The problem is with susbstitutionGroup element.

I have this in my xsd:
===
	<xs:element name="Condition" type="xacml:ConditionType"/>
	<xs:complexType name="ConditionType">
		<xs:sequence>
			<xs:element ref="xacml:Expression"/>
		</xs:sequence>
	</xs:complexType>
	<!-- -->
	<xs:element name="Apply" type="xacml:ApplyType"
substitutionGroup="xacml:Expression"/>
	<xs:complexType name="ApplyType">
		<xs:complexContent>
			<xs:extension base="xacml:ExpressionType">
				<xs:sequence>
					<xs:element
ref="xacml:Expression" minOccurs="0" maxOccurs="unbounded"/>
				</xs:sequence>
				<xs:attribute name="FunctionId"
type="xs:anyURI" use="required"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
===

In my Java code, I get an instance of ConditionType element by parsing
the document. Then I try to retrieve an Expression element, which is in
my particular case is Apply element in the xml, and get a
ClassCastException.

Here's Java code:
===
ConditionType xbct = .... //Get an instance
ExpressionType xbxt = xbct.getExpression(); // here's an exception
thrown
===

Exception:
java.lang.ClassCastException:
org.apache.xmlbeans.impl.values.XmlAnyTypeImpl

Here's XML fragment:
===
        <Condition>
            <Apply FunctionId="bla-bla">

			<!-- some content here -->
        </Apply>
    </Condition>
===

What am I doing wrong?

Thanks
argyn

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: ClassCastException when calling one of the getters of the Type class, substitutionGroup element

Posted by Robin Sander <ro...@gmx.net>.
Hi,

what type does "xacml:Expression" have? If it has e.g. "TypeB"
you would receive TypeB when calling xbct.getExpression(),
because this is how you defined ConditionType.
Maybe you can then use changeType() to change between those
different types? I don't know ...
The problem with substitution-groups is, that you have to
independent hierarchies: one for the types and one for the
elements and you can't really map this to Java.
To be able to work with substitution-groups the type-hierarchy
should mirror the element-hierarchy, in your case
ApplyType should extend the type of the "xacml:Expression"
element.

cheers,

Robin.


Kuketayev, Argyn (Contractor) wrote:
> The problem is with susbstitutionGroup element.
> 
> I have this in my xsd:
> ===
> 	<xs:element name="Condition" type="xacml:ConditionType"/>
> 	<xs:complexType name="ConditionType">
> 		<xs:sequence>
> 			<xs:element ref="xacml:Expression"/>
> 		</xs:sequence>
> 	</xs:complexType>
> 	<!-- -->
> 	<xs:element name="Apply" type="xacml:ApplyType"
> substitutionGroup="xacml:Expression"/>
> 	<xs:complexType name="ApplyType">
> 		<xs:complexContent>
> 			<xs:extension base="xacml:ExpressionType">
> 				<xs:sequence>
> 					<xs:element
> ref="xacml:Expression" minOccurs="0" maxOccurs="unbounded"/>
> 				</xs:sequence>
> 				<xs:attribute name="FunctionId"
> type="xs:anyURI" use="required"/>
> 			</xs:extension>
> 		</xs:complexContent>
> 	</xs:complexType>
> ===
> 
> In my Java code, I get an instance of ConditionType element by parsing
> the document. Then I try to retrieve an Expression element, which is in
> my particular case is Apply element in the xml, and get a
> ClassCastException.
> 
> Here's Java code:
> ===
> ConditionType xbct = .... //Get an instance
> ExpressionType xbxt = xbct.getExpression(); // here's an exception
> thrown
> ===
> 
> Exception:
> java.lang.ClassCastException:
> org.apache.xmlbeans.impl.values.XmlAnyTypeImpl
> 
> Here's XML fragment:
> ===
>         <Condition>
>             <Apply FunctionId="bla-bla">
> 
> 			<!-- some content here -->
>         </Apply>
>     </Condition>
> ===
> 
> What am I doing wrong?
> 
> Thanks
> argyn
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org