protected Object getReferenceKey(String reference) { final Path path = new Path(isNameEncoding ? ((AbstractReader)reader.underlyingReader()).decodeNode(reference) : reference); // We have absolute references, if path starts with '/' return reference.charAt(0) != '/' ? pathTracker.getPath().apply(path) : path; }
protected String createReference(Path currentPath, Object existingReferenceKey) { Path existingPath = (Path)existingReferenceKey; Path referencePath = (mode & ReferenceByXPathMarshallingStrategy.ABSOLUTE) > 0 ? existingPath : currentPath.relativeTo(existingPath); return (mode & ReferenceByXPathMarshallingStrategy.SINGLE_NODE) > 0 ? referencePath.explicit() : referencePath.toString(); }
public Path relativeTo(Path that) { int depthOfPathDivergence = depthOfPathDivergence(chunks, that.chunks); String[] result = new String[chunks.length + that.chunks.length - 2 * depthOfPathDivergence]; int count = 0; for (int i = depthOfPathDivergence; i < chunks.length; i++) { result[count++] = ".."; } for (int j = depthOfPathDivergence; j < that.chunks.length; j++) { result[count++] = that.chunks[j]; } if (count == 0) { return DOT; } else { return new Path(result); } }
public ReferencedImplicitElementException(final Object item, final Path path) { super("Cannot reference implicit element"); add("implicit-element", item.toString()); add("referencing-element", path.toString()); } }
/** * Current Path in stream. */ public Path getPath() { if (currentPath == null) { String[] chunks = new String[pointer + 1]; chunks[0] = ""; for (int i = -pointer; ++i <= 0; ) { final String name = peekElement(i); chunks[i + pointer] = name; } currentPath = new Path(chunks); } return currentPath; } }
? createReferenceKey(currentPath, item) : existingReference.getItem(); if (lastPath == null || !currentPath.isAncestor(lastPath)) { fireValidReference(newReferenceKey); lastPath = currentPath;
public Path(String pathAsString) { // String.split() too slow. StringTokenizer too crappy. List result = new ArrayList(); int currentIndex = 0; int nextSeparator; this.pathAsString = pathAsString; while ((nextSeparator = pathAsString.indexOf('/', currentIndex)) != -1) { // normalize explicit paths result.add(normalize(pathAsString, currentIndex, nextSeparator)); currentIndex = nextSeparator + 1; } result.add(normalize(pathAsString,currentIndex,pathAsString.length())); String[] arr = new String[result.size()]; result.toArray(arr); chunks = arr; }
protected String createReference(Path currentPath, Object existingReferenceKey) { return (mode == ReferenceByXPathMarshallingStrategy.RELATIVE ? currentPath.relativeTo((Path)existingReferenceKey) : existingReferenceKey).toString(); }
public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("path", pathTracker.getPath().toString()); super.appendErrors(errorWriter); }
public Path apply(Path relativePath) { FastStack absoluteStack = new FastStack(16); for (int i = 0; i < chunks.length; i++) { absoluteStack.push(chunks[i]); } for (int i = 0; i < relativePath.chunks.length; i++) { String relativeChunk = relativePath.chunks[i]; if (relativeChunk.equals("..")) { absoluteStack.pop(); } else if (!relativeChunk.equals(".")) { absoluteStack.push(relativeChunk); } } String[] result = new String[absoluteStack.size()]; for (int i = 0; i < result.length; i++) { result[i] = (String) absoluteStack.get(i); } return new Path(result); }
public void convert(Object item, Converter converter) { if (getMapper().isImmutableValueType(item.getClass())) { // strings, ints, dates, etc... don't bother using references. converter.marshal(item, writer, this); } else { Path currentPath = pathTracker.getPath(); Object existingReferenceKey = references.lookupId(item); if (existingReferenceKey != null) { String attributeName = getMapper().aliasForSystemAttribute("reference"); if (attributeName != null) { writer.addAttribute(attributeName, createReference(currentPath, existingReferenceKey)); } } else if (implicitElements.lookupId(item) != null) { throw new ReferencedImplicitElementException(item, currentPath); } else { Object newReferenceKey = createReferenceKey(currentPath, item); if (lastPath == null || !currentPath.isAncestor(lastPath)) { fireValidReference(newReferenceKey); lastPath = currentPath; references.associateId(item, newReferenceKey); } else { implicitElements.associateId(item, newReferenceKey); } converter.marshal(item, writer, this); } } }
public Path(final String pathAsString) { // String.split() too slow. StringTokenizer too crappy. final List<String> result = new ArrayList<>(); int currentIndex = 0; int nextSeparator; this.pathAsString = pathAsString; while ((nextSeparator = pathAsString.indexOf('/', currentIndex)) != -1) { // normalize explicit paths result.add(normalize(pathAsString, currentIndex, nextSeparator)); currentIndex = nextSeparator + 1; } result.add(normalize(pathAsString, currentIndex, pathAsString.length())); final String[] arr = new String[result.size()]; result.toArray(arr); chunks = arr; }
protected String createReference(Path currentPath, Object existingReferenceKey) { return (mode == ReferenceByXPathMarshallingStrategy.RELATIVE ? currentPath.relativeTo((Path)existingReferenceKey) : existingReferenceKey).toString(); }
@Override protected String createReference(final Path currentPath, final Path existingReferenceKey) { final Path existingPath = existingReferenceKey; final Path referencePath = (mode & ReferenceByXPathMarshallingStrategy.ABSOLUTE) > 0 ? existingPath : currentPath.relativeTo(existingPath); return (mode & ReferenceByXPathMarshallingStrategy.SINGLE_NODE) > 0 ? referencePath.explicit() : referencePath .toString(); }
@Override protected Path getReferenceKey(final String reference) { final Path path = new Path(isNameEncoding ? ((AbstractReader)reader.underlyingReader()).decodeNode(reference) : reference); // We have absolute references, if path starts with '/' return reference.charAt(0) != '/' ? pathTracker.getPath().apply(path) : path; }
public Path relativeTo(Path that) { int depthOfPathDivergence = depthOfPathDivergence(chunks, that.chunks); String[] result = new String[chunks.length + that.chunks.length - 2 * depthOfPathDivergence]; int count = 0; for (int i = depthOfPathDivergence; i < chunks.length; i++) { result[count++] = ".."; } for (int j = depthOfPathDivergence; j < that.chunks.length; j++) { result[count++] = that.chunks[j]; } if (count == 0) { return DOT; } else { return new Path(result); } }
/** * @deprecated Use {@link #getPath()} instead. */ public String getCurrentPath() { return getPath().toString(); }
/** * Current Path in stream. */ public Path getPath() { if (currentPath == null) { final String[] chunks = new String[pointer + 1]; chunks[0] = ""; for (int i = -pointer; ++i <= 0;) { final String name = peekElement(i); chunks[i + pointer] = name; } currentPath = new Path(chunks); } return currentPath; } }
public void convert(Object item, Converter converter) { if (getMapper().isImmutableValueType(item.getClass())) { // strings, ints, dates, etc... don't bother using references. converter.marshal(item, writer, this); } else { Path currentPath = pathTracker.getPath(); Object existingReferenceKey = references.lookupId(item); if (existingReferenceKey != null) { String attributeName = getMapper().aliasForSystemAttribute("reference"); if (attributeName != null) { writer.addAttribute(attributeName, createReference(currentPath, existingReferenceKey)); } } else if (implicitElements.lookupId(item) != null) { throw new ReferencedImplicitElementException(item, currentPath); } else { Object newReferenceKey = createReferenceKey(currentPath, item); if (lastPath == null || !currentPath.isAncestor(lastPath)) { fireValidReference(newReferenceKey); lastPath = currentPath; references.associateId(item, newReferenceKey); } else { implicitElements.associateId(item, newReferenceKey); } converter.marshal(item, writer, this); } } }
public Path(String pathAsString) { // String.split() too slow. StringTokenizer too crappy. List result = new ArrayList(); int currentIndex = 0; int nextSeparator; this.pathAsString = pathAsString; while ((nextSeparator = pathAsString.indexOf('/', currentIndex)) != -1) { // normalize explicit paths result.add(normalize(pathAsString, currentIndex, nextSeparator)); currentIndex = nextSeparator + 1; } result.add(normalize(pathAsString,currentIndex,pathAsString.length())); String[] arr = new String[result.size()]; result.toArray(arr); chunks = arr; }