Esempio n. 1
0
 protected static Mapping loadMappingFromString(
     String mappingLocation, String mappingContents, EntityResolver resolver) {
   InputSource mappIS = new org.xml.sax.InputSource(new StringReader(mappingContents));
   Mapping mapping = new Mapping();
   mapping.setEntityResolver(resolver);
   try {
     mapping.loadMapping(mappIS);
   } catch (Exception ex) {
     LOG.error("Error loading castor mapping (" + mappingLocation + "): " + ex.getMessage(), ex);
   }
   return mapping;
 }
 /** @return default mapping file being used for xml serialziation/deserialization */
 public Mapping getMapping() throws XMLUtilityException {
   /* if no mapping file explicity specified then load the default */
   log.debug("mapping is null? " + (mapping == null));
   if (mapping == null) {
     log.info("mapping is null; will try to load it");
     try {
       EntityResolver resolver =
           new EntityResolver() {
             public InputSource resolveEntity(String publicId, String systemId) {
               if (publicId.equals("-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN")) {
                 InputStream in =
                     Thread.currentThread()
                         .getContextClassLoader()
                         .getResourceAsStream("mapping.dtd");
                 return new InputSource(in);
               }
               return null;
             }
           };
       org.xml.sax.InputSource mappIS =
           new org.xml.sax.InputSource(
               Thread.currentThread()
                   .getContextClassLoader()
                   .getResourceAsStream(loadProperty(this.PROPERTIES_MAPPING_KEY)));
       Mapping localMapping = new Mapping();
       localMapping.setEntityResolver(resolver);
       localMapping.loadMapping(mappIS);
       return localMapping;
     } catch (IOException e) {
       log.error(
           "Error reading default xml mapping file ",
           e); // To change body of catch statement use File | Settings | File Templates.
       throw new XMLUtilityException("Error reading default xml mapping file ", e);
     }
   }
   return mapping;
 }