Пример #1
0
 private static void parse(XMLStreamReader reader, URL wsdlUrl, Set<String> excludedPorts)
     throws XMLStreamException, WiseRuntimeException {
   int iterate;
   try {
     iterate = reader.nextTag();
   } catch (XMLStreamException e) {
     // skip non-tag elements
     iterate = reader.nextTag();
   }
   switch (iterate) {
     case END_ELEMENT:
       {
         // we're done
         break;
       }
     case START_ELEMENT:
       {
         if (match(reader, WSDL_NS, DEFINITIONS)) {
           String targetNS = reader.getAttributeValue(null, TARGET_NAMESPACE);
           parseDefinitions(reader, targetNS, wsdlUrl, excludedPorts);
         } else {
           throw new WiseRuntimeException(
               "Unexpected element '"
                   + reader.getLocalName()
                   + "' found parsing "
                   + wsdlUrl.toExternalForm());
         }
       }
   }
 }
  private void parseWebFragmentXml() throws XMLStreamException, IOException, TransformerException {
    final XMLInputFactory xif = XMLInputFactory.newInstance();
    final XMLStreamReader xsr = xif.createXMLStreamReader(getInputStream());
    xsr.nextTag(); // web-fragment tag skipped

    while (xsr.hasNext() && xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
      final String tagName = xsr.getLocalName();
      // webFragmentName
      if ("name".equalsIgnoreCase(tagName)) {
        final String element = xsr.getElementText();
        allWebFragmentNames.add(element);
        webFragmentXmlComponents.add("<name>" + element + "</name>");
      } else {
        final TransformerFactory tf = TransformerFactory.newInstance();
        final Transformer t = tf.newTransformer();
        final StringWriter res = new StringWriter();
        t.transform(new StAXSource(xsr), new StreamResult(res));
        final String element =
            org.apache.commons.lang3.StringUtils.substringAfter(res.toString(), "?>");
        if ("ordering".equalsIgnoreCase(tagName)) {
          // ordering
          parseOrdering(element);
        } else {
          // webFragmentXmlComponents
          webFragmentXmlComponents.add(element);
        }
      }
    }
    if (allWebFragmentNames.isEmpty()) {
      throw new IllegalStateException(
          "Name tag is missing. Please specify a name in the web-fragment.xml!");
    }
  }
  /** Deserializes the object from XML */
  public DataReported parseReported(XMLStreamReader in) throws IOException, XMLStreamException {
    DataReported reported = new DataReported();

    ArrayList<DataField> fieldList = new ArrayList<DataField>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        reported.setFieldList(fieldList);

        return reported;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) {
        fieldList.add(parseField(in));
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "reported");

    return reported;
  }
Пример #4
0
  @Override
  public WikiObject read(XMLStreamReader xmlReader) throws XMLStreamException, FilterException {
    WikiObject wikiObject = new WikiObject();

    for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
      String elementName = xmlReader.getLocalName();
      if (elementName.equals(XARClassModel.ELEMENT_CLASS)) {
        wikiObject.wikiClass = this.classReader.read(xmlReader);
      } else if (elementName.equals(XARObjectPropertyModel.ELEMENT_PROPERTY)) {
        wikiObject.properties.add(readObjectProperty(xmlReader, wikiObject.wikiClass));
      } else {
        String value = xmlReader.getElementText();

        EventParameter parameter = XARObjectModel.OBJECT_PARAMETERS.get(elementName);

        if (parameter != null) {
          Object wsValue = convert(parameter.type, value);
          if (wsValue != null) {
            wikiObject.parameters.put(parameter.name, wsValue);
          }
        }
      }
    }

    return wikiObject;
  }
Пример #5
0
  public static void parseCorrelations(
      XMLStreamReader input, Contextual<?> ctx, ExecCompilerContext context)
      throws XMLStreamException, ParserException {
    while (input.hasNext()) {
      int type = input.getEventType();
      switch (type) {
        case XMLStreamConstants.START_ELEMENT:
          ParserUtils.assertStart(input, CORRELATIONS);
          Contextual<Correlations> corrs =
              new Contextual<Correlations>(CORRELATIONS, Correlations.class, ctx);
          ParserUtils.setLocation(input, context.source().srcRef(), corrs);
          ctx.children().add(corrs);
          while (input.nextTag() == XMLStreamConstants.START_ELEMENT) {
            if (CORRELATION.equals(input.getName())) {
              Instructional<Correlation> corr =
                  new Instructional<Correlation>(CORRELATION, Correlation.class, corrs);
              ParserUtils.setLocation(input, context.source().srcRef(), corr);
              corrs.children().add(corr);
              while (input.nextTag() == XMLStreamConstants.START_ELEMENT) {
                context.parseContent(input, corr);
              }
            } else {
              context.parseContent(input, corrs);
            }
          }

          break;
        case XMLStreamConstants.END_ELEMENT:
          ParserUtils.assertEnd(input, CORRELATIONS);
          return;
      }
    }
  }
Пример #6
0
 public void parseFromParts(
     XMLStreamReader input, Contextual<Receive> receive, ExecCompilerContext context)
     throws XMLStreamException, ParserException {
   while (input.hasNext()) {
     int type = input.getEventType();
     switch (type) {
       case XMLStreamConstants.START_ELEMENT:
         ParserUtils.assertStart(input, FROMPARTS);
         Contextual<FromParts> fromParts =
             new Contextual<FromParts>(FROMPARTS, FromParts.class, receive);
         ParserUtils.setLocation(input, context.source().srcRef(), fromParts);
         receive.children().add(fromParts);
         while (input.nextTag() == XMLStreamConstants.START_ELEMENT) {
           if (FROMPART.equals(input.getName())) {
             Instructional<FromPart> fromPart =
                 new Instructional<FromPart>(FROMPART, FromPart.class, fromParts);
             ParserUtils.setLocation(input, context.source().srcRef(), fromPart);
             fromParts.children().add(fromPart);
             while (input.nextTag() == XMLStreamConstants.START_ELEMENT) {
               context.parseContent(input, fromPart);
             }
           } else {
             context.parseContent(input, fromParts);
           }
         }
         break;
       case XMLStreamConstants.END_ELEMENT:
         ParserUtils.assertEnd(input, FROMPARTS);
         return;
     }
   }
 }
Пример #7
0
  private WikiObjectProperty readObjectProperty(XMLStreamReader xmlReader, WikiClass wikiClass)
      throws XMLStreamException, FilterException {
    xmlReader.nextTag();

    WikiObjectProperty property = new WikiObjectProperty();

    property.name = xmlReader.getLocalName();

    String type;
    if (wikiClass != null) {
      WikiClassProperty classProperty = wikiClass.properties.get(property.name);
      type = classProperty != null ? classProperty.type : null;
    } else {
      type = null;
    }

    try {
      property.value = this.propertySerializerManager.getPropertySerializer(type).read(xmlReader);
    } catch (ComponentLookupException e) {
      throw new FilterException("Failed to get a property parser", e);
    }

    xmlReader.nextTag();

    return property;
  }
  public WikiClass read(XMLStreamReader xmlReader) throws XMLStreamException, WikiStreamException {
    WikiClass wikiClass = new WikiClass();

    for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
      String elementName = xmlReader.getLocalName();

      if (wikiClass.name == null && XARClassModel.ELEMENT_NAME.equals(elementName)) {
        wikiClass.name = xmlReader.getElementText();
      } else if (XARClassModel.CLASS_PARAMETERS.containsKey(elementName)) {
        String value = xmlReader.getElementText();

        EventParameter parameter = XARClassModel.CLASS_PARAMETERS.get(elementName);

        if (parameter != null) {
          Object wsValue = convert(parameter.type, value);
          if (wsValue != null) {
            wikiClass.parameters.put(parameter.name, wsValue);
          }
        }
      } else {
        wikiClass.addProperty((WikiClassProperty) this.propertyReader.read(xmlReader));
      }
    }

    return wikiClass;
  }
  /** Deserializes the object from XML */
  public DataField parseField(XMLStreamReader in) throws IOException, XMLStreamException {
    String label = in.getAttributeValue(null, "label");
    String type = in.getAttributeValue(null, "type");
    String var = in.getAttributeValue(null, "var");

    DataField field = new DataField(type, var, label);

    ArrayList<DataValue> valueList = new ArrayList<DataValue>();
    ArrayList<DataOption> optionList = new ArrayList<DataOption>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        field.setValueList(valueList);
        field.setOptionList(optionList);

        return field;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "desc".equals(in.getLocalName())) {
        String desc = in.getElementText();

        field.setDesc(desc);

        skipToEnd(in, "desc");
      } else if (XMLStreamReader.START_ELEMENT == tag && "option".equals(in.getLocalName())) {
        optionList.add(parseOption(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "required".equals(in.getLocalName())) {
        field.setRequired(true);

        skipToEnd(in, "required");
      } else if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) {
        String value = in.getElementText();

        valueList.add(new DataValue(value));

        skipToEnd(in, "value");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "field");

    return field;
  }
