* </p>
* @param instance
*/
protected Object preParse(InstanceComponent instance) {
// we only preparse text, so simple types
XSDSimpleTypeDefinition type = null;
if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
} else {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance
.getTypeDefinition();
if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
type = (XSDSimpleTypeDefinition) complexType.getContentType();
}
}
String text = instance.getText();
if (type != null) {
//alright, lets preparse some text
//first base on variety
if (type.getVariety() == XSDVariety.LIST_LITERAL) {
//list, whiteSpace is fixed to "COLLAPSE
text = Whitespace.COLLAPSE.preparse(text);
//lists are seperated by spaces
String[] list = text.split(" +");
//apply the facets
// 1. length
// 2. maxLength
// 3. minLength
// 4. enumeration
if (type.getLengthFacet() != null) {
XSDLengthFacet length = type.getLengthFacet();
if (list.length != length.getValue()) {
//validation exception
}
}
if (type.getMaxLengthFacet() != null) {
XSDMaxLengthFacet length = type.getMaxLengthFacet();
if (list.length > length.getValue()) {
//validation exception
}
}
if (type.getMinLengthFacet() != null) {
XSDMinLengthFacet length = type.getMinLengthFacet();
if (list.length < length.getValue()) {
//validation exception
}
}
if (!type.getEnumerationFacets().isEmpty()) {
//gather up all teh possible values
Set values = new HashSet();
for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext();) {
XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
for (Iterator v = enumeration.getValue().iterator(); v.hasNext();) {
values.add(v.next());
}
}
for (int i = 0; i < list.length; i++) {
if (!values.contains(list[i])) {
//validation exception
}
}
}
//now we must parse the items up
final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
List parsed = new ArrayList();
//create a pseudo declaration
final XSDElementDeclaration element = XSDFactory.eINSTANCE
.createXSDElementDeclaration();