Exemplo n.º 1
0
  protected static Mapping getMapping(MessageContext context, String mappingProperty) {
    long startTime = System.currentTimeMillis();

    // determine the mapping location, starting with a default based on the property
    String mappingLocation =
        mappingProperty.equals(CASTOR_MARSHALLER_PROPERTY)
            ? DEFAULT_MARSHALLER_MAPPING
            : DEFAULT_UNMARSHALLER_MAPPING;
    if (context != null) {
      String prop = (String) context.getProperty(mappingProperty);
      if (prop != null && !prop.trim().equals("")) {
        // the property exists in the message context, use the property value
        mappingLocation = prop;
        LOG.debug("Loading castor mapping from message context property[" + mappingProperty + "]");
      } else {
        try {
          // attempt to find the property in the wsdd global configuration
          prop =
              (String) context.getAxisEngine().getConfig().getGlobalOptions().get(mappingProperty);
        } catch (Exception e) {
          LOG.warn("Error reading global configuration:" + e.getMessage(), e);
        }
        if (prop != null && !prop.trim().equals("")) {
          mappingLocation = prop;
          LOG.debug(
              "Loading castor mapping from globalConfiguration property[" + mappingProperty + "]");
        } else {
          // walk through the WSDD config and find the property in service config options
          EngineConfiguration config = context.getAxisEngine().getConfig();
          if (config instanceof WSDDEngineConfiguration) {
            WSDDDeployment wsdd = ((WSDDEngineConfiguration) config).getDeployment();
            WSDDService[] services = wsdd.getServices();
            for (WSDDService service : services) {
              prop = service.getParameter(mappingProperty);
              if (prop != null && !prop.trim().equals("")) {
                // found it!
                mappingLocation = prop;
                LOG.debug(
                    "Loading castor mapping from service "
                        + service.getQName()
                        + " property ["
                        + prop
                        + "]");
                break;
              }
            }
          }
          if (!(prop != null && !prop.trim().equals(""))) {
            LOG.warn(
                "Unable to locate castor mapping property["
                    + mappingProperty
                    + "], using default mapping location:"
                    + mappingLocation);
          }
        }
      }
    } else {
      LOG.debug(
          "Unable to determine message context, using default mapping location:" + mappingLocation);
    }

    // locate the bytes of the mapping file
    String mappingDocument = null;
    try {
      mappingDocument = loadResource(mappingLocation);
    } catch (IOException ex) {
      LOG.error("Error loading mapping file [" + mappingLocation + "] : " + ex.getMessage(), ex);
    }

    Mapping mapping = loadMappingFromString(mappingLocation, mappingDocument, getDtdResolver());

    long duration = System.currentTimeMillis() - startTime;
    LOG.debug("Time to load mapping file:" + duration + " ms.");

    return mapping;
  }