/*
(non-Javadoc)
@see com.tupilabs.pbs.parser.Parser#parse(java.lang.Object)
519288
@Override
    public List<Queue> parse(String text) throws ParseException {
        final List<Queue> queues;
        if (StringUtils.isNotBlank(text)) {
            queues = new LinkedList<Queue>();
            String separator = "\n";
            if (text.indexOf("\r\n") > 0) {
                separator = "\r\n";
            }
            final String[] lines = text.split(separator);
            Queue queue = null;
            for (final String line : lines) {
                Matcher matcher = PATTERN_QUEUE.matcher(line);
                if (matcher.matches()) {
                    if (queue != null) {
                        queues.add(queue);
                    }
                    queue = new Queue();
                    final String name = matcher.group(1);
                    queue.setName(name);
                } else if (StringUtils.isNotBlank(line)) {
                    String[] temp = Utils.splitFirst(line, CHAR_EQUALS);
                    if (temp.length == 2) {
                        final String key = temp[0].trim().toLowerCase();
                        final String value = temp[1].trim();
                        if ("queue_type".equals(key)) {
                            queue.setQueueType(value);
                        } else if ("priority".equals(key)) {
                            try {
                                queue.setPriority(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing queue priority: " + nfe.getMessage(), nfe);
                                queue.setPriority(-1);
                            }
                        } else if ("total_jobs".equals(key)) {
                            try {
                                queue.setTotalJobs(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing queue total jobs: " + nfe.getMessage(), nfe);
                                queue.setPriority(-1);
                            }
                        } else if ("state_count".equals(key)) {
                            queue.setStateCount(value);
                        } else if ("mtime".equals(key)) {
                            queue.setMtime(value);
                        } else if ("max_user_run".equals(key)) {
                            try {
                                queue.setMaxUserRun(Integer.parseInt(value));
                            } catch (NumberFormatException nfe) {
                                LOGGER.log(Level.WARNING, "Failed parsing queue max user run: " + nfe.getMessage(),
                                        nfe);
                                queue.setPriority(-1);
                            }
                        } else if ("enabled".equals(key)) {
                            queue.setEnabled(Boolean.parseBoolean(value));
                        } else if ("started".equals(key)) {
                            queue.setStarted(Boolean.parseBoolean(value));
                        } else if (key.startsWith("resources_max.")) {
                            queue.getResourcesMax().put(key, value);
                        } else if (key.startsWith("resources_min.")) {
                            queue.getResourcesMin().put(key, value);
                        } else if (key.startsWith("resources_assigned.")) {
                            queue.getResourcesAssigned().put(key, value);
                        } else if (key.startsWith("resources_default.")) {
                            queue.getResourcesDefault().put(key, value);
                        } else {
                            LOGGER.info("Unmmaped key, value: " + key + ", " + value);
                        }
                    }
                }
            }
            if (queue != null) {
                queues.add(queue);
            }
            return queues;
        } else {
            return Collections.emptyList();
        }
    }
506536
public static JSON parse(Object obj) {
		if (null == obj) {
			return null;
		}

		JSON json = null;
		if (obj instanceof JSON) {
			json = (JSON) obj;
		} else if (obj instanceof String) {
			String jsonStr = ((String) obj).trim();
			if (jsonStr.startsWith("[")) {
				json = parseArray(jsonStr);
			} else {
				json = parseObj(jsonStr);
			}
		} else if (obj instanceof Collection || obj.getClass().isArray()) {// 列表
			json = new JSONArray(obj);
		} else {// 对象
			json = new JSONObject(obj);
		}

		return json;
	}
46769
public <T> T parse(byte[] in, Class<T> mapTo) throws ParseException {
		return getPBytes().parse(in, JSONValue.defaultReader.getMapper(mapTo));
	}
700610
private void parse()
    {
        this.elements = new ArrayList<>();

        try {
            for (Tokenizer tokenizer = new Tokenizer(this.rawVersion); tokenizer.next();) {
                Element element = new Element(tokenizer);
                this.elements.add(element);
                if (element.getVersionType() != Type.STABLE) {
                    this.type = element.getVersionType();
                }
            }

            trimPadding(this.elements);
        } catch (Exception e) {
            // Make sure to never fail no matter what
            LOGGER.error("Failed to parse version [" + this.rawVersion + "]", e);
            this.elements.add(new Element(this.rawVersion));
        }
    }
836145
protected <T> T parse(JsonReaderI<T> mapper) throws ParseException {
		this.pos = -1;
		T result;
		try {
			read();
			result = readFirst(mapper);
			if (checkTaillingData) {
				if (!checkTaillingSpace)
					skipSpace();
				if (c != EOI)
					throw new ParseException(pos - 1, ERROR_UNEXPECTED_TOKEN, c);
			}
		} catch (IOException e) {
			throw new ParseException(pos, e);
		}
		xs = null;
		xo = null;
		return result;
	}
1328878
public static Object parse(String json, JSONVisitor handler)
            throws ParseException {
        StringReader reader = new StringReader(json);
        try {
            return parse(reader, handler);
        } catch (IOException e) {
            throw new ParseException(e.getMessage(), 0);
        } finally {
            reader.close();
        }
    }
144296
public static void parse(String content, Object data) {
    if (content == null) {
      return;
    }
    try {
      parse(new StringReader(content), data);
    } catch (IOException exception) {
      // I/O exception not expected on a string
      throw Throwables.propagate(exception);
    }
  }
1120055
public void parse() throws ParserException {
        try {
            jsonParser.nextToken();
            contentHandler.startDocument();
            if (shouldAddArtificialRoot()) {
                startElement(artificialRootName);
                parseElement(artificialRootName, false);
                endElement(artificialRootName);
            } else if (START_OBJECT.equals(jsonParser.getCurrentToken())) {
                int elementsWritten = parseObject();
                if (elementsWritten>1) {
                    throw new ParserException("More than one root element. Can not generate legal XML. You can set artificialRootName to generate an artificial root.");
                }
            } else {
                throw new ParserException("Unsupported root element. Can not generate legal XML. You can set artificialRootName to generate an artificial root.");
            }
            contentHandler.endDocument();
        } catch (Exception e) {
            throw new ParserException("Parsing error: " + e.getMessage(), e);
        }
    }
634918
public void parseString(String xml) throws ParserException {

        try {
            nanoElement.parseString(xml);
        } catch (XMLParseException e) {
            throw new ParserException(e.getMessage());
        }
    }
778015
@Override
	public IGPSObject parse(final JSONObject json) throws ParseException {
		IGPSObject gps = null;
		final String clazz = json.optString("class");
		
		if (TPVObject.NAME.equals(clazz)) {
			gps = this.parseTPV(json);
		} else if (SKYObject.NAME.equals(clazz)) {
			gps = this.parseSKY(json);
		} else if (GSTObject.NAME.equals(clazz)) {
			gps = this.parseGST(json);
		} else if (ATTObject.NAME.equals(clazz)) {
			gps = this.parseATT(json);
		} else if (SUBFRAMEObject.NAME.equals(clazz)) {
			gps = this.parseSUBFRAME(json);
		} else if (VersionObject.NAME.equals(clazz)) {
			gps = this.parseVERSION(json);
		} else if (DevicesObject.NAME.equals(clazz)) {
			gps = this.parseDEVICES(json);
		} else if (DeviceObject.NAME.equals(clazz)) {
			gps = this.parseDEVICE(json);
		} else if (WatchObject.NAME.equals(clazz)) {
			gps = this.parseWATCH(json);
		} else if (PollObject.NAME.equals(clazz)) {
			gps = this.parsePOLL(json);
		} else if (json.has("PRN")) { // SATObject
			gps = this.parsePRN(json);
		} else if (json.has("deltai")) { // ALMANACObject
			gps = this.parseALMANAC(json);
		} else if (json.has("IODC")) { // EPHEM1Object
			gps = this.parseEPHEM1(json);
		} else if (json.has("Crs")) { // EPHEM2Object
			gps = this.parseEPHEM2(json);
		} else if (json.has("IDOT")) { // EPHEM3Object
			gps = this.parseEPHEM3(json);
		} else if (json.has("ERD30")) { // ERDObject
			gps = this.parseERD(json);
		} else if (json.has("SVH32")) { // HEALTHObject
			gps = this.parseHEALTH(json);
		} else if (json.has("WNa")) { // HEALTH2Object
			gps = this.parseHEALTH2(json);
		} else if (json.has("WNlsf")) { // IONOObject
			gps = this.parseIONO(json);
		} else {
			throw new ParseException("Invalid object class: " + clazz);
		}
		return gps;
	}
604764
@Override
  public Map<String, Object> parse(String input)
  {
    try {
      Map<String, Object> map = new LinkedHashMap<>();
      Map<String, Object> document = mapper.readValue(
          input,
          new TypeReference<Map<String, Object>>()
          {
          }
      );
      for (Map.Entry<String, Pair<FieldType, JsonPath>> entry : fieldPathMap.entrySet()) {
        String fieldName = entry.getKey();
        Pair<FieldType, JsonPath> pair = entry.getValue();
        JsonPath path = pair.rhs;
        Object parsedVal;
        if (pair.lhs == FieldType.ROOT) {
          parsedVal = document.get(fieldName);
        } else {
          parsedVal = path.read(document, jsonPathConfig);
        }
        if (parsedVal == null) {
          continue;
        }
        parsedVal = valueConversionFunction(parsedVal);
        map.put(fieldName, parsedVal);
      }
      if (useFieldDiscovery) {
        discoverFields(map, document);
      }
      return map;
    }
    catch (Exception e) {
      throw new ParseException(e, "Unable to parse row [%s]", input);
    }
  }
1369184
public Object parseObject(String source, ParsePosition pos) {
        pos.setIndex(0);
        pos.setErrorIndex(0);
        return null;
    }
1050668
public void parse(String s) {
        Preconditions.checkNotNull(s, "s");
        if (s.length() == 0) {
            // Nothing to do.
            return;
        }

        val pairs = s.split(pairDelimiter);
        for (String pair : pairs) {
            int delimiterPos = pair.indexOf(keyValueDelimiter);
            if (delimiterPos < 0) {
                throw new IllegalArgumentException(String.format("Invalid pair '%s' (missing key-value delimiter).", pair));
            }

            String key = pair.substring(0, delimiterPos);
            String value;
            if (delimiterPos == pair.length() - 1) {
                value = "";
            } else {
                value = pair.substring(delimiterPos + 1);
            }

            Extractor<?> e = this.extractors.get(key);
            Preconditions.checkArgument(e != null, String.format("No extractor provided for key '%s'.", key));
            e.process(value);
        }
    }
850143
public Object parse(byte [] bytes) {
        if (bytes == null) {
            throw new IllegalArgumentException("bytes must not be null");
        }

        Object content;
        content = createParser().parse(bytes);
        return content;
    }
810442
@Override
	public E parse(BinderContext context, ParserWrapper parserWrapper) throws Exception {
		E instance = null;

		switch (context.getSupportedFormat()) {
		case XML:
			instance = parseOnXml(((XmlWrapperParser) parserWrapper).xmlParser, 0);
			break;
		default:
			if (context.getSupportedFormat().onlyText)
				instance = parseOnJacksonAsString(((JacksonWrapperParser) parserWrapper).jacksonParser);
			else
				instance = parseOnJackson(((JacksonWrapperParser) parserWrapper).jacksonParser);

			break;
		}

		return instance;
	}
593970
public void parseReader(Reader reader) throws ParserException, IOException {

        try {
            nanoElement.parseFromReader(reader);
        } catch (XMLParseException e) {
            throw new ParserException(e.getMessage());
        }
    }
1261761
@Override
    public Object parse(IGroup group, JsonRuleParser parser) {
        StringBuffer operate = new StringBuffer();

        // NOT
        if (group.getNot() != null && group.getNot()) {
            operate.append("( NOT ");
        }

        if (group.getRules().size() > 0) {
            operate.append("( ");
        }

        // rules
        List<Object> params = new ArrayList<Object>();
        for (int i = 0; i < group.getRules().size(); i++) {
            // json parse
            Operation operation = (Operation) parser.parse(group.getRules().get(i));

            // operate
            operate.append(operation.getOperate());
            if (i < group.getRules().size() - 1) {
                operate.append(EnumCondition.AND.equals(group.getCondition()) ? " AND " : " OR ");
            }
            // params
            if (operation.getHasValue()) {
                if (operation.getValue() instanceof List) {
                    params.addAll((Collection<?>) operation.getValue());
                } else {
                    params.add(operation.getValue());
                }
            }
        }

        if (group.getRules().size() > 0) {
            operate.append(" )");
        }
        if (group.getNot() != null && group.getNot()) {
            operate.append(" )");
        }

        return new Operation(operate, params);
    }