public Token(Mark startMark, Mark endMark) { if (startMark == null || endMark == null) { throw new YAMLException("Token requires marks."); } this.startMark = startMark; this.endMark = endMark; }
public void setIndicatorIndent(int indicatorIndent) { if (indicatorIndent < 0) { throw new YAMLException("Indicator indent must be non-negative."); } if (indicatorIndent > Emitter.MAX_INDENT - 1) { throw new YAMLException("Indicator indent must be at most Emitter.MAX_INDENT-1: " + (Emitter.MAX_INDENT - 1)); } this.indicatorIndent = indicatorIndent; }
public void setIndent(int indent) { if (indent < Emitter.MIN_INDENT) { throw new YAMLException("Indent must be at least " + Emitter.MIN_INDENT); } if (indent > Emitter.MAX_INDENT) { throw new YAMLException("Indent must be at most " + Emitter.MAX_INDENT); } this.indent = indent; }
public static String decode(String buff) { try { return URLDecoder.decode(buff, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new YAMLException(e); } } }
@Override public Object get(Object object) { try { return field.get(object); } catch (Exception e) { throw new YAMLException("Unable to access field " + field.getName() + " on object " + object + " : " + e); } }
private static final String check(String s) { if (s == null) { throw new NullPointerException("Root type must be provided."); } if (s.trim().length() == 0) { throw new YAMLException("Root type must be provided."); } return s; }
public DirectiveToken(String name, List<T> value, Mark startMark, Mark endMark) { super(startMark, endMark); this.name = name; if (value != null && value.size() != 2) { throw new YAMLException("Two strings must be provided instead of " + String.valueOf(value.size())); } this.value = value; }
@Override public Object get(Object object) { try { property.getReadMethod().setAccessible(true);// issue 50 return property.getReadMethod().invoke(object); } catch (Exception e) { throw new YAMLException("Unable to find getter for property '" + property.getName() + "' on object " + object + ":" + e); } }
protected Object newInstance(Node node) { try { return newInstance(Object.class, node); } catch (InstantiationException e) { throw new YAMLException(e); } }
public String getClassName() { if (!value.startsWith(Tag.PREFIX)) { throw new YAMLException("Invalid tag: " + value); } return UriEncoder.decode(value.substring(Tag.PREFIX.length())); }
@Override public void set(Object object, Object value) throws Exception { if (!writable) { throw new YAMLException("No writable property '" + getName() + "' on class: " + object.getClass().getName()); } property.getWriteMethod().invoke(object, value); }
public Property getProperty(Class<? extends Object> type, String name, BeanAccess bAccess) { Map<String, Property> properties = getPropertiesMap(type, bAccess); Property property = properties.get(name); if (property == null && skipMissingProperties) { property = new MissingProperty(name); } if (property == null) { throw new YAMLException( "Unable to find property '" + name + "' on class: " + type.getName()); } return property; }
protected void setProperties(Object bean, Map<String, Object> data) throws Exception { if (data == null) { throw new NullPointerException("Data for Compact Object Notation cannot be null."); } for (Map.Entry<String, Object> entry : data.entrySet()) { String key = entry.getKey(); Property property = getPropertyUtils().getProperty(bean.getClass(), key); try { property.set(bean, entry.getValue()); } catch (IllegalArgumentException e) { throw new YAMLException("Cannot set property='" + key + "' with value='" + data.get(key) + "' (" + data.get(key).getClass() + ") in " + bean); } } }
@Override @SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object object) { if (node.isTwoStepsConstruction()) { constructSet2ndStep((MappingNode) node, (Set<Object>) object); } else { throw new YAMLException("Unexpected recursive set structure. Node: " + node); } } }
@Override @SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object object) { if (node.isTwoStepsConstruction()) { constructMapping2ndStep((MappingNode) node, (Map<Object, Object>) object); } else { throw new YAMLException("Unexpected recursive mapping structure. Node: " + node); } } }
@Override @SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object data) { if (node.isTwoStepsConstruction()) { constructSequenceStep2((SequenceNode) node, (List<Object>) data); } else { throw new YAMLException("Unexpected recursive sequence structure. Node: " + node); } } }
protected Object constructCompactFormat(ScalarNode node, CompactData data) { try { Object obj = createInstance(node, data); Map<String, Object> properties = new HashMap<String, Object>(data.getProperties()); setProperties(obj, properties); return obj; } catch (Exception e) { throw new YAMLException(e); } }
protected void applySequence(Object bean, List<?> value) { try { Property property = getPropertyUtils().getProperty(bean.getClass(), getSequencePropertyName(bean.getClass())); property.set(bean, value); } catch (Exception e) { throw new YAMLException(e); } }
@SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object object) { SequenceNode snode = (SequenceNode) node; if (List.class.isAssignableFrom(node.getType())) { List<Object> list = (List<Object>) object; constructSequenceStep2(snode, list); } else if (node.getType().isArray()) { constructArrayStep2(snode, object); } else { throw new YAMLException("Immutable objects cannot be recursive."); } } }
private void dumpAll(Iterator<? extends Object> data, Writer output, Tag rootTag) { Serializer serializer = new Serializer(new Emitter(output, dumperOptions), resolver, dumperOptions, rootTag); try { serializer.open(); while (data.hasNext()) { Node node = representer.represent(data.next()); serializer.serialize(node); } serializer.close(); } catch (IOException e) { throw new YAMLException(e); } }