[Design of POJO Server] - Re: JAXB Deployer
by alesj
"anil.saldhana(a)jboss.com" wrote : Since you do unmarshalling in the parse method of
| http://anonsvn.jboss.org/repos/jbossas/projects/jboss-deployers/tags/2.0....
|
| a schema validation may be added.
|
Like this?
| protected T parse(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
| {
| if (file == null)
| throw new IllegalArgumentException("Null file");
|
| log.debug("Parsing: " + file.getName());
|
| InputSource source = new VFSInputSource(file);
| Unmarshaller unmarshaller = context.createUnmarshaller();
| if (schemaLocation != null)
| {
| unmarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
| ClassLoader tcl = SecurityActions.getContextClassLoader();
| URL schemaURL = tcl.getResource(schemaLocation);
| if(schemaURL == null)
| throw new IllegalStateException("Schema URL is null:" + schemaLocation);
|
| SchemaFactory scFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
| Schema schema = scFact.newSchema(schemaURL);
| unmarshaller.setSchema(schema);
| }
| Object result = unmarshaller.unmarshal(source);
| return getOutput().cast(result);
| }
|
"anil.saldhana(a)jboss.com" wrote :
| I do not understand the meaning of openStreamAndValidate call being made in the parse into
| http://anonsvn.jboss.org/repos/jbossas/projects/jboss-deployers/tags/2.0....
|
| You are opening a stream. There is no validation. :)
This is now replaced with VFSInputSource.
Validation in this case was meant for "inputStream != null". ;-)
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4219268#4219268
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4219268
17 years
[Design of POJO Server] - Re: JAXB Deployer
by anil.saldhana@jboss.com
"alesj" wrote : How would you do this?
Sorry my fault. That is only when you get the marshaller/unmarshaller of JAXB.
| /**
| * Get the JAXB Marshaller
| * @param pkgName The package name for the jaxb context
| * @param schemaLocation location of the schema to validate against
| * @return Marshaller
| * @throws Exception
| */
| public static Marshaller getValidatingMarshaller(String pkgName, String schemaLocation)
| throws Exception
| {
| Marshaller marshaller = getMarshaller(pkgName);
| marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
| //Validate against schema
| ClassLoader tcl = SecurityActions.getContextClassLoader();
| URL schemaURL = tcl.getResource(schemaLocation);
| if(schemaURL == null)
| throw new IllegalStateException("Schema URL is null:" + schemaLocation);
| SchemaFactory scFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
| Schema schema = scFact.newSchema(schemaURL);
| marshaller.setSchema(schema);
|
| return marshaller;
| }
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4219248#4219248
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4219248
17 years