Пример #10
0
  /**
   * Function that reads the legend properties, specific item properties, dynamic properties and
   * data and converts it to an Item using the specified reader.
   *
   * @param reader the XML reader to read the data from
   * @param newItemIndex used to create the Item
   * @return
   * @throws XMLStreamException
   */
  public Item readXMLToItem(XMLStreamReader reader, Integer newItemIndex)
      throws XMLStreamException {
    Item item = createNewLegendItem(null);
    item.setData(LegendItem.ITEM_INDEX, newItemIndex);

    // opening renderer
    reader.nextTag();
    readXMLToRenderer(reader, item);

    // opening legend properties
    reader.nextTag();
    ArrayList<PreviewProperty> legendProperties = readXMLToLegendProperties(reader, item);

    // opening own properties
    reader.nextTag();
    ArrayList<PreviewProperty> ownProperties = readXMLToOwnProperties(reader, item);

    // opening dynamic properties
    reader.nextTag();
    ArrayList<PreviewProperty> dynamicProperties = readXMLToDynamicProperties(reader, item);
    // closing dynamic properties

    // data
    reader.nextTag();
    readXMLToData(reader, item);

    // finish reading
    reader.next();

    PreviewProperty[] legendPropertiesArray =
        legendProperties.toArray(new PreviewProperty[legendProperties.size()]);
    PreviewProperty[] ownPropertiesArray =
        ownProperties.toArray(new PreviewProperty[ownProperties.size()]);
    PreviewProperty[] dynamicPropertiesArray =
        dynamicProperties.toArray(new PreviewProperty[dynamicProperties.size()]);

    // setting data
    item.setData(LegendItem.ITEM_INDEX, newItemIndex);
    item.setData(LegendItem.OWN_PROPERTIES, ownPropertiesArray);
    item.setData(LegendItem.PROPERTIES, legendPropertiesArray);

    item.setData(LegendItem.HAS_DYNAMIC_PROPERTIES, hasDynamicProperties());
    item.setData(LegendItem.DYNAMIC_PROPERTIES, dynamicPropertiesArray);
    item.setData(LegendItem.IS_SELECTED, Boolean.FALSE);
    item.setData(LegendItem.IS_BEING_TRANSFORMED, Boolean.FALSE);
    item.setData(LegendItem.CURRENT_TRANSFORMATION, "");

    return item;
  }
