I have the following XML code:
<stereotypes>
<stereotype1/>
<stereotype2/>
</stereotypes>
The problem is that I need a general attribute for each stereotype that has a different value for each stereotype type.
Actualy I'm not sure this is even posible or if I can implement such a thing.
I tried this using the following schema fragments (setting the path attribute). What I would like is to give this attribute a fixed value for each stereotype type. The goal would be to have the getPath generated on the AbstractStereotype class and to use it in a generic way. The problem is that I can't seem to find a way of defining the attribute value in the specific Stereotypes.
<xs:element name="stereotypes" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="stereotype1" type="Stereotype1" />
<xs:element name="stereotype2" type="Stereotype2"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="AbstractStereotype" abstract="true">
<xs:attribute name="path" type="amf-base:FQN" use="required"></xs:attribute>
</xs:complexType>
<xs:complexType name="Stereotype1">
<xs:complexContent>
<xs:extension base="AbstractStereotype">
<!-- <xs:attribute name="path" type="amf-base:FQN" fixed="my.path.to.Class1"/> -->
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Stereotype2">
<xs:complexContent>
<xs:extension base="AbstractStereotype">
<!-- <xs:attribute name="path" type="amf-base:FQN" fixed="my.path.to.Class2"/> -->
</xs:extension>
</xs:complexContent>
</xs:complexType>
Any other sugestion that would let me to "have a getPath method generated on the AbstractStereotype class and to use it in a generic way" would be much appreciated.
EDIT: Maybe to be more clear of the outcome I need.
public abstract class AbstractStereotype {
public String getPath();
}
public class Stereotype1 extends AbstractStereotype {
public String getPath() {
return "Path1";
}
}
public class Stereotype2 extends AbstractStereotype {
public String getPath() {
return "Path2";
}
}
I need this because I want to treat these Stereotypes the same way:
public void someMethod() {
for(AbstractStereotype stereotype: getStereotypes()) {
System.out.println(stereotype.getPath());
}
}
As I said before not even sure this is possible using this approach.