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
.lang
.XServiceInfo
;
21 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
22 import com
.sun
.star
.sheet
.FormulaLanguage
;
23 import com
.sun
.star
.sheet
.FormulaMapGroup
;
24 import com
.sun
.star
.sheet
.FormulaOpCodeMapEntry
;
25 import com
.sun
.star
.sheet
.FormulaToken
;
27 import java
.util
.ArrayList
;
30 public final class SOFormulaOpCodeMapper
extends WeakBase
31 implements com
.sun
.star
.sheet
.XFormulaOpCodeMapper
, XServiceInfo
34 private static final String __serviceName
= "org.libreoffice.report.pentaho.SOFormulaOpCodeMapper";
35 private final SOFormulaParser parser
;
37 static final private int m_OpCodeExternal
= 0;
38 static final private int m_OpCodeUnknown
= 0;
40 public SOFormulaOpCodeMapper(SOFormulaParser parser
)
45 // com.sun.star.sheet.XFormulaOpCodeMapper:
46 public int getOpCodeExternal()
48 return m_OpCodeExternal
;
51 public int getOpCodeUnknown()
53 return m_OpCodeUnknown
;
56 public com
.sun
.star
.sheet
.FormulaToken
[] getMappings(String
[] Names
, int Language
) throws com
.sun
.star
.lang
.IllegalArgumentException
58 if (Language
!= FormulaLanguage
.ODFF
)
60 throw new IllegalArgumentException();
62 final ArrayList
<FormulaToken
> token
= new ArrayList
<FormulaToken
>();
63 final Map parserNames
= parser
.getNames();
64 for (int i
= 0; i
< Names
.length
; i
++)
66 if (parserNames
.containsKey(Names
[i
]))
68 token
.add(((FormulaOpCodeMapEntry
) parserNames
.get(Names
[i
])).Token
);
72 return token
.toArray(new FormulaToken
[token
.size()]);
75 public com
.sun
.star
.sheet
.FormulaOpCodeMapEntry
[] getAvailableMappings(int Language
, int Groups
) throws com
.sun
.star
.lang
.IllegalArgumentException
77 if (Language
!= FormulaLanguage
.ODFF
)
79 throw new IllegalArgumentException();
81 final ArrayList
<FormulaOpCodeMapEntry
> token
= new ArrayList
<FormulaOpCodeMapEntry
>();
82 if (Groups
== FormulaMapGroup
.SPECIAL
)
84 return parser
.getSpecialOpCodes().toArray(new FormulaOpCodeMapEntry
[parser
.getSpecialOpCodes().size()]);
88 if ((Groups
& FormulaMapGroup
.ARRAY_SEPARATORS
) != 0)
90 token
.addAll(parser
.getGroup(SOFormulaParser
.ARRAY_SEPARATORS
).values());
92 if ((Groups
& FormulaMapGroup
.SEPARATORS
) != 0)
94 token
.addAll(parser
.getGroup(SOFormulaParser
.SEPARATORS
).values());
96 if ((Groups
& FormulaMapGroup
.ARRAY_SEPARATORS
) != 0)
98 token
.addAll(parser
.getGroup(SOFormulaParser
.ARRAY_SEPARATORS
).values());
100 if ((Groups
& FormulaMapGroup
.UNARY_OPERATORS
) != 0)
102 token
.addAll(parser
.getGroup(SOFormulaParser
.UNARY_OPERATORS
).values());
104 if ((Groups
& FormulaMapGroup
.BINARY_OPERATORS
) != 0)
106 token
.addAll(parser
.getGroup(SOFormulaParser
.BINARY_OPERATORS
).values());
108 if ((Groups
& FormulaMapGroup
.FUNCTIONS
) != 0)
110 token
.addAll(parser
.getGroup(SOFormulaParser
.FUNCTIONS
).values());
114 return token
.toArray(new FormulaOpCodeMapEntry
[token
.size()]);
117 public String
getImplementationName()
119 return SOFormulaOpCodeMapper
.class.getName();
122 public boolean supportsService(String sServiceName
)
124 return sServiceName
.equals(__serviceName
);
127 public String
[] getSupportedServiceNames()
129 return getServiceNames();
133 * This method is a simple helper function to used in the static component initialisation functions as well as
134 * in getSupportedServiceNames.
136 private static String
[] getServiceNames()