Search in sources :

Example 1 with AbstractContainerProperty

use of com.ibm.xsp.registry.AbstractContainerProperty in project org.openntf.nsfodp by OpenNTF.

the class AbstractSchemaServlet method outProperty.

private void outProperty(FacesDefinition def, FacesProperty prop, Element element, SharableRegistryImpl registry) {
    // TODO check run/load binding from FacesSimpleProperty
    Class<?> clazz = prop.getJavaClass();
    if (prop instanceof AbstractContainerProperty) {
        clazz = ((AbstractContainerProperty) prop).getItemProperty().getJavaClass();
    }
    if (isBindingType(prop)) {
        outAttribute(def, prop, element, extMap.get(this.namespace) + ":attrBinding", false);
    } else if (byte.class.equals(clazz) || short.class.equals(clazz) || int.class.equals(clazz) || long.class.equals(clazz) || Byte.class.equals(clazz) || Short.class.equals(clazz) || Integer.class.equals(clazz) || Long.class.equals(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrInteger", false);
    } else if (boolean.class.equals(clazz) || Boolean.class.equals(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrBoolean", false);
    } else if (float.class.equals(clazz) || double.class.equals(clazz) || Number.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrDecimal", false);
    } else if (LocalTime.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrTime", false);
    } else if (Date.class.equals(clazz) || TemporalAccessor.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrDate", false);
    } else if ("id".equals(prop.getName())) {
        outAttribute(def, prop, element, "xs:ID", false);
    } else if (CharSequence.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, "xs:string", false);
    } else if (Object.class.equals(clazz) || FacesListener.class.isAssignableFrom(clazz)) {
        // FacesListeners lead to an xp: prefix below if left unhandled
        outAttribute(def, prop, element, "xs:string", false);
    } else {
        // Figure out if it's complex or not
        Class<?> finalClazz = clazz;
        FacesDefinition propDef = registry.findDefs().stream().filter(def2 -> def2.getJavaClass().equals(finalClazz)).findFirst().orElse(null);
        if (propDef != null) {
            outAttribute(def, prop, element, extMap.get(propDef.getNamespaceUri()) + ':' + toElementName(propDef, false), true);
        } else {
            outAttribute(def, prop, element, "xs:string", false);
        }
    }
}
Also used : FacesDefinition(com.ibm.xsp.registry.FacesDefinition) FacesListener(javax.faces.event.FacesListener) AbstractContainerProperty(com.ibm.xsp.registry.AbstractContainerProperty)

Example 2 with AbstractContainerProperty

use of com.ibm.xsp.registry.AbstractContainerProperty in project org.openntf.nsfodp by OpenNTF.

the class AbstractSchemaServlet method outAttribute.

private void outAttribute(FacesDefinition def, FacesProperty prop, Element element, String type, boolean complex) {
    Document doc = element.getOwnerDocument();
    Element all = (Element) element.getFirstChild();
    // Create a this.child child
    Element thisElement = DOMUtil.createElement(doc, all, "xs:element");
    thisElement.setAttribute("name", "this." + prop.getName());
    if (complex || isBindingType(prop)) {
        Element complexType = DOMUtil.createElement(doc, thisElement, "xs:complexType");
        if (isBindingType(prop)) {
            // Bindings are a mess
            complexType.setAttribute("mixed", "true");
        }
        Element sequence = DOMUtil.createElement(doc, complexType, "xs:choice");
        if (prop instanceof AbstractContainerProperty) {
            // Then mark its upper bound as unlimited
            sequence.setAttribute("maxOccurs", "unbounded");
        }
        sequence.setAttribute("minOccurs", "0");
        Element any = DOMUtil.createElement(doc, sequence, "xs:any");
        any.setAttribute("maxOccurs", "unbounded");
        any.setAttribute("processContents", "lax");
    } else {
        thisElement.setAttribute("type", type);
    }
    outAnnotations(def, prop, thisElement);
    Element attribute = DOMUtil.createElement(doc, element, "xs:attribute");
    attribute.setAttribute("name", prop.getName());
    if (complex) {
        // Attributes have to be simple
        attribute.setAttribute("type", extMap.get(namespace) + ":attrBinding");
    } else {
        attribute.setAttribute("type", type);
    }
    // TODO see if we can match either an attr or a this. child
    // if(prop.isRequired()) {
    // attribute.setAttribute("use", "required");
    // }
    outAnnotations(def, prop, attribute);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) AbstractContainerProperty(com.ibm.xsp.registry.AbstractContainerProperty)

Aggregations

AbstractContainerProperty (com.ibm.xsp.registry.AbstractContainerProperty)2 FacesDefinition (com.ibm.xsp.registry.FacesDefinition)1 FacesListener (javax.faces.event.FacesListener)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1