java 调用 windows com 组件的资料整理-mssql analysis 客户端组件主要

微软的这个联机文档太强大了,强大到要理解他需要耗费相当大的精力。
强大到看到人就让人头痛,呵呵。
不得不这样感叹啊,如果全都看遍,估计就无敌了。
在Analysis service 编程章节中 Decision Support Object Programmer's Reference中
文档分别从Interface,Events,Objects,Enumerations,Collections这些方面比较详细的
介绍了AS中主要对象的一些接口和属性。
比如大部分对象都是继承了Collections。(语言果然是共通的。。。)
Decision Support Objects Architecture 描述了AS中所有基本对象的说明
Server,Database,DataSource,Cube,Deimension,Role,Command,Level,MeaSure,Menber等等。。。
有一点很反感的是微软把文档搞的跟蜘蛛网一样,相当繁琐。
链接来链接去的。。
附微软官方网站添加角色VB代码一段:
Const ServerName = "localhost" '"SERVER-NAME"
Const DatabaseName = "Foodmart 2000" '"OLAP-DATABASE-NAME"
Const UserList = "USERS" '"DOMAIN-NAME\USER-ID;DOMAIN-NAME\USER-ID"
Const CubeName = "HR" '"CUBE-NAME"
Sub Main()

    Dim dsoServer As DSO.Server
    Dim dsoRole As DSO.Role
    Dim dsoCubeRole As DSO.Role
    Dim dsoDB As DSO.Database
    Dim RoleName As String
    
    RoleName = "Fred"
    
    Set dsoServer = New DSO.Server
    'Connect to server.
    dsoServer.Connect ServerName
    
    'Connect to database.
    Set dsoDB = dsoServer.MDStores.Item(DatabaseName)
    
    If dsoDB.Roles.Find(RoleName) Then
       dsoDB.Roles.Remove (RoleName)
    End If
    
    Set dsoRole = dsoDB.Roles.AddNew(RoleName, sbclsRegular) ' 0) ' sbclsRegular
    
    'Set role description.
    dsoRole.Description = "Test through Visual Basic application"
        
    dsoRole.LockObject 1, "Creating Role"
        
    'Set Enforcement Location permission key.
    dsoRole.SetPermissions "EnforcementLocation", "Server"
                
    'Add group of users or single user to roles.
    
    dsoRole.UsersList = UserList
        
    Dim strAllowedSet As String
    Dim strDimensionSecurity As String
    
    'Set Permission on Dimensions Time.
    strAllowedSet = "[Time].[1997].[Q1]:[Time].[1998].[Q4]"
    
    strDimensionSecurity = "<MEMBERSECURITY IsVisible=""True"" VisualTotalsLowestLevel=""[Time].[Quarter]"">"
    strDimensionSecurity = strDimensionSecurity & "<PERMISSION Access=""Read"""
    strDimensionSecurity = strDimensionSecurity & " AllowedSet=""{" & strAllowedSet & "}"""
    strDimensionSecurity = strDimensionSecurity & " UpperLevel=""[Time].[Year]"""
    strDimensionSecurity = strDimensionSecurity & " LowerLevel=""[Time].[Quarter]"""
    strDimensionSecurity = strDimensionSecurity & " /></MEMBERSECURITY>"
        
    dsoRole.SetPermissions "Dimension:Time", strDimensionSecurity
    
    'Set Permission on Dimension Store.
    strAllowedSet = "[Store].[All Stores].[USA].[CA],[Store].[All Stores].[USA].[WA],[Store].[All Stores].[USA].[OR]"
    strDimensionSecurity = "<MEMBERSECURITY IsVisible=""True"" VisualTotalsLowestLevel=""[Store].[Store Country]"">"
    strDimensionSecurity = strDimensionSecurity & "<PERMISSION Access=""Read"""
    strDimensionSecurity = strDimensionSecurity & " AllowedSet=""{" & strAllowedSet & "}"""
    strDimensionSecurity = strDimensionSecurity & " UpperLevel=""[Store].[Store Country]"""
    strDimensionSecurity = strDimensionSecurity & " LowerLevel=""[Store].[Store State]"""
    strDimensionSecurity = strDimensionSecurity & " /></MEMBERSECURITY>"
        
    dsoRole.SetPermissions "Dimension:Store", strDimensionSecurity
        
    'Deny access to other dimensions.
    For i = 1 To dsoDB.Dimensions.Count
        If dsoDB.Dimensions(i).Name <> "Time" Then
           If dsoDB.Dimensions(i).Name <> "Store" Then
           ' Pay Type is a private dimension in the HR cube.
           ' Setting permissions at the Database Level
           ' so preface it with the name of the cube and ^.
              If dsoDB.Dimensions(i).Name <> "HR^Pay Type" Then
                 If dsoDB.Dimensions(i).Name <> "Store Type" Then
                    If dsoDB.Dimensions(i).Name <> "Measures" Then

                    ' Comment these two lines, because they contain an incomplete permission statement.
                      strDimensionSecurity = "<MEMBERSECURITY IsVisible=""False"">"
                      strDimensionSecurity = strDimensionSecurity & "</MEMBERSECURITY>"


                    ' Uncomment these lines, containing a complete permission statement, to apply the security rules.
                      'strDimensionSecurity = "<MEMBERSECURITY IsVisible=""False"">"
                      'strDimensionSecurity = strDimensionSecurity & "<PERMISSION Access=""Read"" "
                      'strDimensionSecurity = strDimensionSecurity & "UpperLevel=""[" & Trim(dsoDB.Dimensions(i).Name) & "].Levels(0)"" "
                      'strDimensionSecurity = strDimensionSecurity & "LowerLevel=""[" & Trim(dsoDB.Dimensions(i).Name) & "].Levels(0)"" "
                      'strDimensionSecurity = strDimensionSecurity & "AllowedSet=""{[" & Trim(dsoDB.Dimensions(i).Name) & "].Levels(0).Members(0)}""/> "
                      'strDimensionSecurity = strDimensionSecurity & "</MEMBERSECURITY>"

                      dsoRole.SetPermissions "Dimension:" & dsoDB.Dimensions(i).Name, strDimensionSecurity
                    End If
                 End If
              End If
           End If
        End If
    Next
    
    'Unlock the database.
    dsoRole.UnlockObject
    'Update the Role.
    dsoRole.Update
    
    Dim dsoCube As DSO.Cube
    Set dsoCube = dsoDB.MDStores(CubeName)

    dsoCube.LockObject 1, "Creating New Roles"
    Set dsoCubeRole = dsoCube.Roles.AddNew(RoleName)
          
    strDimensionSecurity = "<MEMBERSECURITY>"
    strDimensionSecurity = strDimensionSecurity & "<PERMISSION Access=""Read"""
    strDimensionSecurity = strDimensionSecurity & " AllowedSet=""{[Measures].[Org Salary],[Measures].[Count],[Measures].[Number of Employees]}"""
    strDimensionSecurity = strDimensionSecurity & " /></MEMBERSECURITY>"
    
    dsoCubeRole.SetPermissions "Dimension:Measures", strDimensionSecurity
    
    dsoCube.Update

    dsoCube.UnlockObject
    Set dsoCubeRole = Nothing
    Set dsoCube = Nothing
        
    dsoDB.Update
    dsoServer.Update
    dsoServer.UnlockAllObjects
    dsoServer.CloseServer
    Set dsoServer = Nothing
    Set dsoDB = Nothing
    Set dsoRole = Nothing
    
    MsgBox "Done"
End Sub
对之Java代码的改造(部分):
Ole32.CoInitialize();
   DispatchPtr as = new DispatchPtr("DSO.Server");
   as.invoke("Connect" , "localhost");
   DispatchPtr mds = (DispatchPtr) as.get("MDStores");
   DispatchPtr db = (DispatchPtr)mds.invoke("Item","FoodMart 2000");
   DispatchPtr roles = (DispatchPtr) db.get("Roles");
   int rnt = (Integer) roles.get("Count");
   for( int i = 1;i <= rnt;i ++ )
   {
    DispatchPtr role = (DispatchPtr) roles.invoke("Item", i);
    System.err.println("RoleName:" + role.get("Name"));
    String str = (String) role.get("Permissions","Dimension:Time");
    System.out.println(str);
    
   }
Ole32.CoUninitialize();

你可能感兴趣的:(java,编程,windows,Security,vb)