Update ooo320-m1
[ooovba.git] / odk / examples / java / EmbedDocument / EmbeddedObject / OwnEmbeddedObjectFactory.java
blob525d13e63eef19c97bc7c9ebdb83a8d437f51729
1 package org.openoffice.examples.embedding;
3 import com.sun.star.uno.UnoRuntime;
4 import com.sun.star.uno.XComponentContext;
5 import com.sun.star.lib.uno.helper.Factory;
6 import com.sun.star.lang.XSingleComponentFactory;
7 import com.sun.star.registry.XRegistryKey;
8 import com.sun.star.lib.uno.helper.WeakBase;
9 import com.sun.star.uno.Exception;
10 import com.sun.star.lang.IllegalArgumentException;
12 import com.sun.star.embed.*;
14 import org.openoffice.examples.embedding.OwnEmbeddedObject;
16 public final class OwnEmbeddedObjectFactory extends WeakBase
17 implements com.sun.star.lang.XServiceInfo,
18 com.sun.star.embed.XEmbedObjectFactory
20 private final XComponentContext m_xContext;
21 private static final String m_implementationName = OwnEmbeddedObjectFactory.class.getName();
22 private static final String[] m_serviceNames = {
23 "org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D" };
24 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 };
27 public OwnEmbeddedObjectFactory( XComponentContext context )
29 m_xContext = context;
32 public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
33 XSingleComponentFactory xFactory = null;
35 if ( sImplementationName.equals( m_implementationName ) )
36 xFactory = Factory.createComponentFactory(OwnEmbeddedObjectFactory.class, m_serviceNames);
37 return xFactory;
40 public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {
41 return Factory.writeRegistryServiceInfo(m_implementationName,
42 m_serviceNames,
43 xRegistryKey);
46 // com.sun.star.lang.XServiceInfo:
47 public String getImplementationName() {
48 return m_implementationName;
51 public boolean supportsService( String sService ) {
52 int len = m_serviceNames.length;
54 for( int i=0; i < len; i++) {
55 if (sService.equals(m_serviceNames[i]))
56 return true;
58 return false;
61 public String[] getSupportedServiceNames() {
62 return m_serviceNames;
65 // com.sun.star.embed.XEmbedObjectFactory:
66 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
68 if ( xStorage == null || sEntName == null || sEntName.length() == 0 )
69 throw new com.sun.star.lang.IllegalArgumentException();
71 if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT )
73 if ( aClassID != null && aClassID.length != 0 )
75 if ( aClassID.length != m_classID.length )
76 throw new com.sun.star.lang.IllegalArgumentException();
78 for ( int i = 0; i < aClassID.length; i++ )
79 if ( aClassID[i] != m_classID[i] )
80 throw new com.sun.star.lang.IllegalArgumentException();
82 else if ( !xStorage.hasByName( sEntName ) )
83 throw new com.sun.star.lang.IllegalArgumentException();
85 else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT )
87 if ( aClassID.length != m_classID.length )
88 throw new com.sun.star.lang.IllegalArgumentException();
90 for ( int i = 0; i < m_classID.length; i++ )
91 if ( aClassID[i] != m_classID[i] )
92 throw new com.sun.star.lang.IllegalArgumentException();
95 OwnEmbeddedObject aObject = new OwnEmbeddedObject( m_xContext, m_classID );
96 aObject.setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, aArgs, aObjectArgs );
98 return aObject;