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


Java Core.instantiate方法代码示例

本文整理汇总了Java中com.mendix.core.Core.instantiate方法的典型用法代码示例。如果您正苦于以下问题:Java Core.instantiate方法的具体用法?Java Core.instantiate怎么用?Java Core.instantiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mendix.core.Core的用法示例。


在下文中一共展示了Core.instantiate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateModule

import com.mendix.core.Core; //导入方法依赖的package包/类
protected Object validateModule(IContext context, String moduleName) throws CoreException {
	this.activeModule.add(moduleName);

	if (!this.moduleMap.containsKey(moduleName)) {
		this.moduleMap.put(moduleName, null);

		IMendixObject obj = Core.instantiate(context, Module.getType());
		obj.setValue(context, Module.MemberNames.ModuleName.toString(), moduleName);

		if (this.allNewModules) {
			this.moduleMap.put(moduleName, obj);
			obj.setValue(context, Module.MemberNames.SynchronizeObjectsWithinModule.toString(), true);
		}

		Core.commit(context, obj);

	}

	return this.moduleMap.get(moduleName);
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:21,代码来源:Builder.java

示例2: getTypeId

import com.mendix.core.Core; //导入方法依赖的package包/类
protected IMendixIdentifier getTypeId(IContext context, IDataType dataType) throws CoreException {
	String valueTypeName = dataType.getDSLType();
	if (dataType.getType() == DataTypeEnum.Enumeration)
		valueTypeName = "Enum";
	else if (dataType.isList())
		valueTypeName = "List of type: " + dataType.getObjectType();
	else if (dataType.isMendixObject())
		valueTypeName = "Object of type: " + dataType.getObjectType();

	List<IMendixObject> result = Core.retrieveXPathQuery(context, "//" + ValueType.getType() + "[" + ValueType.MemberNames.Name + "='" + valueTypeName + "']");
	if (result.size() > 0)
		return result.get(0).getId();

	IMendixObject memberTypeObject = Core.instantiate(context, ValueType.getType());
	memberTypeObject.setValue(context, ValueType.MemberNames.Name.toString(), valueTypeName);
	memberTypeObject.setValue(context, ValueType.MemberNames.ValueType_MxObjectType.toString(), this.getObjectTypeId(context, dataType));
	
	PrimitiveTypes type = getPrimitiveTypesFromDatatype(dataType);
	memberTypeObject.setValue(context, ValueType.MemberNames.TypeEnum.toString(), (type == null ? null : type.toString()));
	Core.commit(context, memberTypeObject);
	return memberTypeObject.getId();
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:23,代码来源:Builder.java

示例3: updateConversationContext

import com.mendix.core.Core; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Map<String, Object> updateConversationContext(IContext context, ConversationContext conversationContext, MessageResponse response) throws CoreException {
	deleteCurrentDialogStack(conversationContext);

	conversationContext.setConversationId(context, response.getContext().get("conversation_id").toString());
	Map<String, Object> responseContext = response.getContext();
	Map<String, Object> resposeSystemContext = (Map<String, Object>) responseContext.get("system");
	conversationContext.setDialogTurnCounter(new BigDecimal(resposeSystemContext.get("dialog_turn_counter").toString()));
	conversationContext.setDialogRequestCounter(new BigDecimal(resposeSystemContext.get("dialog_request_counter").toString()));

	List<String> dialogStack = (List<String>) resposeSystemContext.get("dialog_stack");
	for(String dialogNode : dialogStack){
		final IMendixObject dialogNodeObject = Core.instantiate(context, DialogNode.entityName );
		dialogNodeObject.setValue(context, DialogNode.MemberNames.Name.toString(), dialogNode);
		final List<IMendixIdentifier> conversationContextList = new ArrayList<IMendixIdentifier>();
		conversationContextList.add(conversationContext.getMendixObject().getId());
		dialogNodeObject.setValue(context, DialogNode.MemberNames.Dialog_Stack.toString(), conversationContextList);

		Core.commit(context, dialogNodeObject);
	}

	conversationContext.commit();
	return resposeSystemContext;
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:25,代码来源:ConversationService.java

示例4: getCloneOfObject

import com.mendix.core.Core; //导入方法依赖的package包/类
private static IMendixIdentifier getCloneOfObject(IContext ctx, IMendixObject src,
           List<String> toskip, List<String> tokeep, List<String> revAssoc,
           List<String> skipEntities, List<String> skipModules,
           Map<IMendixIdentifier, IMendixIdentifier> mappedObjects) throws CoreException
{
    String objType = src.getMetaObject().getName();
    String modName = src.getMetaObject().getModuleName();
    
    // if object is already being cloned, return ref to clone
    if (mappedObjects.containsKey(src.getId())) {
           return mappedObjects.get(src.getId());
       // if object should be skipped based on module or entity, return source object
       } else if (skipEntities.contains(objType) || skipModules.contains(modName)) {
           return src.getId();            
        // if not already being cloned, create clone
       } else { 
           IMendixObject clone = Core.instantiate(ctx, src.getType());
           duplicate(ctx, src, clone, toskip, tokeep, revAssoc, skipEntities, skipModules, mappedObjects);
           return clone.getId();               
       }
}
 
开发者ID:ako,项目名称:MqttClient,代码行数:22,代码来源:ORM.java

示例5: handleMxObject

import com.mendix.core.Core; //导入方法依赖的package包/类
private IMendixObject handleMxObject(IContext context, Map<String,IMendixObject> existingMetaObjects, IMetaObject metaObject) throws CoreException
{
	String completeName = metaObject.getName();
	IMendixObject object;
	if(!existingMetaObjects.containsKey(completeName) && !this.builder.allNewModules)
	{
		object = Core.instantiate(context, MxObjectType.getType());
		existingMetaObjects.put(completeName, object);

		object.setValue(context, MxObjectType.MemberNames.CompleteName.toString(), completeName);
		object.setValue(context, MxObjectType.MemberNames.Name.toString(), completeName.substring(completeName.indexOf(".")+1));
		object.setValue(context, MxObjectType.MemberNames.Module.toString(), completeName.substring(0,completeName.indexOf(".")));
	}
	else
		object = existingMetaObjects.get(completeName);

	if( object != null ) {
		List<IMendixIdentifier> superObjectIds = new ArrayList<IMendixIdentifier>();
		for(IMetaObject superObject : metaObject.getSuperObjects()) {
			IMendixObject superMxObject = this.handleMxObject(context, existingMetaObjects, superObject);
			if( superMxObject != null )
				superObjectIds.add(superMxObject.getId());
		}
		
		object.setValue(context, MxObjectType.MemberNames.MxObjectType_SubClassOf_MxObjectType.toString(), superObjectIds);
		object.setValue(context, MxObjectType.MemberNames.PersistenceType.toString(), (metaObject.isPersistable() ? PersistenceType.Persistable.toString() : PersistenceType.Non_persistent.toString())  );
		
		if( this.builder.moduleMap.get(metaObject.getModuleName()) != null ) {
			object.setValue(context, MxObjectType.MemberNames.MxObjectType_Module.toString(), this.builder.moduleMap.get(metaObject.getModuleName()).getId());
		}
		
		Core.commit(context, object);
	}
	
	return object;
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:37,代码来源:MetaObjectBuilder.java

示例6: getIdentifiableLanguages

import com.mendix.core.Core; //导入方法依赖的package包/类
public static List<IMendixObject> getIdentifiableLanguages(IContext context, String username, String password) throws MendixException {
	LOGGER.debug("Executing IdentifiableLanagues Connector...");

	service.setUsernameAndPassword(username, password);

    List<IdentifiableLanguage> identifieableLanguages;

	try{
		identifieableLanguages = service.getIdentifiableLanguages().execute();
	} catch (Exception e) {
		LOGGER.error("Watson Service Connection - Failed retrieving the identifiable languages", e);
		throw new MendixException(e);
	}

	final List<IMendixObject> results = new ArrayList<IMendixObject>();
	for(IdentifiableLanguage language : identifieableLanguages){

		IMendixObject result = Core.instantiate(context,  watsonservices.proxies.Language.entityName);

		result.setValue(context, "Name", language.getName());
		result.setValue(context, "Code", language.getLanguage());
		results.add(result);
	}

	return results;
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:27,代码来源:LanguageTranslationService.java

示例7: createMessageResponse

import com.mendix.core.Core; //导入方法依赖的package包/类
private static IMendixObject createMessageResponse(IContext context, ConversationContext conversationContext, MessageResponse response) throws CoreException {
	updateConversationContext(context, conversationContext, response);

	final IMendixObject messageResponseObject = Core.instantiate(context, ConversationMessageResponse.entityName);
	messageResponseObject.setValue(context, ConversationMessageResponse.MemberNames.ConversationId.toString(), response.getContext().get("conversation_id"));
	messageResponseObject.setValue(context, ConversationMessageResponse.MemberNames.Input.toString(), response.getInputText());
	messageResponseObject.setValue(context, ConversationMessageResponse.MemberNames.Output.toString(), response.getTextConcatenated(","));

	Core.commit(context, messageResponseObject);

	

	for(Intent intent : response.getIntents()){
		final IMendixObject intentObject = Core.instantiate(context, ConversationIntent.entityName);
		intentObject.setValue(context, ConversationIntent.MemberNames.Name.toString(), intent.getIntent());
		intentObject.setValue(context, ConversationIntent.MemberNames.Confidence.toString(), intent.getConfidence().toString());
		intentObject.setValue(context, ConversationIntent.MemberNames.ConversationIntent_ConversationResponse.toString(), messageResponseObject.getId());

		Core.commit(context, intentObject);
	}
	
	for(Entity entity : response.getEntities()){
		final IMendixObject entityObject = Core.instantiate(context, ConversationEntity.entityName);
		entityObject.setValue(context, ConversationEntity.MemberNames.Name.toString(), entity.getEntity());
		entityObject.setValue(context, ConversationEntity.MemberNames.Value.toString(), entity.getValue());
		entityObject.setValue(context, ConversationEntity.MemberNames.ConversationEntity_ConversationResponse.toString(), messageResponseObject.getId());

		Core.commit(context, entityObject);
	}

	return messageResponseObject;
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:33,代码来源:ConversationService.java

示例8: processMember

import com.mendix.core.Core; //导入方法依赖的package包/类
public void processMember(IContext context, IMendixObject curObject, Map<String, IMendixObject> membersByName, List<IMendixObject> memberList, IMetaPrimitive metaPrimitive, String name) throws CoreException {
	IMendixObject curMember;
	IDataType memberType = Core.createDataType(metaPrimitive.getType().toString());
	if( !membersByName.containsKey(name) )
	{
		curMember = Core.instantiate(context, MxObjectMember.getType());
		curMember.setValue(context, MxObjectMember.MemberNames.AttributeName.toString(), name);
		curMember.setValue(context, MxObjectMember.MemberNames.AttributeType.toString(), metaPrimitive.getType().toString());
		curMember.setValue(context, MxObjectMember.MemberNames.AttributeTypeEnum.toString(), 
				this.builder.getPrimitiveTypesFromPrimitiveType(metaPrimitive.getType()) != null ? this.builder.getPrimitiveTypesFromPrimitiveType(metaPrimitive.getType()).toString() : null);
		curMember.setValue(context, MxObjectMember.MemberNames.MxObjectMember_MxObjectType.toString(), curObject.getId());
		curMember.setValue(context, MxObjectMember.MemberNames.MxObjectMember_Type.toString(), this.builder.getTypeId(context, memberType));
		curMember.setValue(context, MxObjectMember.MemberNames.FieldLength.toString(), metaPrimitive.getLength());
		curMember.setValue(context, MxObjectMember.MemberNames.IsVirtual.toString(), metaPrimitive.isVirtual());
		
		memberList.add(curMember);
	}
	else
	{
		curMember = membersByName.get(name);
		if(MxObjectEnum.getType().equals(curMember.getType()))
		{
			Core.delete(context, curMember);
			curMember = Core.instantiate(context, MxObjectMember.getType());
			curMember.setValue(context, MxObjectMember.MemberNames.AttributeName.toString(), name);
			curMember.setValue(context, MxObjectMember.MemberNames.MxObjectMember_MxObjectType.toString(), curObject.getId());
		}
		curMember.setValue(context, MxObjectMember.MemberNames.MxObjectMember_Type.toString(), this.builder.getTypeId(context, memberType));
		curMember.setValue(context, MxObjectMember.MemberNames.AttributeType.toString(), metaPrimitive.getType().toString());
		curMember.setValue(context, MxObjectMember.MemberNames.AttributeTypeEnum.toString(), 
				this.builder.getPrimitiveTypesFromPrimitiveType(metaPrimitive.getType()) != null ? this.builder.getPrimitiveTypesFromPrimitiveType(metaPrimitive.getType()).toString() : null);
		curMember.setValue(context, MxObjectMember.MemberNames.FieldLength.toString(), metaPrimitive.getLength());
		curMember.setValue(context, MxObjectMember.MemberNames.IsVirtual.toString(), metaPrimitive.isVirtual());
		
		memberList.add(curMember);
		
		membersByName.remove(name);
	}
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:40,代码来源:MetaObjectBuilder.java

示例9: handleMicroflowParams

import com.mendix.core.Core; //导入方法依赖的package包/类
private List<IMendixObject> handleMicroflowParams(IContext context, String microflowName, IMendixObject obj) throws CoreException
{
	Map<String, IMendixObject> existingParams = new HashMap<String, IMendixObject>();
	List<IMendixObject> params = Core.retrieveXPathQuery(context, "//" + Parameter.getType() + "[" + Microflows.MemberNames.Microflows_InputParameter + "='" + obj.getId().toLong() + "']");
	for(IMendixObject param : params)
		existingParams.put((String)param.getValue(context, Parameter.MemberNames.Name.toString()), param);

	List<IMendixIdentifier> inputParameterIds = new ArrayList<IMendixIdentifier>();
	List<IMendixObject> inputParameterObjs = new ArrayList<IMendixObject>();
	for(Entry<String,IDataType> entry : Core.getInputParameters(microflowName).entrySet())
	{
		String inputParameterName = entry.getKey();
		IDataType inputParameterType = entry.getValue();

		IMendixObject parameter;
		if(existingParams.containsKey(inputParameterName))
		{
			parameter = existingParams.get(inputParameterName);
			existingParams.remove(inputParameterName);
		}
		else
			parameter = Core.instantiate(context, Parameter.getType());

		parameter.setValue(context, Parameter.MemberNames.Name.toString(), inputParameterName);
		parameter.setValue(context, Parameter.MemberNames.Parameter_ValueType.toString(), this.builder.getTypeId(context, inputParameterType));
		parameter.setValue(context, Parameter.MemberNames.Parameter_MxObjectType.toString(), this.builder.getObjectTypeId(context, inputParameterType));
		inputParameterObjs.add( parameter );
		inputParameterIds.add(parameter.getId());
	}

	obj.setValue(context, Microflows.MemberNames.Microflows_Output_Type.toString(), this.builder.getTypeId(context, Core.getReturnType(microflowName)));
	obj.setValue(context, Microflows.MemberNames.Microflows_InputParameter.toString(), inputParameterIds);

	this.builder.removeDeletedObjects(context, existingParams);
	return inputParameterObjs;
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:37,代码来源:MicroflowBuilder.java

示例10: constructInstance

import com.mendix.core.Core; //导入方法依赖的package包/类
/**
 * Creates one instance of the type of this XPath query, and initializes the provided attributes to the provided values. 
 * @param keysAndValues AttributeName, AttributeValue, AttributeName2, AttributeValue2... list. 
 * @return
 * @throws CoreException
 */
public T constructInstance(boolean autoCommit, Object... keysAndValues) throws CoreException
{
	assertEven(keysAndValues);
	IMendixObject newObj = Core.instantiate(context, this.entity);
	
	for(int i = 0; i < keysAndValues.length; i+= 2)
		newObj.setValue(context, String.valueOf(keysAndValues[i]), toMemberValue(keysAndValues[i + 1]));
	
	if (autoCommit)
		Core.commit(context, newObj);
	
	return createProxy(context, proxyClass, newObj);
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:20,代码来源:XPath.java

示例11: buildToneCategory

import com.mendix.core.Core; //导入方法依赖的package包/类
private static void buildToneCategory(IContext context, final IMendixObject toneAnalyzerResponse,
		ToneCategory toneCategory) 
{
	final IMendixObject toneCategoryObject = Core.instantiate(context, watsonservices.proxies.ToneCategory.entityName);
	toneCategoryObject.setValue(context, watsonservices.proxies.ToneCategory.MemberNames.CategoryId.toString(), toneCategory.getId());
	toneCategoryObject.setValue(context, watsonservices.proxies.ToneCategory.MemberNames.Name.toString(), toneCategory.getName());

	toneCategory.getTones().forEach(toneScore -> buildTone(context, toneCategoryObject, toneScore));
	toneCategoryObject.setValue(context, watsonservices.proxies.ToneCategory.MemberNames.Tone_Categories.toString(), toneAnalyzerResponse.getId());
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:11,代码来源:ToneAnalyzerService.java

示例12: buildTone

import com.mendix.core.Core; //导入方法依赖的package包/类
private static void buildTone(IContext context, final IMendixObject toneCategoryObject, ToneScore toneScore)
{
	final IMendixObject toneObject = Core.instantiate(context, Tone.entityName);
	toneObject.setValue(context, Tone.MemberNames.ToneId.toString(), toneScore.getId());
	toneObject.setValue(context, Tone.MemberNames.Name.toString(), toneScore.getName());
	toneObject.setValue(context, Tone.MemberNames.Score.toString(), toneScore.getScore().toString());
	toneObject.setValue(context, Tone.MemberNames.Tones.toString(), toneCategoryObject.getId());
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:9,代码来源:ToneAnalyzerService.java

示例13: buildToneCategoryPerSentence

import com.mendix.core.Core; //导入方法依赖的package包/类
private static void buildToneCategoryPerSentence(IContext context, final IMendixObject sentenceToneObject,
		ToneCategory toneCategory) {
	final IMendixObject toneCategoryObject = Core.instantiate(context, watsonservices.proxies.ToneCategory.entityName);
	toneCategoryObject.setValue(context, watsonservices.proxies.ToneCategory.MemberNames.CategoryId.toString(), toneCategory.getId());
	toneCategoryObject.setValue(context, watsonservices.proxies.ToneCategory.MemberNames.Name.toString(), toneCategory.getName());

	for(ToneScore toneScore : toneCategory.getTones()){
		buildTone(context, toneCategoryObject, toneScore);
	}
	
	toneCategoryObject.setValue(context, watsonservices.proxies.ToneCategory.MemberNames.Sentence_Tone_Categories.toString(), sentenceToneObject.getId());
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:13,代码来源:ToneAnalyzerService.java

示例14: handleEnumMember

import com.mendix.core.Core; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private IMendixObject handleEnumMember(IContext context, IMendixObject enumObject, IMetaPrimitive enumPrimitive, IMendixObject curObject) throws CoreException
{
	if(enumObject == null)
		enumObject = Core.instantiate(context, MxObjectEnum.getType());

	Map<String,IMendixObject> curEnumValues = new HashMap<String, IMendixObject>();
	List<IMendixIdentifier> enumValueIds = (List<IMendixIdentifier>) enumObject.getValue(context, MxObjectEnum.MemberNames.Values.toString());
	if(enumValueIds != null)
		for(IMendixObject enumValueObject : Core.retrieveIdList(context, enumValueIds))
			curEnumValues.put((String)enumValueObject.getValue(context, MxObjectEnumValue.MemberNames.Name.toString()), enumValueObject);

	List<IMendixIdentifier> valueIds = new ArrayList<IMendixIdentifier>();
	List<IMendixObject> valueObjs = new ArrayList<IMendixObject>();
	

	List<IMendixIdentifier> captionIds = new ArrayList<IMendixIdentifier>();
	List<IMendixObject> captionObjs = new ArrayList<IMendixObject>();
	for(IMetaEnumValue metaEnumValue : enumPrimitive.getEnumValues())
	{
		IMendixObject enumValue = null;
		if(curEnumValues.containsKey(metaEnumValue.getIdentifier()))
			enumValue = curEnumValues.get(metaEnumValue.getIdentifier());
		else
			enumValue = Core.instantiate(context, MxObjectEnumValue.getType());

		Map<String,IMendixObject> curEnumCaptions = new HashMap<String, IMendixObject>();
		List<IMendixIdentifier> enumCaptionIds = (List<IMendixIdentifier>) enumValue.getValue(context, MxObjectEnumValue.MemberNames.Captions.toString());
		if(enumCaptionIds != null )
			for(IMendixObject enumCaptionObject : Core.retrieveIdList(context, enumCaptionIds))
				curEnumCaptions.put((String)enumCaptionObject.getValue(context, MxObjectEnumCaptions.MemberNames.LanguageCode.toString()), enumCaptionObject);

		IMendixObject enumCaption;
		for(String languageCode : this.languageCodes)
		{
			if(curEnumCaptions.containsKey(languageCode))
				enumCaption = curEnumCaptions.get(languageCode);
			else
				enumCaption = Core.instantiate(context, MxObjectEnumCaptions.getType());

			enumCaption.setValue(context, MxObjectEnumCaptions.MemberNames.Caption.toString(), Core.getInternationalizedString(languageCode, metaEnumValue.getI18NCaptionKey()));
			enumCaption.setValue(context, MxObjectEnumCaptions.MemberNames.LanguageCode.toString(), languageCode);
			captionObjs.add(enumCaption);
			captionIds.add(enumCaption.getId());
		}

		enumValue.setValue(context, MxObjectEnumValue.MemberNames.Name.toString(), metaEnumValue.getIdentifier());
		enumValue.setValue(context, MxObjectEnumValue.MemberNames.Captions.toString(), captionIds);
		Core.commit(context, captionObjs);
		captionObjs.clear();
		captionIds.clear();
		valueIds.add(enumValue.getId());
		valueObjs.add(enumValue);
	}
	
	enumObject.setValue(context, MxObjectEnum.MemberNames.Values.toString(), valueIds);
	enumObject.setValue(context, MxObjectMember.MemberNames.AttributeName.toString(), enumPrimitive.getName());
	enumObject.setValue(context, MxObjectMember.MemberNames.AttributeType.toString(), enumPrimitive.getType().toString());
	enumObject.setValue(context, MxObjectMember.MemberNames.AttributeTypeEnum.toString(), PrimitiveTypes.EnumType.toString());
	enumObject.setValue(context, MxObjectMember.MemberNames.MxObjectMember_MxObjectType.toString(), curObject.getId());
	enumObject.setValue(context, MxObjectMember.MemberNames.MxObjectMember_Type.toString(), this.builder.getTypeId(context,
			Core.createDataType(enumPrimitive.getParent().getName(), enumPrimitive.getName())
	));
	
	
	Core.commit(context, valueObjs);
	valueObjs.clear();
	valueIds.clear();
	
	
	return enumObject;
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:73,代码来源:MetaObjectBuilder.java

示例15: detectFaces

import com.mendix.core.Core; //导入方法依赖的package包/类
public static List<IMendixObject> detectFaces(IContext context, Image image, String apikey) throws MendixException {
	LOGGER.debug("Executing DetectFaces Connector...");
	
	service.setApiKey(apikey);
		
	final File imageToDetectFaces = createImageFile(context, image);

	final VisualRecognitionOptions options = new VisualRecognitionOptions.Builder().
			images(imageToDetectFaces).
			build();
			
	DetectedFaces response;
	try {

		response = service.detectFaces(options).execute();
	} catch (Exception e) {
		LOGGER.error("Watson Service connection - Failed detecting the faces in the image: " + imageToDetectFaces.getName(), e);
		throw new MendixException(e);
	}
	finally{
		imageToDetectFaces.delete();
	}

	final List<IMendixObject> results = new ArrayList<IMendixObject>();
	for (ImageFace imageFace : response.getImages()) {

		if(imageFace.getError() != null){
			LOGGER.warn("Error processing the image "+ imageFace.getImage() + ": " + imageFace.getError().getDescription());
			continue;
		}

		for(Face face :imageFace.getFaces()){

			IMendixObject faceObject = Core.instantiate(context, watsonservices.proxies.Face.entityName);

			if(face.getAge() != null){
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.AgeMax.toString(), face.getAge().getMax());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.AgeMin.toString(), face.getAge().getMin());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.AgeScore.toString(), face.getAge().getScore().toString());
			}

			if(face.getGender() != null){
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.GenderName.toString(), face.getGender().getGender());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.GenderScore.toString(), face.getGender().getScore().toString());
			}

			if(face.getLocation() != null){
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.LocationHeight.toString(), face.getLocation().getHeight());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.LocationLeft.toString(), face.getLocation().getLeft());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.LocationTop.toString(), face.getLocation().getTop());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.LocationWidth.toString(), face.getLocation().getWidth());
			}

			if(face.getIdentity() != null){
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.IdentityName.toString(), face.getIdentity().getName());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.IdentityScore.toString(), face.getIdentity().getScore().toString());
				faceObject.setValue(context, watsonservices.proxies.Face.MemberNames.TypeHierarchy.toString(), face.getIdentity().getTypeHierarchy());
			} 

			results.add(faceObject);
		}			
	}
	return results;
}
 
开发者ID:mendix,项目名称:IBM-Watson-Connector-Suite,代码行数:65,代码来源:VisualRecognitionService.java


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