SchemaBindingResolver HACK!
adrian.brock Dec 13, 2005 2:55 PMSince my work on the work for XSD annotations based parsing is taking longer than
I originally anticipated.
I want to discuss a "HACK" that will look like the xsd annotations are working
when in fact it is still using hardwired classes.
This is sort of already present in the current processing to bootstrap
the jbxb/jaxb model:
public static final XsdAnnotation unmarshal(String annotation) { Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); unmarshaller.mapFactoryToNamespace(JaxbObjectModelFactory.INSTANCE, Constants.NS_JAXB); unmarshaller.mapFactoryToNamespace(JbxbObjectModelFactory.INSTANCE, Constants.NS_JBXB);
Basically what you would be able to do is say that your schema
uses a predefined factory in one annotation:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:jboss:bean-deployer" xmlns="urn:jboss:bean-deployer" xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" > <xsd:annotation> <xsd:documentation> <![CDATA[ The xml deployer schema. The deployment document instance root element should reference the schema in the root deployment element using something like: <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd" xmlns="urn:jboss:bean-deployer"> ... ]]> </xsd:documentation> <xsd:appinfo> <jbxb:schemaBindings factory="org.jboss.kernel.plugins.deployment.xml.BeanSchemaBinding"> </jbxb:schemaBindings> </xsd:appinfo> </xsd:annotation>
This avoids everybody have to do their own schema binding resolvers
across the entire codebase or trying to keep these registrations in sync.
e.g. Bill's AOP prototype version
public static SchemaBinding getSchemaBinding(SchemaFactory factory) { if (schemaBinding == null) { schemaBinding = readXsd(); schemaBinding.setSchemaResolver(new SchemaBindingResolver() { public String getBaseURI() { throw new UnsupportedOperationException("getBaseURI is not implemented."); } public void setBaseURI(String baseURI) { throw new UnsupportedOperationException("setBaseURI is not implemented."); } public SchemaBinding resolve(String nsUri, String baseURI, String schemaLocation) { if (schemaLocation == null) return null; if (schemaLocation.endsWith("bean-deployer_1_0.xsd")) return BeanSchemaBinding.getSchemaBinding(); return null; } public LSInput resolveAsLSInput(String nsUri, String baseUri, String schemaLocation) { throw new UnsupportedOperationException("resolveResource is not implemented."); } } );
For example, I want to split up the bean xsd to separate deployment from bean
which will obviously break Bill's code.