Examples of Convertor


Examples of com.alibaba.tamper.process.convertor.Convertor

                    Class clazz = ReflectionHelper.forName(clazzNode.getNodeValue());
                    if (!Convertor.class.isAssignableFrom(clazz)) { // 检查下必须为Convertor的子类
                        throw new BeanMappingException(clazz.toString() + " is not implements Convertor");
                    }

                    Convertor convertor = (Convertor) ReflectionHelper.newInstance(clazz);
                    if (aliasNode != null) {
                        // 注册为别名
                        String alias = aliasNode.getNodeValue();
                        ConvertorHelper.getInstance().registerConvertor(alias, convertor);
View Full Code Here

Examples of com.alibaba.tamper.process.convertor.Convertor

        // 处理下自己的业务
        BeanMappingField currentField = invocation.getContext().getCurrentField();
        if (value == null && StringUtils.isNotEmpty(currentField.getDefaultValue())
            && currentField.isMapping() == false) {
            if (currentField.getSrcField().getClazz() != null) {// 有指定对应的SrcClass
                Convertor convertor = ConvertorHelper.getInstance().getConvertor(String.class,
                                                                                 currentField.getSrcField().getClazz());
                if (convertor != null) {
                    // 先对String字符串进行一次转化
                    value = convertor.convert(currentField.getDefaultValue(), currentField.getSrcField().getClazz());
                }
            }

            if (value == null) {
                // 不存在对默认值处理的convertor,不予处理,后续尝试下自定义的convertor
View Full Code Here

Examples of com.alibaba.tamper.process.convertor.Convertor

    @Override
    public Object process(Object value, ValueProcessInvocation invocation) throws BeanMappingException {
        if (value != null && invocation.getContext().getCurrentField().isMapping() == false) {
            BeanMappingField currentField = invocation.getContext().getCurrentField();
            String customConvertorName = currentField.getConvertor();
            Convertor convertor = currentField.getConvertorRef();// 取上一次实例化后的convertor对象

            if (convertor == null && currentField.getConvertorClass() != null) {
                // 进行自定义convertor初始化
                Class clazz = currentField.getConvertorClass();
                convertor = (Convertor) ReflectionHelper.newInstance(clazz);
                currentField.setConvertorRef(convertor);
            }

            if (StringUtils.isNotEmpty(customConvertorName)) { // 判断是否有自定义的convertor
                convertor = ConvertorHelper.getInstance().getConvertor(customConvertorName);
            } else if (convertor == null) {
                // srcClass针对直接使用script的情况,会出现为空,这时候需要依赖value.getClass进行转化
                // 优先不选择使用value.getClass()的原因:原生类型会返回对应的Object类型,导出会出现不必要的convertor转化
                Class srcClass = currentField.getSrcField().getClazz();
                if (srcClass == null || srcClass.isPrimitive() == false) {
                    srcClass = value.getClass();
                }
                Class targetClass = currentField.getTargetField().getClazz();
                if (targetClass != null) {
                    // targetClass可能存在为空,比如这里的Value配置了DefaultValue,在MapSetExecutor解析时会无法识别TargetClass
                    // 无法识别后,就不做转化
                    convertor = ConvertorHelper.getInstance().getConvertor(srcClass, targetClass);

                    if (convertor == null && !targetClass.isAssignableFrom(srcClass) && logger.isWarnEnabled()) {
                        // 记录下日志
                        StringBuilder builder = new StringBuilder();
                        builder.append("srcName[" + currentField.getSrcField().getName());
                        builder.append("],srcClass[" + ObjectUtils.toString(srcClass, "null"));
                        builder.append("],targetName[" + currentField.getTargetField().getName());
                        builder.append("],targetClass[" + ObjectUtils.toString(targetClass, "null") + "]");
                        logger.warn(builder.toString() + " convertor is null!");
                    }
                }
            }

            if (convertor != null && currentField.getTargetField().getClazz() != null) {
                List<Class> componentClasses = currentField.getTargetField().getComponentClasses();
                Class[] array = null;
                if (componentClasses != null && componentClasses.size() > 0) {
                    array = componentClasses.toArray(new Class[componentClasses.size()]);
                }
                if (array != null && convertor instanceof CollectionConvertor) {
                    // 进行嵌套对象处理
                    value = ((CollectionConvertor) convertor).convertCollection(
                                                                                currentField,
                                                                                value,
                                                                                currentField.getTargetField().getClazz(),
                                                                                array);
                } else {
                    value = convertor.convert(value, currentField.getTargetField().getClazz());
                }
            }
        }

        // 继续下一步的调用
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

            Element updateWrapElement =
                DomHelper.getChildElement(bindingElm, BindingManager.NAMESPACE, "on-update");
            JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement);

            Convertor convertor = null;
            Locale convertorLocale = Locale.US;
            Element convertorEl = DomHelper.getChildElement(bindingElm, Constants.DEFINITION_NS, "convertor");
            if (convertorEl != null) {
                String datatype = DomHelper.getAttribute(convertorEl, "datatype");
                String localeStr = convertorEl.getAttribute("locale");
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

        return selectionList;
    }

    private  SelectionList buildStaticList(Element selectionListElement, Datatype datatype) throws Exception {
        StaticSelectionList selectionList = new StaticSelectionList(datatype);
        Convertor convertor = null;
        Convertor.FormatCache formatCache = new DefaultFormatCache();

        NodeList children = selectionListElement.getChildNodes();
        for (int i = 0; children.item(i) != null; i++) {
            Node node = children.item(i);
            if (convertor == null && node instanceof Element && Constants.DEFINITION_NS.equals(node.getNamespaceURI()) && "convertor".equals(node.getLocalName())) {
                Element convertorConfigElement = (Element)node;
                try {
                    convertor = datatype.getBuilder().buildConvertor(convertorConfigElement);
                } catch (Exception e) {
                    throw new SAXException("Error building convertor from convertor configuration embedded in selection list XML.", e);
                }
            } else if (node instanceof Element && Constants.DEFINITION_NS.equals(node.getNamespaceURI()) && "item".equals(node.getLocalName())) {
                if (convertor == null) {
                    convertor = datatype.getConvertor();
                }
                Element element = (Element)node;
                String stringValue = element.getAttribute("value");
                Object value;
                if ("".equals(stringValue)) {
                    // Empty value translates into the null object
                    value = null;
                } else {
                    ConversionResult conversionResult = convertor.convertFromString(stringValue, Locale.US, formatCache);
                    if (!conversionResult.isSuccessful()) {
                        throw new Exception("Could not convert the value \"" + stringValue +
                                            "\" to the type " + datatype.getDescriptiveName() +
                                            ", defined at " + DomHelper.getLocation(element));
                    }
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

            Element updateWrapElement =
                DomHelper.getChildElement(bindingElem, BindingManager.NAMESPACE, "on-update");
            JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement);

            Convertor convertor = null;
            Locale convertorLocale = Locale.US;
            Element convertorEl = DomHelper.getChildElement(bindingElem, Constants.DEFINITION_NS, "convertor");
            if (convertorEl != null) {
                String datatype = DomHelper.getAttribute(convertorEl, "datatype");
                String localeStr = convertorEl.getAttribute("locale");
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

        }
    }

    public void buildConvertor(Element datatypeEl, AbstractDatatype datatype) throws Exception {
        Element convertorEl = DomHelper.getChildElement(datatypeEl, Constants.DEFINITION_NS, "convertor", false);
        Convertor convertor = buildConvertor(convertorEl);
        datatype.setConvertor(convertor);
    }
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

        return selectionList;
    }
  
    private  SelectionList buildStaticList(Element selectionListElement, Datatype datatype) throws Exception {
        StaticSelectionList selectionList = new StaticSelectionList(datatype);
        Convertor convertor = null;
        Convertor.FormatCache formatCache = new DefaultFormatCache();

        NodeList children = selectionListElement.getChildNodes();
        for (int i = 0; children.item(i) != null; i++) {
            Node node = children.item(i);
            if (convertor == null && node instanceof Element && Constants.DEFINITION_NS.equals(node.getNamespaceURI()) && "convertor".equals(node.getLocalName())) {
                Element convertorConfigElement = (Element)node;
                try {
                    convertor = datatype.getBuilder().buildConvertor(convertorConfigElement);
                } catch (Exception e) {
                    throw new SAXException("Error building convertor from convertor configuration embedded in selection list XML.", e);
                }
            } else if (node instanceof Element && Constants.DEFINITION_NS.equals(node.getNamespaceURI()) && "item".equals(node.getLocalName())) {
                if (convertor == null) {
                    convertor = datatype.getConvertor();
                }
                Element element = (Element)node;
                String stringValue = element.getAttribute("value");
                Object value;
                if ("".equals(stringValue)) {
                    // Empty value translates into the null object
                    value = null;
                } else {
                    ConversionResult conversionResult = convertor.convertFromString(stringValue, Locale.US, formatCache);
                    if (!conversionResult.isSuccessful()) {
                        throw new Exception("Could not convert the value \"" + stringValue +
                                            "\" to the type " + datatype.getDescriptiveName() +
                                            ", defined at " + DomHelper.getLocation(element));
                    }
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

            Element updateWrapElement =
                DomHelper.getChildElement(bindingElem, BindingManager.NAMESPACE, "on-update");
            JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement);

            Convertor convertor = null;
            Locale convertorLocale = Locale.US;
            Element convertorEl = DomHelper.getChildElement(bindingElem, Constants.DEFINITION_NS, "convertor");
            if (convertorEl != null) {
                String datatype = DomHelper.getAttribute(convertorEl, "datatype");
                String localeStr = convertorEl.getAttribute("datatype");
View Full Code Here

Examples of org.apache.cocoon.forms.datatype.convertor.Convertor

            Element updateWrapElement =
                DomHelper.getChildElement(bindingElm, BindingManager.NAMESPACE, "on-update");
            JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement);

            Convertor convertor = null;
            Locale convertorLocale = Locale.US;
            Element convertorEl = DomHelper.getChildElement(bindingElm, Constants.DEFINITION_NS, "convertor");
            if (convertorEl != null) {
                String datatype = DomHelper.getAttribute(convertorEl, "datatype");
                String localeStr = convertorEl.getAttribute("datatype");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.