import java.io.PrintStream;
import java.util.*;
import wt.iba.definition.DefinitionLoader;
import wt.iba.definition.litedefinition.*;
import wt.iba.definition.service.IBADefinitionHelper;
import wt.iba.definition.service.IBADefinitionService;
import wt.iba.value.*;
import wt.iba.value.litevalue.AbstractValueView;
import wt.iba.value.service.*;
import wt.session.SessionHelper;
import wt.session.SessionManager;
import wt.util.WTPropertyVetoException;
public class IBAUtil
{
Hashtable ibaContainer;
private IBAUtil()
{
ibaContainer = new Hashtable();
}
public IBAUtil(IBAHolder ibaHolder)
{
initializeIBAPart(ibaHolder);
}
public String toString()
{
StringBuffer tempString = new StringBuffer();
Enumeration enum = ibaContainer.keys();
try
{
while (enum.hasMoreElements())
{
String theKey = (String) enum.nextElement();
AbstractValueView theValue =
(AbstractValueView) ((Object[]) ibaContainer.get(theKey))[1];
tempString.append(
theKey
+ " - "
+ IBAValueUtility.getLocalizedIBAValueDisplayString(
theValue,
SessionHelper.manager.getLocale()));
tempString.append('/n');
}
}
catch (Exception e)
{
e.printStackTrace();
}
return tempString.toString();
}
public String getIBAValue(String name)
{
try
{
return getIBAValue(name, SessionHelper.manager.getLocale());
}
catch (Exception exception)
{
return null;
}
}
public String getIBAValue(String name, Locale locale)
{
try
{
AbstractValueView theValue = (AbstractValueView) ((Object[]) ibaContainer.get(name))[1];
return IBAValueUtility.getLocalizedIBAValueDisplayString(theValue, locale);
}
catch (Exception exception)
{
return null;
}
}
private void initializeIBAPart(IBAHolder ibaHolder)
{
ibaContainer = new Hashtable();
try
{
ibaHolder =
IBAValueHelper.service.refreshAttributeContainer(
ibaHolder,
null,
SessionHelper.manager.getLocale(),
null);
DefaultAttributeContainer theContainer =
(DefaultAttributeContainer) ibaHolder.getAttributeContainer();
if (theContainer != null)
{
AttributeDefDefaultView theAtts[] = theContainer.getAttributeDefinitions();
for (int i = 0; i < theAtts.length; i++)
{
AbstractValueView theValues[] = theContainer.getAttributeValues(theAtts[i]);
if (theValues != null)
{
Object temp[] = new Object[2];
temp[0] = theAtts[i];
temp[1] = theValues[0];
ibaContainer.put(theAtts[i].getName(), ((Object) (temp)));
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public IBAHolder updateIBAPart(IBAHolder ibaHolder) throws Exception
{
ibaHolder =
IBAValueHelper.service.refreshAttributeContainer(
ibaHolder,
null,
SessionHelper.manager.getLocale(),
null);
DefaultAttributeContainer theContainer =
(DefaultAttributeContainer) ibaHolder.getAttributeContainer();
for (Enumeration enum = ibaContainer.elements(); enum.hasMoreElements();)
try
{
Object temp[] = (Object[]) enum.nextElement();
AbstractValueView theValue = (AbstractValueView) temp[1];
AttributeDefDefaultView theDef = (AttributeDefDefaultView) temp[0];
//theDef.ge
if (theValue.getState() == 1)
{
theContainer.deleteAttributeValues(theDef);
theValue.setState(3);
theContainer.addAttributeValue(theValue);
}
}
catch (Exception e)
{
e.printStackTrace();
}
ibaHolder.setAttributeContainer(theContainer);
return ibaHolder;
}
public void setIBAValue(String name, String value) throws WTPropertyVetoException
{
AbstractValueView ibaValue = null;
AttributeDefDefaultView theDef = null;
Object obj[] = (Object[]) ibaContainer.get(name);
if (obj != null)
{
ibaValue = (AbstractValueView) obj[1];
theDef = (AttributeDefDefaultView) obj[0];
}
if (ibaValue == null)
{
// System.out.println("IBA Value is null.");
}
if (ibaValue == null)
{
theDef = getAttributeDefinition(name);
}
if (theDef == null)
{
//System.out.println("definition is null ...");
return;
}
ibaValue = internalCreateValue(theDef, value);
if (ibaValue == null)
{
//System.out.println("after creation, iba value is null ..");
return;
}
else
{
ibaValue.setState(1);
Object temp[] = new Object[2];
temp[0] = theDef;
temp[1] = ibaValue;
ibaContainer.put(theDef.getName(), ((Object) (temp)));
return;
}
}
private AttributeDefDefaultView getAttributeDefinition(String ibaPath)
{
AttributeDefDefaultView ibaDef = null;
try
{
ibaDef = IBADefinitionHelper.service.getAttributeDefDefaultViewByPath(ibaPath);
if (ibaDef == null)
{
AbstractAttributeDefinizerView ibaNodeView =
DefinitionLoader.getAttributeDefinition(ibaPath);
if (ibaNodeView != null)
ibaDef =
IBADefinitionHelper.service.getAttributeDefDefaultView(
(AttributeDefNodeView) ibaNodeView);
}
}
catch (Exception wte)
{
wte.printStackTrace();
}
return ibaDef;
}
private AbstractValueView internalCreateValue(
AbstractAttributeDefinizerView theDef,
String theValue)
{
AbstractValueView theView = null;
if (theDef instanceof FloatDefView)
theView = LoadValue.newFloatValue(theDef, theValue, null);
else if (theDef instanceof StringDefView)
theView = LoadValue.newStringValue(theDef, theValue);
else if (theDef instanceof IntegerDefView)
theView = LoadValue.newIntegerValue(theDef, theValue);
else if (theDef instanceof RatioDefView)
theView = LoadValue.newRatioValue(theDef, theValue, null);
else if (theDef instanceof TimestampDefView)
theView = LoadValue.newTimestampValue(theDef, theValue);
else if (theDef instanceof BooleanDefView)
theView = LoadValue.newBooleanValue(theDef, theValue);
else if (theDef instanceof URLDefView)
theView = LoadValue.newURLValue(theDef, theValue, null);
else if (theDef instanceof ReferenceDefView)
theView = LoadValue.newReferenceValue(theDef, "ClassificationNode", theValue);
else if (theDef instanceof UnitDefView)
theView = LoadValue.newUnitValue(theDef, theValue, null);
return theView;
}
}
windchill中IBA軟屬性值查詢、設定、更新的工具類
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
windchill 項目如何針對IDEA(IntelliJ IDEA)配置Debug調試
锋兄/八戒
2020-06-23 05:48:15
在Windchill中編寫rbInfo類型的資源文件,編譯過後:報在資源文件中找不到相應的Key
jason9157zb
2020-06-15 20:51:52
Windchill8.0中WTPartUsageLink的用法及介紹
背景介紹: Windchill8.0中要實現一個產品和其多個零件組成情況時,例如實現:一個汽車有四個輪子,這個汽車是一個產品,而輪子是零件,四個就是他
jason9157zb
2020-06-15 20:51:52
Windchill8.0中使用高級查詢:根據Name查詢
背景介紹: 在Windchill中根據Name模糊查詢出最後版序的WTProduct 分析:在用到Name為條件的查詢時,在Windchill
jason9157zb
2020-06-15 20:51:52
windchill中查詢最大最新版本的數據中遇到的坑
锋兄/八戒
2020-02-26 01:32:44
無法在瀏覽器中創建CAD文檔
紫铭
2020-02-22 10:10:37
Creo中替換裝配中的某元件後,檢入裝配時依然收集該元件
紫铭
2020-02-22 10:10:37
能夠通過保存副本的方式複製族表嗎?
紫铭
2020-02-22 10:10:37
Windchill8.0中checkOut,checkIn,undoCheckout
jason9157zb
2020-02-20 13:24:27
windchill刻制中 代碼中實現:HTTP遠程訪問鑒權,RMI遠程訪問鑒權,WebService客戶端測試訪問
jason9157zb
2020-02-20 13:24:27
在windchill8.0 中如何查詢產品(WTProduct)關聯的所有零件(WTPart)
jason9157zb
2020-02-20 13:24:27
windchill 項目如何針對IDEA(IntelliJ IDEA)配置Debug調試
锋兄/八戒
2020-06-23 05:48:15
在Windchill中編寫rbInfo類型的資源文件,編譯過後:報在資源文件中找不到相應的Key
jason9157zb
2020-06-15 20:51:52
24小時熱門文章