Package org.pdf4j.saxon.type

Examples of org.pdf4j.saxon.type.ItemType


    public ItemType getItemType(TypeHierarchy th) {
        switch (node.getNodeKind()) {
            case Type.DOCUMENT:
                // Need to know whether the document is well-formed and if so what the element type is
                AxisIterator iter = node.iterateAxis(Axis.CHILD);
                ItemType elementType = null;
                while (true) {
                    NodeInfo n = (NodeInfo)iter.next();
                    if (n==null) {
                        break;
                    }
View Full Code Here


     * @return the conversion preference. A high number indicates a low preference;
     * -1 indicates that conversion is not possible.
     */

    private int getConversionPreference(TypeHierarchy th, Expression arg, cli.System.Type required) {
        ItemType itemType = arg.getItemType(th);
        int cardinality = arg.getCardinality();
        if (required == DotNetExtensionFunctionCall.CLI_OBJECT) {
            return 100;
        } else if (Cardinality.allowsMany(cardinality)) {
            if (required.IsAssignableFrom(DotNetExtensionFunctionCall.CLI_SEQUENCEITERATOR)) {
                return 20;
//            } else if (required.IsAssignableFrom(DotNetExtensionFunctionCall.CLI_XDMVALUE)) {
//                return 21;
            } else if (required.IsAssignableFrom(DotNetExtensionFunctionCall.CLI_VALUE)) {
                return 22;
            } else if (DotNetExtensionFunctionCall.CLI_ICOLLECTION.IsAssignableFrom(required)) {
                return 23;
            } else if (required.get_IsArray()) {
                return 24;
                // sort out at run-time whether the component type of the array is actually suitable
            } else {
                return 80;    // conversion possible only if external object model supports it
            }
        } else {
            if (Type.isNodeType(itemType)) {
                if (required.IsAssignableFrom(DotNetExtensionFunctionCall.CLI_NODEINFO)) {
                    return 20;
                } else if (required.IsAssignableFrom(DotNetExtensionFunctionCall.CLI_DOCUMENTINFO)) {
                    return 21;
//                } else if (required.IsAssignableFrom(DotNetExtensionFunctionCall.CLI_XDMNODE)) {
//                    return 20;
                } else {
                    return 80;
                }
//            } else if (itemType instanceof ExternalObjectType) {
                // TODO: support wrapping of external .NET objects
//                cli.System.Type ext = ((ExternalObjectType)itemType).getJavaClass();
//                if (required.IsAssignableFrom(ext)) {
//                    return 10;
//                } else {
//                    return -1;
//                }
            } else {
                int primitiveType = itemType.getPrimitiveType();
                return atomicConversionPreference(primitiveType, required);
            }
        }
    }
View Full Code Here

            trace.setContainer(compiledTemplate);
            exp = trace;
            compiledTemplate.setBody(exp);
        }

        ItemType contextItemType = Type.ITEM_TYPE;
        if (getObjectName() == null) {
            // the template can't be called by name, so the context item must match the match pattern
            contextItemType = match.getNodeTest();
        }
View Full Code Here

            }
        }
        Expression expr = ExpressionTool.make(expression, staticContext,
                0, Token.EOF, getDocumentLocator().getLineNumber(locationId), false);
        expr.setContainer(staticContext);
        ItemType contextItemType = Type.ITEM_TYPE;
        ExpressionVisitor visitor = ExpressionVisitor.make(staticContext);
        expr = visitor.typeCheck(expr, contextItemType);
        SlotManager stackFrameMap = getPipelineConfiguration().getConfiguration().makeSlotManager();
        ExpressionTool.allocateSlots(expr, stackFrameMap.getNumberOfVariables(), stackFrameMap);
        Controller controller = new Controller(getConfiguration());
View Full Code Here

    * "external". (EXSLT spec not yet modified to cater for XPath 2.0 data model)
    */

    public static String objectType(XPathContext context, ValueRepresentation value) {
        final TypeHierarchy th = context.getConfiguration().getTypeHierarchy();
        ItemType type = Value.asValue(value).getItemType(th);
        if (th.isSubType(type, AnyNodeTest.getInstance())) {
            return "node-set";
        } else if (th.isSubType(type, BuiltInAtomicType.STRING)) {
            return "string";
        } else if (th.isSubType(type, BuiltInAtomicType.NUMERIC)) {
            return "number";
        } else if (th.isSubType(type, BuiltInAtomicType.BOOLEAN)) {
            return "boolean";
        } else {
            return type.toString(context.getNamePool());
        }
    }
View Full Code Here

            resultConverter = JPConverter.allocate(resultClass, config);
        } else {
            throw new AssertionError("Unknown component type");
        }

        ItemType resultType = resultConverter.getItemType();
        checkForNodes = resultType == AnyItemType.getInstance() || resultType instanceof NodeTest;
        resetLocalStaticProperties();
       
        return this;
    }
View Full Code Here

     * @return the conversion preference. A high number indicates a low preference;
     * -1 indicates that conversion is not possible.
     */

    private int getConversionPreference(TypeHierarchy th, Expression arg, Class required) {
        ItemType itemType = arg.getItemType(th);
        int cardinality = arg.getCardinality();
        if (required == Object.class) {
            return 100;
        } else if (Cardinality.allowsMany(cardinality)) {
            if (required.isAssignableFrom(SequenceIterator.class)) {
                return 20;
            } else if (required.isAssignableFrom(Value.class)) {
                return 21;
            } else if (Collection.class.isAssignableFrom(required)) {
                return 22;
            } else if (required.isArray()) {
                return 24;
                // sort out at run-time whether the component type of the array is actually suitable
            } else {
                return 80;    // conversion possible only if external object model supports it
            }
        } else {
            if (Type.isNodeType(itemType)) {
                if (required.isAssignableFrom(NodeInfo.class)) {
                    return 20;
                } else if (required.isAssignableFrom(DocumentInfo.class)) {
                    return 21;
                } else {
                    return 80;
                }
            } else if (itemType instanceof ExternalObjectType) {
                Class ext = ((ExternalObjectType)itemType).getJavaClass();
                if (required.isAssignableFrom(ext)) {
                    return 10;
                } else {
                    return -1;
                }
            } else {
                int primitiveType = itemType.getPrimitiveType();
                return atomicConversionPreference(primitiveType, required);
            }
        }
    }
View Full Code Here

    }

    public boolean effectiveBooleanValue(XPathContext context) throws XPathException {
        // EBV is independent of sequence order unless the sequence mixes atomic values and nodes
        // Note, calls to get the EBV of reverse() should normally have been rewritten at compile time
        ItemType type = argument[0].getItemType(context.getConfiguration().getTypeHierarchy());
        if (type == AnyItemType.getInstance()) {
            return super.effectiveBooleanValue(context);
        } else {
            return argument[0].effectiveBooleanValue(context);
        }
View Full Code Here

            if (var.getRequiredType() == SequenceType.ANY_SEQUENCE && !(var instanceof GlobalParam)) {
                // no type was declared; try to deduce a type from the value
                try {
                    final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy();
                    final ItemType itemType = value.getItemType(th);
                    final int cardinality = value.getCardinality();
                    var.setRequiredType(SequenceType.makeSequenceType(itemType, cardinality));
                    Value constantValue = null;
                    if (value2 instanceof Literal) {
                        constantValue = ((Literal)value2).getValue();
View Full Code Here

                    for (int i=1; i<10; i++) {
                        pexpr.variables[i-1] = staticContext.declareVariable("", "p"+i);
                    }
                    Expression expr = ExpressionTool.make(exprText, staticContext, 0, Token.EOF, 1, false);

                    ItemType contextItemType = Type.ITEM_TYPE;
                    expr = visitor.typeCheck(expr, contextItemType);
                    pexpr.stackFrameMap = staticContext.getStackFrameMap();
                    ExpressionTool.allocateSlots(expr, pexpr.stackFrameMap.getNumberOfVariables(), pexpr.stackFrameMap);
                    pexpr.expression = expr;
                    return new Literal(new ObjectValue(pexpr));
View Full Code Here

TOP

Related Classes of org.pdf4j.saxon.type.ItemType

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