Пример #11
0
  public LoggingEvents read(XMLStreamReader reader) throws XMLStreamException {
    LoggingEvents result = null;
    String rootNamespace = NAMESPACE_URI;
    int type = reader.getEventType();

    if (XMLStreamConstants.START_DOCUMENT == type) {
      reader.nextTag();
      type = reader.getEventType();
      rootNamespace = null;
    }
    if (XMLStreamConstants.START_ELEMENT == type
        && LOGGING_EVENTS_NODE.equals(reader.getLocalName())) {
      result = new LoggingEvents();
      String idxStr =
          StaxUtilities.readAttributeValue(reader, NAMESPACE_URI, START_INDEX_ATTRIBUTE);
      long idx = 0;
      if (idxStr != null) {
        idx = Long.parseLong(idxStr);
      }
      result.setStartIndex(idx);
      reader.nextTag();
      SourceIdentifier sourceId = sourceIdentifierReader.read(reader);
      if (sourceId != null) {
        result.setSource(sourceId);
        reader.require(
            XMLStreamConstants.END_ELEMENT,
            null,
            EventSourceSchemaConstants.SOURCE_IDENTIFIER_NODE);
        reader.nextTag();
      }

      List<LoggingEvent> events = null;
      for (; ; ) {
        LoggingEvent event = loggingEventReader.read(reader);
        if (event == null) {
          break;
        }
        reader.require(XMLStreamConstants.END_ELEMENT, null, LOGGING_EVENT_NODE);
        reader.nextTag();
        if (events == null) {
          events = new ArrayList<LoggingEvent>();
        }
        events.add(event);
      }
      result.setEvents(events);
      reader.require(XMLStreamConstants.END_ELEMENT, null, LOGGING_EVENTS_NODE);
    }
    return result;
  }
