1ae15d43aSAndrew Rist /************************************************************** 2*be8bac39Smseidel * 3ae15d43aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ae15d43aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ae15d43aSAndrew Rist * distributed with this work for additional information 6ae15d43aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ae15d43aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ae15d43aSAndrew Rist * "License"); you may not use this file except in compliance 9ae15d43aSAndrew Rist * with the License. You may obtain a copy of the License at 10*be8bac39Smseidel * 11ae15d43aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*be8bac39Smseidel * 13ae15d43aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ae15d43aSAndrew Rist * software distributed under the License is distributed on an 15ae15d43aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ae15d43aSAndrew Rist * KIND, either express or implied. See the License for the 17ae15d43aSAndrew Rist * specific language governing permissions and limitations 18ae15d43aSAndrew Rist * under the License. 19*be8bac39Smseidel * 20ae15d43aSAndrew Rist *************************************************************/ 21ae15d43aSAndrew Rist 22*be8bac39Smseidel 23*be8bac39Smseidel 24cdf0e10cSrcweir package org.openoffice.examples.embedding; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 28cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory; 29cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory; 30cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 31cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase; 32cdf0e10cSrcweir import com.sun.star.uno.Exception; 33cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException; 34cdf0e10cSrcweir 35cdf0e10cSrcweir import com.sun.star.embed.*; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import org.openoffice.examples.embedding.OwnEmbeddedObject; 38cdf0e10cSrcweir 39cdf0e10cSrcweir public final class OwnEmbeddedObjectFactory extends WeakBase 40cdf0e10cSrcweir implements com.sun.star.lang.XServiceInfo, 41cdf0e10cSrcweir com.sun.star.embed.XEmbedObjectFactory 42cdf0e10cSrcweir { 43cdf0e10cSrcweir private final XComponentContext m_xContext; 44cdf0e10cSrcweir private static final String m_implementationName = OwnEmbeddedObjectFactory.class.getName(); 45cdf0e10cSrcweir private static final String[] m_serviceNames = { 46cdf0e10cSrcweir "org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D" }; 47cdf0e10cSrcweir private static final byte[] m_classID = { 0x69, 0x47, 0x43, 0x66, (byte)0xFD, 0x6F, 0x48, 0x06, (byte)0x83, 0x74, (byte)0x8E, (byte)0xDD, 0x1B, 0x6E, 0x77, 0x1D }; 48cdf0e10cSrcweir 49cdf0e10cSrcweir OwnEmbeddedObjectFactory( XComponentContext context )50cdf0e10cSrcweir public OwnEmbeddedObjectFactory( XComponentContext context ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir m_xContext = context; 53cdf0e10cSrcweir }; 54cdf0e10cSrcweir __getComponentFactory( String sImplementationName )55cdf0e10cSrcweir public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) { 56cdf0e10cSrcweir XSingleComponentFactory xFactory = null; 57cdf0e10cSrcweir 58cdf0e10cSrcweir if ( sImplementationName.equals( m_implementationName ) ) 59cdf0e10cSrcweir xFactory = Factory.createComponentFactory(OwnEmbeddedObjectFactory.class, m_serviceNames); 60cdf0e10cSrcweir return xFactory; 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration 64cdf0e10cSrcweir // was changed to passive component registration. For more details see 65*be8bac39Smseidel // https://wiki.openoffice.org/wiki/Passive_Component_Registration 66cdf0e10cSrcweir 67cdf0e10cSrcweir // public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) { 68cdf0e10cSrcweir // return Factory.writeRegistryServiceInfo(m_implementationName, 69cdf0e10cSrcweir // m_serviceNames, 70cdf0e10cSrcweir // xRegistryKey); 71cdf0e10cSrcweir // } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // com.sun.star.lang.XServiceInfo: getImplementationName()74cdf0e10cSrcweir public String getImplementationName() { 75cdf0e10cSrcweir return m_implementationName; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir supportsService( String sService )78cdf0e10cSrcweir public boolean supportsService( String sService ) { 79cdf0e10cSrcweir int len = m_serviceNames.length; 80cdf0e10cSrcweir 81cdf0e10cSrcweir for( int i=0; i < len; i++) { 82cdf0e10cSrcweir if (sService.equals(m_serviceNames[i])) 83cdf0e10cSrcweir return true; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir return false; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir getSupportedServiceNames()88cdf0e10cSrcweir public String[] getSupportedServiceNames() { 89cdf0e10cSrcweir return m_serviceNames; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir // com.sun.star.embed.XEmbedObjectFactory: createInstanceUserInit(byte[] aClassID, String sClassName, com.sun.star.embed.XStorage xStorage, String sEntName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aArgs, com.sun.star.beans.PropertyValue[] aObjectArgs)93cdf0e10cSrcweir public Object createInstanceUserInit(byte[] aClassID, String sClassName, com.sun.star.embed.XStorage xStorage, String sEntName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException, com.sun.star.uno.Exception 94cdf0e10cSrcweir { 95cdf0e10cSrcweir if ( xStorage == null || sEntName == null || sEntName.length() == 0 ) 96cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 97*be8bac39Smseidel 98cdf0e10cSrcweir if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if ( aClassID != null && aClassID.length != 0 ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if ( aClassID.length != m_classID.length ) 103cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 104cdf0e10cSrcweir 105cdf0e10cSrcweir for ( int i = 0; i < aClassID.length; i++ ) 106cdf0e10cSrcweir if ( aClassID[i] != m_classID[i] ) 107cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir else if ( !xStorage.hasByName( sEntName ) ) 110cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir if ( aClassID.length != m_classID.length ) 115cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir for ( int i = 0; i < m_classID.length; i++ ) 118cdf0e10cSrcweir if ( aClassID[i] != m_classID[i] ) 119cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir OwnEmbeddedObject aObject = new OwnEmbeddedObject( m_xContext, m_classID ); 123cdf0e10cSrcweir aObject.setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, aArgs, aObjectArgs ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir return aObject; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir } 129*be8bac39Smseidel 130