Esempio n. 1
0
  private boolean validatePartType(String namespace, String name, boolean isElement) {

    boolean partvalid = false;

    if (namespace.equals(WSDLConstants.NS_SCHEMA_XSD)) {
      if (isElement) {
        XmlSchemaElement schemaEle =
            schemaCollection.getElementByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));
        partvalid = schemaEle != null ? true : false;
      } else {
        if ("anyType".equals(name)) {
          return true;
        }
        XmlSchemaType schemaType =
            schemaCollection.getTypeByQName(new QName(WSDLConstants.NS_SCHEMA_XSD, name));

        partvalid = schemaType != null ? true : false;
      }

    } else {
      if (isElement) {
        if (schemaCollection.getElementByQName(new QName(namespace, name)) != null) {
          partvalid = true;
        }
      } else {
        if (schemaCollection.getTypeByQName(new QName(namespace, name)) != null) {
          partvalid = true;
        }
      }
    }
    return partvalid;
  }
Esempio n. 2
0
  public void initialize(Service service) {
    if (LOG.isLoggable(Level.FINER)) {
      LOG.log(Level.FINER, "Creating XmlBeansDatabinding for " + service.getName());
    }
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
      SchemaCollection col = serviceInfo.getXmlSchemaCollection();

      if (col.getXmlSchemas().length > 1) {
        // someone has already filled in the types
        continue;
      }

      XmlBeansSchemaInitializer schemaInit = new XmlBeansSchemaInitializer(serviceInfo, col, this);
      schemaInit.walk();
    }
  }
  private void buildMessage(
      MessageInfo minfo,
      javax.wsdl.Message msg,
      SchemaCollection schemas,
      int nextId,
      String partNameFilter) {
    for (Part part : cast(msg.getParts().values(), Part.class)) {

      if (StringUtils.isEmpty(partNameFilter) || part.getName().equals(partNameFilter)) {

        if (StringUtils.isEmpty(part.getName())) {
          throw new RuntimeException(
              "Problem with WSDL: part element in message "
                  + msg.getQName().getLocalPart()
                  + " does not specify a name.");
        }
        QName pqname = new QName(minfo.getName().getNamespaceURI(), part.getName());
        MessagePartInfo pi = minfo.getMessagePart(pqname);
        if (pi != null && pi.getMessageInfo().getName().equals(msg.getQName())) {
          continue;
        }
        pi = minfo.addOutOfBandMessagePart(pqname);

        if (!minfo.getName().equals(msg.getQName())) {
          pi.setMessageContainer(new MessageInfo(minfo.getOperation(), null, msg.getQName()));
        }

        if (part.getTypeName() != null) {
          pi.setTypeQName(part.getTypeName());
          pi.setElement(false);
          pi.setXmlSchema(schemas.getTypeByQName(part.getTypeName()));
        } else {
          pi.setElementQName(part.getElementName());
          pi.setElement(true);
          pi.setXmlSchema(schemas.getElementByQName(part.getElementName()));
        }
        pi.setProperty(OUT_OF_BAND_HEADER, Boolean.TRUE);
        pi.setProperty(HEADER, Boolean.TRUE);
        pi.setIndex(nextId);
        nextId++;
      }
    }
  }
Esempio n. 4
0
 /**
  * This copes with an observed phenomenon in the schema built by the ReflectionServiceFactoryBean.
  * It is creating element such that: (a) the type is not set. (b) the refName is set. (c) the
  * namespaceURI in the refName is set empty. This apparently indicates 'same Schema' to everyone
  * else, so thus function implements that convention here. It is unclear if that is a correct
  * structure, and it if changes, we can simplify or eliminate this function.
  *
  * @param name
  * @param referencingURI
  */
 public static XmlSchemaElement findElementByRefName(
     SchemaCollection xmlSchemaCollection, QName name, String referencingURI) {
   String uri = name.getNamespaceURI();
   if ("".equals(uri)) {
     uri = referencingURI;
   }
   QName copyName = new QName(uri, name.getLocalPart());
   XmlSchemaElement target = xmlSchemaCollection.getElementByQName(copyName);
   assert target != null;
   return target;
 }
Esempio n. 5
0
 public static List<XmlSchemaAnnotated> getContentAttributes(
     XmlSchemaComplexType type, SchemaCollection collection) {
   List<XmlSchemaAnnotated> results = new ArrayList<XmlSchemaAnnotated>();
   QName baseTypeName = getBaseType(type);
   if (baseTypeName != null) {
     XmlSchemaComplexType baseType =
         (XmlSchemaComplexType) collection.getTypeByQName(baseTypeName);
     // recurse onto the base type ...
     results.addAll(getContentAttributes(baseType, collection));
     // and now process our sequence.
     List<XmlSchemaAttributeOrGroupRef> extAttrs = getContentAttributes(type);
     results.addAll(extAttrs);
     return results;
   } else {
     // no base type, the simple case.
     List<XmlSchemaAttributeOrGroupRef> attrs = type.getAttributes();
     results.addAll(attrs);
     return results;
   }
 }
Esempio n. 6
0
  @SuppressWarnings("unchecked")
  public synchronized void initialize(Service service) {

    inInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
    inFaultInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);

    // context is already set, don't redo it
    if (context != null) {
      return;
    }

    contextClasses = new LinkedHashSet<Class<?>>();
    Map<String, Object> unmarshallerProps = new HashMap<String, Object>();
    this.setUnmarshallerProperties(unmarshallerProps);
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {

      JAXBContextInitializer initializer =
          new JAXBContextInitializer(
              serviceInfo, contextClasses, typeRefs, this.getUnmarshallerProperties());
      initializer.walk();
      if (serviceInfo.getProperty("extra.class") != null) {
        Set<Class<?>> exClasses = serviceInfo.getProperty("extra.class", Set.class);
        contextClasses.addAll(exClasses);
      }
    }

    String tns = getNamespaceToUse(service);
    CachedContextAndSchemas cachedContextAndSchemas = null;
    JAXBContext ctx = null;
    try {
      cachedContextAndSchemas = createJAXBContextAndSchemas(contextClasses, tns);
    } catch (JAXBException e1) {
      throw new ServiceConstructionException(e1);
    }
    ctx = cachedContextAndSchemas.getContext();
    if (LOG.isLoggable(Level.FINE)) {
      LOG.log(Level.FINE, "CREATED_JAXB_CONTEXT", new Object[] {ctx, contextClasses});
    }
    setContext(ctx);

    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
      SchemaCollection col = serviceInfo.getXmlSchemaCollection();

      if (col.getXmlSchemas().length > 1) {
        // someone has already filled in the types
        justCheckForJAXBAnnotations(serviceInfo);
        continue;
      }

      boolean schemasFromCache = false;
      Collection<DOMSource> schemas = getSchemas();
      if (schemas == null || schemas.size() == 0) {
        schemas = cachedContextAndSchemas.getSchemas();
        if (schemas != null) {
          schemasFromCache = true;
        }
      } else {
        schemasFromCache = true;
      }
      Set<DOMSource> bi = new LinkedHashSet<DOMSource>();
      if (schemas == null) {
        schemas = new LinkedHashSet<DOMSource>();
        try {
          for (DOMResult r : generateJaxbSchemas()) {
            DOMSource src = new DOMSource(r.getNode(), r.getSystemId());
            if (BUILT_IN_SCHEMAS.containsValue(r)) {
              bi.add(src);
            } else {
              schemas.add(src);
            }
          }
          // put any builtins at the end.   Anything that DOES import them
          // will cause it to load automatically and we'll skip them later
          schemas.addAll(bi);
        } catch (IOException e) {
          throw new ServiceConstructionException("SCHEMA_GEN_EXC", LOG, e);
        }
      }
      Set<String> ids = new HashSet<String>();
      for (DOMSource r : schemas) {
        ids.add(r.getSystemId());
      }
      for (DOMSource r : schemas) {
        if (bi.contains(r)) {
          String ns = ((Document) r.getNode()).getDocumentElement().getAttribute("targetNamespace");
          if (serviceInfo.getSchema(ns) != null) {
            continue;
          }
        }
        // StaxUtils.print(r.getNode());
        // System.out.println();
        addSchemaDocument(serviceInfo, col, (Document) r.getNode(), r.getSystemId());
      }

      JAXBSchemaInitializer schemaInit =
          new JAXBSchemaInitializer(serviceInfo, col, context, this.qualifiedSchemas, tns);
      schemaInit.walk();
      if (cachedContextAndSchemas != null && !schemasFromCache) {
        cachedContextAndSchemas.setSchemas(schemas);
      }
    }
  }