微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试通过 Java 在 PowerDesigner 中创建模型时出错

如何解决尝试通过 Java 在 PowerDesigner 中创建模型时出错

实际代码

package OOM.src.createOOM;

import org.eclipse.swt.internal.ole.win32.COM;
import com.sybase.stf.powerdesigner.PdCommon.*;
import com.sybase.stf.powerdesigner.PdOOM.*;

/**
 * @author Xiao Wang
 *
 * This Java sample program shows how to use PowerDesigner Java proxies and 
 * OLE automation to create a PowerDesigner OOM model and display the contains of the OOM model.
 */
public class CreateOOM {

   /** PowerDesigner application object */
   private Application pdApp;
   
   private int nbClasses;
   
   /** 
    * Program entry point 
    */
   public static void main(String[] args) {
       System.out.println("shhs");
          // Create an instance of this class
          CreateOOM createOOM1 = new CreateOOM();
          // Create an OOM and display the result
          createOOM1.CreateAnddisplayOOM();
       }
   /**
    *  Create an OOM and display the result 
    */
   public void CreateAnddisplayOOM() {
      int hr = COM.OleInitialize(0);
      try {
         // Get PowerDesigner application instance and start PowerDesigner if necessary
         pdApp = Application.getInstance();
         if (pdApp != null)
         {
            // Create an OOM
            Model newModel;
            newModel = createOOM();
         
            // Show the information of the current OOM
            showOOMInfo();
                 
            // Release PowerDesigner application.  
            // This may close PowerDesigner if PowerDesigner was started by this program.
            // pdApp.Release();
         }
      }
      catch (Exception e) {
     System.out.println("Cannot create PowerDesigner application object.  Please verify that PowerDesigner is installed.");
      }
      finally {
         if (hr == COM.S_OK)
            COM.OleUninitialize();
      }
   }
      
   /**
    *  Create an OOM for Java
    */
   public Model createOOM() {
      try {
         // Create an OOM model,use Java as the language,create a default class diagram
         // Convert the return object to PdOOM.Model proxy object
         Model newModel = new Model(pdApp.CreateModel(PdOOM_Classes.cls_Model,"|Language=Java|Diagram=ClassDiagram"));
         // set name and code
         newModel.SetName("Customer Management");
         newModel.SetCode("CustomerManagement");
         //System.out.println("reach");
         // Create a customer class.  
         // Use the fully qualified name here to avoid conflict with Java
         com.sybase.stf.powerdesigner.PdOOM.Class newClass1 =
            new com.sybase.stf.powerdesigner.PdOOM.Class(newModel.GetClasses().CreateNew());
         newClass1.SetName("Customer");
         newClass1.SetCode("Customer");
         newClass1.SetComment("Customer class");

         Attribute newAttribute;
         // Create an id attribute
         newAttribute = new Attribute(newClass1.GetAttributes().CreateNew());
         newAttribute.SetName("Id");
         newAttribute.SetCode("id");
         // id is the primary identifier (primary key)
         newAttribute.SetPrimaryIdentifier(true);
         // set the Java data type
         newAttribute.SetDataType("int");

         // Create a name attribute
         newAttribute = new Attribute(newClass1.GetAttributes().CreateNew());
         newAttribute.SetName("Name");
         newAttribute.SetCode("name");
         // set the Java data type
         newAttribute.SetDataType("java.lang.String");

         // Create a phone attribute
         newAttribute = new Attribute(newClass1.GetAttributes().CreateNew());
         newAttribute.SetName("Phone");
         newAttribute.SetCode("phone");
         // set the Java data type
         newAttribute.SetDataType("java.lang.String");

         // Create an email attribute
         newAttribute = new Attribute(newClass1.GetAttributes().CreateNew());
         newAttribute.SetName("Email");
         newAttribute.SetCode("email");
         // set the Java data type
         newAttribute.SetDataType("java.lang.String");

         // Create an SalesOrder class.  
         // Use the fully qualified name here to avoid conflict with Java
         com.sybase.stf.powerdesigner.PdOOM.Class newClass2 =
            new com.sybase.stf.powerdesigner.PdOOM.Class(newModel.GetClasses().CreateNew());
         newClass2.SetName("SalesOrder");
         newClass2.SetCode("SalesOrder");
         newClass2.SetComment("Sales order class");

         // Create an orderId attribute
         newAttribute = new Attribute(newClass2.GetAttributes().CreateNew());
         newAttribute.SetName("Order id");
         newAttribute.SetCode("orderId");
         // id is the primary identifier (primary key)
         newAttribute.SetPrimaryIdentifier(true);
         // set the Java data type
         newAttribute.SetDataType("int");

         // Create an orderDate attribute
         newAttribute = new Attribute(newClass2.GetAttributes().CreateNew());
         newAttribute.SetName("Order date");
         newAttribute.SetCode("orderDate");
         // set the Java data type
         newAttribute.SetDataType("java.util.Date");

         // Create an association
         Association association1 = new Association(newModel.GetAssociations().CreateNew());
         // Set linked classes
         association1.Setobject1(newClass1);
         association1.Setobject2(newClass2);
         // Set role A name and multiplicity
         association1.SetRoleAName("customer");
         association1.SetRoleAMultiplicity("1");
         // Set role B name and multiplicity
         association1.SetRoleBName("orders");
         association1.SetRoleBMultiplicity("0..*");

         // Get the default class diagram
         ClassDiagram newDiagram = new ClassDiagram(newModel.GetDefaultDiagram());

         // show the symbol in the default diagram if it is a class diagram
         newDiagram.AttachObject(newClass1);
         newDiagram.AttachObject(newClass2);
         newDiagram.AttachLinkObject(association1);
        
         return newModel;
      }
      catch (Exception e) {
         e.printstacktrace();
         return null;
      }
   }
   
