1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.comp.juhtest;
24 
25 import com.sun.star.lang.XMultiComponentFactory;
26 import com.sun.star.lib.uno.helper.WeakBase;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XComponentContext;
29 import com.sun.star.lang.XServiceInfo;
30 import com.sun.star.ucb.XCommandEnvironment;
31 
32 /** This service is for use by the smoketest which checks the installation of
33  * extensions. The service provides the XCommandEnvironment interface, which
34  * is needed for adding extensions.
35  */
36 public class SmoketestCommandEnvironment extends WeakBase
37     implements XServiceInfo, XCommandEnvironment {
38 
39     static private final String __serviceName =
40     "com.sun.star.deployment.test.SmoketestCommandEnvironment";
41 
42     private XComponentContext m_cmpCtx;
43     private XMultiComponentFactory m_xMCF;
44 
45 
SmoketestCommandEnvironment(XComponentContext xCompContext)46     public SmoketestCommandEnvironment(XComponentContext xCompContext) {
47         try {
48             m_cmpCtx = xCompContext;
49             m_xMCF = m_cmpCtx.getServiceManager();
50         }
51         catch( Exception e ) {
52             e.printStackTrace();
53         }
54     }
55 
getServiceNames()56     public static String[] getServiceNames() {
57         String[] sSupportedServiceNames = { __serviceName};
58         return sSupportedServiceNames;
59     }
60 
61     //XServiceInfo -------------------------------------------------------------
getSupportedServiceNames()62     public String[] getSupportedServiceNames() {
63         return getServiceNames();
64     }
65 
66 
supportsService( String sServiceName )67     public boolean supportsService( String sServiceName ) {
68         boolean bSupported = false;
69         if (sServiceName.equals(__serviceName))
70             bSupported = true;
71         return bSupported;
72     }
73 
getImplementationName()74     public String getImplementationName() {
75         return  SmoketestCommandEnvironment.class.getName();
76     }
77 
78     //XCommandEnvironment ================================================
getInteractionHandler()79     public com.sun.star.task.XInteractionHandler getInteractionHandler()
80     {
81         return new InteractionImpl();
82     }
83 
getProgressHandler()84     public com.sun.star.ucb.XProgressHandler getProgressHandler()
85     {
86         return new ProgressImpl();
87     }
88 }
89 
90 
91 
92 
93 class InteractionImpl implements com.sun.star.task.XInteractionHandler
94 {
handle( com.sun.star.task.XInteractionRequest xRequest )95     public void handle( com.sun.star.task.XInteractionRequest xRequest )
96     {
97         Object request = xRequest.getRequest();
98 
99         boolean approve = true;
100         boolean abort = false;
101 //             Object install_Exception =
102 //                 AnyConverter.toObject(
103 //                     com.sun.star.deployment.InstallException.class, request);
104 //             if (install_Exception != null)
105 //             {
106 //                 approve = true;
107 //             }
108 
109         com.sun.star.task.XInteractionContinuation[] conts = xRequest.getContinuations();
110         for (int i = 0; i < conts.length; i++)
111         {
112             if (approve)
113             {
114                 com.sun.star.task.XInteractionApprove xApprove =
115                     UnoRuntime.queryInterface(com.sun.star.task.XInteractionApprove.class, conts[i]);
116                 if (xApprove != null)
117                     xApprove.select();
118                 //don't query again for ongoing extensions
119                 approve = false;
120             }
121             else if (abort)
122             {
123                 com.sun.star.task.XInteractionAbort xAbort =
124                     UnoRuntime.queryInterface(com.sun.star.task.XInteractionAbort.class, conts[i]);
125                 if (xAbort != null)
126                     xAbort.select();
127                 //don't query again for ongoing extensions
128                 abort = false;
129             }
130         }
131     }
132 }
133 
134 class ProgressImpl implements com.sun.star.ucb.XProgressHandler
135 {
push(Object status)136     public void push(Object status)
137     {
138     }
139 
update(Object status)140     public void update(Object status)
141     {
142     }
143 
pop()144     public void pop()
145     {
146     }
147 }
148