• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UncastData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.javarosa.core.model.data.UncastData的典型用法代码示例。如果您正苦于以下问题:Java UncastData类的具体用法?Java UncastData怎么用?Java UncastData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UncastData类属于org.javarosa.core.model.data包,在下文中一共展示了UncastData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setAttribute

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public static void setAttribute(TreeElement parent, List<TreeElement> attrs, String namespace, String name, String value) {

		TreeElement attribut = getAttribute(attrs, namespace, name);
		if ( attribut != null ) {
			if (value == null) {
				attrs.remove(attribut);
			} else {
				attribut.setValue(new UncastData(value));
			}
			return;
		}

		// null-valued attributes are a "remove-this" instruction... ignore them
		if ( value == null ) return;

		// create an attribute...
		TreeElement attr = TreeElement.constructAttributeElement(namespace, name, value);
		attr.setParent(parent);

		attrs.add(attr);
	}
 
开发者ID:medic,项目名称:javarosa,代码行数:22,代码来源:TreeElement.java


示例2: getWidgetValue

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
protected IAnswerData getWidgetValue () throws InvalidDataException {
    String s = textField().getString().trim();
    if (s == null || s.equals("")) {
        return null;
    }
    try {
        return template.cast(new UncastData(s));
    } catch (IllegalArgumentException iae) {
        String message;
        //See if we can provide good details
        if(template instanceof LongData) {
            message = Localization.get("form.entry.badnum.long", new String[] {s});
        } else if(template instanceof IntegerData) {
            message = Localization.get("form.entry.badnum.int", new String[] {s});
        } else if(template instanceof DecimalData) {
            message = Localization.get("form.entry.badnum.dec", new String[] {s});
        } else {
            message = Localization.get("form.entry.badnum", new String[] {s, template.getClass().getName()});
        }
        throw new InvalidDataException(message, new UncastData(s));
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:23,代码来源:NumericEntryWidget.java


示例3: replayQuestion

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
private String replayQuestion() {
    FormIndex questionIndex = formEntryController.getModel().getFormIndex();
    TreeReference questionRef = questionIndex.getReference();
    FormEntryAction action = formEntrySession.getAndRemoveActionForRef(questionRef);
    if (action != null) {
        if (!action.isSkipAction()) {
            FormEntryPrompt entryPrompt =
                    formEntryController.getModel().getQuestionPrompt(questionIndex);
            IAnswerData answerData =
                    AnswerDataFactory.template(entryPrompt.getControlType(),
                            entryPrompt.getDataType()).cast(new UncastData(action.getValue()));
            formEntryController.answerQuestion(questionIndex, answerData);
        }
    }
    return questionRef.toString();
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:17,代码来源:FormEntrySessionReplayer.java


示例4: addDefaultClasses

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
private void addDefaultClasses() {
    Class[] baseTypes = {
            Object.class,
            Integer.class,
            Long.class,
            Short.class,
            Byte.class,
            Character.class,
            Boolean.class,
            Float.class,
            Double.class,
            String.class,
            Date.class,
            UncastData.class
    };

    for (Class baseType : baseTypes) {
        addClass(baseType);
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:21,代码来源:PrototypeFactory.java


示例5: testLoopedRepeatIndexFetches

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
/**
 * Regressions around complex repeat behaviors
 */
@Test
public void testLoopedRepeatIndexFetches() throws Exception {
    FormParseInit fpi = new FormParseInit("/xform_tests/test_looped_form_index_fetch.xml");
    FormEntryController fec = initFormEntry(fpi);

    fec.stepToNextEvent();
    fec.stepToNextEvent();

    fec.answerQuestion(new IntegerData(2));
    while(fec.stepToNextEvent() != FormEntryController.EVENT_QUESTION);

    fec.answerQuestion(new UncastData("yes"));
    while(fec.stepToNextEvent() != FormEntryController.EVENT_QUESTION) ;

    fec.getNextIndex(fec.getModel().getFormIndex(), true);
    fec.answerQuestion(new IntegerData(2));
    fec.getNextIndex(fec.getModel().getFormIndex(), true);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:22,代码来源:FormDefTest.java


示例6: setCaseProperties

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
private void setCaseProperties(Case c, TreeElement cacheBuilder) {
    for (Enumeration en = c.getProperties().keys(); en.hasMoreElements(); ) {
        String key = (String)en.nextElement();

        //this is an unfortunate complication of our internal model
        if (LAST_MODIFIED_KEY.equals(key)) {
            continue;
        }

        TreeElement scratch = new TreeElement(parent.intern(key));
        Object temp = c.getProperty(key);
        if (temp instanceof String) {
            scratch.setValue(new UncastData((String)temp));
        } else {
            scratch.setValue(PreloadUtils.wrapIndeterminedObject(temp));
        }
        cacheBuilder.addChild(scratch, true);
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:20,代码来源:CaseChildElement.java


示例7: answer

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public SurveyAction answer(String answerText){
	int answerResult=0;
	
	try{
		if(answerText == null || answerText.equals("")){
			//try to add empty answer
			answerResult = formController.answerQuestion(formController.getFormIndex(), null);
		}else{
			IAnswerData answerContainer = getAnswerContainer();
			UncastData uncastData = new UncastData(answerText);
			IAnswerData answeredContainer = answerContainer.cast(uncastData);
			answerResult = formController.answerQuestion(formController.getFormIndex(),answeredContainer);	
		}
	}catch(JavaRosaException e){
		flagInvalidAnswer(e.getLocalizedMessage());
	}
	
	if(answerResult == FormEntryController.ANSWER_CONSTRAINT_VIOLATED)
		flagInvalidAnswer("Constraint Violated");
	else if(answerResult == FormEntryController.ANSWER_REQUIRED_BUT_EMPTY)
		flagInvalidAnswer(SurveyMessageConstants.ANSWER_REQUIRED_TEXT);
	
	if(invalidAnswerProvided)
		return SurveyAction.stay;
	return SurveyAction.forward;
}
 
开发者ID:smap-consulting,项目名称:smap-survey-manager,代码行数:27,代码来源:QuestionEvent.java


示例8: buildPartialElementFromMetadata

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
private TreeElement buildPartialElementFromMetadata(String[] columnNames, String[] metadataValues) {
    TreeElement partial = new TreeElement(parent.getChildHintName());
    partial.setMult(mult);
    partial.setParent(this.parent);

    for(int i =0 ; i < columnNames.length; ++i) {
        String columnName = columnNames[i];
        String value = metadataValues[i];

        String metadataName = StorageIndexedTreeElementModel.
                getElementOrAttributeFromSqlColumnName(columnName);

        if (metadataName.startsWith("@")) {
            partial.setAttribute(null, metadataName.substring(1), value);
        } else {
            TreeElement child = new TreeElement(metadataName);
            child.setValue(new UncastData(value));
            partial.addChild(child);
        }
    }
    return partial;
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:23,代码来源:IndexedFixtureChildElement.java


示例9: distance

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
/**
 * Returns the distance between two GeoPointData locations, in meters, given objects to unpack.
 * Ignores altitude and accuracy.
 * Note that the arguments can be strings.
 * Returns -1 if one of the arguments is null or the empty string.
 */
public static Double distance(Object from, Object to) {
    String unpackedFrom = (String)FunctionUtils.unpack(from);
    String unpackedTo = (String)FunctionUtils.unpack(to);

    if (unpackedFrom == null || "".equals(unpackedFrom) || unpackedTo == null || "".equals(unpackedTo)) {
        return new Double(-1.0);
    }

    try {
        // Casting and uncasting seems strange but is consistent with the codebase
        GeoPointData castedFrom = new GeoPointData().cast(new UncastData(unpackedFrom));
        GeoPointData castedTo = new GeoPointData().cast(new UncastData(unpackedTo));

        return new Double(GeoPointUtils.computeDistanceBetween(castedFrom, castedTo));
    } catch (NumberFormatException e) {
        throw new XPathTypeMismatchException("distance() function requires arguments containing " +
                "numeric values only, but received arguments: " + unpackedFrom + " and " + unpackedTo);
    }
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:26,代码来源:XPathDistanceFunc.java


示例10: processAction

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
@Override
public TreeReference processAction(FormDef model, TreeReference contextRef) {
    SubmissionProfile profile = model.getSubmissionProfile(this.submissionId);
    String url = profile.getResource();

    TreeReference ref = profile.getRef();
    Map<String, String> map = null;
    if(ref != null) {
        map = getKeyValueMapping(model, ref);
    }

    String result = null;
    try {
        result = model.dispatchSendCallout(url, map);
    } catch (Exception e ) {
        Logger.exception("send-action", e);
    }
    if(result == null) {
        return null;
    } else {
        TreeReference target = profile.getTargetRef();
        model.setValue(new UncastData(result), target);
        return target;
    }
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:26,代码来源:SendAction.java


示例11: unpackValue

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public static Object unpackValue (IAnswerData val) {
	if (val == null) {
		return "";
	} else if (val instanceof UncastData) {
		return val.getValue();
	} else if (val instanceof IntegerData) {
		return new Double(((Integer)val.getValue()).doubleValue());
	} else if (val instanceof LongData) {
		return new Double(((Long)val.getValue()).doubleValue());
	} else if (val instanceof DecimalData) {
		return val.getValue();
	} else if (val instanceof StringData) {
		return val.getValue();
	} else if (val instanceof SelectOneData) {
		return ((Selection)val.getValue()).getValue();
	} else if (val instanceof SelectMultiData) {
		return (new XFormAnswerDataSerializer()).serializeAnswerData(val);
	} else if (val instanceof DateData) {
		return val.getValue();
	} else if (val instanceof BooleanData) {
		return val.getValue();
	} else if (val instanceof GeoPointData) {
		// we have no access fns that interact with double[4] arrays (the getValue() data type)...
		return val.getDisplayText();
	} else if (val instanceof GeoShapeData) {
		// we have no access fns that interact with GeoShape objects (the getValue() data type)...
		return val.getDisplayText();
	} else if (val instanceof GeoTraceData) {
		// we have no access fns that interact with GeoTrace objects (the getValue() data type)...
		return val.getDisplayText();
	} else {
		System.out.println("warning: unrecognized data type in xpath expr: " + val.getClass().getName());
		return val.getValue(); //is this a good idea?
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:36,代码来源:XPathPathExpr.java


示例12: canSerialize

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public boolean canSerialize(IAnswerData data) {
	if (data instanceof StringData || data instanceof DateData || data instanceof TimeData ||
	    data instanceof SelectMultiData || data instanceof SelectOneData ||
	    data instanceof IntegerData || data instanceof DecimalData || data instanceof PointerAnswerData	||
	    data instanceof MultiPointerAnswerData ||
	    data instanceof GeoPointData || data instanceof GeoTraceData || data instanceof GeoShapeData ||
	    data instanceof LongData || data instanceof DateTimeData || data instanceof UncastData) {
		return true;
	} else {
		return false;
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:13,代码来源:XFormAnswerDataSerializer.java


示例13: serializeAnswerData

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public Object serializeAnswerData(IAnswerData data) {
	if (data instanceof StringData) {
		return serializeAnswerData((StringData)data);
	} else if (data instanceof SelectMultiData) {
		return serializeAnswerData((SelectMultiData)data);
	} else if (data instanceof SelectOneData) {
		return serializeAnswerData((SelectOneData)data);
	} else if (data instanceof IntegerData){
		return serializeAnswerData((IntegerData)data);
	} else if (data instanceof LongData){
		return serializeAnswerData((LongData)data);
	} else if (data instanceof DecimalData) {
		return serializeAnswerData((DecimalData)data);
	} else if (data instanceof DateData) {
		return serializeAnswerData((DateData)data);
	} else if (data instanceof TimeData) {
		return serializeAnswerData((TimeData)data);
	} else if (data instanceof PointerAnswerData) {
		return serializeAnswerData((PointerAnswerData)data);
	} else if (data instanceof MultiPointerAnswerData) {
		return serializeAnswerData((MultiPointerAnswerData)data);
	} else if (data instanceof GeoShapeData) {
           return serializeAnswerData((GeoShapeData)data);
	} else if (data instanceof GeoTraceData) {
           return serializeAnswerData((GeoTraceData)data);
	} else if (data instanceof GeoPointData) {
           return serializeAnswerData((GeoPointData)data);
       } else if (data instanceof DateTimeData) {
           return serializeAnswerData((DateTimeData)data);
       } else if (data instanceof BooleanData) {
           return serializeAnswerData((BooleanData)data);
       } else if (data instanceof UncastData) {
           return serializeAnswerData((UncastData)data);
       }

	return null;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:38,代码来源:XFormAnswerDataSerializer.java


示例14: handlePreload

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public IAnswerData handlePreload(String preloadParams) {
    System.out.println("asked to preload: " + preloadParams);
    if(preloadParams.equals("UserName")) {
        return new UncastData(u.getUsername());
    }else if(preloadParams.equals("UserID")) {
        return new UncastData(String.valueOf(u.getUniqueId()));
    } else if(preloadParams.equals("AppVersion")) {
        return new StringData(CommCareUtil.getVersion());
    }
    System.out.println("FAILED to preload: " + preloadParams);
    return null;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:13,代码来源:MetaPreloadHandler.java


示例15: cast

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
protected IAnswerData cast(IAnswerData data) {
    if(data == null) { return null; }

    Class template  = getAnswerTemplate().getClass();
    if(data instanceof UncastData) {
        return getAnswerTemplate().cast((UncastData)data);
    } else if(!template.isAssignableFrom(data.getClass())) {
        System.out.println("Casting type " + data.getClass().getName() + " to type " + template.getName());
        return getAnswerTemplate().cast(data.uncast());
    } else {
        return data;
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:14,代码来源:ExpandedWidget.java


示例16: handlePreload

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public IAnswerData handlePreload(String preloadParams) {
    if(preloadParams.equals("username")) {
        return new UncastData(user.getUsername());
    } else if(preloadParams.equals("uuid")) {
        return new UncastData(user.getUniqueId());
    }
    String property = user.getProperty(preloadParams);
    if(property == null) {
        return null;
    }
    return new UncastData(property);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:13,代码来源:UserPreloadHandler.java


示例17: parse

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public TreeElement parse() throws InvalidStructureException, IOException, XmlPullParserException {

        int depth = parser.getDepth();
        TreeElement element = new TreeElement(parser.getName(), multiplicity);
        element.setInstanceName(instanceId);
        for(int i = 0 ; i < parser.getAttributeCount(); ++i) {
            element.setAttribute(parser.getAttributeNamespace(i), parser.getAttributeName(i), parser.getAttributeValue(i));
        }

        Hashtable<String, Integer> multiplicities = new Hashtable<String, Integer>();
        //NOTE: We never expect this to be the exit condition
        while(parser.getDepth() >= depth) {
        switch(this.nextNonWhitespace()) {
            case KXmlParser.START_TAG:
                String name = parser.getName();
                int val;
                if(multiplicities.containsKey(name)) {
                    val = multiplicities.get(name).intValue()+1;
                } else {
                    val = 0;
                }
                multiplicities.put(name,  new Integer(val));

                TreeElement kid = new TreeElementParser(parser, val, instanceId).parse();
                element.addChild(kid);
                break;
            case KXmlParser.END_TAG:
                return element;
            case KXmlParser.TEXT:
                element.setValue(new UncastData(parser.getText().trim()));
                break;
            default:
                throw new InvalidStructureException("Exception while trying to parse an XML Tree, got something other than tags and text", parser);
            }
        }

        return element;
    }
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:39,代码来源:TreeElementParser.java


示例18: parse

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public TreeElement parse() throws InvalidStructureException, IOException,
        XmlPullParserException, UnfullfilledRequirementsException {

    int depth = parser.getDepth();
    TreeElement element = new TreeElement(parser.getName(), multiplicity);
    element.setInstanceName(instanceId);
    for (int i = 0; i < parser.getAttributeCount(); ++i) {
        element.setAttribute(parser.getAttributeNamespace(i), parser.getAttributeName(i), parser.getAttributeValue(i));
    }

    Hashtable<String, Integer> multiplicities = new Hashtable<String, Integer>();

    // loop parses all siblings at a given depth
    while (parser.getDepth() >= depth) {
        switch (this.nextNonWhitespace()) {
            case KXmlParser.START_TAG:
                String name = parser.getName();
                int val;
                if (multiplicities.containsKey(name)) {
                    val = multiplicities.get(name).intValue() + 1;
                } else {
                    val = 0;
                }
                multiplicities.put(name, new Integer(val));

                TreeElement kid = new TreeElementParser(parser, val, instanceId).parse();
                element.addChild(kid);
                break;
            case KXmlParser.END_TAG:
                return element;
            case KXmlParser.TEXT:
                element.setValue(new UncastData(parser.getText().trim()));
                break;
            default:
                throw new InvalidStructureException("Exception while trying to parse an XML Tree, got something other than tags and text", parser);
        }
    }

    return element;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:41,代码来源:TreeElementParser.java


示例19: distance

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
/**
 * Returns the distance between two GeoPointData locations, in meters, given objects to unpack.
 * Ignores altitude and accuracy.
 * Note that the arguments can be strings.
 * Returns -1 if one of the arguments is null or the empty string.
 */
public static Double distance(Object from, Object to) {
    String unpackedFrom = (String) unpack(from);
    String unpackedTo = (String) unpack(to);

    if (unpackedFrom == null || "".equals(unpackedFrom) || unpackedTo == null || "".equals(unpackedTo)) {
        return new Double(-1.0);
    }

    // Casting and uncasting seems strange but is consistent with the codebase
    GeoPointData castedFrom = new GeoPointData().cast(new UncastData(unpackedFrom));
    GeoPointData castedTo = new GeoPointData().cast(new UncastData(unpackedTo));

    return new Double(GeoPointUtils.computeDistanceBetween(castedFrom, castedTo));
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:21,代码来源:XPathFuncExpr.java


示例20: unpackValue

import org.javarosa.core.model.data.UncastData; //导入依赖的package包/类
public static Object unpackValue(IAnswerData val) {
    if (val == null) {
        return "";
    } else if (val instanceof UncastData) {
        return val.getValue();
    } else if (val instanceof IntegerData) {
        return new Double(((Integer)val.getValue()).doubleValue());
    } else if (val instanceof LongData) {
        return new Double(((Long)val.getValue()).doubleValue());
    } else if (val instanceof DecimalData) {
        return val.getValue();
    } else if (val instanceof StringData) {
        return val.getValue();
    } else if (val instanceof SelectOneData) {
        return ((Selection)val.getValue()).getValue();
    } else if (val instanceof SelectMultiData) {
        return (new XFormAnswerDataSerializer()).serializeAnswerData(val);
    } else if (val instanceof DateData) {
        return val.getValue();
    } else if (val instanceof DateTimeData) {
        return val.getValue();
    } else if (val instanceof BooleanData) {
        return val.getValue();
    } else if (val instanceof GeoPointData) {
        return val.uncast().getString();
    } else {
        System.out.println("warning: unrecognized data type in xpath expr: " + val.getClass().getName());

        //TODO: Does this mess up any of our other plans?
        return val.uncast().getString();
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:33,代码来源:XPathPathExpr.java



注:本文中的org.javarosa.core.model.data.UncastData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CellRangeAddress类代码示例发布时间:2022-05-22
下一篇:
Java KnowledgeRuntimeLoggerFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap