private static ReferenceFactory rf=new ReferenceFactory();
private static final boolean serverFlag=RemoteMethodServer.getDefault().ServerFlag;
/**
* @param args
* @throws WTException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
OutputStream os=new FileOutputStream(new File("E:/test.xls"));
bomexport(os,"VR:wt.part.WTPart:311117");
//bomexport(os, "VR:wt.part.WTPart:311189");
}
public static Object getObjectByOid(String oid) throws WTException{
return rf.getReference(oid).getObject();
}
public static void bomexport(OutputStream os,String oid) throws Exception{
RemoteMethodServer methodServer = RemoteMethodServer.getDefault();
methodServer.setUserName("wcadmin");
methodServer.setPassword("wcadmin");
if(oid!=null && oid.length()>0){
ArrayList list=new ArrayList();
WTPart part=(WTPart) getObjectByOid(oid);
list=getBOM(part,list);
createBOMExcel(os, list, part);
}
}
public static ArrayList getBOM(WTPart part,ArrayList list) throws Exception{
System.out.println("whodd");
//if(serverFlag){
if(part==null){
return list;
}
WTPrincipal currentUser=null;
try {
currentUser=SessionHelper.getPrincipal();
SessionHelper.manager.setAdministrator();
if(part.isEndItem()){
addAttrToList(list, part);
}
QueryResult qr=WTPartHelper.service.getUsesWTPartMasters(part);
if(qr.size()!=0){
while(qr.hasMoreElements()){
WTPartUsageLink link=(WTPartUsageLink) qr.nextElement();
if(link!=null){
WTPartMaster partmaster=(WTPartMaster) link.getRoleBObject();
WTPart subpart=getLastPart(partmaster);
if(subpart!=null){
addAttrToList(list, subpart);
}
getBOM(subpart,list);
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
SessionHelper.manager.setPrincipal(currentUser.getName());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
return list;