diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /odk/examples/java/MinimalComponent | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
6 files changed, 566 insertions, 0 deletions
diff --git a/odk/examples/java/MinimalComponent/BuildMinimalComponent.xml b/odk/examples/java/MinimalComponent/BuildMinimalComponent.xml new file mode 100644 index 000000000..10dfde5ec --- /dev/null +++ b/odk/examples/java/MinimalComponent/BuildMinimalComponent.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<project name="MinimalComponent" basedir="." default="all"> + + <target name="init"> + <!-- + In this target you have to change all parts, so that the properties + fit to your odk installation and to your service + --> + <property name="ODKPATH" value="D:/cvs/api/odk"/> + <property name="OUTPUTPATH" value="D:/cvs/api/odk/WINexample.out"/> + <property name="PACKAGE_NAME" value="org.OpenOffice."/> + <property name="JAR_FILE_NAME" value="MinimalComponent"/> + <property name="INTERFACE_NAME" value="MinimalComponent"/> + <property name="RDB_NAME" value="MinimalComponent.rdb"/> + </target> + <target depends="init" name="unoidl"> + + <exec dir="${ODKPATH}/WINexample.out/misc/" executable="${ODKPATH}/windows/bin/idlc.exe" timeout="600"> + <arg line="-I. -I${ODKPATH}/idl ${ODKPATH}/examples/java/MinimalComponent/${INTERFACE_NAME}.idl"/> + </exec> + + <exec dir="." executable="${ODKPATH}/windows/bin/regmerge.exe" timeout="600"> + <arg line="./${RDB_NAME} /UCR ./${INTERFACE_NAME}.urd"/> + </exec> + + <exec dir="." executable="${ODKPATH}/windows/bin/regmerge.exe" timeout="600"> + <arg line="./${RDB_NAME} / ${ODKPATH}/windows/bin/applicat.rdb"/> + </exec> + + <exec dir="." executable="${ODKPATH}/windows/bin/javamaker.exe" timeout="600"> + <arg line="-O${OUTPUTPATH}/class/${INTERFACE_NAME} -nD ./${RDB_NAME}"/> +<!-- + <arg line="-T${PACKAGE_NAME}${INTERFACE_NAME} -O${OUTPUTPATH}/class/${INTERFACE_NAME} -nD ./${INTERFACE_NAME}.urd"/> + --> + </exec> + + </target> + + <target depends="init,unoidl" name="compile"> + <mkdir dir="classes"/> + <javac debug="on" destdir="./classes" srcdir="." > + <classpath> + <fileset dir="${ODKPATH}/classes/"> + <include name="**/*.jar"/> + </fileset> + <pathelement location="./classes"/> + </classpath> + </javac> + </target> + + <target depends="compile,init" name="jar"> + <jar basedir="./classes" compress="true" jarfile="${JAR_FILE_NAME}.jar" manifest="Manifest"> + </jar> + </target> + + <target depends="compile,init,jar" name="all"> + <!-- WRITEME --> + </target> +</project> diff --git a/odk/examples/java/MinimalComponent/Makefile b/odk/examples/java/MinimalComponent/Makefile new file mode 100644 index 000000000..0639b1cac --- /dev/null +++ b/odk/examples/java/MinimalComponent/Makefile @@ -0,0 +1,204 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the Java Minimal component example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings + +# we use the sample directory name for separating this example +# from others in the output directory +SAMPLE_NAME=MinimalComponent +SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME) +SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME) + +COMP_NAME=MinimalComponent +COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME) +COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME) +COMP_RDB_NAME=$(COMP_NAME).uno.rdb +COMP_RDB=$(COMP_GEN_OUT)/$(COMP_RDB_NAME) +COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_JAR_NAME=$(COMP_NAME).uno.jar +COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME) +COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).uno.Manifest +COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml +COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag +COMP_COMPONENTS=$(COMP_NAME).components + +APP1_NAME=TestMinimalComponent +APP1_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(APP1_NAME) +APP1_GEN_OUT=$(SAMPLE_GEN_OUT)/$(APP1_NAME) +APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar +APP1_JAR_MANIFEST=$(APP1_GEN_OUT)/$(APP1_NAME).mf + +IDLFILES = MinimalComponent.idl + +# normally the idl file should be stored in a directory tree fitting the module structure, +# for the example we know the module structure +PACKAGE = org/openoffice + +COMP_JAVAFILES = MinimalComponent.java +COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES)) + +GEN_CLASSFILES = $(patsubst %.idl,$(SAMPLE_CLASS_OUT)/$(PACKAGE)/%.class,$(IDLFILES)) +GEN_TYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES))) +GEN_URDFILES = $(patsubst %.idl,$(SAMPLE_GEN_OUT)/%.urd,$(IDLFILES)) + +# the generated types are necessary for the component and the application jar +GEN_CLASSFILENAMES = $(subst $(SAMPLE_CLASS_OUT)/,,$(GEN_CLASSFILES)) + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\ + $(PATH_SEPARATOR)$(COMP_CLASS_OUT)\ + $(PATH_SEPARATOR)$(APP1_CLASS_OUT)) + + +# Targets +.PHONY: ALL +ALL : JavaMinimalComponentExample + +include $(SETTINGS)/stdtarget.mk + +$(COMP_GEN_OUT)/%.Manifest : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo UNO-Type-Path: $(basename $*).uno.jar> $@ + @echo RegistrationClassName: $(basename $*)>> $@ + +$(SAMPLE_GEN_OUT)/%.urd : %.idl + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(IDLC) -C -I. -I$(IDL_DIR) -O$(SAMPLE_GEN_OUT) $< + +$(COMP_GEN_OUT)/%.rdb : $(GEN_URDFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(REGMERGE) $@ /UCR $(GEN_URDFILES) + +$(GEN_CLASSFILES) : $(COMP_RDB) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(JAVAMAKER) -nD $(GEN_TYPELIST) -O$(SAMPLE_CLASS_OUT) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES) + +# component as well as application are dependent from the generated types +# rule for component class files +$(COMP_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $< + +# rule for example application class files +$(APP1_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(APP1_CLASS_OUT) $< + +# rule for client/example application manifest file +$(APP1_GEN_OUT)/%.mf : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo Main-Class: com.sun.star.lib.loader.Loader> $@ + $(ECHOLINE)>> $@ + @echo Name: com/sun/star/lib/loader/Loader.class>> $@ + @echo Application-Class: $*>> $@ + +# rule for client/example application jar file +$(APP1_JAR) : $(APP1_JAR_MANIFEST) $(APP1_CLASS_OUT)/$(APP1_NAME).class $(GEN_CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAR) cvfm $@ $< -C $(APP1_CLASS_OUT) . + +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES) + +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES) + +# rule for component jar file +$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) . + +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES) + +# rule for component package manifest +$(COMP_GEN_OUT)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP)>> $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP)>> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP)>> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_ZIP) $@ $(COMP_NAME).components + cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) $(COMP_RDB_NAME) + cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_JAR_NAME) + cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(COMP_REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(subst /,$(PS),$@) +else + @echo -------------------------------------------------------------------------------- + @echo If you want to install your component automatically, please set the environment + @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only + @echo possible if no office instance is running. + @echo -------------------------------------------------------------------------------- +endif + +JavaMinimalComponentExample : $(COMP_REGISTERFLAG) $(APP1_JAR) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) $(APP1_NAME).run + @echo ------ + @echo The $(COMP_NAME) component was installed if SDK_AUTO_DEPLOYMENT = YES. + @echo You can use this component inside your office installation, see the example + @echo description. + @echo -------------------------------------------------------------------------------- + +%.run: $(SAMPLE_CLASS_OUT)/%.jar + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.components b/odk/examples/java/MinimalComponent/MinimalComponent.components new file mode 100644 index 000000000..9e413f2b6 --- /dev/null +++ b/odk/examples/java/MinimalComponent/MinimalComponent.components @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components xmlns="http://openoffice.org/2010/uno-components"> + <component loader="com.sun.star.loader.Java2" uri="MinimalComponent.uno.jar"> + <implementation name="MinimalComponent$_MinimalComponent"> + <service name="org.openoffice.MinimalComponent"/> + </implementation> + </component> +</components> diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.idl b/odk/examples/java/MinimalComponent/MinimalComponent.idl new file mode 100644 index 000000000..1b63b7705 --- /dev/null +++ b/odk/examples/java/MinimalComponent/MinimalComponent.idl @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +#ifndef _org_openoffice_MinimalComponent_idl_ +#define _org_openoffice_MinimalComponent_idl_ + +#include <com/sun/star/lang/XServiceInfo.idl> + +// org +module org { + // openoffice + module openoffice { + // example service, XServiceInfo is implemented here for demonstration + // issues. XServiceInfo must be implemented by all components. But + // here it is used to show the new code generation feature for services. + // See the TestMinimalComponent.java how it can be used! + service MinimalComponent: ::com::sun::star::lang::XServiceInfo; + }; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/java/MinimalComponent/MinimalComponent.java b/odk/examples/java/MinimalComponent/MinimalComponent.java new file mode 100644 index 000000000..b8efbafcc --- /dev/null +++ b/odk/examples/java/MinimalComponent/MinimalComponent.java @@ -0,0 +1,156 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +import com.sun.star.lib.uno.helper.Factory; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XServiceInfo; + +/** This class capsulates the class, that implements the minimal component, a + * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a + * method, that writes the information into the given registry key + * (<CODE>__writeRegistryServiceInfo</CODE>). + */ +public class MinimalComponent { + /** This class implements the component. At least the interfaces XServiceInfo, + * XTypeProvider, and XInitialization should be provided by the service. + */ + public static class _MinimalComponent extends WeakBase + implements XInitialization, XServiceInfo { + /** The service name, that must be used to get an instance of this service. + */ + private static final String __serviceName = + "org.openoffice.MinimalComponent"; + + /** The initial component contextr, that gives access to + * the service manager, supported singletons, ... + * It's often later used + */ + private XComponentContext m_cmpCtx; + + /** The service manager, that gives access to all registered services. + * It's often later used + */ + private XMultiComponentFactory m_xMCF; + + /** The constructor of the inner class has a XMultiServiceFactory parameter. + * @param xCompContext A special service factory + * could be introduced while initializing. + */ + public _MinimalComponent(XComponentContext xCompContext) { + try { + m_cmpCtx = xCompContext; + m_xMCF = m_cmpCtx.getServiceManager(); + } + catch( Exception e ) { + e.printStackTrace(); + } + } + + /** This method is a member of the interface for initializing an object + * directly after its creation. + * @param object This array of arbitrary objects will be passed to the + * component after its creation. + * @throws com.sun.star.uno.Exception Every exception will not be handled, but will be + * passed to the caller. + */ + public void initialize( Object[] object ) + throws com.sun.star.uno.Exception { + /* The component describes what arguments are expected and in which + * order! At this point you can read the objects and initialize + * your component using these objects. + */ + } + + /** This method returns an array of all supported service names. + * @return Array of supported service names. + */ + public String[] getSupportedServiceNames() { + return getServiceNames(); + } + + /** This method is a simple helper function to used in the + * static component initialisation functions as well as in + * getSupportedServiceNames. + */ + private static String[] getServiceNames() { + String[] sSupportedServiceNames = { __serviceName }; + return sSupportedServiceNames; + } + + /** This method returns true, if the given service will be + * supported by the component. + * @param sServiceName Service name. + * @return True, if the given service name will be supported. + */ + public boolean supportsService( String sServiceName ) { + return sServiceName.equals( __serviceName ); + } + + /** Return the class name of the component. + * @return Class name of the component. + */ + public String getImplementationName() { + return _MinimalComponent.class.getName(); + } + } + + + /** + * Gives a factory for creating the service. + * This method is called by the <code>JavaLoader</code> + * <p> + * @return returns a <code>XSingleComponentFactory</code> for creating + * the component + * @param sImplName the name of the implementation for which a + * service is desired + * @see com.sun.star.comp.loader.JavaLoader + */ + public static XSingleComponentFactory __getComponentFactory(String sImplName) + { + XSingleComponentFactory xFactory = null; + + if ( sImplName.equals( _MinimalComponent.class.getName() ) ) + xFactory = Factory.createComponentFactory(_MinimalComponent.class, + _MinimalComponent.getServiceNames()); + + return xFactory; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/java/MinimalComponent/TestMinimalComponent.java b/odk/examples/java/MinimalComponent/TestMinimalComponent.java new file mode 100644 index 000000000..604e16163 --- /dev/null +++ b/odk/examples/java/MinimalComponent/TestMinimalComponent.java @@ -0,0 +1,67 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +import com.sun.star.lang.XServiceInfo; + +public class TestMinimalComponent { + public static void main(String args[]) { + com.sun.star.uno.XComponentContext xContext = null; + + try { + // get the remote office component context + xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); + if( xContext != null ) + System.out.println("Connected to a running office ..."); + + XServiceInfo xSIMinimalComponent = + org.openoffice.MinimalComponent.create(xContext); + + System.out.println("\nXServiceInfo is used to get the implementation" + + " name: " + + xSIMinimalComponent.getImplementationName() + + "\nOk\n"); + xContext = null; + + System.exit(0); + } + catch( Exception e ) { + System.err.println( e ); + e.printStackTrace(); + System.exit(1); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |