org.xmlbeam.XBProjector - java examples

Here are the examples of the java api org.xmlbeam.XBProjector taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

59 Examples 7

19 View Complete Implementation : TestBug51ClassCastException.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testSetChildOnParentAsDoreplacedentRoot() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    ParentNoRootElement parent = projector.projectEmptyDoreplacedent(ParentNoRootElement.clreplaced);
    Child child = projector.projectEmptyElement("Child", Child.clreplaced);
    child.setData("child data...");
    parent.setChild(child);
    System.out.println("Result: " + parent);
}

19 View Complete Implementation : TestProjectionWithFormats.java
Copyright Apache License 2.0
Author : SvenEwald
@Before
public void init() throws IOException {
    final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    projector.config().as(DefaultXMLFactoriesConfig.clreplaced).setPrettyPrinting(false);
    projection = projector.projectEmptyDoreplacedent(ProjectionWithFormats.clreplaced);
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionNestedNoChild() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setConditionNestedNoChild("Value");
    replacedertXMLStringsEquals("<Root>\n" + "   <Intermediate>\n" + "      <X>\n" + "         <Y>Preplaceded</Y>\n" + "      </X>\n" + "      Value\n" + "   </Intermediate>\n" + "</Root>\n", test.toString());
}

19 View Complete Implementation : XBTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void object2Xml() {
    XBProjector projector = new XBProjector();
    BaseObject baseObject = projector.projectEmptyDoreplacedent(BaseObject.clreplaced);
    baseObject.setId(1);
    baseObject.setColor(123);
    SubObject subObject = projector.projectEmptyElement("SubObject", SubObject.clreplaced);
    subObject.setId(456);
    subObject.setText("The text");
    List<SubObject> subs = new ArrayList<SubObject>();
    subs.add(subObject);
    baseObject.setSubObjects(subs);
    String xml = projector.replacedtring(baseObject);
    System.out.println(xml);
    // OK
    replacedertTrue(xml.contains("123"));
    // fails!
    replacedertTrue(xml.contains("456"));
}

19 View Complete Implementation : TestCustomTypeConversion.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testApplyOffsetToCoordinates() throws IOException {
    XBProjector projector = new XBProjector(new DefaultXMLFactoriesConfig().setNamespacePhilosophy(NamespacePhilosophy.AGNOSTIC));
    DefaultTypeConverter converter = new DefaultTypeConverter(Locale.getDefault(), TimeZone.getDefault()).setConversionForType(CoordinateList.clreplaced, new CoordinateListConversion());
    projector.config().setTypeConverter(converter);
    KML kml = projector.io().fromURLAnnotation(KML.clreplaced);
    // Extract the list of coordinates
    CoordinateList coordinates = kml.getCoordinates();
    replacedertTrue(coordinates.iterator().hasNext());
    // Apply some offset
    for (Coordinate a : coordinates) {
        a.setX(a.getX() + 10);
    }
    // Set the list again
    kml.setCoordinates(coordinates);
}

19 View Complete Implementation : XBAutoMapRefCardTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void textCreateXMLByMap() {
    // START SNIPPET: ProjectedMapRefCardExample3
    XBProjector projector = new XBProjector();
    Map<String, Integer> map = projector.autoMapEmptyDoreplacedent(Integer.clreplaced);
    map.put("/root/foo/@bar", 13);
    System.out.println(projector.replacedtring(map));
// END SNIPPET: ProjectedMapRefCardExample3
}

19 View Complete Implementation : TestBug53NPEWhenSettingDocAsElement.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testSetEmptyChildNonEmptyParent() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    ParentWithRootElement parent = projector.projectEmptyDoreplacedent(ParentWithRootElement.clreplaced);
    parent.setData("parent data...");
    Child child = projector.projectEmptyElement("Child", Child.clreplaced);
    // Child child = projector.projectEmptyDoreplacedent(Child.clreplaced);
    // child.setData(""); // Uncommenting fixes NPE error (replacedertion will fail of course, but that's fine)
    parent.setChild(child);
    /* Throws
        java.lang.NullPointerException
            at org.xmlbeam.ProjectionInvocationHandler$WriteInvocationHandler.invokeProjection(ProjectionInvocationHandler.java:659)
            at org.xmlbeam.ProjectionInvocationHandler$ProjectionMethodInvocationHandler.invoke(ProjectionInvocationHandler.java:206)
            at org.xmlbeam.ProjectionInvocationHandler.invoke(ProjectionInvocationHandler.java:879)
            at com.sun.proxy.$Proxy5.setChild(Unknown Source)
         */
    // replacedertEquals(
    // "<Root>\n"
    // + "   <ParentData>parent data...</ParentData>\n"
    // + "</Root>",
    // parent.toString());
    // 
    System.out.println("Result: " + parent);
}

19 View Complete Implementation : IOHelper.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @param projector
 * @param is
 *            anonymous input stream
 * @return Doreplacedent
 */
public static Doreplacedent loadDoreplacedent(final XBProjector projector, final InputStream is) {
    final DoreplacedentBuilder doreplacedentBuilder = projector.config().createDoreplacedentBuilder();
    try {
        return doreplacedentBuilder.parse(is, "");
    } catch (SAXException e) {
        throw new XBDoreplacedentParsingException(e);
    } catch (IOException e) {
        throw new XBIOException("Error during doreplacedent loading", e);
    }
}

19 View Complete Implementation : TestCustomTypeConverter.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testAutoHexConversion() {
    XBProjector projector = new XBProjector();
    DefaultTypeConverter converter = projector.config().getTypeConverterAs(DefaultTypeConverter.clreplaced);
    converter.setConversionForType(Long.TYPE, new HexToLongConversion(0L));
    Projection projection = projector.projectXMLString("<foo>CAFEBABE</foo>", Projection.clreplaced);
    replacedertEquals(3405691582L, projection.getData());
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionNestedWithChild() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setConditionNestedWithChild("Value");
    replacedertXMLStringsEquals("<Root>\n" + "   <X>\n" + "      <Y>Preplaceded</Y>\n" + "   </X>\n" + "   <Child>Value</Child>\n" + "</Root>\n", test.toString());
}

19 View Complete Implementation : MetsManifestBuilder.java
Copyright GNU General Public License v3.0
Author : ubleipzig
/**
 * @param url File
 * @return MetsData
 */
static MetsData getMetsFromFile(final File url) {
    try {
        final XBProjector projector = new XBProjector(TO_STRING_RENDERS_XML);
        return projector.io().file(url).read(MetsData.clreplaced);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Cannot Read XML: " + e.getMessage());
    }
}

19 View Complete Implementation : TestSchemaHandling.java
Copyright Apache License 2.0
Author : SvenEwald
@Before
public void readVegetables() throws Exception {
    XBProjector projector = new XBProjector(new DefaultXMLFactoriesConfig() {

        private static final long serialVersionUID = 1L;

        @Override
        public DoreplacedentBuilderFactory createDoreplacedentBuilderFactory() {
            DoreplacedentBuilderFactory factory = super.createDoreplacedentBuilderFactory();
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            try {
                Schema schema = schemaFactory.newSchema(getClreplaced().getResource("schema.xsd"));
                factory.setSchema(schema);
            } catch (SAXException e) {
                throw new RuntimeException("Error loading schema", e);
            }
            return factory;
        }
    });
    vegetables = projector.io().fromURLAnnotation(Vegetables.clreplaced);
}

19 View Complete Implementation : NSDemoTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testNoNamespacedElementAccess() throws IOException {
    XBProjector projector = new XBProjector(new DefaultXMLFactoriesConfig() {

        @Override
        public DoreplacedentBuilderFactory createDoreplacedentBuilderFactory() {
            DoreplacedentBuilderFactory instance = DoreplacedentBuilderFactory.newInstance();
            instance.setNamespaceAware(false);
            return instance;
        }
    });
    projector.config().as(DefaultXMLFactoriesConfig.clreplaced).setNamespacePhilosophy(NamespacePhilosophy.AGNOSTIC);
    NameSpaceProjection projection = projector.io().fromURLAnnotation(NameSpaceProjection.clreplaced);
    replacedertTrue(projection.getTable().contains("African Coffee Table"));
    replacedertNull(projection.getNamepsacedTable());
    replacedertNull(projection.getDefaultNamepsacedTable());
// System.out.println(projection.getTable());
// System.out.println(projection.getNamepsacedTable());
// System.out.println(projection.getDefaultNamepsacedTable());
}

19 View Complete Implementation : XBTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void xml2Object() throws IOException {
    XBProjector projector = new XBProjector();
    BaseObject fromFile = projector.io().file("src/test/java/org/xmlbeam/tests/bugs/bug54/xb.xml").read(BaseObject.clreplaced);
    replacedertEquals(1, fromFile.getId());
    replacedertEquals(5, fromFile.getColor());
    SubObject subObject = fromFile.getSubObjects().get(0);
    replacedertEquals(2, subObject.getId());
    replacedertEquals("The description", subObject.getText());
}

19 View Complete Implementation : FAQSnippetsTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void unCamelCaseTest() {
    XBProjector projector = new XBProjector();
    projector.config().setExternalizer(new ExternalizerAdapter() {

        @Override
        public String resolveXPath(final String annotationValue, final Method method, final Object[] args) {
            // Simplest conversion of camel case getter to xpath expression.
            return method.getName().substring(3).replaceAll("[A-Z]", "/$0");
        }
    });
    List<String> departmentUsers = projector.projectXMLString("<Department><Users><Name>John Doe</Name><Name>Tommy Atkins</Name></Users></Department>", ExampleProjection.clreplaced).getDepartmentUsersName();
    replacedertTrue(departmentUsers.size() == 2);
    replacedertEquals("John Doe", departmentUsers.get(0));
    replacedertEquals("Tommy Atkins", departmentUsers.get(1));
}

19 View Complete Implementation : TestBug52IntermediateElementMissing.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testSetChildProjectionEmptyParent() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    ParentWithRootElement parent = projector.projectEmptyDoreplacedent(ParentWithRootElement.clreplaced);
    // Child child = projector.projectEmptyDoreplacedent(Child.clreplaced);
    Child child = projector.projectEmptyElement("Child", Child.clreplaced);
    child.setData("child data...");
    parent.setChild(child);
    System.out.println("Result: " + parent);
    // Doesn't generate <Child> intermediate level
    DOMDiagnoseHelper.replacedertXMLStringsEquals("<Root>\n" + "  <Child>\n" + "    <ChildData>child data...</ChildData>\n" + "  </Child>\n" + "</Root>".replaceAll(" ", ""), parent.toString());
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionSingleLevelOnRootNoChild() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setConditionSingleLevelOnRootNoChild("Value");
    replacedertXMLStringsEquals(("<Root>\n" + "   <X>Preplaceded</X>\n" + "   Value\n" + "</Root>\n"), test.toString());
}

19 View Complete Implementation : TestFloatReturnsNull.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testIssue19() {
    final XBProjector projector = new XBProjector();
    Conversion<Float> floatConversion = new Conversion<Float>(null) {

        @Override
        public Float convert(final String data) {
            return Float.valueOf(data);
        }
    };
    projector.config().getTypeConverterAs(DefaultTypeConverter.clreplaced).setConversionForType(Float.clreplaced, floatConversion);
    final Issue19 issue19 = projector.projectXMLString("<foo/>", Issue19.clreplaced);
    replacedertNull(issue19.getFloat());
}

19 View Complete Implementation : InvocationContext.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * Context of an projection method invocation. May be cached if the the same method is called again.
 */
public clreplaced InvocationContext {

    /**
     * @return resolved XPath string.
     */
    public String getResolvedXPath() {
        return resolvedXPath;
    }

    /**
     * @return currently used XPath instance
     */
    public XPath getxPath() {
        return xPath;
    }

    /**
     * @return compiled XPath expression
     */
    public XPathExpression getxPathExpression() {
        return xPathExpression;
    }

    /**
     * @return compiled duplex expression
     */
    public DuplexExpression getDuplexExpression() {
        return duplexExpression;
    }

    /**
     * Constructor.
     *
     * @param resolvedXPath
     * @param xPath
     * @param xPathExpression
     * @param duplexExpression
     * @param resolver
     * @param targetComponentType
     * @param projector
     */
    public InvocationContext(final String resolvedXPath, final XPath xPath, final XPathExpression xPathExpression, final DuplexExpression duplexExpression, final MethodParamVariableResolver resolver, final Clreplaced<?> targetComponentType, final XBProjector projector) {
        this.resolvedXPath = resolvedXPath;
        this.xPath = xPath;
        this.xPathExpression = xPathExpression;
        this.duplexExpression = duplexExpression;
        this.resolver = resolver;
        this.targetComponentType = targetComponentType;
        this.projector = projector;
    }

    final String resolvedXPath;

    final XPath xPath;

    final XPathExpression xPathExpression;

    final DuplexExpression duplexExpression;

    final MethodParamVariableResolver resolver;

    final Clreplaced<?> targetComponentType;

    final XBProjector projector;

    /**
     * @param resolvedXpath
     * @return true if this invocation context may be reused for given path
     */
    public boolean isStillValid(final String resolvedXpath) {
        return resolvedXpath.equals(this.resolvedXPath);
    }

    /**
     * @return Format pattern for the expression within with this context.
     */
    public String getExpressionFormatPattern() {
        if (duplexExpression == null) {
            return null;
        }
        return duplexExpression.getExpressionFormatPattern();
    }

    /**
     * A context may be reused even when method parameters change. But the change needs to be
     * reflected to XPath variable bindings.
     *
     * @param args
     */
    public void updateMethodArgs(final Object[] args) {
        if (resolver != null) {
            resolver.updateArgs(args);
        }
    }

    /**
     * @return target type of evaluation
     */
    public Clreplaced<?> getTargetComponentType() {
        return targetComponentType;
    }

    /**
     * Projector used when the projection was created.
     *
     * @return the projector instance.
     */
    public XBProjector getProjector() {
        return projector;
    }

    /**
     * @param duplexExpression2
     */
    public void useDuplexExpression(final DuplexExpression duplexExpression2) {
    // TODO Auto-generated method stub
    }
}

