2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org
.libreoffice
.report
.pentaho
;
20 import com
.sun
.star
.container
.NoSuchElementException
;
21 import com
.sun
.star
.lang
.XServiceInfo
;
22 import com
.sun
.star
.lib
.uno
.helper
.ComponentBase
;
23 import com
.sun
.star
.report
.meta
.XFunctionCategory
;
24 import com
.sun
.star
.report
.meta
.XFunctionDescription
;
25 import com
.sun
.star
.report
.meta
.XFunctionManager
;
26 import com
.sun
.star
.uno
.XComponentContext
;
28 import org
.pentaho
.reporting
.libraries
.formula
.DefaultFormulaContext
;
29 import org
.pentaho
.reporting
.libraries
.formula
.function
.FunctionCategory
;
30 import org
.pentaho
.reporting
.libraries
.formula
.function
.FunctionDescription
;
31 import org
.pentaho
.reporting
.libraries
.formula
.function
.FunctionRegistry
;
33 public final class SOFunctionManager
extends ComponentBase
implements XFunctionManager
, XServiceInfo
36 private final XComponentContext m_xContext
;
38 * The service name, that must be used to get an instance of this service.
40 private static final String __serviceName
=
41 "com.sun.star.report.meta.FunctionManager";
42 final private FunctionCategory
[] categories
;
43 final private FunctionRegistry functionRegistry
;
44 final private DefaultFormulaContext defaultContext
;
46 public SOFunctionManager(XComponentContext context
)
49 final ClassLoader cl
= java
.lang
.Thread
.currentThread().getContextClassLoader();
50 Thread
.currentThread().setContextClassLoader(this.getClass().getClassLoader());
51 defaultContext
= new DefaultFormulaContext();
52 functionRegistry
= defaultContext
.getFunctionRegistry();
53 categories
= functionRegistry
.getCategories();
54 Thread
.currentThread().setContextClassLoader(cl
);
59 * This method returns an array of all supported service names.
61 * @return Array of supported service names.
63 public String
[] getSupportedServiceNames()
65 return getServiceNames();
69 * This method is a simple helper function to used in the static component initialisation functions as well as
70 * in getSupportedServiceNames.
72 public static String
[] getServiceNames()
81 * This method returns true, if the given service will be supported by the component.
83 * @param sServiceName Service name.
84 * @return True, if the given service name will be supported.
86 public boolean supportsService(final String sServiceName
)
88 return sServiceName
.equals(__serviceName
);
92 * Return the class name of the component.
94 * @return Class name of the component.
96 public String
getImplementationName()
98 return SOFunctionManager
.class.getName();
101 // com.sun.star.container.XElementAccess:
102 public com
.sun
.star
.uno
.Type
getElementType()
104 return new com
.sun
.star
.uno
.Type(XFunctionCategory
.class);
107 public boolean hasElements()
109 return categories
.length
!= 0;
112 // com.sun.star.container.XIndexAccess:
113 public int getCount()
115 return categories
.length
;
118 public Object
getByIndex(int Index
) throws com
.sun
.star
.lang
.IndexOutOfBoundsException
, com
.sun
.star
.lang
.WrappedTargetException
120 return getCategory(Index
);
123 // com.sun.star.report.meta.XFunctionManager:
124 public com
.sun
.star
.report
.meta
.XFunctionCategory
getCategory(int position
) throws com
.sun
.star
.lang
.IndexOutOfBoundsException
, com
.sun
.star
.lang
.WrappedTargetException
126 if (position
>= categories
.length
)
128 throw new com
.sun
.star
.lang
.IndexOutOfBoundsException();
130 return new StarFunctionCategory(defaultContext
, m_xContext
, functionRegistry
, position
, categories
[position
]);
133 public XFunctionDescription
getFunctionByName(String arg0
) throws NoSuchElementException
135 final FunctionDescription func
= functionRegistry
.getMetaData(arg0
);
138 throw new NoSuchElementException();
141 for (; i
< categories
.length
; i
++)
143 if (categories
[i
] == func
.getCategory())
150 return new StarFunctionDescription(defaultContext
, m_xContext
, getCategory(i
), func
);