当前位置: 首页>>代码示例>>Java>>正文


Java UncastData类代码示例

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


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


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