19 View Complete Implementation : TestIOBehavior.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testFileIO() throws IOException {
    XBProjector projector = new XBProjector(new DefaultXMLFactoriesConfig().setPrettyPrinting(false));
    FooProjection p = projector.projectXMLString("<foo><bar/></foo>", FooProjection.clreplaced);
    File tempFile = File.createTempFile(this.getClreplaced().getSimpleName(), Long.toBinaryString(System.currentTimeMillis()));
    {
        projector.io().file(tempFile).write(p);
        replacedertEquals(17, tempFile.length());
    }
    {
        FooProjection p2 = new XBProjector().io().file(tempFile).read(FooProjection.clreplaced);
        replacedertEquals(p, p2);
    }
    {
        int count = new XBProjector().io().file(tempFile).evalXPath("count(//bar)").asInt();
        replacedertEquals(1, count);
    }
    {
        projector.io().file(tempFile).setAppend(true).write(p);
        replacedertEquals(34, tempFile.length());
    }
    {
        projector.io().file(tempFile).setAppend(false).write(p);
        replacedertEquals(17, tempFile.length());
    }
    tempFile.delete();
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionSingleLevelOnIntermediateNoChild() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setConditionSingleLevelOnIntermediateNoChild("Value");
    replacedertXMLStringsEquals("<Root>\n" + "   <Intermediate>\n" + "      <X>Preplaceded</X>\n" + "      Value\n" + "   </Intermediate>\n" + "</Root>\n", test.toString());
}

19 View Complete Implementation : TestDom4jMimicry.java
Copyright Apache License 2.0
Author : SvenEwald
/* START SNIPPET: TutorialDescription
~~
 In this tutorial we make extensive use of XPath to mimicry an existing 3rd Party-API.
END SNIPPET: TutorialDescription */
@Test
public void testAPIMimicry() throws IOException {
    // START SNIPPET:TestDom4jMimicry
    XBProjector projector = new XBProjector();
    Doreplacedent doreplacedent = projector.io().fromURLAnnotation(Doreplacedent.clreplaced);
    Element element = doreplacedent.getRootElement();
    System.out.println(element.getName());
    Element element2 = element.element("eelement");
    System.out.println(element2.getText());
    Attribute attribute = element2.attribute("eattribute");
    System.out.println(attribute.getValue());
    org.w3c.dom.Element newRootNode = ((DOMAccess) doreplacedent).getDOMOwnerDoreplacedent().createElement("newRoot");
    Element newRootElement = projector.projectDOMNode(newRootNode, Element.clreplaced);
    doreplacedent.setRootElement(newRootElement);
    System.out.println(doreplacedent);
// END SNIPPET:TestDom4jMimicry
}

19 View Complete Implementation : DefaultXPathEvaluator.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * This clreplaced is used to provide an fluid interface for direct evaluation of XPath expressions.
 *
 * @author sven
 */
public final clreplaced DefaultXPathEvaluator implements XPathEvaluator {

    private final DoreplacedentResolver doreplacedentProvider;

    private final DuplexExpression duplexExpression;

    private final XBProjector projector;

    /**
     * Constructor for DefaultXPathEvaluator.
     *
     * @param projector
     * @param doreplacedentProvider
     * @param xpath
     */
    public DefaultXPathEvaluator(final XBProjector projector, final DoreplacedentResolver doreplacedentProvider, final String xpath) {
        this.projector = projector;
        this.doreplacedentProvider = doreplacedentProvider;
        this.duplexExpression = new DuplexXPathParser(projector.config().getUserDefinedNamespaceMapping()).compile(xpath);
    }

    /**
     * Evaluates the XPath as a boolean value. This method is just a shortcut for as(Boolean.TYPE);
     *
     * @return true when the selected value equals (ignoring case) 'true'
     */
    @Override
    public boolean asBoolean() {
        final Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        return evaluateSingeValue(Boolean.TYPE, callerClreplaced);
    }

    /**
     * Evaluates the XPath as a int value. This method is just a shortcut for as(Integer.TYPE);
     *
     * @return int value of evaluation result.
     */
    @Override
    public int asInt() {
        final Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        return evaluateSingeValue(Integer.TYPE, callerClreplaced);
    }

    /**
     * Evaluates the XPath as a String value. This method is just a shortcut for as(String.clreplaced);
     *
     * @return String value of evaluation result.
     */
    @Override
    public String replacedtring() {
        final Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        return evaluateSingeValue(String.clreplaced, callerClreplaced);
    }

    /**
     * Evaluates the XPath as a Date value. This method is just a shortcut for as(Date.clreplaced); You
     * probably want to specify ' using ' followed by some formatting pattern consecutive to the
     * XPAth.
     *
     * @return Date value of evaluation result.
     */
    @Override
    public Date asDate() {
        final Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        return evaluateSingeValue(Date.clreplaced, callerClreplaced);
    }

    /**
     * Evaluate the XPath as a value of the given type.
     *
     * @param returnType
     *            Possible values: primitive types (e.g. Short.Type), Projection interfaces, any
     *            clreplaced with a String constructor or a String factory method, and org.w3c.Node
     * @return a value of return type that reflects the evaluation result.
     */
    @Override
    public <T> T as(final Clreplaced<T> returnType) {
        validateEvaluationType(returnType);
        final Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        return evaluateSingeValue(returnType, callerClreplaced);
    }

    @SuppressWarnings("unchecked")
    private <T> T evaluateSingeValue(final Clreplaced<T> returnType, final Clreplaced<?> callerClreplaced) {
        try {
            final Doreplacedent doreplacedent = doreplacedentProvider.resolve(returnType, callerClreplaced);
            final XPathExpression expression = projector.config().createXPath(doreplacedent).compile(duplexExpression.getExpressionreplacedtringWithoutFormatPatterns());
            if (projector.config().getTypeConverter().isConvertable(returnType)) {
                String data;
                if (duplexExpression.getExpressionType().isMustEvalreplacedtring()) {
                    data = (String) expression.evaluate(doreplacedent, XPathConstants.STRING);
                } else {
                    Node dataNode = (Node) expression.evaluate(doreplacedent, XPathConstants.NODE);
                    data = dataNode == null ? null : dataNode.getTextContent();
                }
                if ((data == null) && (projector.getFlags().contains(Flags.ABSENT_IS_EMPTY))) {
                    data = "";
                }
                final Object result = projector.config().getTypeConverter().convertTo(returnType, data, duplexExpression.getExpressionFormatPattern());
                return (T) result;
            }
            if (Node.clreplaced.isreplacedignableFrom(returnType)) {
                final Object result = expression.evaluate(doreplacedent, XPathConstants.NODE);
                return (T) result;
            }
            if (returnType.isInterface()) {
                final Node node = (Node) expression.evaluate(doreplacedent, XPathConstants.NODE);
                if (node == null) {
                    return null;
                }
                return projector.projectDOMNode(node, returnType);
            }
        } catch (XPathExpressionException e) {
            throw new XBPathException(e, duplexExpression.getExpressionreplacedtringWithoutFormatPatterns());
        } catch (IOException e) {
            throw new XBIOException(e);
        }
        throw new IllegalPathStateException();
    }

    private <T> void validateEvaluationType(final Clreplaced<T> returnType) {
        if (ReflectionHelper.isOptional(returnType)) {
            throw new IllegalArgumentException("Type Optional is only allowed as a method return type.");
        }
        if (Collection.clreplaced.isreplacedignableFrom(returnType)) {
            throw new IllegalArgumentException("A collection type can not be component type.");
        }
    }

    /**
     * Evaluate the XPath as an array of the given type.
     *
     * @param componentType
     *            Possible values: primitive types (e.g. Short.Type), Projection interfaces, any
     *            clreplaced with a String constructor or a String factory method, and org.w3c.Node
     * @return an array of return type that reflects the evaluation result.
     */
    @SuppressWarnings("unchecked")
    @Override
    public <T> T[] asArrayOf(final Clreplaced<T> componentType) {
        Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        List<T> list = evaluateMultiValues(componentType, callerClreplaced);
        return list.toArray((T[]) java.lang.reflect.Array.newInstance(componentType, list.size()));
    }

    /**
     * Evaluate the XPath as a list of the given type.
     *
     * @param componentType
     *            Possible values: primitive types (e.g. Short.Type), Projection interfaces, any
     *            clreplaced with a String constructor or a String factory method, and org.w3c.Node
     * @return List of return type that reflects the evaluation result.
     */
    @Override
    public <T> List<T> asListOf(final Clreplaced<T> componentType) {
        Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        return evaluateMultiValues(componentType, callerClreplaced);
    }

    @SuppressWarnings("unchecked")
    private <T> List<T> evaluateMultiValues(final Clreplaced<T> componentType, final Clreplaced<?> callerClreplaced) {
        validateEvaluationType(componentType);
        try {
            Doreplacedent doreplacedent = doreplacedentProvider.resolve(componentType, callerClreplaced);
            XPathExpression expression = projector.config().createXPath(doreplacedent).compile(duplexExpression.getExpressionreplacedtringWithoutFormatPatterns());
            InvocationContext invocationContext = new InvocationContext(null, null, expression, duplexExpression, null, componentType, projector);
            return (List<T>) evaluateAsList(expression, doreplacedent, null, invocationContext);
        } catch (XPathExpressionException e) {
            throw new XBPathException(e, duplexExpression.getExpressionreplacedtringWithoutFormatPatterns());
        } catch (IOException e) {
            throw new XBIOException(e);
        }
    }

    /**
     * Perform an XPath evaluation on an invocation context.
     *
     * @param expression
     * @param node
     * @param method
     * @param invocationContext
     * @return a list of evaluation results
     * @throws XPathExpressionException
     */
    public static List<?> evaluateAsList(final XPathExpression expression, final Node node, final Method method, final InvocationContext invocationContext) throws XPathExpressionException {
        // replacedert targetComponentType != null;
        final Clreplaced<?> targetComponentType = invocationContext.getTargetComponentType();
        final NodeList nodes = (NodeList) expression.evaluate(node, XPathConstants.NODESET);
        final List<Object> linkedList = new LinkedList<Object>();
        final TypeConverter typeConverter = invocationContext.getProjector().config().getTypeConverter();
        if (typeConverter.isConvertable(targetComponentType)) {
            for (int i = 0; i < nodes.getLength(); ++i) {
                linkedList.add(typeConverter.convertTo(targetComponentType, nodes.item(i).getTextContent(), invocationContext.getExpressionFormatPattern()));
            }
            return linkedList;
        }
        if (Node.clreplaced.equals(targetComponentType)) {
            for (int i = 0; i < nodes.getLength(); ++i) {
                linkedList.add(nodes.item(i));
            }
            return linkedList;
        }
        if (targetComponentType.isInterface()) {
            for (int i = 0; i < nodes.getLength(); ++i) {
                Object subprojection = invocationContext.getProjector().projectDOMNode(nodes.item(i), targetComponentType);
                linkedList.add(subprojection);
            }
            return linkedList;
        }
        throw new IllegalArgumentException("Return type " + targetComponentType + " is not valid for list or array component type returning from method " + method + " using the current type converter:" + invocationContext.getProjector().config().getTypeConverter() + ". Please change the return type to a sub projection or add a conversion to the type converter.");
    }

    /**
     * @param invocationContext
     *            invocation context
     * @param item
     * @param targetComponentType
     * @return node content as target type
     */
    @SuppressWarnings("unchecked")
    public static <E> E convertToComponentType(final InvocationContext invocationContext, final Node item, final Clreplaced<?> targetComponentType) {
        TypeConverter typeConverter = invocationContext.getProjector().config().getTypeConverter();
        if (typeConverter.isConvertable(invocationContext.getTargetComponentType())) {
            return (E) typeConverter.convertTo(targetComponentType, item != null ? DOMHelper.directTextContent(item) : null, invocationContext.getExpressionFormatPattern());
        }
        if (Node.clreplaced.equals(targetComponentType)) {
            return (E) item;
        }
        if (targetComponentType.isInterface()) {
            if (item == null) {
                return null;
            }
            Object subprojection = invocationContext.getProjector().projectDOMNode(item, targetComponentType);
            return (E) subprojection;
        }
        throw new IllegalArgumentException("Return type " + targetComponentType + " is not valid for a ProjectedList using the current type converter:" + invocationContext.getProjector().config().getTypeConverter() + ". Please change the return type to a sub projection or add a conversion to the type converter.");
    }

    /**
     * @param componentType
     * @return map bound to the element resolved by XPath.
     * @see org.xmlbeam.evaluation.XPathEvaluator#asMapOf(java.lang.Clreplaced)
     */
    @Override
    public <T> XBAutoMap<T> asMapOf(final Clreplaced<T> componentType) {
        try {
            final Clreplaced<?> callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
            Doreplacedent doreplacedent = doreplacedentProvider.resolve(componentType, callerClreplaced);
            final String resolvedXPath = duplexExpression.getExpressionreplacedtringWithoutFormatPatterns();
            final XPath xpath = projector.config().createXPath(doreplacedent);
            XPathExpression expression = xpath.compile(resolvedXPath);
            // final Node baseNode = (Node) expression.evaluate(doreplacedent, XPathConstants.NODE);
            // if (baseNode.getNodeType() != Node.ELEMENT_NODE) {
            // throw new XBException("XPath expression does not resolve to an element. Maps can only be created for elements.");
            // }
            InvocationContext invocationContext = new InvocationContext(resolvedXPath, xpath, expression, duplexExpression, null, componentType, projector);
            return new AutoMap<T>(doreplacedent, invocationContext, componentType);
        } catch (IOException e) {
            throw new XBIOException(e);
        } catch (XPathExpressionException e) {
            throw new XBPathException(e, duplexExpression.getExpressionreplacedtringWithoutFormatPatterns());
        }
    }
}

