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