Пример #12
0
 private static void parseFilterList(
     final XMLStreamReader reader, final MultiplePathFilterBuilder builder)
     throws XMLStreamException {
   // xsd:choice
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case INCLUDE:
               parsePath(reader, true, builder);
               break;
             case EXCLUDE:
               parsePath(reader, false, builder);
               break;
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
Пример #13
0
 private static void parseDependencies(
     final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   // xsd:choice
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case MODULE:
               parseModuleDependency(reader, specBuilder);
               break;
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
Пример #14
0
 private static void parseResources(
     final File root, final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   // xsd:choice
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case RESOURCE_ROOT:
               {
                 parseResourceRoot(root, reader, specBuilder);
                 break;
               }
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
  public static HttpHandlerMetaData parse(XMLStreamReader reader, PropertyReplacer propertyReplacer)
      throws XMLStreamException {
    HttpHandlerMetaData valve = new HttpHandlerMetaData();

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CLASS_NAME:
          valve.setHandlerClass(getElementText(reader, propertyReplacer));
          break;
        case MODULE:
          valve.setModule(getElementText(reader, propertyReplacer));
          break;
        case PARAM:
          List<ParamValueMetaData> params = valve.getParams();
          if (params == null) {
            params = new ArrayList<ParamValueMetaData>();
            valve.setParams(params);
          }
          params.add(ParamValueMetaDataParser.parse(reader, propertyReplacer));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return valve;
  }
Пример #16
0
  Pair<Stroke, Continuation<Stroke>> parseStroke(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Stroke");

    Stroke base = new Stroke();
    Continuation<Stroke> contn = null;

    while (!(in.isEndElement() && in.getLocalName().equals("Stroke"))) {
      in.nextTag();

      if (in.getLocalName().endsWith("Parameter")) {
        contn = parseParameter(contn, in, base);
      } else if (in.getLocalName().equals("GraphicFill")) {
        contn = parseGraphicFill(contn, in, base);
      } else if (in.getLocalName().equals("GraphicStroke")) {
        contn = parseGraphicStroke(contn, in, base);
      } else if (in.isStartElement()) {
        LOG.error("Found unknown element '{}', skipping.", in.getLocalName());
        skipElement(in);
      }
    }

    in.require(END_ELEMENT, null, "Stroke");

    return new Pair<Stroke, Continuation<Stroke>>(base, contn);
  }
Пример #17
0
  public static void main(String[] args) throws Exception {

    XMLInputFactory xif = XMLInputFactory.newFactory();
    StreamSource xml = new StreamSource("src/main/resources/PClientCreate_001_Request.xml");
    XMLStreamReader xsr = xif.createXMLStreamReader(xml);
    xsr.nextTag();

    /* System.out.println(xsr.getElementText()); */

    int event = 0;
    // here we advance to next tag untill we find node called "kitchen"
    for (event = xsr.next(); event != XMLStreamReader.END_DOCUMENT; event = xsr.next()) {

      if (event == XMLStreamReader.START_ELEMENT) {
        System.out.println(xsr.getLocalName());
        if (xsr.getLocalName() == "s2465") {
          break;
        }
      }
    }

    JAXBContext jc = JAXBContext.newInstance(S2465.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();

    JAXBElement<S2465> jb = unmarshaller.unmarshal(xsr, S2465.class);
    xsr.close();

    S2465 s2465 = jb.getValue();
    System.out.println(s2465.getLgivname());
    System.out.println(s2465.getLsurname());
  }
Пример #18
0
 public static VDBMetaData unmarshell(InputStream content) throws XMLStreamException {
   XMLInputFactory inputFactory = XMLType.getXmlInputFactory();
   XMLStreamReader reader = inputFactory.createXMLStreamReader(content);
   try {
     // elements
     while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
       Element element = Element.forName(reader.getLocalName());
       switch (element) {
         case VDB:
           VDBMetaData vdb = new VDBMetaData();
           Properties props = getAttributes(reader);
           vdb.setName(props.getProperty(Element.NAME.getLocalName()));
           vdb.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName())));
           parseVDB(reader, vdb);
           return vdb;
         default:
           throw new XMLStreamException(
               AdminPlugin.Util.gs(
                   "unexpected_element1", reader.getName(), Element.VDB.getLocalName()),
               reader.getLocation());
       }
     }
   } finally {
     try {
       content.close();
     } catch (IOException e) {
       Logger.getLogger(VDBMetadataParser.class.getName())
           .log(Level.FINE, "Exception closing vdb stream", e);
     }
   }
   return null;
 }
 private void parseArtifactVersions(
     final XMLStreamReader reader, final FeaturePackDescription result) throws XMLStreamException {
   final Set<Artifact> artifactVersions = result.getArtifactVersions();
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           final Element element = Element.of(reader.getName());
           switch (element) {
             case ARTIFACT:
               artifactVersions.add(parseArtifact(reader));
               break;
             default:
               throw ParsingUtils.unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw ParsingUtils.unexpectedContent(reader);
         }
     }
   }
   throw ParsingUtils.endOfDocument(reader.getLocation());
 }
Пример #20
0
 /** Constructor for XML Parser */
 public static OSMWay create(long id, XMLStreamReader parser) throws XMLStreamException {
   OSMWay way = new OSMWay(id);
   parser.nextTag();
   way.readNodes(parser);
   way.readTags(parser);
   return way;
 }
  public static FilterMappingMetaData parse(XMLStreamReader reader) throws XMLStreamException {
    FilterMappingMetaData filterMapping = new FilterMappingMetaData();

    // Handle attributes
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final String value = reader.getAttributeValue(i);
      if (reader.getAttributeNamespace(i) != null) {
        continue;
      }
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case ID:
          {
            filterMapping.setId(value);
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case FILTER_NAME:
          filterMapping.setFilterName(getElementText(reader));
          break;
        case URL_PATTERN:
          List<String> urlPatterns = filterMapping.getUrlPatterns();
          if (urlPatterns == null) {
            urlPatterns = new ArrayList<String>();
            filterMapping.setUrlPatterns(urlPatterns);
          }
          urlPatterns.add(getElementText(reader));
          break;
        case SERVLET_NAME:
          List<String> servletNames = filterMapping.getServletNames();
          if (servletNames == null) {
            servletNames = new ArrayList<String>();
            filterMapping.setServletNames(servletNames);
          }
          servletNames.add(getElementText(reader));
          break;
        case DISPATCHER:
          List<DispatcherType> dispatchers = filterMapping.getDispatchers();
          if (dispatchers == null) {
            dispatchers = new ArrayList<DispatcherType>();
            filterMapping.setDispatchers(dispatchers);
          }
          dispatchers.add(DispatcherType.valueOf(getElementText(reader)));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return filterMapping;
  }
Пример #22
0
 private static ModuleSpec parseDocument(
     final File root, XMLStreamReader reader, ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.START_DOCUMENT:
         {
           parseRootElement(root, reader, specBuilder);
           return specBuilder.create();
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           if (Element.of(reader.getName()) != Element.MODULE) {
             throw unexpectedContent(reader);
           }
           parseModuleContents(root, reader, specBuilder);
           parseEndDocument(reader);
           return specBuilder.create();
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
Пример #23
0
  private Collection<Object> processFile(
      Mode mode,
      Set<String> xmlRootElements,
      Map<String, Class<?>> entityClasses,
      XMLStreamReader xmlStreamReader,
      Collection<Object> batch)
      throws Exception {
    do {
      xmlStreamReader.nextTag();
    } while (xmlRootElements.contains(xmlStreamReader.getLocalName()));

    do {
      final Class<?> entityClass = entityClasses.get(xmlStreamReader.getLocalName());
      try {
        final Object entity = extractEntity(xmlStreamReader, entityClass);
        batch.add(entity);

        if (batch.size() == batchSize) {
          batch = processBatch(mode, batch);
        }
      } catch (Throwable e) {
        LOGGER.error("{} Error", mode, e);
      }
    } while (xmlStreamReader.isStartElement() && xmlStreamReader.hasNext());

    return batch;
  }
Пример #24
0
  public static void parse(final XMLStreamReader reader, final XmlRpcListener listener)
      throws XMLStreamException, XmlRpcException {
    listener.startResponse();

    boolean paramDetected = false;
    boolean faultDetected = false;

    int type = -1;
    do {
      type = reader.nextTag();
      if (type == START_ELEMENT) {
        final String tag = reader.getName().getLocalPart();
        if (XmlRpcConstants.FAULT.equals(tag)) {
          faultDetected = true;
          FaultHelper.parse(reader, listener);
          break;
        } else if (XmlRpcConstants.PARAMS.equals(tag)) {
          paramDetected = true;
          ParamHelper.parse(reader, listener);
        }
      } else if (type == XMLStreamReader.END_ELEMENT
          && XmlRpcConstants.RESPONSE.equals(reader.getName().getLocalPart())) {
        break;
      }
    } while (type != END_DOCUMENT);

    if (paramDetected && faultDetected) {
      throw new XmlRpcException("Cannot specify both fault and parameters in XML-RPC response.");
    }

    listener.endResponse();
  }
  public static ContainerListenerMetaData parse(XMLStreamReader reader) throws XMLStreamException {
    ContainerListenerMetaData containerListener = new ContainerListenerMetaData();

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case CLASS_NAME:
          containerListener.setListenerClass(getElementText(reader));
          break;
        case MODULE:
          containerListener.setModule(getElementText(reader));
          break;
        case LISTENER_TYPE:
          containerListener.setListenerType(ContainerListenerType.valueOf(getElementText(reader)));
          break;
        case PARAM:
          List<ParamValueMetaData> params = containerListener.getParams();
          if (params == null) {
            params = new ArrayList<ParamValueMetaData>();
            containerListener.setParams(params);
          }
          params.add(ParamValueMetaDataParser.parse(reader));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return containerListener;
  }
Пример #26
0
  private static void parseModel(XMLStreamReader reader, ModelMetaData model)
      throws XMLStreamException {
    Properties props = getAttributes(reader);
    model.setName(props.getProperty(Element.NAME.getLocalName()));
    model.setModelType(props.getProperty(Element.TYPE.getLocalName(), "PHYSICAL"));
    model.setVisible(
        Boolean.parseBoolean(props.getProperty(Element.VISIBLE.getLocalName(), "true")));
    model.setPath(props.getProperty(Element.PATH.getLocalName()));

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case DESCRIPTION:
          model.setDescription(reader.getElementText());
          break;
        case PROPERTY:
          parseProperty(reader, model);
          break;
        case SOURCE:
          Properties sourceProps = getAttributes(reader);
          String name = sourceProps.getProperty(Element.NAME.getLocalName());
          String translatorName =
              sourceProps.getProperty(Element.SOURCE_TRANSLATOR_NAME_ATTR.getLocalName());
          String connectionName =
              sourceProps.getProperty(Element.SOURCE_CONNECTION_JNDI_NAME_ATTR.getLocalName());
          model.addSourceMapping(name, translatorName, connectionName);
          ignoreTillEnd(reader);
          break;
        case VALIDATION_ERROR:
          Properties validationProps = getAttributes(reader);
          String msg = reader.getElementText();
          String severity =
              validationProps.getProperty(Element.VALIDATION_SEVERITY_ATTR.getLocalName());
          String path = validationProps.getProperty(Element.PATH.getLocalName());
          Message ve = new Message(Severity.valueOf(severity), msg);
          ve.setPath(path);
          model.addMessage(ve);
          break;
        case METADATA:
          Properties metdataProps = getAttributes(reader);
          String type = metdataProps.getProperty(Element.TYPE.getLocalName(), "DDL");
          String schema = reader.getElementText();
          model.setSchemaSourceType(type);
          model.setSchemaText(schema);
          break;
        default:
          throw new XMLStreamException(
              AdminPlugin.Util.gs(
                  "unexpected_element5",
                  reader.getName(),
                  Element.DESCRIPTION.getLocalName(),
                  Element.PROPERTY.getLocalName(),
                  Element.SOURCE.getLocalName(),
                  Element.METADATA.getLocalName(),
                  Element.VALIDATION_ERROR.getLocalName()),
              reader.getLocation());
      }
    }
  }
Пример #27
0
  /**
   * Read ParticipantSet from given parser (also recursive)
   *
   * @param r The given {@link XMLStreamReader}
   * @param nsMap The used namespacemap
   * @return ParticipantSet
   * @throws MalformedTLGLSyntaxException
   * @throws XMLStreamException
   */
  private static ParticipantSet readInParticipantSet(
      XMLStreamReader r, INamespaceMap<String, String> nsMap)
      throws MalformedTLGLSyntaxException, XMLStreamException {
    ParticipantSet participantSet = null;

    String psName = null;
    String psType = null;
    if (!(r.getEventType() == XMLStreamConstants.END_ELEMENT)) {

      psName = BPEL4ChorReader.getStrAttribute(r, "name", true).toString();
      psType = BPEL4ChorReader.getStrAttribute(r, "type", true).toString();

      participantSet = new ParticipantSet(psName, psType);

      QName scope = BPEL4ChorReader.getQNAttribute(r, "scope", nsMap, false);
      if (scope != null) {
        participantSet.setScope(scope);
      }

      List<QName> forEachs = BPEL4ChorReader.getQNsAttribute(r, "forEach", nsMap, false);
      if ((forEachs != null) && (forEachs.size() > 0)) {
        participantSet.setForEach(forEachs);
      }
    }

    r.nextTag();
    // Read (sub)participantSet(s)
    if (r.hasNext() && r.getLocalName().equals("participantSet")) {
      while (r.hasNext() && r.getLocalName().equals("participantSet")) {
        ParticipantSet participantSetSub = BPEL4ChorReader.readInParticipantSet(r, nsMap);
        participantSet.getParticipantSetList().add(participantSetSub);
      }
      r.nextTag();
    }

    // Read (sub)participant(s)
    if (r.hasNext() && r.getLocalName().equals("participant")) {
      while (r.hasNext() && r.getLocalName().equals("participant")) {

        Participant participant = BPEL4ChorReader.readInParticipant(r, nsMap, true);
        participantSet.getParticipantList().add(participant);
      }
      r.nextTag();
    }
    return participantSet;
  }
 private String readElement(XMLStreamReader parser, String string) throws XMLStreamException {
   while (true) {
     if (parser.nextTag() == XMLStreamConstants.START_ELEMENT
         && parser.getLocalName().equals(string)) {
       return parser.getElementText();
     }
   }
 }
 private void searchTag(XMLStreamReader parser, String string) throws XMLStreamException {
   while (true) {
     if (parser.nextTag() == XMLStreamConstants.START_ELEMENT
         && parser.getLocalName().equals(string)) {
       return;
     }
   }
 }
Пример #30
0
  protected static Pair<Filter, ConstraintLanguage> parseConstraint(
      XMLAdapter adapter, OMElement omQueryElement) {
    Pair<Filter, ConstraintLanguage> pc = null;
    if (omQueryElement != null
        && new QName(CSWConstants.CSW_202_NS, "Constraint").equals(omQueryElement.getQName())) {
      Version versionConstraint =
          adapter.getRequiredNodeAsVersion(omQueryElement, new XPath("@version", nsContext));

      OMElement filterEl = omQueryElement.getFirstChildWithName(new QName(OGCNS, "Filter"));
      OMElement cqlTextEl = omQueryElement.getFirstChildWithName(new QName("", "CQLTEXT"));
      if ((filterEl != null) && (cqlTextEl == null)) {

        ConstraintLanguage constraintLanguage = ConstraintLanguage.FILTER;
        Filter constraint;
        try {
          // TODO remove usage of wrapper (necessary at the moment to work around problems
          // with AXIOM's

          XMLStreamReader xmlStream =
              new XMLStreamReaderWrapper(filterEl.getXMLStreamReaderWithoutCaching(), null);
          // skip START_DOCUMENT
          xmlStream.nextTag();

          if (versionConstraint.equals(new Version(1, 1, 0))) {

            constraint = Filter110XMLDecoder.parse(xmlStream);

          } else if (versionConstraint.equals(new Version(1, 0, 0))) {
            constraint = Filter100XMLDecoder.parse(xmlStream);
          } else {
            String msg =
                Messages.get(
                    "CSW_FILTER_VERSION_NOT_SPECIFIED",
                    versionConstraint,
                    Version.getVersionsString(new Version(1, 1, 0)),
                    Version.getVersionsString(new Version(1, 0, 0)));
            LOG.info(msg);
            throw new InvalidParameterValueException(msg);
          }
        } catch (XMLStreamException e) {
          String msg =
              "FilterParsingException: There went something wrong while parsing the filter expression, so please check this!";
          LOG.debug(msg);
          throw new XMLParsingException(adapter, filterEl, e.getMessage());
        }
        pc = new Pair<Filter, CSWConstants.ConstraintLanguage>(constraint, constraintLanguage);
      } else if ((filterEl == null) && (cqlTextEl != null)) {
        String msg = Messages.get("CSW_UNSUPPORTED_CQL_FILTER");
        LOG.info(msg);
        throw new NotImplementedError(msg);
      } else {
        String msg = Messages.get("CSW_MISSING_FILTER_OR_CQL");
        LOG.debug(msg);
        throw new InvalidParameterValueException(msg);
      }
    }
    return pc;
  }