Package com.sun.star.uno

Examples of com.sun.star.uno.XComponentContext


import com.sun.star.uno.XComponentContext;

public final class Relay implements XRelay, XSource {
    public void start(XSource source) {
        this.source = source;
        XComponentContext context;
        try {
            context = Bootstrap.createInitialComponentContext(null);
        } catch (RuntimeException e) {
            throw e;
        } catch (com.sun.star.uno.Exception e) {
            throw new WrappedTargetRuntimeException(e.toString(), this, e);
        } catch (Exception e) {
            throw new com.sun.star.uno.RuntimeException(e.toString(), this);
        }
        final XAcceptor acceptor = Acceptor.create(context);
        final XBridgeFactory factory;
        try {
            factory = UnoRuntime.queryInterface(
                XBridgeFactory.class,
                context.getServiceManager().createInstanceWithContext(
                    "com.sun.star.bridge.BridgeFactory", context));
        } catch (com.sun.star.uno.Exception e) {
            throw new WrappedTargetRuntimeException(e.toString(), this, e);
        }
        new Thread() {
View Full Code Here


            this.provider = provider;
        }

        public void run() {
            try {
                XComponentContext context
                    = Bootstrap.createInitialComponentContext(null);
                XAcceptor acceptor = Acceptor.create(context);
                XBridgeFactory factory
                    = UnoRuntime.queryInterface(
                        XBridgeFactory.class,
                        context.getServiceManager().createInstanceWithContext(
                            "com.sun.star.bridge.BridgeFactory", context));
                System.out.println("Server: Accepting...");
                synchronized (this) {
                    state = ACCEPTING;
                    notifyAll();
View Full Code Here

public final class TestAcquire {
    public static void main(String[] arguments) throws Exception {
        // - arguments[0] must be "client" or "server"
        // - arguments[1] must be the UNO URL to connect to (client) or accept
        //   on (server)
        XComponentContext context
            = Bootstrap.createInitialComponentContext(null);
        if (arguments[0].equals("client")) {
            execClient(context, arguments[1]);
        } else {
            execServer(context, arguments[1]);
View Full Code Here

                                            XDerived.class, test2Aa);

                                    Hashtable params = new Hashtable();
                                    params.put("UNO_TYPES", unoTypes);
                                    params.put("UNO_SERVICES", unoServices);
                                    XComponentContext context = Bootstrap.
                                       defaultBootstrap_InitialComponentContext(
                                            null, params);
                                    XMultiComponentFactory factory
                                        = context.getServiceManager();
                                    XImplementationLoader loader =
                                        UnoRuntime.queryInterface(
                                            XImplementationLoader.class,
                                            factory.createInstanceWithContext(
                                                "com.sun.star.loader."
View Full Code Here

        // add smgr
        context_entries.put(
            "/singletons/com.sun.star.lang.theServiceManager",
            new ComponentContextEntry( null, xSMgr ) );
        // ... xxx todo: add standard entries
        XComponentContext xContext = new ComponentContext( context_entries, null );
       
        // post init smgr
    xInit = UnoRuntime.queryInterface(
            XInitialization.class, xSMgr );
    args = new Object [] { null, xContext }; // no registry, default context
View Full Code Here

   * @since UDK 3.1.0
     */   
    public static final XComponentContext bootstrap()
        throws BootstrapException {
       
        XComponentContext xContext = null;
       
        try {
            // create default local component context               
            XComponentContext xLocalContext =
                createInitialComponentContext( null );
            if ( xLocalContext == null )
                throw new BootstrapException( "no local component context!" );
           
            // find office executable relative to this class's class loader
            String sOffice =
                System.getProperty( "os.name" ).startsWith( "Windows" ) ?
                "soffice.exe" : "soffice";           
            File fOffice = NativeLibraryLoader.getResource(
                Bootstrap.class.getClassLoader(), sOffice );
            if ( fOffice == null )
                throw new BootstrapException( "no office executable found!" );

            // create random pipe name
            String sPipeName = "uno" +
                Long.toString( (new Random()).nextLong() & 0x7fffffffffffffffL );
           
            // create call with arguments
            String[] cmdArray = new String[7];
            cmdArray[0] = fOffice.getPath();
            cmdArray[1] = "-nologo";
            cmdArray[2] = "-nodefault";
            cmdArray[3] = "-norestore";
            cmdArray[4] = "-nocrashreport";
            cmdArray[5] = "-nolockcheck";
            cmdArray[6] = "-accept=pipe,name=" + sPipeName + ";urp;";
           
            // start office process
            Process p = Runtime.getRuntime().exec( cmdArray );
            pipe( p.getInputStream(), System.out, "CO> " );
            pipe( p.getErrorStream(), System.err, "CE> " );
           
            // initial service manager
            XMultiComponentFactory xLocalServiceManager =
                xLocalContext.getServiceManager();
            if ( xLocalServiceManager == null )
                throw new BootstrapException( "no initial service manager!" );
           
            // create a URL resolver
            XUnoUrlResolver xUrlResolver =
View Full Code Here

*/
public class UrlResolver_Test
{
    public static void main(String[] args) {
        try {
            XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext( null );

            // initial serviceManager
            XMultiComponentFactory xLocalServiceManager = xcomponentcontext.getServiceManager();

            // create a connector, so that it can contact the office
            XUnoUrlResolver urlResolver
                = UnoUrlResolver.create( xcomponentcontext );

            Object initialObject = urlResolver.resolve(
                "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" );

            XMultiComponentFactory  xOfficeFactory= UnoRuntime.queryInterface(
                XMultiComponentFactory.class, initialObject );

            // retrieve the component context (it's not yet exported from the office)
            // Query for the XPropertySet interface.
            XPropertySet xProperySet = UnoRuntime.queryInterface(
                XPropertySet.class, xOfficeFactory);

            // Get the default context from the office server.
            Object oDefaultContext = xProperySet.getPropertyValue( "DefaultContext" );

            // Query for the interface XComponentContext.
            XComponentContext xOfficeComponentContext = UnoRuntime.queryInterface(
                XComponentContext.class, oDefaultContext );

            // now create the desktop service
            // NOTE: use the office component context here !
            Object oDesktop = xOfficeFactory.createInstanceWithContext("com.sun.star.frame.Desktop",
View Full Code Here

  private XComponentContext connect()
  {
    try
    {
      // create default local component context
      XComponentContext xLocalContext =
          com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
     
      // initial serviceManager
      XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
       
      // try to connect to soffice
      Object aInitialObject = null;
      try
      {
                aInitialObject = resolve(xLocalContext, mURL);
      }
      catch( com.sun.star.connection.NoConnectException e )
      {
        // launch soffice
        OfficeService aSOffice = new OfficeService();
        aSOffice.startupService();
   
        // wait until soffice is started
        long nMaxMillis = System.currentTimeMillis() + 1000*aSOffice.getStartupTime();
        while ( aInitialObject == null )
        {
          try
          {
            // try to connect to soffice
            Thread.currentThread().sleep( 500 );
                        aInitialObject = resolve(xLocalContext, mURL);
          }
          catch( com.sun.star.connection.NoConnectException aEx )
          {
            // soffice did not start in time
            if ( System.currentTimeMillis() > nMaxMillis )
              throw aEx;

          }
        }
      }
      finally
      {
      }
     
      // XComponentContext
      if( null != aInitialObject )
      {
        XPropertySet xPropertySet = (XPropertySet)
          UnoRuntime.queryInterface( XPropertySet.class, aInitialObject);
                  Object xContext = xPropertySet.getPropertyValue("DefaultContext");           
                  XComponentContext xComponentContext = (XComponentContext) UnoRuntime.queryInterface(
          XComponentContext.class, xContext);
        return xComponentContext;
      }
    }
    catch( com.sun.star.connection.NoConnectException e )
View Full Code Here

       private XToolkit queryAWTToolkit()
               throws com.sun.star.uno.Exception
       {
      // Create a UNO toolkit.
      XMultiComponentFactory  compfactory;
      XComponentContext xContext = mConnection.getComponentContext();
      if ( xContext != null )
      {
        compfactory     = mConnection.getComponentContext().getServiceManager();
        XMultiServiceFactory    factory;
        factory = (XMultiServiceFactory)UnoRuntime.queryInterface(
View Full Code Here

       private XToolkit queryAWTToolkit()
               throws com.sun.star.uno.Exception
       {
      // Create a UNO toolkit.
      XMultiComponentFactory  compfactory;
      XComponentContext xContext = mConnection.getComponentContext();
      if ( xContext != null )
      {
        compfactory     = mConnection.getComponentContext().getServiceManager();
        XMultiServiceFactory    factory;
        factory = (XMultiServiceFactory)UnoRuntime.queryInterface(
View Full Code Here

TOP

Related Classes of com.sun.star.uno.XComponentContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.