Stefano Maestri [
http://community.jboss.org/people/maeste] created the discussion
"Metadata design - xsds"
To view the discussion, visit:
http://community.jboss.org/message/552535#552535
--------------------------------------------------------------
Hi All,
I'm designing our new metadatas layer and I've imported in the projects XSDs form
jboss-metadata-rar.
I've started with jboss-ra_2_0.xsd and I've already done some changes to that one
I'd like to share with you because it would guidelines I'd like to follow in next
future for our own XSDs (i.e. not included in JCA specs):
diff --git a/common/src/main/resources/schema/jboss-ra_2_0.xsd
b/common/src/main/resources/schema/jboss-ra_2_0.xsd
index b8f86cc..3b53927 100644
--- a/common/src/main/resources/schema/jboss-ra_2_0.xsd
+++ b/common/src/main/resources/schema/jboss-ra_2_0.xsd
@@ -5,12 +5,9 @@
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
elementFormDefault="qualified" attributeFormDefault="unqualified"
version="2.0">
-
- <xs:import
namespace="http://java.sun.com/xml/ns/javaee"
schemaLocation="http://java.sun.com/xml/ns/javaee/javaee_5.xsd"...
-
- <xs:element name="jboss-ra"
type="ra:jbossRaType"/>
+ <xs:element name="jboss-ra"
type="ra:jboss-ra-type"/>
- <xs:complexType name="jbossRaType">
+ <xs:complexType name="jboss-ra-type">
<xs:sequence>
<xs:element name="ra-config-property"
type="ra:ra-config-property-type" minOccurs="0"
maxOccurs="unbounded"/>
@@ -26,10 +23,10 @@
<xs:sequence>
<xs:element name="ra-config-property-name"
type="xs:string" minOccurs="1" maxOccurs="1"/>
- <xs:element name="ra-config-property-type"
type="ra:ra-config-property-typeType" minOccurs="1"
maxOccurs="1"/>
+ <xs:element name="ra-config-property-type"
type="ra:ra-config-property-type-type" minOccurs="1"
maxOccurs="1"/>
<xs:element name="ra-config-property-value"
type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
- <xs:attribute name="override-element" type="xs:string"
default="resourceadapter"/>
+ <xs:attribute name="override-element"
type="ra:override-element-type" default="resourceadapter"/>
</xs:complexType>
<xs:complexType name="bean-validation-groups-type">
@@ -45,31 +42,27 @@
</xs:sequence>
</xs:complexType>
- <xs:complexType name="ra-config-property-typeType">
- <xs:simpleContent>
- <xs:restriction base="javaee:string">
- <xs:enumeration value="java.lang.Boolean"/>
- <xs:enumeration value="java.lang.String"/>
- <xs:enumeration value="java.lang.Integer"/>
- <xs:enumeration value="java.lang.Double"/>
- <xs:enumeration value="java.lang.Byte"/>
- <xs:enumeration value="java.lang.Short"/>
- <xs:enumeration value="java.lang.Long"/>
- <xs:enumeration value="java.lang.Float"/>
- <xs:enumeration value="java.lang.Character"/>
- </xs:restriction>
- </xs:simpleContent>
- </xs:complexType>
+ <xs:simpleType name="ra-config-property-type-type">
+ <xs:restriction base="xs:token">
+ <xs:enumeration value="java.lang.Boolean"/>
+ <xs:enumeration value="java.lang.String"/>
+ <xs:enumeration value="java.lang.Integer"/>
+ <xs:enumeration value="java.lang.Double"/>
+ <xs:enumeration value="java.lang.Byte"/>
+ <xs:enumeration value="java.lang.Short"/>
+ <xs:enumeration value="java.lang.Long"/>
+ <xs:enumeration value="java.lang.Float"/>
+ <xs:enumeration value="java.lang.Character"/>
+ </xs:restriction>
+ </xs:simpleType>
- <xs:complexType name="override-elementType">
- <xs:simpleContent>
- <xs:restriction base="javaee:string">
+ <xs:simpleType name="override-element-type">
+ <xs:restriction base="xs:token">
<xs:enumeration value="connection-definition"/>
<xs:enumeration value="resourceadapter"/>
<xs:enumeration value="activationspec"/>
<xs:enumeration value="adminobject"/>
<xs:enumeration value="authentication-mechanism"/>
</xs:restriction>
- </xs:simpleContent>
- </xs:complexType>
+ </xs:simpleType>
</xs:schema>
As you can see above what I've basically done is
1. removing dependency from j2ee schema. It was used just for j2ee:string that is an
xs:token. I think using xs:token keep xsd more readable and easy to understand. Moreover
it is the important to build enumeration type as xs:simpleType and so making possible to
use them also for attribute type
2. Use of simpletype where it is possible for enumeration making possible to use them for
attributes type
3. All element name and type name are lower case
I have elaborated a bit more on this xsd, and I think a great enhancement we can is to
define type for ra-config-property at xsd level instead of define 2 different element to
express value and type. IOW doing this changes to previous xsd
diff --git a/common/src/main/resources/schema/jboss-ra_2_0.xsd
b/common/src/main/resources/schema/jboss-ra_2_0.xsd
index 08c5e17..58572d9 100644
--- a/common/src/main/resources/schema/jboss-ra_2_0.xsd
+++ b/common/src/main/resources/schema/jboss-ra_2_0.xsd
@@ -23,8 +23,17 @@
<xs:sequence>
<xs:element name="ra-config-property-name"
type="xs:token" minOccurs="1" maxOccurs="1"/>
- <xs:element name="ra-config-property-type"
type="ra:ra-config-property-type-type" minOccurs="1"
maxOccurs="1"/>
- <xs:element name="ra-config-property-value"
type="xs:token" minOccurs="0" maxOccurs="1"/>
+ <xs:choice>
+ <xs:element name="ra-config-property-booelan"
type="xs:boolean" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-string"
type="xs:string" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-integer"
type="xs:integer" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-double"
type="xs:double" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-byte"
type="xs:byte" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-short"
type="xs:short" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-long"
type="xs:long" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-float"
type="xs:float" minOccurs="0" maxOccurs="1"/>
+ <xs:element name="ra-config-property-char"
type="ra:char" minOccurs="0" maxOccurs="1"/>
+ </xs:choice>
</xs:sequence>
<xs:attribute name="override-element"
type="ra:override-element-type" default="resourceadapter"/>
</xs:complexType>
@@ -42,20 +51,13 @@
</xs:sequence>
</xs:complexType>
- <xs:simpleType name="ra-config-property-type-type">
- <xs:restriction base="xs:token">
- <xs:enumeration value="java.lang.Boolean"/>
- <xs:enumeration value="java.lang.String"/>
- <xs:enumeration value="java.lang.Integer"/>
- <xs:enumeration value="java.lang.Double"/>
- <xs:enumeration value="java.lang.Byte"/>
- <xs:enumeration value="java.lang.Short"/>
- <xs:enumeration value="java.lang.Long"/>
- <xs:enumeration value="java.lang.Float"/>
- <xs:enumeration value="java.lang.Character"/>
- </xs:restriction>
- </xs:simpleType>
-
+ <xsi:simpleType name="char">
+ <xsi:restriction base="xsi:string">
+ <xsi:maxLength value="1"/>
+ <xsi:minLength value="1"/>
+ </xsi:restriction>
+ </xsi:simpleType>
+
<xs:simpleType name="override-element-type">
<xs:restriction base="xs:token">
<xs:enumeration value="connection-definition"/>
As you can see the xsd is a bit more verbose, and parsing it will be too. But IMHO it
drives to more readable config files and give us the opportunity to effective validate xml
and values before èarsing if we decide to.
Look forward for your feedback
S
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/552535#552535]
Start a new discussion in JCA Development at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]