   /**
    *  display information about the currnt OOM
    */
   public void showOOMInfo() {
      try {
         // Get the current OOM model
         if (!pdApp.GetActiveModel().isNull())
         {
            if (pdApp.GetActiveModel().IsKindOf(PdOOM_Classes.cls_Model))
            {
               // Convert the active model to an OOM model proxy object
               Model aModel = new Model(pdApp.GetActiveModel());

               // Initialize the number of classes
               nbClasses = 0;
                              
               // display a message in PowerDesigner outut window
               pdApp.Output("display the list of classes in the system output window.");
               
               // Show classes and packages defined under the model
               // Convert model proxy object to package proxy object
               showPackageInfo(new com.sybase.stf.powerdesigner.PdOOM.Package(aModel));
               
               System.out.println("There are " + nbClasses + " class(es) in this model.");
               
            }
            else
            {
               System.out.println("The current model is not an OOM model.");
            }
         }
         else
         {
            System.out.println("There is no active model opened in PowerDesigner.");
         }
      }
      catch (Exception e) {
         e.printstacktrace();
      }
   }

   /**
    *  display information about an OOM package
    */
   public void showPackageInfo(com.sybase.stf.powerdesigner.PdOOM.Package aPackage) {
      if (!aPackage.isNull() && !aPackage.IsShortcut())
      {
         // display the number of classes and packages in the system output window
         System.out.println("The " + aPackage.GetobjectType() + " '" + aPackage.GetCode() + "' contains " + aPackage.GetClasses().GetCount() + " class(es)," + aPackage.GetPackages().GetCount() + " package(s).");

         // Use the fully qualified name here to avoid conflict with Java
         com.sybase.stf.powerdesigner.PdOOM.Class aClass;
         for (int n = 0; n < aPackage.GetClasses().GetCount(); n++)
         {
            nbClasses++;
            if (nbClasses < 100)
            {
               // display class info
               aClass = new com.sybase.stf.powerdesigner.PdOOM.Class(aPackage.GetClasses().Item(n));
               showClassInfo(aClass);
            }
            else
            {
               if (nbClasses == 100)                
                  System.out.println("...");
               break;
            }
         }

         // display classes of subpackages         
         com.sybase.stf.powerdesigner.PdOOM.Package subPackage;
         for (int nPackage = 0; nPackage < aPackage.GetPackages().GetCount(); nPackage++)
         {
            subPackage = new com.sybase.stf.powerdesigner.PdOOM.Package(aPackage.GetPackages().Item(nPackage));
            showPackageInfo(subPackage);
         }
      }
   }
   
   /**
    *  display information about a class
    */
   public void showClassInfo(com.sybase.stf.powerdesigner.PdOOM.Class aClass) {
      try {
         if (!aClass.isNull() && !aClass.IsShortcut())
         {
            System.out.println("Class No." + nbClasses + ": " + aClass.GetCode() + "," + aClass.GetAttributes().GetCount() + " attribute(s)," + aClass.Getoperations().GetCount() + " operation(s)");
         }
      }
      catch (Exception e) {
     e.printstacktrace();
      }
   }
}

我遇到的问题是--

org.eclipse.swt.SWTException:无法执行操作。结果 = -2137456383 (com.sybase.stf.powerdesigner.com.COMException: COM 失败 [HRESULT: 0x80990101]) 在 org.eclipse.swt.ole.win32.OLE.error(OLE.java:345) 在 com.sybase.stf.powerdesigner.com.COMException.raiSEOnFail(COMException.java:83) 在 com.sybase.stf.powerdesigner.com.IdispatchEx.risingInvoke(IdispatchEx.java:231) 在 com.sybase.stf.powerdesigner.PdCommon.IApplication.CreateModel(IApplication.java:84) 在 OOM.src.createOOM.CreateOOM.createOOM(CreateOOM.java:68) 在 OOM.src.createOOM.CreateOOM.CreateAnddisplayOOM(CreateOOM.java:42) 在 OOM.src.createOOM.CreateOOM.main(CreateOOM.java:28) 引起:com.sybase.stf.powerdesigner.com.COMException: COM 失败 [HRESULT: 0x80990101] 在 com.sybase.stf.powerdesigner.com.COMException.raiSEOnFail(COMException.java:88) ……还有 5 个 PowerDesigner 中没有打开活动模型。

我该如何解决这个问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。