Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B9AE868AA for ; Fri, 24 Jun 2011 08:48:52 +0000 (UTC) Received: (qmail 12627 invoked by uid 500); 24 Jun 2011 08:48:51 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 12035 invoked by uid 500); 24 Jun 2011 08:48:32 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 11851 invoked by uid 99); 24 Jun 2011 08:47:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jun 2011 08:47:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jun 2011 08:47:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 028EF2388A1C; Fri, 24 Jun 2011 08:46:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1139205 - /geronimo/server/trunk/plugins/bval/geronimo-bval-builder/src/main/java/org/apache/geronimo/bval/deployment/BValModuleBuilderExtension.java Date: Fri, 24 Jun 2011 08:46:52 -0000 To: scm@geronimo.apache.org From: xuhaihong@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110624084653.028EF2388A1C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: xuhaihong Date: Fri Jun 24 08:46:52 2011 New Revision: 1139205 URL: http://svn.apache.org/viewvc?rev=1139205&view=rev Log: Reuse the schema and jaxbcontext instance Modified: geronimo/server/trunk/plugins/bval/geronimo-bval-builder/src/main/java/org/apache/geronimo/bval/deployment/BValModuleBuilderExtension.java Modified: geronimo/server/trunk/plugins/bval/geronimo-bval-builder/src/main/java/org/apache/geronimo/bval/deployment/BValModuleBuilderExtension.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/bval/geronimo-bval-builder/src/main/java/org/apache/geronimo/bval/deployment/BValModuleBuilderExtension.java?rev=1139205&r1=1139204&r2=1139205&view=diff ============================================================================== --- geronimo/server/trunk/plugins/bval/geronimo-bval-builder/src/main/java/org/apache/geronimo/bval/deployment/BValModuleBuilderExtension.java (original) +++ geronimo/server/trunk/plugins/bval/geronimo-bval-builder/src/main/java/org/apache/geronimo/bval/deployment/BValModuleBuilderExtension.java Fri Jun 24 08:46:52 2011 @@ -60,13 +60,46 @@ import org.xml.sax.SAXException; /** * Validation Module Builder extension to support customization of ValidatorFactory using validation.xml descriptors. - * + * * @version $Rev$ $Date$ */ @GBean(j2eeType = NameFactory.MODULE_BUILDER) public class BValModuleBuilderExtension implements ModuleBuilderExtension { private static final Logger log = LoggerFactory.getLogger(BValModuleBuilderExtension.class); - + + private static final Schema VALIDATION_CONFIGURATION_SCHMEA; + + private static final Schema VALIDATION_MAPPING_SCHMEA; + + private static final JAXBContext VALIDATION_CONFIGURATION_JAXBCONTEXT; + + private static final JAXBContext CONSTRAINTMAPPINGSTYPE_JAXBCONTEXT; + + static { + try { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + URL schemaUrl = ValidationParser.class.getClassLoader().getResource("META-INF/validation-configuration-1.0.xsd"); + VALIDATION_CONFIGURATION_SCHMEA = sf.newSchema(schemaUrl); + URL mappingSchemaUrl = ValidationMappingParser.class.getClassLoader().getResource("META-INF/validation-mapping-1.0.xsd"); + VALIDATION_MAPPING_SCHMEA = sf.newSchema(mappingSchemaUrl); + } catch (SAXException e) { + log.error("Unable to initialize validation schema", e); + throw new RuntimeException("Unable to initialize validation schema", e); + } + try { + VALIDATION_CONFIGURATION_JAXBCONTEXT = JAXBContext.newInstance(ValidationConfigType.class); + } catch (JAXBException e) { + log.error("Unable to initialize validation configuration JAXBContext", e); + throw new RuntimeException("Unable to initialize validation configuration JAXBContext", e); + } + try { + CONSTRAINTMAPPINGSTYPE_JAXBCONTEXT = JAXBContext.newInstance(ConstraintMappingsType.class); + } catch (JAXBException e) { + log.error("Unable to initialize constraint mapping JAXBContext", e); + throw new RuntimeException("Unable to initialize constraint mapping JAXBContext", e); + } + } + // our default environment protected Environment defaultEnvironment; @@ -92,16 +125,16 @@ public class BValModuleBuilderExtension if (module.getDeployable() instanceof DeployableBundle) { return; } - + String moduleName = null; - String validationConfig = null; - // the location of the validation config varies depending + String validationConfig = null; + // the location of the validation config varies depending // on the module type if (module.getType() == ConfigurationModuleType.WAR) { - validationConfig = "WEB-INF/validation.xml"; + validationConfig = "WEB-INF/validation.xml"; } else if (module.getType() == ConfigurationModuleType.EAR|| module.getType() == ConfigurationModuleType.EJB || module.getType() == ConfigurationModuleType.CAR || module.getType() == ConfigurationModuleType.RAR) { - validationConfig = "META-INF/validation.xml"; + validationConfig = "META-INF/validation.xml"; } if(validationConfig != null) { @@ -116,39 +149,33 @@ public class BValModuleBuilderExtension // No validation.xml file validationConfig = null; } else { - // Parse the validation xml and log debug messages if there are any errors - URL schemaUrl = ValidationParser.class.getClassLoader().getResource("META-INF/validation-configuration-1.0.xsd"); - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); InputStream inp = null; try { - Schema schema = sf.newSchema(schemaUrl); - JAXBContext jc = JAXBContext.newInstance(ValidationConfigType.class); - Unmarshaller unmarshaller = jc.createUnmarshaller(); - unmarshaller.setSchema(schema); + Unmarshaller unmarshaller = VALIDATION_CONFIGURATION_JAXBCONTEXT.createUnmarshaller(); + unmarshaller.setSchema(VALIDATION_CONFIGURATION_SCHMEA); inp = validationConfigEntry.openStream(); StreamSource stream = new StreamSource(inp); JAXBElement root = unmarshaller.unmarshal(stream, ValidationConfigType.class); ValidationConfigType xmlConfig = root.getValue(); if(xmlConfig.getConstraintMapping().size() > 0) { - URL mappingSchemaUrl = ValidationMappingParser.class.getClassLoader().getResource("META-INF/validation-mapping-1.0.xsd"); - Schema mappingSchema = sf.newSchema(mappingSchemaUrl); for (JAXBElement mappingFileNameElement : xmlConfig.getConstraintMapping()) { String mappingFileName = mappingFileNameElement.getValue(); if(bundle.getEntry(mappingFileName) == null) { - log.debug("Non-existent constraint mapping file "+mappingFileName+" specified in "+validationConfig+" in module "+module.getName()); + if (log.isDebugEnabled()) { + log.debug("Non-existent constraint mapping file " + mappingFileName + " specified in " + validationConfig + " in module " + module.getName()); + } } else { // Parse the constraint mappings file and log debug messages if there are any errors InputStream inp1 = null; - try { - jc = JAXBContext.newInstance(ConstraintMappingsType.class); + try { if(module.isStandAlone()) { inp1 = bundle.getEntry(mappingFileName).openStream(); } else { inp1 = module.getDeployable().getResource(mappingFileName).openStream(); } stream = new StreamSource(inp1); - unmarshaller = jc.createUnmarshaller(); - unmarshaller.setSchema(mappingSchema); + unmarshaller = CONSTRAINTMAPPINGSTYPE_JAXBCONTEXT.createUnmarshaller(); + unmarshaller.setSchema(VALIDATION_MAPPING_SCHMEA); JAXBElement mappingRoot = unmarshaller.unmarshal(stream, ConstraintMappingsType.class); ConstraintMappingsType constraintMappings = mappingRoot.getValue(); } catch (JAXBException e) { @@ -161,12 +188,10 @@ public class BValModuleBuilderExtension } } } - } catch (SAXException e) { - log.debug("Error processing validation configuration "+validationConfig+" in module "+module.getName(), e); } catch (JAXBException e) { - log.debug("Error processing validation configuration "+validationConfig+" in module "+module.getName(), e); + log.debug("Error processing validation configuration " + validationConfig + " in module " + module.getName(), e); } catch (IOException e) { - log.debug("Error processing validation configuration "+validationConfig+" in module "+module.getName(), e); + log.debug("Error processing validation configuration " + validationConfig + " in module " + module.getName(), e); } finally { IOUtils.close(inp); }