19 View Complete Implementation : TestPlistAccess.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testReadPList() throws IOException {
    final XBProjector projector = new XBProjector(new NonValidatingXMLFactoriesConfig());
    projector.config().setExternalizer(new PListExternalizer());
    final PList plist = projector.io().fromURLAnnotation(PList.clreplaced);
    System.out.println(plist.getAuthor() + " (" + plist.getBirthdate() + ")");
    for (final String line : plist.getLines()) {
        System.out.println(line);
    }
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionSingleLevelOnIntermediateWithChild() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setConditionSingleLevelOnIntermediateWithChild("Value");
    replacedertXMLStringsEquals("<Root>\n" + "<Intermediate>\n" + "<X>Preplaceded</X>\n" + "<Child>Value</Child>\n" + "</Intermediate>\n" + "</Root>\n", test.toString());
}

19 View Complete Implementation : TestXPathParsing.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testXPathParsing() throws Exception {
    // String xpath = "let $incr :=       function($n) {$n+1}  \n return $incr(2)";
    // if ((before!=null) && (before.getDOMNode()!=null)) {
    // Node node = before.getDOMNode().cloneNode(true);
    // doreplacedent.adoptNode(node);
    // doreplacedent.appendChild(node);
    // }
    doreplacedent = before.getDOMOwnerDoreplacedent();
    // String xpath = "/hoo[@id='wutz']/foo/loo";
    createByXParser(xpath, value);
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML, Flags.ABSENT_IS_EMPTY);
    Projection result = projector.projectDOMNode(doreplacedent, Projection.clreplaced);
    after.getDOMNode().normalize();
    result.getDOMNode().normalize();
    DOMHelper.trim(after.getDOMNode());
    DOMHelper.trim(result.getDOMNode());
    after.getDOMOwnerDoreplacedent().normalizeDoreplacedent();
    result.getDOMOwnerDoreplacedent().normalizeDoreplacedent();
    DOMHelper.nodesAreEqual(after.getDOMNode(), result.getDOMNode());
    replacedertEquals(after.toString(), result.toString());
}

19 View Complete Implementation : ComposeSVGDocTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testSVGComposition() throws IOException {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    Rect rect = projector.io().fromURLAnnotation(Rect.clreplaced);
    Circle circle = projector.io().fromURLAnnotation(Circle.clreplaced);
    Ellipse ellipse = projector.io().fromURLAnnotation(Ellipse.clreplaced);
    List<Shape> shapes = new LinkedList<Shape>();
    shapes.add(rect.setX(10).setY(120));
    shapes.add(circle.setX(60).setY(60));
    shapes.add(ellipse.setX(180).setY(120));
    SVG svgDoc = projector.io().fromURLAnnotation(SVG.clreplaced);
    svgDoc.setShapes(shapes);
    System.out.println(svgDoc.toString());
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionNestedNoChild2() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setPathInPredicate2("Value");
    replacedertEquals("Value", test.getPathInPredicate2());
    replacedertXMLStringsEquals(("<someroot>\n" + "  <elements>\n" + "    <with>\n" + "      <subelement>oink</subelement>\n" + "    </with>\n" + "    <element3>Value</element3>\n" + "  </elements>\n" + "</someroot>"), test.toString());
}

19 View Complete Implementation : MetsManifestBuilder.java
Copyright GNU General Public License v3.0
Author : ubleipzig
/**
 * getMetsFromFile.
 *
 * @param url String
 * @return XBProjector
 */
static MetsData getMetsFromFile(final String url) {
    try {
        final XBProjector projector = new XBProjector(TO_STRING_RENDERS_XML);
        return projector.io().file(url).read(MetsData.clreplaced);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Cannot Read XML: " + e.getMessage());
    }
}

19 View Complete Implementation : UrlIO.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author <a href="https://github.com/SvenEwald">Sven Ewald</a>
 */
public clreplaced UrlIO implements CanEvaluate {

    private final XBProjector projector;

    private final Map<String, String> requestProperties = new HashMap<String, String>();

    private final String url;

    /**
     * Constructor with defaults for request parameters.
     *
     * @param projector
     * @param url
     */
    public UrlIO(final XBProjector projector, final String url) {
        this.projector = projector;
        this.url = url;
        requestProperties.put("Content-Type", "text/xml");
    }

    /**
     * Create a new projection using a given URL parameter. When the URL starts with the protocol
     * identifier "resource://" the clreplacedloader of projection interface will be used to read the
     * resource from the current clreplaced path.
     *
     * @param projectionInterface
     *            A Java interface to project the data on.
     * @return a new projection instance.
     * @throws IOException
     */
    @Scope(DocScope.IO)
    public <T> T read(final Clreplaced<T> projectionInterface) throws IOException {
        Clreplaced<?> callerClreplaced = null;
        if (IOHelper.isResourceProtocol(url)) {
            callerClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        }
        Doreplacedent doreplacedent = IOHelper.getDoreplacedentFromURL(projector.config().createDoreplacedentBuilder(), url, requestProperties, projectionInterface, callerClreplaced);
        return projector.projectDOMNode(doreplacedent, projectionInterface);
    }

    /**
     * Post the projected doreplacedent to a HTTP URL. The response is provided as a raw string.
     *
     * @param projection
     * @return response as String
     * @throws IOException
     */
    @SuppressWarnings("unchecked")
    @Scope(DocScope.IO)
    public String write(final Object projection) throws IOException {
        return IOHelper.inputStreamToString(IOHelper.httpPost(url, projection.toString(), requestProperties));
    }

    /**
     * Allows to add some request properties.
     *
     * @param params
     * @return this for convenience.
     */
    @Scope(DocScope.IO)
    public UrlIO addRequestProperties(final Map<String, String> params) {
        requestProperties.putAll(params);
        return this;
    }

    /**
     * Allows to add a single request property.
     *
     * @param name
     * @param value
     * @return this for convenience.
     */
    @Scope(DocScope.IO)
    public UrlIO addRequestProperty(final String name, final String value) {
        requestProperties.put(name, value);
        return this;
    }

    /**
     * Evaluate XPath on the url doreplacedent.
     *
     * @param xpath
     * @return xpath evaluator
     * @see org.xmlbeam.evaluation.CanEvaluate#evalXPath(java.lang.String)
     */
    @Override
    @Scope(DocScope.IO)
    public XPathEvaluator evalXPath(final String xpath) {
        return new DefaultXPathEvaluator(projector, new DoreplacedentResolver() {

            @Override
            public Doreplacedent resolve(final Clreplaced<?>... resourceAwareClreplacedes) throws IOException {
                return IOHelper.getDoreplacedentFromURL(projector.config().createDoreplacedentBuilder(), url, requestProperties, resourceAwareClreplacedes);
            }
        }, xpath);
    }

    /**
     * Read complete doreplacedent to a Map.
     *
     * @param valueType
     * @return Closeable map bound to complete doreplacedent.
     * @throws IOException
     */
    @Scope(DocScope.IO)
    public <T> XBAutoMap<T> readAsMapOf(final Clreplaced<T> valueType) throws IOException {
        DefaultXPathBinder.validateEvaluationType(valueType);
        final Clreplaced<?> resourceAwareClreplaced = ReflectionHelper.getDirectCallerClreplaced();
        Doreplacedent doreplacedent = IOHelper.getDoreplacedentFromURL(projector.config().createDoreplacedentBuilder(), url, requestProperties, resourceAwareClreplaced);
        InvocationContext invocationContext = new InvocationContext(null, null, null, null, null, valueType, projector);
        return new AutoMap<T>(doreplacedent, invocationContext, valueType);
    }
}

19 View Complete Implementation : StreamInput.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author <a href="https://github.com/SvenEwald">Sven Ewald</a>
 */
public clreplaced StreamInput implements CanEvaluate {

    private final XBProjector projector;

    private final InputStream is;

    private String systemID;

    /**
     * @param xmlProjector
     * @param is
     */
    public StreamInput(final XBProjector xmlProjector, final InputStream is) {
        this.projector = xmlProjector;
        this.is = is;
    }

    /**
     * Create a new projection by parsing the data provided by the input stream.
     *
     * @param projectionInterface
     *            A Java interface to project the data on.
     * @return a new projection instance pointing to the stream content.
     * @throws IOException
     */
    @Scope(DocScope.IO)
    public <T> T read(final Clreplaced<T> projectionInterface) throws IOException {
        Doreplacedent doreplacedent = readDoreplacedent();
        return projector.projectDOMNode(doreplacedent, projectionInterface);
    }

    private Doreplacedent readDoreplacedent() throws IOException {
        try {
            DoreplacedentBuilder doreplacedentBuilder = projector.config().createDoreplacedentBuilder();
            Doreplacedent doreplacedent = systemID == null ? doreplacedentBuilder.parse(is) : doreplacedentBuilder.parse(is, systemID);
            return doreplacedent;
        } catch (SAXException e) {
            throw new XBDoreplacedentParsingException(e);
        }
    }

    /**
     * As the system id usually cannot be determined by looking at the stream, this method allows it
     * to be set.
     *
     * @param systemID
     * @return this for convenience.
     */
    @Scope(DocScope.IO)
    public StreamInput setSystemID(final String systemID) {
        this.systemID = systemID;
        return this;
    }

    @Override
    public XPathEvaluator evalXPath(final String xpath) {
        return new DefaultXPathEvaluator(projector, new DoreplacedentResolver() {

            @Override
            public Doreplacedent resolve(final Clreplaced<?>... resourceAwareClreplaced) {
                try {
                    return StreamInput.this.readDoreplacedent();
                } catch (IOException e) {
                    throw new XBIOException(e);
                }
            }
        }, xpath);
    }
}

