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軟屬性值查詢、設定、更新的工具類
最新推荐文章于 2024-12-28 16:44:45 发布