샘플 코드
지정된 예에서 CustomChangeOrderWTChangeOrder2의 모델링된 하위 유형입니다. CustomChangeOrder는 서식 있는 텍스트 속성 longDescription을 포함하도록 수정됩니다. 또한 단순 텍스트 속성 myAttribute 및 해당하는 서식 있는 텍스트 속성 myLongAttribute가 모델링된 하위 유형에 추가됩니다. descriptionmyAttribute 등의 단순 텍스트 설명 속성을 longDescriptionmyLongAttribute 등의 서식 있는 텍스트 설명 속성으로 변환하기 위해 지정된 대로 CustomChangeOrderDelegate 위임이 작성됩니다.
package com.myCompany;
public class CustomChangeOrderDelegate extends ChangeItemRichTextConverterDelegate
{
private static final Logger classLogger = LogR.getLogger(ChangeSimpleToRichTextUtility.class.getName());
/**
* This method returns a concrete class, that is a model class, which implements wt.change2.ChangeItem or wt.maturity.PromotionNotice.
*
* @return class for which the delegate is implemented.
*/
@Override
public Class getTargetClass()
{
return CustomChangeOrder.class;
}
/**
* This method returns an unmodifiable map. Each entry in the map contains key as the source attribute, which is the
* simple text, and value as the target attribute, which is the rich text. The map should not be blank.
*
* @return collection of source and destination attributes for conversion
*/
@Override
public Map<String, String> getAttributesForConversion()
{
Map<String, String> srcAndDestAttributesMap = new HashMap<>(2);
srcAndDestAttributesMap.put(CustomChangeOrder.DESCRIPTION, CustomChangeOrder.LONG_DESCRIPTION);
srcAndDestAttributesMap.put(CustomChangeOrder.myAttribute, CustomChangeOrder.LONG_myAttribute);
return Collections.unmodifiableMap(srcAndDestAttributesMap);
}
/**
* This method copies or moves the attributes. The method prevents conversion
* if source attribute value is blank. If cleanSource flag is true, source attribute is set to null.
*
* @param persistable
* @param cleanSource
* @throws WTPropertyVetoException
* @return true if conversion was successful or false if conversion was not performed or was unsuccessful.
*/
@Override
public boolean convert(Persistable persistable, boolean cleanSource) throws WTPropertyVetoException {
boolean isConversionSucessful = false, areSourceAttributesNull = true;
if (persistable instanceof CustomChangeOrder) {
CustomChangeOrder changeNotice = (CustomChangeOrder) persistable;
String description = changeNotice.getDescription();
if (StringUtils.isNotBlank(description)) {
changeNotice.setLongDescription(getRichText(description));
if (cleanSource) {
changeNotice.setDescription(null);
}
isConversionSucessful = true;
areSourceAttributesNull = false;
}
String myAttribute = changeNotice.getMyAttribute();
if (StringUtils.isNotBlank(myAttribute)) {
changeNotice.setLongMyAttribute(getRichText(myAttribute));
if (cleanSource) {
changeNotice.setMyAttribute(null);
}
isConversionSucessful = true;
areSourceAttributesNull = false;
}
if (areSourceAttributesNull && classLogger.isDebugEnabled()) {
classLogger.debug("The source attributes, description and myAttribute, are blank for customChangeOrder:"
+ changeNotice.getNumber() + " " + changeNotice.getName()
+ ". Simple to rich text conversion was not performed for this object.");
}
}
else if (classLogger.isDebugEnabled()) {
classLogger
.debug("The persistable class is not an instance of CustomChangeOrder. The persistable class is:"
+ persistable.getClass().getName()
+ ". Simple to rich text conversion was not performed for this object.");
}
return isConversionSucessful;
}
}
CustomChangeOrderDelegate 클래스는 다음과 같이 지정된 대로 등록됩니다.
<service context="default" name="wt.change2.converter.richtext.ChangeRichTextConverterDelegate">
<Option serviceClass="com.myCompany.CustomChangeOrderDelegate"
requestor="wt.change2.ChangeItem"
selector="customChangeOrder"
cardinality="singleton"/>
</Service>
도움이 되셨나요?