19 View Complete Implementation : FAQSnippetsTest.java
Copyright Apache License 2.0
Author : SvenEwald
@SuppressWarnings({ "serial", "javadoc" })
public clreplaced FAQSnippetsTest {

    /**
     * @author sven
     */
    public clreplaced MyOwnXpathFactory extends XPathFactory {

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean isObjectModelSupported(final String objectModel) {
            return false;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void setFeature(final String name, final boolean value) throws XPathFactoryConfigurationException {
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean getFeature(final String name) throws XPathFactoryConfigurationException {
            return false;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void setXPathVariableResolver(final XPathVariableResolver resolver) {
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void setXPathFunctionResolver(final XPathFunctionResolver resolver) {
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public XPath newXPath() {
            return null;
        }
    }

    XBProjector projector = new XBProjector();

    {
    }

    // START SNIPPET: DOMProjection
    public interface ProjectionWithDomAccess {

        // Just declare Node as return type
        @XBRead("/some/path/to/element/or/@attribute")
        org.w3c.dom.Node getSomeValue();
    }

    public interface ProjectionExtendingDOMAccess extends DOMAccess {

        // add your projections here
        // you inherit some useful methods
        @Override
        Node getDOMNode();

        @Override
        Element getDOMBaseElement();

        @Override
        String replacedtring();
    }

    // END SNIPPET: DOMProjection
    // START SNIPPET: MixinOverridingToString
    public interface MixinOverridingToString {

        @Override
        String toString();
    }

    // END SNIPPET: MixinOverridingToString
    // START SNIPPET: Projection
    public interface Projection extends MixinOverridingToString {

        // Your projection methods here
        @XBRead("...")
        String getSomeValue();
    }

    // END SNIPPET: Projection
    {
        // START SNIPPET: MixinRegistration
        Object mixin = new Object() {

            private Projection me;

            @Override
            public String toString() {
                return "I have value " + me.getSomeValue();
            }
        };
        projector.mixins().addProjectionMixin(Projection.clreplaced, mixin);
    // END SNIPPET: MixinRegistration
    }

    {
        // START SNIPPET: OwnXPathFactoriesImplementation
        XMLFactoriesConfig myConfig = new DefaultXMLFactoriesConfig() {

            {
                // We should change the behavior of the config to not
                // interfere with the name space handling of an
                // unknown XPath implementation.
                setNamespacePhilosophy(NamespacePhilosophy.AGNOSTIC);
            }

            /**
             * Override this method to inject your own factory.
             */
            @Override
            public XPathFactory createXPathFactory() {
                return new MyOwnXpathFactory();
            }
        };
        XBProjector projector = new XBProjector(myConfig);
        // END SNIPPET: OwnXPathFactoriesImplementation
        projector.hashCode();
    }

    {
        // START SNIPPET: OwnXPathImplementation
        XMLFactoriesConfig myConfig = new DefaultXMLFactoriesConfig() {

            {
                // We should change the behavior of the config to not
                // interfere with the name space handling of an
                // unknown XPath implementation.
                setNamespacePhilosophy(NamespacePhilosophy.AGNOSTIC);
            }

            /**
             * Or override this to bypreplaced the factory and create your own XPath implementation here.
             */
            @Override
            public XPath createXPath(final Doreplacedent... doreplacedent) {
                return super.createXPath(doreplacedent);
            }
        };
        XBProjector projector = new XBProjector(myConfig);
        // END SNIPPET: OwnXPathImplementation
        projector.hashCode();
    }

    public interface ExampleProjection {

        @XBRead
        List<String> getDepartmentUsersName();
    }

    @Test
    public void unCamelCaseTest() {
        XBProjector projector = new XBProjector();
        projector.config().setExternalizer(new ExternalizerAdapter() {

            @Override
            public String resolveXPath(final String annotationValue, final Method method, final Object[] args) {
                // Simplest conversion of camel case getter to xpath expression.
                return method.getName().substring(3).replaceAll("[A-Z]", "/$0");
            }
        });
        List<String> departmentUsers = projector.projectXMLString("<Department><Users><Name>John Doe</Name><Name>Tommy Atkins</Name></Users></Department>", ExampleProjection.clreplaced).getDepartmentUsersName();
        replacedertTrue(departmentUsers.size() == 2);
        replacedertEquals("John Doe", departmentUsers.get(0));
        replacedertEquals("Tommy Atkins", departmentUsers.get(1));
    }
    // START SNIPPET: NO_FORMATTING
    /*
//START SNIPPET:Java8OverrideToString
        @XBOverride("toString")
        default String toString_() {
            return "String from overriden toString() method";
        }
//END SNIPPET:Java8OverrideToString
*/
}

19 View Complete Implementation : NestedPathInPredicateTest.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testConditionSingleLevelOnRootWithChild() {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    NestedPathInPredicate test = projector.projectEmptyDoreplacedent(NestedPathInPredicate.clreplaced);
    test.setConditionSingleLevelOnRootWithChild("Value");
    replacedertXMLStringsEquals(("<Root>\n" + "   <X>Preplaceded</X>\n" + "   <Child>Value</Child>\n" + "</Root>\n"), test.toString());
}

19 View Complete Implementation : TestAutoCDList.java
Copyright Apache License 2.0
Author : SvenEwald
@Test
public void testAddCDToList() throws IOException {
    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
    CDLib cdlib = projector.io().url("res://cdlib.xml").read(CDLib.clreplaced);
    CDLib.CD cd = projector.projectEmptyElement("CD", CDLib.CD.clreplaced);
    cdlib.list().add(cd.replacedle("replacedle").artist("artist").price(15.99f).year(2015));
    System.out.println(cdlib.toString());
}

18 View Complete Implementation : StreamOutput.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author <a href="https://github.com/SvenEwald">Sven Ewald</a>
 */
public clreplaced StreamOutput {

    private final XBProjector projector;

    private final OutputStream os;

    /**
     * @param xmlProjector
     * @param os
     */
    public StreamOutput(final XBProjector xmlProjector, final OutputStream os) {
        this.projector = xmlProjector;
        this.os = os;
    }

    /**
     * @param projection
     */
    @Scope(DocScope.IO)
    public void write(final Object projection) {
        try {
            projector.config().createTransformer().transform(new DOMSource(((DOMAccess) projection).getDOMNode()), new StreamResult(os));
        } catch (TransformerException e) {
            throw new XBException("Error during writing doreplacedent", e);
        }
    }
}

18 View Complete Implementation : GenerateAPIDoc.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced GenerateAPIDoc {

    static {
        System.setProperty("java.awt.headless", "true");
    }

    final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    final XBAutoMap<String> map = projector.autoMapEmptyDoreplacedent(String.clreplaced);

    final XBAutoList<Section> nodes = map.getList("/section[@name='xgml']/section[@name='graph']/section[@name='node']", Section.clreplaced);

    final XBAutoList<Section> edges = map.getList("/section[@name='xgml']/section[@name='graph']/section[@name='edge']", Section.clreplaced);

    final Map<MethodSignature, Section> nodeMap = new HashMap<MethodSignature, Section>();

    final Set<String> createdEdges = new HashSet<String>();

    final Set<String> createdLeaves = new HashSet<String>();

    final Set<Method> visitedMethods = new HashSet<Method>();

    private int maxID = 0;

    AffineTransform affinetransform = new AffineTransform();

    FontRenderContext frc = new FontRenderContext(affinetransform, true, true);

    Font font = new Font("Dialog", Font.PLAIN, 12);

    private static clreplaced MethodSignature {

        @Override
        public String toString() {
            return getLabel();
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            // result = (prime * result) + ((declaringClreplaced == null) ? 0 : declaringClreplaced.hashCode());
            result = (prime * result) + ((name == null) ? 0 : name.hashCode());
            result = (prime * result) + Arrays.hashCode(parameterTypes);
            result = (prime * result) + ((returnType == null) ? 0 : returnType.hashCode());
            result = (prime * result) + (varArgs ? 1231 : 1237);
            return result;
        }

        @Override
        public boolean equals(final Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null) {
                return false;
            }
            if (getClreplaced() != obj.getClreplaced()) {
                return false;
            }
            MethodSignature other = (MethodSignature) obj;
            // if (declaringClreplaced == null) {
            // if (other.declaringClreplaced != null) {
            // return false;
            // }
            // } else if (!declaringClreplaced.equals(other.declaringClreplaced)) {
            // return false;
            // }
            if (name == null) {
                if (other.name != null) {
                    return false;
                }
            } else if (!name.equals(other.name)) {
                return false;
            }
            if (!Arrays.equals(parameterTypes, other.parameterTypes)) {
                return false;
            }
            if (returnType == null) {
                if (other.returnType != null) {
                    return false;
                }
            } else if (!returnType.equals(other.returnType)) {
                return false;
            }
            if (varArgs != other.varArgs) {
                return false;
            }
            return true;
        }

        String getLabel() {
            StringBuffer sb = new StringBuffer(name);
            if (parameterTypes != null) {
                sb.append("(");
                Clreplaced[] params = parameterTypes;
                int length = varArgs ? params.length - 1 : params.length;
                for (int j = 0; j < length; j++) {
                    sb.append(getTypeName(params[j]));
                    if (j < (params.length - 1)) {
                        sb.append(",");
                    }
                }
                sb.append(")");
            }
            return sb.toString();
        }

        private final String name;

        private final Type returnType;

        private Clreplaced<?> declaringClreplaced;

        private Clreplaced[] parameterTypes;

        private boolean varArgs;

        /**
         * @param string
         * @param clreplaced1
         */
        public MethodSignature(final String string, final Type clreplaced1) {
            this.name = string;
            this.returnType = clreplaced1;
        }

        public MethodSignature(final Method m) {
            this.name = m.getName();
            this.returnType = m.getGenericReturnType();
            this.declaringClreplaced = m.getDeclaringClreplaced();
            parameterTypes = m.getParameterTypes();
            varArgs = m.isVarArgs();
        }
    }

    @Test
    public void generateIOAPIDoc() throws IOException {
        // dump("new XBProjector()", XBProjector.clreplaced, DocScope.IO);
        dump(new MethodSignature("new XBProjector()", XBProjector.clreplaced), XBProjector.clreplaced, DocScope.IO);
        // System.out.println(projector.replacedtring(map));
        projector.io().file("test.xgml").write(map);
    }

    /**
     * @param clreplaced1
     * @param io
     */
    private void dump(final MethodSignature prefix, final Clreplaced<?> clreplaced1, final DocScope scope) {
        if (clreplaced1 == null) {
            return;
        }
        for (Method m : allPublicMethods(clreplaced1)) {
            Scope annotation = m.getAnnotation(Scope.clreplaced);
            if (annotation == null) {
                continue;
            }
            if (!scope.equals(annotation.value())) {
                continue;
            }
            if (visitedMethods.contains(m)) {
                continue;
            }
            if (!isAPIClreplaced(m.getReturnType())) {
                // System.out.println(prefix + "." + methodreplacedtring(m) + (Void.TYPE.equals(m.getReturnType()) ? "" : " -> " + getTypeName(m.getGenericReturnType())));
                // System.out.println(prefix + "->" + methodreplacedtring(m));
                Section from = createNode(prefix);
                Section to = createNode(/* methodreplacedtring(m) */
                new MethodSignature(m));
                createEdge(from, to);
                if (!Void.TYPE.equals(m.getReturnType())) {
                    MethodSignature ms = new MethodSignature(getTypeName(m.getGenericReturnType()), new Type() {
                    });
                    // createEdge(to, createNode(getTypeName(m.getGenericReturnType())));
                    if (!createdLeaves.contains(to.id().get() + ms.getLabel())) {
                        createEdge(to, createNode(ms));
                        createdLeaves.add(to.id().get() + ms.getLabel());
                    }
                }
                continue;
            }
            boolean methodIsOptional = m.getReturnType().equals(m.getDeclaringClreplaced());
            if (methodIsOptional) {
                // prefix += "[." + methodreplacedtring(m) + "]";
                continue;
            }
            // System.out.println(prefix + "->" + methodreplacedtring(m));
            createEdge(createNode(prefix), createNode(new MethodSignature(m)));
            visitedMethods.add(m);
            // dump(prefix + optionalMethodsreplacedtring(clreplaced1, scope) + "." + methodreplacedtring(m), m.getReturnType(), scope);
            // dumpOptionalMethods(clreplaced1, prefix, scope);
            dump(new MethodSignature(m), /* methodreplacedtring(m) */
            m.getReturnType(), scope);
        // visitedMethods.remove(m);
        }
    }

    // private void dumpOptionalMethods(final Clreplaced<?> clreplaced1, final String prefix, final DocScope scope) {
    // for (Method m : getAllOptionalMethod(clreplaced1)) {
    // if (!scope.equals(m.getAnnotation(Scope.clreplaced).value())) {
    // continue;
    // }
    // //sb.append("[." + methodreplacedtring(m) + "]");
    // createEdge(createNode(prefix), createNode(methodreplacedtring(m)));
    // createEdge(createNode(methodreplacedtring(m)), createNode(prefix));
    // }
    // }
    /**
     * @param clreplaced1
     * @param scope
     * @return
     */
    private String optionalMethodsreplacedtring(final Clreplaced<?> clreplaced1, final DocScope scope) {
        StringBuilder sb = new StringBuilder();
        for (Method m : getAllOptionalMethod(clreplaced1)) {
            if (!scope.equals(m.getAnnotation(Scope.clreplaced).value())) {
                continue;
            }
            sb.append("[." + methodreplacedtring(m) + "]");
        }
        return sb.toString();
    }

    /**
     * @param clreplaced1
     * @return
     */
    private Collection<Method> allPublicMethods(final Clreplaced<?> clreplaced1) {
        if (clreplaced1 == null) {
            return Collections.emptyList();
        }
        Set<Method> methods = new HashSet<Method>();
        methods.addAll(Arrays.asList(clreplaced1.getDeclaredMethods()));
        methods.addAll(allPublicMethods(clreplaced1.getSuperclreplaced()));
        for (Clreplaced<?> c : clreplaced1.getInterfaces()) {
            methods.addAll(allPublicMethods(c));
        }
        return methods;
    }

    private Collection<Method> getAllOptionalMethod(final Clreplaced<?> clreplaced1) {
        Set<Method> methods = new HashSet<Method>();
        for (Method m : allPublicMethods(clreplaced1)) {
            if (m.getAnnotation(Scope.clreplaced) == null) {
                continue;
            }
            if (m.getDeclaringClreplaced().equals(m.getReturnType())) {
                methods.add(m);
            }
        }
        return methods;
    }

    /**
     * @param returnType
     * @return
     */
    private boolean isAPIClreplaced(final Clreplaced<?> returnType) {
        for (Method m : returnType.getDeclaredMethods()) {
            Scope annotation = m.getAnnotation(Scope.clreplaced);
            if (annotation != null) {
                return true;
            }
        }
        return false;
    }

    /**
     * @param m
     */
    private String methodreplacedtring(final Method m) {
        try {
            StringBuffer sb = new StringBuffer();
            sb.append(m.getName() + "(");
            Clreplaced[] params = m.getParameterTypes();
            int length = m.isVarArgs() ? params.length - 1 : params.length;
            for (int j = 0; j < length; j++) {
                sb.append(getTypeName(params[j]));
                if (j < (params.length - 1)) {
                    sb.append(",");
                }
            }
            sb.append(")");
            return sb.toString();
        } catch (Exception e) {
            return "<" + e + ">";
        }
    }

    static String getTypeName(final Clreplaced type) {
        if (type.isArray()) {
            try {
                Clreplaced cl = type;
                int dimensions = 0;
                while (cl.isArray()) {
                    dimensions++;
                    cl = cl.getComponentType();
                }
                StringBuffer sb = new StringBuffer();
                sb.append(cl.getName());
                for (int i = 0; i < dimensions; i++) {
                    sb.append("[]");
                }
                return sb.toString();
            } catch (Throwable e) {
            /* FALLTHRU */
            }
        }
        StringBuffer tps = new StringBuffer();
        for (TypeVariable<GenericDeclaration> t : type.getTypeParameters()) {
            if (tps.length() > 0) {
                tps.append(", ");
            }
            tps.append(t.getName());
        }
        return type.getSimpleName() + (tps.length() > 0 ? "<" + tps.toString() + ">" : "");
    }

    static String getTypeName(final Type type) {
        // if (type instanceof ParameterizedType) {
        return type.toString().replaceAll("(clreplaced )?([a-z\\.]+\\.)*", "");
    // }
    // return type.toString();
    }

    @Ignore
    public void testGraphCreation() throws IOException {
    // 
    // Section from = createNode("from");
    // Section to = createNode("to");
    // createEdge(from, to);
    // 
    // System.out.println(projector.replacedtring(map));
    // projector.io().file("test.xgml").write(map);
    }

    private void createEdge(final Section from, final Section to) {
        if (createdEdges.contains(from.id() + "#" + to.id())) {
            return;
        }
        Section edge = projector.projectEmptyElement("section", Section.clreplaced);
        edge.name().set("edge");
        edge.source().set(from.id().get());
        edge.target().set(to.id().get());
        edge.graphics().set("standard");
        edges.add(edge);
        createdEdges.add(from.id() + "#" + to.id());
    }

    private Section createNode(final MethodSignature ms) {
        if (nodeMap.containsKey(ms)) {
            return nodeMap.get(ms);
        }
        System.out.println("new node " + ms.getLabel() + " " + ms.declaringClreplaced);
        Section node = projector.projectEmptyElement("section", Section.clreplaced);
        node.id().set(++maxID);
        node.name().set("node");
        String label = ms.getLabel();
        node.label().set(label);
        node.fill().set("#FEFEFE");
        double width = font.getStringBounds(label, frc).getWidth();
        node.widh().set(5 + width);
        nodeMap.put(ms, node);
        nodes.add(node);
        return node;
    }
}

18 View Complete Implementation : XBProjectorReferenceCard.java
Copyright Apache License 2.0
Author : SvenEwald
// END SNIPPET: XBProjectorReferenceCard0
@Ignore
public // This must compile, but it won't run
void ensureFileReading() throws Exception {
    File file = null;
    Clreplaced<Object> projectionInterface = null;
    InputStream is = null;
    OutputStream os = null;
    String url = null, httpurl = null;
    Object[] params = null;
    Map<String, String> props = null;
    String name = null;
    Node node = null;
    String systemID = null;
    {
        // START SNIPPET: XBProjectorReferenceCard1
        Projection projection = projector.projectEmptyDoreplacedent(Projection.clreplaced);
        Projection subProjection = projector.projectEmptyElement(name, Projection.clreplaced);
        // END SNIPPET: XBProjectorReferenceCard1
        projection.hashCode();
        subProjection.hashCode();
    }
    {
        // START SNIPPET: XBProjectorReferenceCard2
        Projection projection = projector.projectXMLString("<xml/>", Projection.clreplaced);
        // END SNIPPET: XBProjectorReferenceCard2
        // START SNIPPET: XBProjectorReferenceCard2b
        // Let the projector convert your projection
        String xml = projector.replacedtring(projection);
        // Or, configure the projector this way before you create a projection
        XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
        // ... and later call:
        projection.toString();
        // END SNIPPET: XBProjectorReferenceCard2b
        projector.hashCode();
        xml.hashCode();
    }
    {
        // START SNIPPET: XBProjectorReferenceCard3
        Projection projection = projector.projectDOMNode(node, Projection.clreplaced);
        // END SNIPPET: XBProjectorReferenceCard3
        projection.hashCode();
    }
    {
        // START SNIPPET: XBProjectorReferenceCard4
        Projection projection = projector.io().file(file).read(Projection.clreplaced);
        projector.io().file(file).write(projection);
        projector.io().file(file).setAppend(true).write(projection);
    // END SNIPPET: XBProjectorReferenceCard4
    }
    {
        // START SNIPPET: XBProjectorReferenceCard5
        Projection projection = projector.io().fromURLAnnotation(Projection.clreplaced, params);
        projector.io().toURLAnnotationViaPOST(projectionInterface, projection, params);
    // END SNIPPET: XBProjectorReferenceCard5
    }
    {
        // START SNIPPET: XBProjectorReferenceCard6
        Projection projection = projector.io().url(url).read(Projection.clreplaced);
        projector.io().url(url).write(projection);
    // END SNIPPET: XBProjectorReferenceCard6
    }
    {
        // START SNIPPET: XBProjectorReferenceCard7
        Projection projection = projector.io().url(httpurl).addRequestProperty("key", "value").read(Projection.clreplaced);
        Projection projection2 = projector.io().url(httpurl).addRequestProperties(props).read(Projection.clreplaced);
        // END SNIPPET: XBProjectorReferenceCard7
        projection.hashCode();
        projection2.hashCode();
    }
    {
        Object projection = null;
        // START SNIPPET: XBProjectorReferenceCard8
        Map<String, String> credentials = IOHelper.createBasicAuthenticationProperty("user", "pwd");
        projector.io().url(httpurl).addRequestProperties(credentials).write(projection);
    // END SNIPPET: XBProjectorReferenceCard8
    }
    {
        // START SNIPPET: XBProjectorReferenceCard9
        Projection projection = projector.io().stream(is).read(Projection.clreplaced);
        Projection projectionWithSystemID = projector.io().stream(is).setSystemID(systemID).read(Projection.clreplaced);
        projector.io().stream(os).write(projection);
        // END SNIPPET: XBProjectorReferenceCard9
        projectionWithSystemID.hashCode();
    }
}

18 View Complete Implementation : XBProjectorReferenceCard.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced XBProjectorReferenceCard {

    // START SNIPPET: mainExample
    public interface Example {

        @XBRead("/xml/example/content")
        String getContent();

        @XBRead("/xml/example/content/@type")
        String getType();
    }

    // END SNIPPET: mainExample
    {
        try {
            if (false) {
                // START SNIPPET: mainExample2
                {
                    // Read xml file
                    CloseableMap<String> map = new XBProjector().io().file("example.xml").bindAsMapOf(String.clreplaced);
                    // Get content via XPath
                    // "bar"
                    String content = map.get("/xml/example/content");
                    // Create new attribute "type"
                    map.put("/xml/example/content/@type", "foo");
                    // Apply changes to the file
                    map.close();
                }
            // END SNIPPET: mainExample2
            }
        } catch (IOException e) {
        }
    }

    // START SNIPPET: XBProjectorReferenceCardI
    public interface Projection {
        // Define your projection methods in a public interface.
    }

    @XBDocURL("http://...")
    public interface ProjectionWithSourceDeclaration {
        // Define your projection methods in a public interface.
        // You may add a doreplacedent url to specify where to get the doreplacedent for this projection.
    }

    // END SNIPPET: XBProjectorReferenceCardI
    // START SNIPPET: XBProjectorReferenceCard0
    XBProjector projector = new XBProjector();

    // END SNIPPET: XBProjectorReferenceCard0
    @Ignore
    public // This must compile, but it won't run
    void ensureFileReading() throws Exception {
        File file = null;
        Clreplaced<Object> projectionInterface = null;
        InputStream is = null;
        OutputStream os = null;
        String url = null, httpurl = null;
        Object[] params = null;
        Map<String, String> props = null;
        String name = null;
        Node node = null;
        String systemID = null;
        {
            // START SNIPPET: XBProjectorReferenceCard1
            Projection projection = projector.projectEmptyDoreplacedent(Projection.clreplaced);
            Projection subProjection = projector.projectEmptyElement(name, Projection.clreplaced);
            // END SNIPPET: XBProjectorReferenceCard1
            projection.hashCode();
            subProjection.hashCode();
        }
        {
            // START SNIPPET: XBProjectorReferenceCard2
            Projection projection = projector.projectXMLString("<xml/>", Projection.clreplaced);
            // END SNIPPET: XBProjectorReferenceCard2
            // START SNIPPET: XBProjectorReferenceCard2b
            // Let the projector convert your projection
            String xml = projector.replacedtring(projection);
            // Or, configure the projector this way before you create a projection
            XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
            // ... and later call:
            projection.toString();
            // END SNIPPET: XBProjectorReferenceCard2b
            projector.hashCode();
            xml.hashCode();
        }
        {
            // START SNIPPET: XBProjectorReferenceCard3
            Projection projection = projector.projectDOMNode(node, Projection.clreplaced);
            // END SNIPPET: XBProjectorReferenceCard3
            projection.hashCode();
        }
        {
            // START SNIPPET: XBProjectorReferenceCard4
            Projection projection = projector.io().file(file).read(Projection.clreplaced);
            projector.io().file(file).write(projection);
            projector.io().file(file).setAppend(true).write(projection);
        // END SNIPPET: XBProjectorReferenceCard4
        }
        {
            // START SNIPPET: XBProjectorReferenceCard5
            Projection projection = projector.io().fromURLAnnotation(Projection.clreplaced, params);
            projector.io().toURLAnnotationViaPOST(projectionInterface, projection, params);
        // END SNIPPET: XBProjectorReferenceCard5
        }
        {
            // START SNIPPET: XBProjectorReferenceCard6
            Projection projection = projector.io().url(url).read(Projection.clreplaced);
            projector.io().url(url).write(projection);
        // END SNIPPET: XBProjectorReferenceCard6
        }
        {
            // START SNIPPET: XBProjectorReferenceCard7
            Projection projection = projector.io().url(httpurl).addRequestProperty("key", "value").read(Projection.clreplaced);
            Projection projection2 = projector.io().url(httpurl).addRequestProperties(props).read(Projection.clreplaced);
            // END SNIPPET: XBProjectorReferenceCard7
            projection.hashCode();
            projection2.hashCode();
        }
        {
            Object projection = null;
            // START SNIPPET: XBProjectorReferenceCard8
            Map<String, String> credentials = IOHelper.createBasicAuthenticationProperty("user", "pwd");
            projector.io().url(httpurl).addRequestProperties(credentials).write(projection);
        // END SNIPPET: XBProjectorReferenceCard8
        }
        {
            // START SNIPPET: XBProjectorReferenceCard9
            Projection projection = projector.io().stream(is).read(Projection.clreplaced);
            Projection projectionWithSystemID = projector.io().stream(is).setSystemID(systemID).read(Projection.clreplaced);
            projector.io().stream(os).write(projection);
            // END SNIPPET: XBProjectorReferenceCard9
            projectionWithSystemID.hashCode();
        }
    }

    // START SNIPPET: XBProjectorReferenceCard10
    public interface MyProjection {

        @XBRead("some/path/to/data")
        MyCustomType getData();
    }

    // END SNIPPET: XBProjectorReferenceCard10
    // START SNIPPET: XBProjectorReferenceCard11
    public clreplaced MyCustomType {

        public MyCustomType(final String data) {
        // ...
        }
    }

    // END SNIPPET: XBProjectorReferenceCard11
    // START SNIPPET: XBProjectorReferenceCard12
    public static MyCustomType valueOf(final String data) {
        return somehowCreateInstanceFor(data);
    }

    public static MyCustomType of(final String data) {
        return somehowCreateInstanceFor(data);
    }

    public static MyCustomType parse(final String data) {
        return somehowCreateInstanceFor(data);
    }

    public static MyCustomType getInstance(final String data) {
        return somehowCreateInstanceFor(data);
    }

    // END SNIPPET: XBProjectorReferenceCard12
    public static MyCustomType somehowCreateInstanceFor(final Object o) {
        return null;
    }

    interface Snipped13 {

        // START SNIPPET: XBProjectorReferenceCard13
        @XBRead("/{parentNode}/{subnode}[@id='{id}']")
        String readSomeValue(String parentNode, String subnode, int id);
        // END SNIPPET: XBProjectorReferenceCard13
    }

    interface Snipped14 {

        // START SNIPPET: XBProjectorReferenceCard14
        @XBRead("/{0}/{1}[@id='{2}']")
        String readSomeValue(String parentNode, String subnode, int id);
        // END SNIPPET: XBProjectorReferenceCard14
    }

    {
        // START SNIPPET: XBProjectorReferenceCard15
        new XBProjector().config().getTypeConverterAs(DefaultTypeConverter.clreplaced).setLocale(Locale.ROOT);
    // END SNIPPET: XBProjectorReferenceCard15
    }

    {
        // START SNIPPET: XBProjectorReferenceCard16
        new XBProjector().config().getTypeConverterAs(DefaultTypeConverter.clreplaced).setTimeZone(TimeZone.getDefault());
    // END SNIPPET: XBProjectorReferenceCard16
    }
}

18 View Complete Implementation : TestAutoIntegerList.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author sven
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoIntegerList {

    private final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    private final static String XML = "<root><list><e>1</e><e>2</e><e>3</e></list></root>";

    private final Projection projection = projector.projectXMLString(XML, Projection.clreplaced);

    interface Projection {

        @XBRead("/root/list/e")
        List<Integer> reference();

        @XBRead("/root/list/e")
        XBAutoList<Integer> projectList();

        @XBRead("/root/list2/e2")
        List<Integer> reference2();

        @XBRead("/root/list2/e2")
        XBAutoList<Integer> projectList2();
    }

    @Test
    public void testSimpleAdd() {
        List<Integer> list = projection.projectList();
        replacedertFalse(list.isEmpty());
        replacedertEquals("[1, 2, 3]", projection.reference().toString());
        list.add(4);
        replacedertEquals("[1, 2, 3, 4]", projection.reference().toString());
        list.add(0, 0);
        replacedertEquals("[0, 1, 2, 3, 4]", projection.reference().toString());
        list.add(4, 1);
        replacedertEquals("[0, 1, 2, 3, 1, 4]", projection.reference().toString());
        list.add(list.size(), 9);
        replacedertEquals("[0, 1, 2, 3, 1, 4, 9]", projection.reference().toString());
        list.clear();
        replacedertTrue(projection.reference().isEmpty());
        replacedertTrue(list.isEmpty());
        list.addAll(Arrays.asList(10, 11, 12));
        replacedertEquals("[10, 11, 12]", projection.reference().toString());
        list.addAll(1, Arrays.asList(20, 21, 22));
        replacedertEquals("[10, 20, 21, 22, 11, 12]", projection.reference().toString());
    }

    @Test
    public void testAddForNonExistingParent() {
        List<Integer> list = projection.projectList2();
        replacedertTrue(projection.reference2().isEmpty());
        replacedertTrue(list.isEmpty());
        list.add(4);
        replacedertEquals("[4]", projection.reference2().toString());
    }

    @SuppressWarnings("unchecked")
    @Test
    public void testContains() {
        replacedertFalse(projection.projectList().contains(null));
        replacedertTrue(projection.projectList().contains(1));
        replacedertTrue(projection.projectList().contains(2));
        replacedertTrue(projection.projectList().contains(3));
        replacedertFalse(projection.projectList().contains("Y"));
        replacedertTrue(projection.projectList().containsAll(Arrays.asList(1, 2, 3)));
        replacedertFalse(projection.projectList().containsAll(Arrays.asList(1, "T", 3)));
    }

    @Test
    public void testIndexOf() {
        replacedertEquals(0, projection.projectList().indexOf(1));
        replacedertEquals(1, projection.projectList().indexOf(2));
        replacedertEquals(2, projection.projectList().indexOf(3));
        replacedertEquals(-1, projection.projectList().indexOf("X"));
    }

    @Test
    public void testGet() {
        replacedertEquals(Integer.valueOf(1), projection.projectList().get(0));
        replacedertEquals(Integer.valueOf(2), projection.projectList().get(1));
        replacedertEquals(Integer.valueOf(3), projection.projectList().get(2));
    }

    @Test(expected = IndexOutOfBoundsException.clreplaced)
    public void testGetFail() {
        projection.projectList().get(4);
    }

    @Test
    public void tesreplacederator() {
        Iterator<Integer> iterator = projection.projectList().iterator();
        replacedertTrue(iterator.hasNext());
        replacedertEquals(Integer.valueOf(1), iterator.next());
        replacedertTrue(iterator.hasNext());
        replacedertEquals(Integer.valueOf(2), iterator.next());
        replacedertTrue(iterator.hasNext());
        replacedertEquals(Integer.valueOf(3), iterator.next());
        replacedertFalse(iterator.hasNext());
    }

    @Test
    public void tesreplacederatorRemove() {
        Iterator<Integer> iterator = projection.projectList().iterator();
        replacedertTrue(iterator.hasNext());
        replacedertEquals(Integer.valueOf(1), iterator.next());
        iterator.remove();
        replacedertEquals("[2, 3]", projection.reference().toString());
    }

    @Test
    public void testRemove() {
        replacedertEquals(Integer.valueOf(2), projection.projectList().remove(1));
        replacedertEquals("[1, 3]", projection.reference().toString());
        replacedertEquals(Integer.valueOf(1), projection.projectList().remove(0));
        replacedertEquals("[3]", projection.reference().toString());
        replacedertEquals(Integer.valueOf(3), projection.projectList().remove(0));
        replacedertTrue(projection.reference().isEmpty());
    }
}

18 View Complete Implementation : TestAutoListOnEmptyDocuments.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoListOnEmptyDoreplacedents {

    private final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    interface Projection {

        @XBRead("/root/entry")
        XBAutoList<String> mapRootList();

        @XBDelete("/root/entry[text()='{0}']")
        Projection deleteEntry(String entry);
    }

    @Test
    public void testCreateElementsViaProjectedList() {
        Projection projection = projector.projectEmptyDoreplacedent(Projection.clreplaced);
        List<String> list = projection.mapRootList();
        replacedertTrue(list.isEmpty());
        list.add("a");
        list.add(0, "b");
        projection.deleteEntry("a");
        list.add(0, "c");
        Collections.sort(list);
        replacedertEquals("[b, c]", list.toString());
    }

    @Test(expected = IndexOutOfBoundsException.clreplaced)
    public void testEmptyList() {
        XBAutoMap<String> map = projector.autoMapEmptyDoreplacedent(String.clreplaced);
        XBAutoList<String> list = map.getList("non/existing/path");
        replacedertTrue(list.isEmpty());
        list.get(0);
    }

    @Test(expected = IndexOutOfBoundsException.clreplaced)
    public void testEmptyList2() {
        XBAutoMap<String> map = projector.onXMLString("<root/>").evalXPath("/foo").asMapOf(String.clreplaced);
        XBAutoList<String> list = map.getList("non/existing/path");
        replacedertTrue(list.isEmpty());
        list.get(0);
    }
}

18 View Complete Implementation : TestAutoListWithSubProjections.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoListWithSubProjections {

    private final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    interface Projection {

        interface Entry {

            // @XBRead("./@key")
            // Projected<String> key();
            // 
            // @XBRead("./@value")
            // Projected<String> value();
            @XBWrite("./@key")
            Entry setKey(String key);

            @XBWrite("./@value")
            Entry setValue(String value);
        }

        @XBRead("/root/mid/entry")
        XBAutoList<Entry> mapRootList();
    }

    @Test
    public void testSubProjections() {
        Projection projection = projector.projectEmptyDoreplacedent(Projection.clreplaced);
        Entry entry = projector.projectEmptyElement("entry", Entry.clreplaced);
        // entry.key().set("key");
        // entry.value().set("value");
        projection.mapRootList().add(entry.setKey("key").setValue("value"));
        projection.mapRootList().add(entry.setKey("key2").setValue("value2"));
        projection.mapRootList().add(entry.setKey("key3").setValue("value3"));
        projection.mapRootList().remove(entry);
        System.out.println(projection);
    }
}

18 View Complete Implementation : TestAutoMaps.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author sven
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoMaps {

    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    @SuppressWarnings("deprecation")
    @Test
    public void testMapKeyPresent() {
        XBAutoMap<String> map = projector.onXMLString("<root><value>foo</value></root>").createMapOf(String.clreplaced);
        replacedertFalse(map.containsKey("/root/value/notthere"));
        replacedertTrue(map.containsKey("/root/value"));
        replacedertTrue(map.containsKey((Object) "/root/value"));
        replacedertTrue(map.containsValue("foo"));
        replacedertFalse(map.containsValue("bar"));
        replacedertFalse(map.containsValue(null));
    }

    @Test
    public void ensureDOMAccessImplementation() {
        XBAutoMap<String> map = projector.onXMLString("<root><value>foo</value></root>").createMapOf(String.clreplaced);
        DOMAccess da = ((DOMAccess) map);
        replacedertEquals(XBAutoMap.clreplaced, da.getProjectionInterface());
        DOMDiagnoseHelper.replacedertXMLStringsEquals("<root><value>foo</value></root>", da.replacedtring());
        replacedertEquals(Node.DOreplacedENT_NODE, da.getDOMNode().getNodeType());
        replacedertTrue(da.getDOMNode() == da.getDOMOwnerDoreplacedent());
        replacedertNotNull(da.getDOMBaseElement());
    }
}

18 View Complete Implementation : TestAutoStringList.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author sven
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoStringList {

    private final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    private final static String XML = "<root><list><e>1</e><e>2</e><e>3</e></list></root>";

    private final Projection projection = projector.projectXMLString(XML, Projection.clreplaced);

    interface Projection {

        @XBRead("/root/list/e")
        List<String> reference();

        @XBRead("/root/list/e")
        XBAutoList<String> projectList();

        @XBRead("/root/list2/e2")
        List<String> reference2();

        @XBRead("/root/list2/e2")
        XBAutoList<String> projectList2();
    }

    @Test
    public void testSimpleAdd() {
        List<String> list = projection.projectList();
        replacedertFalse(list.isEmpty());
        replacedertEquals("[1, 2, 3]", projection.reference().toString());
        list.add("4");
        replacedertEquals("[1, 2, 3, 4]", projection.reference().toString());
        list.add(0, "0");
        replacedertEquals("[0, 1, 2, 3, 4]", projection.reference().toString());
        list.add(4, "x");
        replacedertEquals("[0, 1, 2, 3, x, 4]", projection.reference().toString());
        list.add(list.size(), "z");
        replacedertEquals("[0, 1, 2, 3, x, 4, z]", projection.reference().toString());
        list.clear();
        replacedertTrue(projection.reference().isEmpty());
        replacedertTrue(list.isEmpty());
        list.addAll(Arrays.asList("a", "b", "c"));
        replacedertEquals("[a, b, c]", projection.reference().toString());
        list.addAll(1, Arrays.asList("a2", "b2", "c2"));
        replacedertEquals("[a, a2, b2, c2, b, c]", projection.reference().toString());
    }

    @Test
    public void testAddForNonExistingParent() {
        List<String> list = projection.projectList2();
        replacedertTrue(projection.reference2().isEmpty());
        replacedertTrue(list.isEmpty());
        list.add("4");
        replacedertEquals("[4]", projection.reference2().toString());
    }

    @Test
    public void testContains() {
        replacedertFalse(projection.projectList().contains(null));
        replacedertTrue(projection.projectList().contains("1"));
        replacedertTrue(projection.projectList().contains("2"));
        replacedertTrue(projection.projectList().contains("3"));
        replacedertFalse(projection.projectList().contains("Y"));
        replacedertTrue(projection.projectList().containsAll(Arrays.asList("1", "2", "3")));
        replacedertFalse(projection.projectList().containsAll(Arrays.asList("1", "T", "3")));
    }

    @Test
    public void testIndexOf() {
        replacedertEquals(0, projection.projectList().indexOf("1"));
        replacedertEquals(1, projection.projectList().indexOf("2"));
        replacedertEquals(2, projection.projectList().indexOf("3"));
        replacedertEquals(-1, projection.projectList().indexOf("X"));
    }

    @Test
    public void testIndexOfNode() {
        replacedertEquals(-1, projection.projectList().indexOf((Node) null));
        replacedertEquals(-1, projection.projectList().indexOf(((DOMAccess) projection).getDOMNode()));
    }

    @Test
    public void testGet() {
        replacedertEquals("1", projection.projectList().get(0));
        replacedertEquals("2", projection.projectList().get(1));
        replacedertEquals("3", projection.projectList().get(2));
    }

    @Test(expected = IndexOutOfBoundsException.clreplaced)
    public void testGetFail() {
        projection.projectList().get(4);
    }

    @Test
    public void tesreplacederator() {
        Iterator<String> iterator = projection.projectList().iterator();
        replacedertTrue(iterator.hasNext());
        replacedertEquals("1", iterator.next());
        replacedertTrue(iterator.hasNext());
        replacedertEquals("2", iterator.next());
        replacedertTrue(iterator.hasNext());
        replacedertEquals("3", iterator.next());
        replacedertFalse(iterator.hasNext());
    }

    @Test
    public void tesreplacederatorRemove() {
        Iterator<String> iterator = projection.projectList().iterator();
        replacedertTrue(iterator.hasNext());
        replacedertEquals("1", iterator.next());
        iterator.remove();
        replacedertEquals("[2, 3]", projection.reference().toString());
    }

    @Test
    public void testRemoveByIndex() {
        replacedertEquals("2", projection.projectList().remove(1));
        replacedertEquals("[1, 3]", projection.reference().toString());
        replacedertEquals("1", projection.projectList().remove(0));
        replacedertEquals("[3]", projection.reference().toString());
        replacedertEquals("3", projection.projectList().remove(0));
        replacedertTrue(projection.reference().isEmpty());
    }

    @Test
    public void testRemoveByValue() {
        replacedertFalse(projection.projectList().remove("not there"));
        replacedertEquals("[1, 2, 3]", projection.reference().toString());
        replacedertTrue(projection.projectList().remove("2"));
        replacedertEquals("[1, 3]", projection.reference().toString());
    }

    @Test
    public void testEvaluationAPIForAutoList() throws IOException {
        File file = new File("bindTest.xml");
        if (file.exists()) {
            file.delete();
        }
        CloseableList<String> list = projector.io().file(file).bindXPath("/root/list/e").asListOf(String.clreplaced);
        list.clear();
        list.add("a");
        list.add("b");
        list.add("c");
        list.close();
        replacedertXMLStringsEquals("<root><list><e>a</e><e>b</e><e>c</e></list></root>", TestIOUtils.file2String(file));
        replacedertXMLStringsEquals("<list><e>a</e><e>b</e><e>c</e></list>", projector.replacedtring(list));
        replacedertTrue(file.delete());
    }

    @Test
    public void testEvaluationAPIForAutoValue() throws IOException {
        final File file = new File("bindTest.xml");
        FileWriter writer = new FileWriter(file);
        writer.write("<root><list><a>1</a><b>2</b><c>true</c></list></root>");
        writer.close();
        FileInputStream fileInputStream = new FileInputStream(file);
        IOHelper.loadDoreplacedent(projector, fileInputStream);
        fileInputStream.close();
        CloseableValue<Integer> valueA = projector.io().file(file).bindXPath("/root/list/a").asInt();
        replacedertEquals(Integer.valueOf(1), valueA.set(14));
        valueA.close();
        replacedertXMLStringsEquals("<root><list><a>14</a><b>2</b><c>true</c></list></root>", TestIOUtils.file2String(file));
        CloseableValue<String> string = projector.io().file(file).bindXPath("/root/list/b").replacedtring();
        replacedertEquals("2", string.get());
        string.set("foo");
        string.close();
        replacedertXMLStringsEquals("<root><list><a>14</a><b>foo</b><c>true</c></list></root>", TestIOUtils.file2String(file));
        CloseableValue<Boolean> bool = projector.io().file(file).bindXPath("/root/list/c").asBoolean();
        replacedertTrue(bool.get());
        bool.set(false);
        bool.close();
        replacedertXMLStringsEquals("<root><list><a>14</a><b>foo</b><c>false</c></list></root>", TestIOUtils.file2String(file));
        replacedertTrue(file.delete());
    }

    @Test
    public void testEvaluationAPIWithDateAndFormat() throws IOException {
        final File file = new File("bindTest.xml");
        FileWriter writer = new FileWriter(file);
        writer.write("<root><list><a>19990102</a></list></root>");
        writer.close();
        CloseableValue<Date> valueA = projector.io().file(file).bindXPath("/root/list/a using yyyymmdd").asDate();
        replacedertEquals(915235260000L, valueA.set(new Date(0)).getTime());
        valueA.close();
        replacedertXMLStringsEquals("<root><list><a>19700001</a></list></root>", TestIOUtils.file2String(file));
        replacedertEquals("a", valueA.getName());
    }

    @Test
    public void testEvaluationAPIWithDateAndFormatInEvalAPI() throws IOException {
        Date valueA = projector.onXMLString("<root><list><a>19990102</a></list></root>").evalXPath("/root/list/a using yyyymmdd").asDate();
        replacedertEquals(915235260000L, valueA.getTime());
    }
}

18 View Complete Implementation : TestAutoSubProjectionList.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * @author sven
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoSubProjectionList {

    private final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    private final static String XML = "<root><list><e>1</e><e>2</e><e>3</e></list></root>";

    private final Projection projection = projector.projectXMLString(XML, Projection.clreplaced);

    interface Projection {

        interface E {

            @XBRead("./value/int")
            XBAutoValue<Integer> value();
        }

        @XBRead("/root/list/e")
        List<E> reference();

        @XBRead("/root/list/e")
        XBAutoList<E> projectList();

        @XBRead("/root/list2/e2")
        List<E> reference2();

        @XBRead("/root/list2/e2")
        XBAutoList<E> projectList2();
    }

    @Test
    public void testSimpleAdd() {
        List<Projection.E> list = projection.projectList();
        replacedertFalse(list.isEmpty());
        replacedertEquals("[<e>1</e>,<e>2</e>,<e>3</e>]", projection.reference().toString().replaceAll("\\s", ""));
        Projection.E e = projector.projectEmptyElement("e", Projection.E.clreplaced);
        e.value().set(17);
        list.add(e);
        System.out.println(list);
    // list.add("4");
    // replacedertEquals("[1, 2, 3, 4]",projection.reference().toString());
    // list.add(0, "0");
    // replacedertEquals("[0, 1, 2, 3, 4]",projection.reference().toString());
    // list.add(4, "x");
    // replacedertEquals("[0, 1, 2, 3, x, 4]",projection.reference().toString());
    // list.add(list.size(),"z");
    // replacedertEquals("[0, 1, 2, 3, x, 4, z]",projection.reference().toString());
    // list.clear();
    // replacedertTrue(projection.reference().isEmpty());
    // replacedertTrue(list.isEmpty());
    // list.addAll(Arrays.asList("a","b","c"));
    // replacedertEquals("[a, b, c]",projection.reference().toString());
    // list.addAll(1,Arrays.asList("a2","b2","c2"));
    // replacedertEquals("[a, a2, b2, c2, b, c]",projection.reference().toString());
    }
}

18 View Complete Implementation : TestAutoValues.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced TestAutoValues {

    private final XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    interface EntryWithAttributes {

        @XBRead("./@key")
        XBAutoValue<String> key();

        @XBRead("./@value")
        XBAutoValue<String> value();
    }

    interface EntryWithSubelements {

        @XBRead("./key")
        XBAutoValue<String> key();

        @XBRead("./value")
        XBAutoValue<String> value();
    }

    @Test
    public void testProjecetedAttributes() {
        EntryWithAttributes entry = projector.projectEmptyElement("entry", EntryWithAttributes.clreplaced);
        replacedertEquals("<entry/>", entry.toString().trim());
        entry.key().set("key");
        DOMDiagnoseHelper.replacedertXMLStringsEquals("key=\"key\"", projector.replacedtring(entry.key()));
        replacedertEquals("<entry key=\"key\"/>", entry.toString().trim());
        entry.value().set("value");
        replacedertEquals("<entry key=\"key\" value=\"value\"/>", entry.toString().trim());
        replacedertTrue(entry.value().equals("value"));
        replacedertFalse(entry.value().equals("value2"));
        replacedertEquals("value".hashCode(), entry.value().hashCode());
        entry.value().remove();
        replacedertEquals("<entry key=\"key\"/>", entry.toString().trim());
        replacedertTrue(entry.key().isPresent());
        entry.key().rename("huhu");
        replacedertEquals("<entry huhu=\"key\"/>", entry.toString().trim());
        replacedertFalse(entry.value().isPresent());
        replacedertFalse(entry.key().isPresent());
    }

    @Test
    public void testProjecetedElements() {
        EntryWithSubelements entry = projector.projectEmptyElement("entry", EntryWithSubelements.clreplaced);
        replacedertEquals("<entry/>", entry.toString().trim());
        entry.key().set("key");
        replacedertEquals("<entry><key>key</key></entry>", entry.toString().replaceAll("\\s", ""));
        entry.value().set("value");
        replacedertEquals("<entry><key>key</key><value>value</value></entry>", entry.toString().replaceAll("\\s", ""));
        entry.value().remove();
        replacedertEquals("<entry><key>key</key></entry>", entry.toString().replaceAll("\\s", ""));
        replacedertTrue(entry.key().isPresent());
        entry.key().rename("huhu");
        replacedertEquals("<entry><huhu>key</huhu></entry>", entry.toString().replaceAll("\\s", ""));
        replacedertFalse(entry.value().isPresent());
        replacedertFalse(entry.key().isPresent());
    }

    @Test
    public void testRenameNonexistingAutoValue() {
        EntryWithSubelements entry = projector.projectEmptyElement("entry", EntryWithSubelements.clreplaced);
        XBAutoValue<String> value = entry.value();
        replacedertFalse(value.isPresent());
        value.rename("value2");
        DOMDiagnoseHelper.replacedertXMLStringsEquals("<entry><value2/></entry>", projector.replacedtring(entry));
    }

    @Test
    public void tesreplacederator() {
        EntryWithSubelements entry = projector.projectEmptyElement("entry", EntryWithSubelements.clreplaced);
        replacedertFalse(entry.key().iterator().hasNext());
        entry.key().set("huhu");
        replacedertTrue(entry.key().iterator().hasNext());
        Iterator<String> iterator = entry.key().iterator();
        iterator.next();
        replacedertFalse(iterator.hasNext());
        iterator.remove();
        replacedertFalse(entry.key().iterator().hasNext());
    }
}

18 View Complete Implementation : TestBindAnnotation.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced TestBindAnnotation {

    private final static XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    private final Projection projection = projector.projectEmptyDoreplacedent(Projection.clreplaced);

    private final static String XMLFORMAP = "<root><map><element1>value1</element1><element2><element3 att1=\"attvalue1\" >value2</element3></element2></map></root>";

    private final Projection mapProjection = new XBProjector(Flags.TO_STRING_RENDERS_XML).projectXMLString(XMLFORMAP, Projection.clreplaced);

    interface Subprojection {
    }

    interface Projection {

        @XBAuto("/root/first/second/@attr")
        XBAutoValue<String> attr();

        @XBAuto("/root/list/element")
        List<String> list();

        @XBAuto("/root/map")
        XBAutoMap<String> map();

        @XBAuto("/root/map")
        XBAutoMap<Subprojection> mapSubProjection();

        @XBRead("/root/map")
        Map<String, String> map2();
    }

    interface InvalidProjection {

        @XBAuto("/root")
        Map<Integer, Integer> invalidReturnType();
    }

    @Test
    public void testProjectionBindMethod() {
        projection.attr().set("foo");
        replacedertXMLStringsEquals("<root><first><second attr=\"foo\"/></first></root>", projection.toString());
    }

    @Test
    public void testProjectionBindList() {
        List<String> list = projection.list();
        list.add("foo");
        list.add("bar");
        replacedertEquals("[foo, bar]", list.toString());
    }

    @Test
    public void testProjectionBindMapCreation() {
        Map<String, String> map = mapProjection.map();
        replacedertEquals(null, map.get("a/b/c"));
        map.put("./a/b/c", "newValue");
        replacedertEquals("value1", map.get("./element1"));
        replacedertEquals("newValue", map.get("a/b/c"));
    }

    @Test
    public void testProjectionAutoMapRemove() {
        Map<String, String> map = mapProjection.map();
        replacedertEquals("value2", map.get("element2/element3"));
        replacedertEquals("", map.remove("element2"));
        replacedertNull(map.remove("nonexisting"));
        replacedertEquals(null, map.get("element2/element3"));
    }

    @Test
    public void testProjectionBindMapEmptyAndSize() {
        Map<String, String> map = mapProjection.map();
        replacedertFalse(map.isEmpty());
        replacedertEquals(3, map.size());
    }

    @Test
    public void testProjectionBindMapValues() {
        Map<String, String> map = mapProjection.map();
        System.out.println(mapProjection);
        System.out.println(map.keySet());
        replacedertEquals("[value1, value2, attvalue1]", map.values().toString());
        map.clear();
        replacedertEquals("[]", map.values().toString());
        map.put("ele1/ele2/@att", "someAttValue");
        replacedertEquals("[./ele1/ele2/@att=someAttValue]", map.entrySet().toString());
    }

    @Test
    public void testProjectionBindMapValues2() {
        Map<String, String> map = mapProjection.map2();
        replacedertEquals("[value1, value2, attvalue1]", map.values().toString());
        map.clear();
        replacedertEquals("[]", map.values().toString());
        map.put("ele1/ele2/@att", "someAttValue");
        replacedertEquals("[./ele1/ele2/@att=someAttValue]", map.entrySet().toString());
    }

    @Test
    public void testProjectionAutoMapFullDoreplacedent() {
        XBAutoMap<String> map = projector.autoMapEmptyDoreplacedent(String.clreplaced);
        map.put("someroot/elements/element1", "value1");
        map.put("someroot/elements/element2", "value2");
        map.put("someroot/elements[with/subelement='oink']/element3", "value3");
        map.put("someroot/elements[with/subelement='oink']/element4", "value4");
        map.put("someroot/elements/element5", "value5");
        System.out.println(projector.replacedtring(map));
    }

    @Test
    public void testAmbigousPaths() {
        XBAutoMap<String> map = projector.autoMapEmptyDoreplacedent(String.clreplaced);
        map.put("someroot/elements[@pos='first']/sub[@pos='first']/element1", "value1");
        map.put("someroot/elements[@pos='second']/sub[@pos='second']/element2", "value2");
        map.put("someroot/elements[@pos='second']/sub[@pos='second']/element3", "value3");
        replacedertXMLStringsEquals("<someroot>\n" + "  <elements pos=\"first\">\n" + "    <sub pos=\"first\">\n" + "      <element1>value1</element1>\n" + "    </sub>\n" + "  </elements>\n" + "  <elements pos=\"second\">\n" + "    <sub pos=\"second\">\n" + "      <element2>value2</element2>\n" + "      <element3>value3</element3>\n" + "    </sub>\n" + "  </elements>\n" + "</someroot>\n", projector.replacedtring(map));
    }

    @Test
    public void testPutSubprojection() {
        XBAutoMap<Projection> map = projector.autoMapEmptyDoreplacedent(Projection.clreplaced);
        replacedertTrue(map.isEmpty());
        map.put("root/a", projector.projectEmptyElement("x", Projection.clreplaced));
        map.put("root/b/y", projector.projectEmptyElement("y", Projection.clreplaced));
        replacedertFalse(map.isEmpty());
        replacedertEquals(4, map.size());
        System.out.println(projector.replacedtring(map));
        replacedertXMLStringsEquals("<root>\n" + "  <x/>\n" + "  <b>\n" + "    <y/>\n" + "  </b>\n" + "</root>", projector.replacedtring(map));
    }

    @Test(expected = IllegalArgumentException.clreplaced)
    public void testPutSubprojectionToAttribute() {
        XBAutoMap<Projection> map = projector.autoMapEmptyDoreplacedent(Projection.clreplaced);
        replacedertTrue(map.isEmpty());
        map.put("root/@a", projector.projectEmptyElement("x", Projection.clreplaced));
        System.out.println(projector.replacedtring(map));
    }

    @Test
    public void testSubProjection() {
        System.out.println(projector.replacedtring(mapProjection));
        XBAutoMap<Subprojection> map = mapProjection.mapSubProjection();
        System.out.println(projector.replacedtring(map));
        System.out.println(projector.replacedtring(map.get("element2/element3")));
    }

    @Test(expected = XBException.clreplaced)
    public void testInvalidProjectionReturnType() {
        projector.projectXMLString("<xml></xml>", InvalidProjection.clreplaced);
    }

    @Test
    public void testMapNoNeedToEvaluate() {
        CloseableMap<String> map = projector.io().file("test.xml").bindXPath("/does/not/Exist").asMapOf(String.clreplaced);
        replacedertNull(map.get("another/nonexistend/path"));
    }

    @Test
    public void testMaptoString() {
        XBAutoMap<String> map = projector.onXMLString("<root><foo><bar>huhu</bar><bar>huhu2</bar></foo></root>").createMapOf(String.clreplaced);
        XBAutoList<String> list = map.getList("root/foo/bar");
        replacedertEquals("[huhu, huhu2]", list.toString());
    }
}

18 View Complete Implementation : TestSoapReading.java
Copyright Apache License 2.0
Author : SvenEwald
@SuppressWarnings("javadoc")
public clreplaced TestSoapReading {

    private final static XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    @Test
    public void canParseXML() throws Exception {
        SOAPResponse soapResponse = projector.io().url("res://soap.xml").read(SOAPResponse.clreplaced);
        replacedert.replacedertNotNull(soapResponse.getBody());
        Result result = soapResponse.getBody().getResult();
        replacedert.replacedertNotNull(result);
        replacedert.replacedertEquals("B133243153928547", result.getAlias());
        replacedert.replacedertEquals("Default", result.getAliasType());
        replacedert.replacedertEquals("8514873382743402", result.getPspReference().trim());
        replacedert.replacedertEquals("8414873382748121", result.getRecurringDetailReference().trim());
        replacedert.replacedertEquals("Success", result.getResult());
    }
}

18 View Complete Implementation : TestBug36EmptyLinesAfterChange.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 * This test ensures that after changing a list of elements, no empty lines in the result
 * doreplacedent are created. See bug https://github.com/SvenEwald/xmlbeam/issues/36
 */
@SuppressWarnings("javadoc")
public clreplaced TestBug36EmptyLinesAfterChange {

    private final static XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    private final static String XML = "<root>\n<list>\n<entry>a</entry>\n<entry>b</entry>\n<entry>c</entry>\n</list>\n</root>";

    private interface TestProjection {

        interface Entry {

            @XBRead(".")
            String getValue();

            @XBWrite(".")
            Entry setValue(String value);
        }

        @XBRead("/root/list/entry")
        List<Entry> getEntries();

        @XBWrite("/root/list/entry")
        TestProjection setEntries(List<Entry> entries);

        @XBRead("/root/list/entry")
        List<String> getStringEntries();

        @XBWrite("/root/list/entry")
        TestProjection setStringEntries(List<String> entries);
    }

    @Test
    public void testNoEmptyLinesAfterChange() {
        TestProjection projection = projector.projectXMLString(XML, TestProjection.clreplaced);
        // System.out.println(projection.toString());
        List<TestProjection.Entry> entries = projection.getEntries();
        entries.remove(0);
        entries.add(projector.projectEmptyElement("entry", TestProjection.Entry.clreplaced).setValue("x"));
        projection.setEntries(entries);
        // System.out.println(projection.toString());
        ensureNoEmptyLine(projection.toString());
    }

    @Test
    public void testNoEmptyLinesAfterChange2() {
        TestProjection projection = projector.projectXMLString(XML, TestProjection.clreplaced);
        // System.out.println(projection.toString());
        List<String> entries = projection.getStringEntries();
        entries.remove(0);
        entries.add("x");
        projection.setStringEntries(entries);
        // System.out.println(projection.toString());
        ensureNoEmptyLine(projection.toString());
    }

    private void ensureNoEmptyLine(String string) {
        Scanner scanner = new Scanner(string).useDelimiter("\n");
        while (scanner.hasNext()) {
            String line = scanner.next();
            replacedertFalse(line.trim().isEmpty());
        }
    }
}

18 View Complete Implementation : TestDataNotFoundException.java
Copyright Apache License 2.0
Author : SvenEwald
/**
 */
@SuppressWarnings("javadoc")
public clreplaced TestDataNotFoundException {

    private final static XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    private final static String XML = "<root><element attrib='attribValue'>elementValue</element></root>";

    private final static TestProjection projection = projector.projectXMLString(XML, TestProjection.clreplaced);

    interface TestProjection {

        @XBRead("/root/element/@notthere")
        String getNonexistingAttribute() throws XBDataNotFoundException;

        @XBRead("/root/element/notthere")
        String getNonexistingValue() throws XBDataNotFoundException;

        @XBUpdate("/root/element/@notthere")
        void updateNonexistingAttribute(String v) throws XBDataNotFoundException;

        @XBUpdate("/root/element/notthere")
        void updateNonexistingValue(String v) throws XBDataNotFoundException;

        @XBDelete("/root/element/@notthere")
        void deleteNonexistingAttribute() throws XBDataNotFoundException;

        @XBDelete("/root/element/notthere")
        void deleteNonexistingValue() throws XBDataNotFoundException;
    }

    @Test(expected = XBDataNotFoundException.clreplaced)
    public void testExceptionOnAttributget() {
        projection.getNonexistingAttribute();
    }

    @Test(expected = XBDataNotFoundException.clreplaced)
    public void testExceptionOnValueget() {
        projection.getNonexistingValue();
    }

    @Test(expected = XBDataNotFoundException.clreplaced)
    public void testExceptionOnAttributupdate() {
        projection.updateNonexistingAttribute("x");
    }

    @Test(expected = XBDataNotFoundException.clreplaced)
    public void testExceptionOnValueupdate() {
        projection.updateNonexistingValue("x");
    }

    @Test(expected = XBDataNotFoundException.clreplaced)
    public void testExceptionOnAttributdelete() {
        projection.deleteNonexistingAttribute();
    }

    @Test(expected = XBDataNotFoundException.clreplaced)
    public void testExceptionOnValuedelete() {
        projection.deleteNonexistingValue();
    }
}

18 View Complete Implementation : TestAutoFileBindings.java
Copyright Apache License 2.0
Author : SvenEwald
@SuppressWarnings("javadoc")
public clreplaced TestAutoFileBindings {

    XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);

    File file;

    private String origEOL;

    @Before
    public void createFile() throws IOException {
        origEOL = System.getProperty("line.separator");
        System.setProperty("line.separator", "\r\n");
        File tempFile = File.createTempFile(this.getClreplaced().getSimpleName(), Long.toBinaryString(System.currentTimeMillis()));
        DOMAccess domAccess = projector.projectXMLString("<root><foo><bar>huhu</bar></foo></root>", DOMAccess.clreplaced);
        projector.io().file(tempFile).write(domAccess);
        this.file = tempFile;
    }

    @After
    public void deleteFile() {
        file.delete();
        System.setProperty("line.separator", origEOL);
    }

    @Test
    public void testMapExistingFile() throws IOException {
        replacedertEquals(57, file.length());
        CloseableMap<String> map = projector.io().file(file).bindAsMapOf(String.clreplaced);
        replacedertEquals("huhu", map.get("root/foo/bar"));
        map.put("root/foo2/bar2", "huhu2");
        map.close();
        replacedertEquals(102, file.length());
    }

    @Test
    public void testMapExistingFileWithXpath() throws IOException {
        replacedertEquals(57, file.length());
        CloseableMap<String> map = projector.io().file(file).bindXPath("root").asMapOf(String.clreplaced);
        replacedertEquals("huhu", map.get("foo/bar"));
        map.put("foo2/bar2", "huhu2");
        map.close();
        replacedertEquals(102, file.length());
    }

    @Test
    public void testMapNonExistingFile() throws IOException {
        File file = File.createTempFile(this.getClreplaced().getSimpleName(), Long.toBinaryString(System.currentTimeMillis()));
        file.delete();
        replacedertEquals(0, file.length());
        CloseableMap<String> map = projector.io().file(file).bindAsMapOf(String.clreplaced);
        replacedertTrue(map.isEmpty());
        map.put("root/foo2/bar2", "huhu2");
        map.close();
        replacedertEquals(62, file.length());
        file.delete();
    }

    @Test(expected = FileNotFoundException.clreplaced)
    public void testMapNonExistingFileFails() throws IOException {
        projector.io().file("doesNot.Exist").failIfNotExists().bindAsMapOf(String.clreplaced);
    }

    @Test
    public void testListExistingFile() throws IOException {
        replacedertEquals(57, file.length());
        CloseableList<String> list = projector.io().file(file).bindXPath("/root/foo/bar").asListOf(String.clreplaced);
        replacedertEquals(1, list.size());
        replacedertEquals("huhu", list.get(0));
        list.add("huhu2");
        list.close();
        replacedertEquals(79, file.length());
    }

    @Test
    public void testMapExistingFileReadOnly() throws IOException {
        replacedertEquals(57, file.length());
        XBAutoMap<String> map = projector.io().file(file).readAsMapOf(String.clreplaced);
        replacedertEquals("huhu", map.get("root/foo/bar"));
        map.put("root/foo2/bar2", "huhu2");
        if (map instanceof Closeable) {
            ((Closeable) map).close();
        }
        replacedertEquals(57, file.length());
    }

    @Test
    public void testvalueBindToFile() throws IOException {
        replacedertEquals(57, file.length());
        CloseableValue<String> value = projector.io().file(file).bindXPath("/root/foo/bar").as(String.clreplaced);
        replacedertEquals("huhu", value.get());
        value.set("huhu2");
        value.close();
        replacedertEquals(58, file.length());
    }

    @Test
    public void testMapExistingFileReadOnlyThenToList() throws IOException {
        replacedertEquals(57, file.length());
        XBAutoMap<String> map = projector.io().file(file).readAsMapOf(String.clreplaced);
        replacedertEquals("huhu", map.get("root/foo/bar"));
        XBAutoList<String> list = map.getList("root/foo/bar");
        replacedertEquals("[huhu]", list.toString());
        list.add("huhu2");
        System.out.println(projector.replacedtring(map));
        DOMDiagnoseHelper.replacedertXMLStringsEquals("<root><foo><bar>huhu</bar><bar>huhu2</bar></foo></root>", projector.replacedtring(map));
    }
}