1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.uno
.XComponentContext
;
21 import com
.sun
.star
.lib
.uno
.helper
.Factory
;
22 import com
.sun
.star
.lang
.XSingleComponentFactory
;
23 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
25 public final class OwnEmbeddedObjectFactory
extends WeakBase
26 implements com
.sun
.star
.lang
.XServiceInfo
,
27 com
.sun
.star
.embed
.XEmbedObjectFactory
29 private final XComponentContext m_xContext
;
30 private static final String m_implementationName
= OwnEmbeddedObjectFactory
.class.getName();
31 private static final String
[] m_serviceNames
= {
32 "org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D" };
33 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 };
36 public OwnEmbeddedObjectFactory( XComponentContext context
)
41 public static XSingleComponentFactory
__getComponentFactory( String sImplementationName
) {
42 XSingleComponentFactory xFactory
= null;
44 if ( sImplementationName
.equals( m_implementationName
) )
45 xFactory
= Factory
.createComponentFactory(OwnEmbeddedObjectFactory
.class, m_serviceNames
);
49 // com.sun.star.lang.XServiceInfo:
50 public String
getImplementationName() {
51 return m_implementationName
;
54 public boolean supportsService( String sService
) {
55 int len
= m_serviceNames
.length
;
57 for( int i
=0; i
< len
; i
++) {
58 if (sService
.equals(m_serviceNames
[i
]))
64 public String
[] getSupportedServiceNames() {
65 return m_serviceNames
;
68 // com.sun.star.embed.XEmbedObjectFactory:
69 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
71 if ( xStorage
== null || sEntName
== null || sEntName
.length() == 0 )
72 throw new com
.sun
.star
.lang
.IllegalArgumentException();
74 if ( nEntryConnectionMode
== com
.sun
.star
.embed
.EntryInitModes
.DEFAULT_INIT
)
76 if ( aClassID
!= null && aClassID
.length
!= 0 )
78 if ( aClassID
.length
!= m_classID
.length
)
79 throw new com
.sun
.star
.lang
.IllegalArgumentException();
81 for ( int i
= 0; i
< aClassID
.length
; i
++ )
82 if ( aClassID
[i
] != m_classID
[i
] )
83 throw new com
.sun
.star
.lang
.IllegalArgumentException();
85 else if ( !xStorage
.hasByName( sEntName
) )
86 throw new com
.sun
.star
.lang
.IllegalArgumentException();
88 else if ( nEntryConnectionMode
== com
.sun
.star
.embed
.EntryInitModes
.TRUNCATE_INIT
)
90 if ( aClassID
.length
!= m_classID
.length
)
91 throw new com
.sun
.star
.lang
.IllegalArgumentException();
93 for ( int i
= 0; i
< m_classID
.length
; i
++ )
94 if ( aClassID
[i
] != m_classID
[i
] )
95 throw new com
.sun
.star
.lang
.IllegalArgumentException();
98 OwnEmbeddedObject aObject
= new OwnEmbeddedObject( m_xContext
, m_classID
);
99 aObject
.setPersistentEntry( xStorage
, sEntName
, nEntryConnectionMode
, aArgs
, aObjectArgs
);
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */