Package com.thoughtworks.xstream.io.path

Examples of com.thoughtworks.xstream.io.path.Path


    public void convert(final Object item, final Converter converter) {
        if (getMapper().isImmutableValueType(item.getClass())) {
            // strings, ints, dates, etc... don't bother using references.
            converter.marshal(item, writer, this);
        } else {
            final Path currentPath = pathTracker.getPath();
            final Id<R> existingReference = references.lookupId(item);
            if (existingReference != null && existingReference.getPath() != currentPath) {
                final String attributeName = getMapper().aliasForSystemAttribute("reference");
                if (attributeName != null) {
                    writer.addAttribute(attributeName, createReference(currentPath, existingReference.getItem()));
                }
            } else {
                final R newReferenceKey = existingReference == null
                    ? createReferenceKey(currentPath, item)
                    : existingReference.getItem();
                if (lastPath == null || !currentPath.isAncestor(lastPath)) {
                    fireValidReference(newReferenceKey);
                    lastPath = currentPath;
                    references.associateId(item, new Id<R>(newReferenceKey, currentPath));
                }
                converter.marshal(item, writer, new ReferencingMarshallingContext<R>() {
View Full Code Here


        isNameEncoding = reader.underlyingReader() instanceof AbstractReader;
    }

    @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;
    }
View Full Code Here

        this.mode = mode;
    }

    @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();
    }
View Full Code Here

        super(writer, converterLookup, mapper);
        this.mode = mode;
    }

    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();
    }
View Full Code Here

    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 {
            final Path currentPath = pathTracker.getPath();
            Id existingReference = (Id)references.lookupId(item);
            if (existingReference != null && existingReference.getPath() != currentPath) {
                String attributeName = getMapper().aliasForSystemAttribute("reference");
                if (attributeName != null) {
                    writer.addAttribute(attributeName, createReference(currentPath, existingReference.getItem()));
                }
            } else {
                final Object newReferenceKey = existingReference == null
                    ? createReferenceKey(currentPath, item)
                    : existingReference.getItem();
                if (lastPath == null || !currentPath.isAncestor(lastPath)) {
                    fireValidReference(newReferenceKey);
                    lastPath = currentPath;
                    references.associateId(item, new Id(newReferenceKey, currentPath));
                }
                converter.marshal(item, writer, new ReferencingMarshallingContext() {
View Full Code Here

        this.reader = new PathTrackingReader(reader, pathTracker);
        isNameEncoding = reader.underlyingReader() instanceof AbstractReader;
    }

    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;
    }
View Full Code Here

    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) {
                if (implicitElements.contains(existingReferenceKey)) {
                    throw new ReferencedImplicitElementException("Cannot reference implicit element: " + item.toString());
                }
                writer.addAttribute(getMapper().aliasForAttribute("reference"), createReference(currentPath, existingReferenceKey));
            } else {
                Object newReferenceKey = createReferenceKey(currentPath);
                if (lastPath == null || !currentPath.isAncestor(lastPath)) {
                    fireValidReference(newReferenceKey);
                    lastPath = currentPath;
                } else {
                    implicitElements.add(newReferenceKey);
                }
View Full Code Here

                                        ConverterLookup converterLookup, ClassMapper classMapper) {
        this(root, reader, converterLookup, (Mapper)classMapper);
    }

    protected Object getReferenceKey(String reference) {
        final Path path = new Path(reference);
        // We have absolute references, if path starts with '/'
        return reference.charAt(0) != '/' ? pathTracker.getPath().apply(path) : path;
    }
View Full Code Here

    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);
View Full Code Here

                                        ConverterLookup converterLookup, ClassMapper classMapper) {
        this(root, reader, converterLookup, (Mapper)classMapper);
    }

    protected Object getReferenceKey(String reference) {
        final Path path = new Path(isXmlFriendly ? ((XmlFriendlyReader)reader.underlyingReader()).unescapeXmlName(reference) : reference);
        // We have absolute references, if path starts with '/'
        return reference.charAt(0) != '/' ? pathTracker.getPath().apply(path) : path;
    }
View Full Code Here

TOP

Related Classes of com.thoughtworks.xstream.io.path.Path

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.