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