Windchill10x建模.docx
《Windchill10x建模.docx》由会员分享,可在线阅读,更多相关《Windchill10x建模.docx(9页珍藏版)》请在冰点文库上搜索。
Windchill10x建模
WIndchill10.x建模
一、在Windchill中建一个简单的模型
第一步,编辑java文件
创建com.acme.example.SimpleExample和.acme.example.SimpleExampleLink文件
package.acme.example;
importwt.fc.InvalidAttributeException;
importwt.fc.WTObject;
importwt.inf.container.WTContained;
importwt.util.WTException;
importwt.util.WTPropertyVetoException;
import.ptc.windchill.annotations.metadata.*;
GenAsPersistable(
superClass=WTObject.class,
interfaces={WTContained.class},
properties={GeneratedProperty(
name="name",
type=String.class,
constraints=PropertyConstraints(required=true))})
publicclassSimpleExampleextends_SimpleExample{
staticfinallongserialVersionUID=1;
publicstaticSimpleExamplenewSimpleExample()throwsWTException{
finalSimpleExampleinstance=newSimpleExample();
instance.initialize();
returninstance;
}
Override
publicvoidcheckAttributes()throwsInvalidAttributeException{
super.checkAttributes();
try{
nameValidate(name);
}catch(WTPropertyVetoExceptionwtpve){
thrownewInvalidAttributeException(wtpve);
}
}
}
package.acme.example;
importwt.fc.ObjectToObjectLink;
importwt.util.WTException;
import.ptc.windchill.annotations.metadata.*;
GenAsBinaryLink(
superClass=ObjectToObjectLink.class,
roleA=GeneratedRole(name="parent",type=SimpleExample.class),
roleB=GeneratedRole(name="child",type=SimpleExample.class))
publicclassSimpleExampleLinkextends_SimpleExampleLink{
staticfinallongserialVersionUID=1;
publicstaticSimpleExampleLinknewSimpleExampleLink(
finalSimpleExampleparent,finalSimpleExamplechild)
throwsWTException{
finalSimpleExampleLinkinstance=newSimpleExampleLink();
instance.initialize(parent,child);
returninstance;
}
}
第二步,编译模型的java文件
ant-fbin/tools.xmlclass-Dclass.includes=/acme/example/*
命令执行之后,会在/src_gen目录下生成一些java文件,这些java文件和之前我们自己写的java文件一一对应
第三步,生成sql文件
ant-fbin/tools.xmlsql_script-Dgen.input=.acme.example.*
命令执行之后,在/db下生成sql文件
第四步,导入sql文件
Cddb/sql3
Sqlpluswind/windWIND
Make_pkg_sql3_Table.sql
Make_pkg_sql3_Index.sql
第五步,Start/restarttheMethodServer
二、GenAs介绍
1、GenAsPersistable和GenAsBinaryLink提供三种机制指定数据库中的列:
1.properties(一个GeneratedPropertys的数组)表示strings,
numbers,booleans等等.
2.foreignKeys(一个GeneratedForeignKeys的数组)参考其他持久化对象(andarestoredasaclassname/keypair)
3.roleA/roleB(仅有GenAsBinaryLink中使用)一种特殊形式的外键,用来表述关联关系
2、常用注释介绍:
GenAsPersistable创建持久化对象,并将该类映射为一表表
GenAsBinaryLink创建两个持久对象关联关系的对象,并将这种关联关系映射为一表
GeneratedRole和GenAsBinaryLink一起使用用来描述link关系
GeneratedProperty生成属性
PropertyConstraints指定约束,(required=true)则需要进行验证,需要重写方法checkAttributes()
GeneratedForeignKey指定外键
GeneratedForeignKey(name="ContainerLink",
foreignKeyRole=ForeignKeyRole(name="container",
type=wt.inf.container.WTContainer.class,
referenceType=wt.inf.container.WTContainerRef.class,
supportedAPI=SupportedAPI.PRIVATE,
constraints=PropertyConstraints(required=true)),
myRole=MyRole(name="contents",supportedAPI=SupportedAPI.PRIVATE))
DerivedProperty控制外键关联对象属性的调用
DerivedProperty(name="c",derivedFrom="a.b.c")
DerivedProperty(name="name",derivedFrom="master>name")
三、创建并注册服务(Service)
1、创建Helper类
package.acme.example;
importwt.services.ServiceFactory;
/**
*Helpersarenotinstantiatedandshouldconsistofonlystaticfields/methods
**/
publicfinalclassExampleHelper{
/**UsetheServiceFactorytoacquireaninstanceoftheservice.**/
publicstaticfinalExampleServiceservice=ServiceFactory
.getService(ExampleService.class);
}
2、创建服务接口
package.acme.example;
importwt.method.RemoteInterface;
importwt.util.WTException;
/**RemoteInterfaceannotationisrequiredforallserviceinterfaces**/
RemoteInterface
publicinterfaceExampleService{
/**AllinterfacemethodsarecallableviaRMIandmustthrowWTException**/
SimpleExamplecreateSimpleExampleByName(finalStringname)
throwsWTException;
}
3、创建标准服务类
package.acme.example;
importwt.fc.PersistenceHelper;
importwt.services.StandardManager;
importwt.util.WTException;
importwt.util.WTPropertyVetoException;
/**servicemustextendStandardManager,implementserviceinterface**/
publicclassStandardExampleServiceextendsStandardManagerimplements
ExampleService{
/**MethodServerrefectivelycallsthisAPIduringstartup**/
publicstaticStandardExampleServicenewStandardExampleService()
throwsWTException{
finalStandardExampleServiceinstance=newStandardExampleService();
instance.initialize();
returninstance;
}
Override
publicSimpleExamplecreateSimpleExampleByName(finalStringname)
throwsWTException{
finalSimpleExampleexample=SimpleExample.newSimpleExample();
try{
example.setName(name);
}catch(WTPropertyVetoExceptionwtpve){
thrownewWTException(wtpve);
}
return(SimpleExample)PersistenceHelper.manager.store(example);
}
}
4、在site.xconf文件中注册服务
targetFile="codebase/wt.properties"value=".acme.example.ExampleService/.acme.example.
StandardExampleService"/>
四、本地化显示信息
1、创建exampleModelRB.rbInfo
ResourceInfo.class=wt.tools.resource.MetadataResourceInfo
#EntryFormat(valuesequaltodefaultvaluearenotincluded)
#.value=
#.category=
#.comment=
#.argComment=
#.constant=
#.customizable=
#.deprecated=
#.abbreviatedDisplay=
#.fullDisplay=
#.shortDescription=
#.longDescription=
#EntryContents
SimpleExample.value=Simple
SimpleExample.name.value=aka
2、创建exampleResource.java
package.acme.example;
importwt.util.resource.*;
/**ThisexampleblatantlyplagiarizedfromtheJavaDoc.**/
RBUUID(".acme.example.exampleResource")
publicclassexampleResourceextendsWTListResourceBundle{
RBEntry("Thisisthelocalizedtextwithasinglesubstitution:
\"{0}\".")
RBComment("Anexampleentry.")
RBArgComment0("Anystring...")
publicstaticfinalStringEXAMPLE_STRING="0";
}
3、执行如下命令:
ant-fbin/tools.xmlbundle-Dbundle.input=.acme.example.*
ant-fbin/tools.xmlclass-Dclass.includes=/acme/example/exampleResource.java
五、枚举类型
1、创建ComputerType.java文件
package.acme.example;
import.ptc.windchill.annotations.metadata.*;
GenAsEnumeratedType
publicclassComputerTypeextends_ComputerType{
publicstaticfinalComputerTypeDESKTOP=toComputerType("desktop");
publicstaticfinalComputerTypeLAPTOP=toComputerType("laptop");
publicstaticfinalComputerTypeSERVER=toComputerType("server");
}
2、创建ComputerTypeRB.rbInfo文件
RB文件对应的是枚举值,RB文件的命名格式为RB.rbInfo,X为枚举类的类名称,支持国际化。
ResourceInfo.class=wt.tools.resource.EnumResourceInfo
desktop.value=Desktop
desktop.order=10
laptop.value=Laptop
laptop.order=20
laptop.defaultValue=true
server.value=Server
server.order=30
3、执行命令
ant-fbin/tools.xmlbundle-Dbundle.input=.acme.example.*
ant-fbin/tools.xmlclass-Dclass.includes=/acme/example/ComputerType.java
六、Eclipse集成开发
七、部署客制化建模
1.注册模型/codebase(modelRegistry.properties,
associationRegistry.properties,和
descendentRegistry.properties)
2.添加编译的类文件,包括*.class、*.ClassInfo.ser和*.RB.ser
3.更新数据库(包括索引).