public TypeDescription(Class<? extends Object> clazz, String tag) { this(clazz, new Tag(tag), null); }
public void setTag(String tag) { setTag(new Tag(tag)); }
public Node representData(Object data) { Tag tag = new Tag(data.getClass()); return representScalar(getTag(data.getClass(), tag), ((Enum<?>) data).name()); } }
public Node representData(Object data) { return representScalar(getTag(data.getClass(), new Tag(UUID.class)), data.toString()); } }
public Constructor(TypeDescription theRoot, Collection<TypeDescription> moreTDs) { if (theRoot == null) { throw new NullPointerException("Root type must be provided."); } this.yamlConstructors.put(null, new ConstructYamlObject()); if (!Object.class.equals(theRoot.getType())) { rootTag = new Tag(theRoot.getType()); } yamlClassConstructors.put(NodeId.scalar, new ConstructScalar()); yamlClassConstructors.put(NodeId.mapping, new ConstructMapping()); yamlClassConstructors.put(NodeId.sequence, new ConstructSequence()); addTypeDescription(theRoot); if (moreTDs != null) { for (TypeDescription td : moreTDs) { addTypeDescription(td); } } }
Tag tag; Tag customTag = classTags.get(javaBean.getClass()); tag = customTag != null ? customTag : new Tag(javaBean.getClass());
protected Node composeSequenceNode(String anchor) { SequenceStartEvent startEvent = (SequenceStartEvent) parser.getEvent(); String tag = startEvent.getTag(); Tag nodeTag; boolean resolved = false; if (tag == null || tag.equals("!")) { nodeTag = resolver.resolve(NodeId.sequence, null, startEvent.getImplicit()); resolved = true; } else { nodeTag = new Tag(tag); } final ArrayList<Node> children = new ArrayList<Node>(); SequenceNode node = new SequenceNode(nodeTag, resolved, children, startEvent.getStartMark(), null, startEvent.getFlowStyle()); if (anchor != null) { anchors.put(anchor, node); } while (!parser.checkEvent(Event.ID.SequenceEnd)) { children.add(composeNode(node)); } Event endEvent = parser.getEvent(); node.setEndMark(endEvent.getEndMark()); return node; }
protected Node composeMappingNode(String anchor) { MappingStartEvent startEvent = (MappingStartEvent) parser.getEvent(); String tag = startEvent.getTag(); Tag nodeTag; boolean resolved = false; if (tag == null || tag.equals("!")) { nodeTag = resolver.resolve(NodeId.mapping, null, startEvent.getImplicit()); resolved = true; } else { nodeTag = new Tag(tag); } final List<NodeTuple> children = new ArrayList<NodeTuple>(); MappingNode node = new MappingNode(nodeTag, resolved, children, startEvent.getStartMark(), null, startEvent.getFlowStyle()); if (anchor != null) { anchors.put(anchor, node); } while (!parser.checkEvent(Event.ID.MappingEnd)) { composeMappingChildren(children, node); } Event endEvent = parser.getEvent(); node.setEndMark(endEvent.getEndMark()); return node; }
/** * Ensure that the stream contains a single document and construct it * * @param type the class of the instance being created * @return constructed instance * @throws ComposerException in case there are more documents in the stream */ public Object getSingleData(Class<?> type) { // Ensure that the stream contains a single document and construct it Node node = composer.getSingleNode(); if (node != null && !Tag.NULL.equals(node.getTag())) { if (Object.class != type) { node.setTag(new Tag(type)); } else if (rootTag != null) { node.setTag(rootTag); } return constructDocument(node); } return null; }
protected Node composeScalarNode(String anchor) { ScalarEvent ev = (ScalarEvent) parser.getEvent(); String tag = ev.getTag(); boolean resolved = false; Tag nodeTag; if (tag == null || tag.equals("!")) { nodeTag = resolver.resolve(NodeId.scalar, ev.getValue(), ev.getImplicit().canOmitTagInPlainScalar()); resolved = true; } else { nodeTag = new Tag(tag); } Node node = new ScalarNode(nodeTag, resolved, ev.getValue(), ev.getStartMark(), ev.getEndMark(), ev.getScalarStyle()); if (anchor != null) { anchors.put(anchor, node); } return node; }
@Override public Node representData(Object data) { if (!(data instanceof URI)) throw new IllegalArgumentException("URIRepresenter -- data should be a URI"); URI uri = (URI) data; String value = uri.toString(); return representScalar(new Tag("!emf.URI"), value); }
@Override public Node representData(Object data) { if (!(data instanceof ProjectClassification)) throw new IllegalArgumentException("ProjectClassificationRepresenter -- data should be a ProjectClassification"); ProjectClassification pc = (ProjectClassification) data; String value = pc.name(); return representScalar(new Tag("!SSCAE.Classification"), value); }
public MappingConstructor() { super(); this.addTypeDescription(new TypeDescription(GemSpecification.class, new Tag("!ruby/object:Gem::Specification"))); this.addTypeDescription(new TypeDescription(GemDependency.class, new Tag("!ruby/object:Gem::Dependency"))); this.addTypeDescription(new TypeDescription(GemRequirement.class, new Tag("!ruby/object:Gem::Requirement"))); this.addTypeDescription(new TypeDescription(GemVersion.class, new Tag("!ruby/object:Gem::Version"))); } }
public CoreFixy(Persister persister, String defaultPackage, BeanAccess beanAccess) { this.yamlConstructors.put(new Tag("!import"), new ConstructImport(this)); this.yamlConstructors.put(new Tag("!package"), new ConstructPackage(this)); this.defaultPackage = defaultPackage; this.packageName = defaultPackage; this.persister = persister; this.beanAccess = beanAccess; }
void registerConstruct(String tag, Construct construct) { if (construct instanceof MgnlYamlConstruct) { ((MgnlYamlConstruct) construct).setConstructor(this); } yamlConstructors.put(new Tag(tag), construct); }
public Node representData(Object data) { Tag tag = new Tag(data.getClass()); return representScalar(getTag(data.getClass(), tag), ((Enum<?>) data).name()); } }
private JcrPropertySupportingConstructor(ValueFactory valueFactory) { yamlConstructors.put(new Tag("!" + StringUtils.lowerCase(PropertyType.TYPENAME_PATH)), new JcrConstruct(PropertyType.PATH, valueFactory)); yamlConstructors.put(new Tag("!" + StringUtils.lowerCase(PropertyType.TYPENAME_URI)), new JcrConstruct(PropertyType.URI, valueFactory)); yamlConstructors.put(new Tag("!" + StringUtils.lowerCase(PropertyType.TYPENAME_REFERENCE)), new JcrConstruct(PropertyType.REFERENCE, valueFactory)); yamlConstructors.put(new Tag("!" + StringUtils.lowerCase(PropertyType.TYPENAME_WEAKREFERENCE)), new JcrConstruct(PropertyType.WEAKREFERENCE, valueFactory)); yamlConstructors.put(new Tag("!" + StringUtils.lowerCase(PropertyType.TYPENAME_BINARY)), new JcrConstruct(PropertyType.BINARY, valueFactory)); } }
public JodaTimeRepresenter() { multiRepresenters.put(DateTime.class, data -> { DateTime date = (DateTime) data; return super.representData(new Date(date.getMillis())); }); multiRepresenters.put(LocalDateTime.class, data -> { LocalDateTime date = (LocalDateTime) data; return super.representScalar(new Tag("!localTimestamp"), date.toString()); }); }
@Override public Node representData(Object data) { RecordedResponse recordedResponse = (RecordedResponse) data; Tag tag = getTag(RecordedResponse.class, new Tag(RecordedResponse.class)); return representSequence(tag, Arrays.asList(recordedResponse.code(), recordedResponse .headers(), recordedResponse.getBody()), true); } }
@Override public Node representData(Object data) { RecordedRequest recordedRequest = (RecordedRequest) data; Tag tag = getTag(RecordedRequest.class, new Tag(RecordedRequest.class)); return representSequence(tag, Arrays.asList(recordedRequest.method(), recordedRequest.url() .toString(), recordedRequest.headers(), recordedRequest.getBody()), true); } }