├── .classpath ├── .gitignore ├── .project ├── AL2.0 ├── LGPL2.1 ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── eu │ └── doppel_helix │ └── jna │ └── tlbcodegenerator │ ├── imp │ ├── FormatHelper.java │ ├── TlbAlias.java │ ├── TlbCoClass.java │ ├── TlbEntry.java │ ├── TlbEnum.java │ ├── TlbEnumMember.java │ ├── TlbFunctionCall.java │ ├── TlbFunctionCallParam.java │ ├── TlbInterface.java │ ├── TlbVariable.java │ └── TypeLib.java │ └── maven │ ├── Generator.java │ ├── List.java │ └── util │ └── JULBridge.java └── resources └── eu └── doppel_helix └── jna └── tlbcodegenerator ├── CoClass.ftl ├── Enum.ftl ├── Interface.ftl ├── InterfaceListener.ftl ├── InterfaceListenerHandler.ftl ├── Package.ftl └── output ├── CoClass.ftl ├── Enum.ftl ├── Interface.ftl └── InterfaceListener.ftl /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TlbCodeGenerator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /AL2.0: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /LGPL2.1: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This code generator is considered a utility for JNA and so the same license 2 | should apply: 3 | 4 | ================================================================================ 5 | 6 | TlbCodeGenerator is dual-licensed under 2 alternative Open Source/Free licenses: 7 | LGPL 2.1 and Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to the project. 10 | 11 | You may obtain a copy of the LGPL License at: 12 | 13 | http://www.gnu.org/licenses/licenses.html 14 | 15 | A copy is also included in the downloadable source code package, in file 16 | "LGPL2.1", under the same directory as this file. 17 | 18 | You may obtain a copy of the ASL License at: 19 | 20 | http://www.apache.org/licenses/ 21 | 22 | A copy is also included in the downloadable source code package, in file 23 | "ASL2.0", under the same directory as this file. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TlbCodeGenerator is a code generator for COM libraries. Based on the 2 | type library information, bindings for many COM based libraries can 3 | be created automaticly. 4 | 5 | Usage 6 | ===== 7 | 8 | Please note: This plugin uses the typelibrary parser, that is build into the 9 | Windows COM subsystem by directly calling into the native libraries. It won't 10 | work on non-windows platforms! 11 | 12 | The basic idea is, that per bound COM library one maven project is 13 | created. This is for example reflected in the option to derive the 14 | version of the type library from the project version. 15 | 16 | The type library can be used/referenced in two ways: 17 | 18 | - by specifying the file that holds the typelibrary or 19 | - by specifying the triplet: GUID/major/minor 20 | 21 | The second options requires the COm library to be correctly registered in the 22 | system. 23 | 24 | Download 25 | -------- 26 | 27 | [![Maven Central](https://img.shields.io/maven-central/v/eu.doppel-helix.jna.tlbcodegenerator/TlbCodeGenerator.svg?label=Maven%20Central)](https://search.maven.org/artifact/eu.doppel-helix.jna.tlbcodegenerator/TlbCodeGenerator/1.0.1/jar) [TlbCodeGenerator-1.0.1.jar](http://repo1.maven.org/maven2/eu/doppel-helix/jna/tlbcodegenerator/TlbCodeGenerator/1.0.1/TlbCodeGenerator-1.0.1.jar) 28 | 29 | Listing 30 | ------- 31 | 32 | A list of all installed libraries can be generated by calling the `list` mojo: 33 | 34 | ``` 35 | mvn eu.doppel-helix.jna.tlbcodegenerator:TlbCodeGenerator:list 36 | ``` 37 | 38 | This will generate a list with columns: 39 | 40 | - GUID 41 | - Major verion 42 | - Minor version 43 | - Name of the type library (internal) 44 | - User visible name of the type library 45 | 46 | The task can be called without a project. 47 | 48 | Generation 49 | ---------- 50 | 51 | The complete sources for the following samples can be found here: 52 | 53 | https://github.com/matthiasblaesing/COMTypelibraries 54 | 55 | The first sample creates bindings for "OLE Automation (Ver 2.0)". 56 | 57 | ```xml 58 | 59 | 60 | 4.0.0 61 | 62 | 63 | eu.doppel-helix.jna.tlb 64 | parent 65 | 1.1 66 | 67 | 68 | stdole2 69 | 2.0.1 70 | jar 71 | 72 | 73 | 74 | 75 | eu.doppel-helix.jna.tlbcodegenerator 76 | TlbCodeGenerator 77 | 1.0.1 78 | 79 | {00020430-0000-0000-C000-000000000046} 80 | 81 | 82 | 83 | 84 | 85 | ``` 86 | 87 | The major and minor version of the type library are 2 and 0. In this sample 88 | the values are derived from the first two components of the project version. 89 | 90 | In this case the third part of the version string denotes the revision of the 91 | bindings. 92 | 93 | The only configuration in this case is the specification of the GUID of the 94 | library that is to be bound. 95 | 96 | Invoking the `generate` mojo will generate the sources in the project: 97 | 98 | ``` 99 | mvn eu.doppel-helix.jna.tlbcodegenerator:TlbCodeGenerator:generate 100 | ``` 101 | 102 | Existing source will be overwritten without warning. 103 | 104 | The plugin does not bind to any maven lifecycle phase, so it is only executed 105 | if explicitly called. 106 | 107 | Dependencies 108 | ------------ 109 | 110 | COM type libraries can depend on each other. For example the "OLE Automation 111 | (Ver 2.0)" library is a pre-requisite for the "Windows Image Acquisition Automation" 112 | library. To enable resolving dependencies, this plugin uses a combination of 113 | maven depdencies and additional meta-data. 114 | 115 | Each generated type library created by this plugin contains two files in the 116 | `META-INF/typelib` folder. Both files are java property files: 117 | 118 | - PACKAGE_NAME.info.properties: 119 | - GUID 120 | - Major version 121 | - Minor version 122 | - Native version 123 | - package name 124 | 125 | - PACKAGE_NAME.types.properties: This file mapps CLSIDs to java class names 126 | 127 | The bindings of WIA looks like this: 128 | 129 | ```xml 130 | 131 | 132 | 4.0.0 133 | 134 | 135 | eu.doppel-helix.jna.tlb 136 | parent 137 | 1.1 138 | 139 | 140 | wia1 141 | 1.0.1 142 | jar 143 | 144 | Windows Image Acquisition Automation 145 | 146 | 147 | 148 | eu.doppel-helix.jna.tlb 149 | stdole2 150 | 2.0.1 151 | 152 | 153 | 154 | 155 | 156 | 157 | eu.doppel-helix.jna.tlbcodegenerator 158 | TlbCodeGenerator 159 | 1.0.1 160 | 161 | c:/windows/system32/wiaaut.dll 162 | 163 | 164 | 165 | 166 | 167 | ``` 168 | 169 | This file shows two thinks: 170 | 171 | - demonstrate dependency 172 | - building bindings from a typelibrary file 173 | 174 | As in the simple case, the bindings are generated by invoking: 175 | 176 | ``` 177 | mvn eu.doppel-helix.jna.tlbcodegenerator:TlbCodeGenerator:generate 178 | ``` 179 | 180 | Release 181 | ======= 182 | 183 | - Update README.md with the new version number in the samples 184 | - For a local snapshot run `mvn install` 185 | - To deploy a snapshot to `https://oss.sonatype.org/content/repositories/snapshots/` 186 | run `mvn deploy` if you don't have a siging key configured and want to be 187 | closer to the final release run `mvn -P release-profile deploy` 188 | - To do a full release run `mvn release:prepare` followed by `mvn release:perform` -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.doppel-helix.jna.tlbcodegenerator 5 | TlbCodeGenerator 6 | 1.0.3-SNAPSHOT 7 | maven-plugin 8 | 9 | TlbCodeGenerator 10 | Code generator for JNA COM support 11 | https://github.com/matthiasblaesing/TlbCodeGenerator 12 | 13 | 14 | UTF-8 15 | 1.8 16 | 1.8 17 | 18 | 19 | 20 | 21 | LGPL, version 2.1 22 | http://www.gnu.org/licenses/licenses.html 23 | repo 24 | 25 | 26 | Apache License v2.0 27 | http://www.apache.org/licenses/LICENSE-2.0.txt 28 | repo 29 | 30 | 31 | 32 | 33 | 34 | mblaesing@doppel-helix.eu 35 | Matthias Bläsing 36 | https://github.com/matthiasblaesing/ 37 | 38 | Owner 39 | 40 | 41 | 42 | 43 | 44 | scm:git:https://github.com/matthiasblaesing/TlbCodeGenerator.git 45 | scm:git:ssh://git@github.com/matthiasblaesing/TlbCodeGenerator.git 46 | https://github.com/matthiasblaesing/TlbCodeGenerator 47 | HEAD 48 | 49 | 50 | 51 | 52 | org.apache.maven 53 | maven-plugin-api 54 | 3.3.9 55 | 56 | 57 | org.apache.maven.plugin-tools 58 | maven-plugin-annotations 59 | 3.4 60 | provided 61 | 62 | 63 | org.apache.maven 64 | maven-project 65 | 2.2.1 66 | 67 | 68 | org.freemarker 69 | freemarker 70 | 2.3.23 71 | 72 | 73 | net.java.dev.jna 74 | jna-platform 75 | 5.4.0 76 | 77 | 78 | 79 | 80 | 81 | 82 | src/main/resources 83 | 84 | 85 | target/generated-resources/license-files 86 | 87 | 88 | 89 | 90 | org.apache.maven.plugins 91 | maven-plugin-plugin 92 | 3.4 93 | 94 | 95 | default-descriptor 96 | process-classes 97 | 98 | 99 | 100 | help-goal 101 | 102 | helpmojo 103 | 104 | 105 | 106 | 107 | 108 | maven-source-plugin 109 | 3.1.0 110 | 111 | 112 | attach-sources 113 | 114 | jar-no-fork 115 | 116 | 117 | 118 | 119 | 120 | maven-javadoc-plugin 121 | 3.1.1 122 | 123 | 124 | attach-javadocs 125 | 126 | jar 127 | 128 | 129 | 130 | 131 | 132 | maven-deploy-plugin 133 | 3.0.0-M1 134 | 135 | true 136 | 137 | 138 | 139 | maven-resources-plugin 140 | 3.1.0 141 | 142 | 143 | license-files 144 | generate-resources 145 | 146 | copy-resources 147 | 148 | 149 | ${basedir}/target/generated-resources/license-files/META-INF 150 | 151 | 152 | ${basedir} 153 | 154 | README.md 155 | LICENSE 156 | AL2.0 157 | LGPL2.1 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | oss.sonatype.org 171 | https://oss.sonatype.org/content/repositories/snapshots 172 | 173 | 174 | oss.sonatype.org 175 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 176 | 177 | 178 | 179 | 180 | 181 | release-profile 182 | 183 | 184 | 185 | performRelease 186 | true 187 | 188 | 189 | 190 | 191 | 192 | 193 | org.apache.maven.plugins 194 | maven-enforcer-plugin 195 | 3.0.0-M2 196 | 197 | 198 | enforce-versions 199 | 200 | enforce 201 | 202 | 203 | 204 | 205 | [1.8,9) 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | org.apache.maven.plugins 214 | maven-gpg-plugin 215 | 1.5 216 | 217 | 218 | sign-artifacts 219 | verify 220 | 221 | sign 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/FormatHelper.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | public class FormatHelper { 28 | public static String replaceJavaKeyword(String name) { 29 | if (name.equalsIgnoreCase("final")) { 30 | return "_" + name; 31 | } else if (name.equalsIgnoreCase("default")) { 32 | return "_" + name; 33 | } else if (name.equalsIgnoreCase("case")) { 34 | return "_" + name; 35 | } else if (name.equalsIgnoreCase("char")) { 36 | return "_" + name; 37 | } else if (name.equalsIgnoreCase("private")) { 38 | return "_" + name; 39 | } else if (name.equalsIgnoreCase("class")) { 40 | return "_" + name; 41 | } else if (name.equalsIgnoreCase("toString")) { 42 | return "_" + name; 43 | } else { 44 | return name; 45 | } 46 | } 47 | 48 | public static String prepareProperty(String name, boolean property, boolean setter) { 49 | if (name == null) { 50 | return null; 51 | } 52 | name = replaceJavaKeyword(name); 53 | if(! property) { 54 | return name; 55 | } 56 | if (name.length() < 1) { 57 | return (setter ? "set" : "get") + name.toUpperCase(); 58 | } 59 | return (setter ? "set" : "get") + name.substring(0, 1).toUpperCase() + name.substring(1); 60 | } 61 | 62 | public static String preparePropertySetter(String name) { 63 | return prepareProperty(name, true, true); 64 | } 65 | 66 | public static String preparePropertyGetter(String name) { 67 | return prepareProperty(name, true, false); 68 | } 69 | 70 | public static String formatHex(Integer input) { 71 | return "0x" + Integer.toHexString(input); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbAlias.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.OaIdl; 29 | 30 | public class TlbAlias extends TlbEntry { 31 | private final OaIdl.TYPEDESC referenced; 32 | private final TypeInfoUtil tiu; 33 | 34 | public TlbAlias(TypeLib tl, int index) { 35 | super(tl, index); 36 | tiu = tl.getTypeLibUtil().getTypeInfoUtil(index); 37 | referenced = tiu.getTypeAttr().tdescAlias; 38 | } 39 | 40 | public String getReferencedType() { 41 | return getTypeLib().getType(tiu, referenced); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "TlbAlias{" + "referenced=" + referenced + ", tiu=" + tiu + '}'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbCoClass.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.ITypeInfo; 28 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 29 | import com.sun.jna.platform.win32.OaIdl; 30 | import java.util.ArrayList; 31 | import java.util.Collections; 32 | import java.util.List; 33 | 34 | public class TlbCoClass extends TlbEntry { 35 | private static final int IMPLTYPEFLAG_FDEFAULT = 0x00000001; 36 | private static final int IMPLTYPEFLAG_FSOURCE = 0x00000002; 37 | private static final int IMPLTYPEFLAG_FRESTRICTED = 0x00000001; 38 | private static final int IMPLTYPEFLAG_FDEFAULTVTABLE = 0x00000008; 39 | 40 | private final List interfaces; 41 | private final List sourceInterfaces; 42 | 43 | public TlbCoClass(TypeLib tl, int index) { 44 | super(tl, index); 45 | 46 | TypeInfoUtil typeInfoUtil = tl.getTypeLibUtil().getTypeInfoUtil(index); 47 | 48 | // Get the TypeAttributes 49 | OaIdl.TYPEATTR typeAttr = typeInfoUtil.getTypeAttr(); 50 | int cImplTypes = typeAttr.cImplTypes.intValue(); 51 | 52 | List interfaceBuilder = new ArrayList<>(); 53 | List sourceInterfacesBuilder = new ArrayList<>(); 54 | 55 | for (int i = 0; i < cImplTypes; i++) { 56 | int lImplTypeFlags = typeInfoUtil.getImplTypeFlags(i); 57 | OaIdl.HREFTYPE refTypeOfImplType = typeInfoUtil.getRefTypeOfImplType(i); 58 | ITypeInfo refTypeInfo = typeInfoUtil.getRefTypeInfo(refTypeOfImplType); 59 | TypeInfoUtil refTypeInfoUtil = new TypeInfoUtil(refTypeInfo); 60 | TypeInfoUtil.TypeInfoDoc documentation = refTypeInfoUtil.getDocumentation(new OaIdl.MEMBERID(-1)); 61 | // Only interfaces that are not marked as source 62 | if((lImplTypeFlags & IMPLTYPEFLAG_FSOURCE) == 0) { 63 | if((lImplTypeFlags & IMPLTYPEFLAG_FDEFAULT) == IMPLTYPEFLAG_FDEFAULT) { 64 | interfaceBuilder.add(0, documentation.getName()); 65 | } else { 66 | interfaceBuilder.add(documentation.getName()); 67 | } 68 | } else { 69 | if((lImplTypeFlags & IMPLTYPEFLAG_FDEFAULT) == IMPLTYPEFLAG_FDEFAULT) { 70 | sourceInterfacesBuilder.add(0, documentation.getName()); 71 | } else { 72 | sourceInterfacesBuilder.add(documentation.getName()); 73 | } 74 | } 75 | } 76 | 77 | interfaces = Collections.unmodifiableList(interfaceBuilder); 78 | sourceInterfaces = Collections.unmodifiableList(sourceInterfacesBuilder); 79 | } 80 | 81 | public List getInterfaces() { 82 | return interfaces; 83 | } 84 | 85 | public List getSourceInterfaces() { 86 | return sourceInterfaces; 87 | } 88 | 89 | @Override 90 | public String toString() { 91 | return "TlbCoClass{" + super.toString() + ", interfaces=" + interfaces + '}'; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbEntry.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.COM.TypeLibUtil; 29 | import com.sun.jna.platform.win32.Guid; 30 | import com.sun.jna.platform.win32.OaIdl; 31 | import java.util.Collections; 32 | import java.util.HashSet; 33 | import java.util.Set; 34 | 35 | public abstract class TlbEntry { 36 | private final TypeLib typeLib; 37 | private final String name; 38 | private final String guid; 39 | private final String docString; 40 | protected final int index; 41 | 42 | public TlbEntry(TypeLib typeLib, int index) { 43 | this.index = index; 44 | this.typeLib = typeLib; 45 | 46 | TypeLibUtil.TypeLibDoc typeLibDoc = typeLib.getTypeLibUtil().getDocumentation(index); 47 | name = typeLibDoc.getName(); 48 | docString = typeLibDoc.getDocString(); 49 | 50 | // Get the TypeAttributes 51 | TypeInfoUtil typeInfoUtil = typeLib.getTypeLibUtil().getTypeInfoUtil(index); 52 | OaIdl.TYPEATTR typeAttr = typeInfoUtil.getTypeAttr(); 53 | 54 | if(! typeAttr.guid.dataEquals(Guid.IID_NULL)) { 55 | guid = typeAttr.guid.toGuidString(); 56 | } else { 57 | guid = null; 58 | } 59 | } 60 | 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | public int getIndex() { 66 | return index; 67 | } 68 | 69 | public String getGuid() { 70 | return guid; 71 | } 72 | 73 | public String getDocString() { 74 | return docString; 75 | } 76 | 77 | public TypeLib getTypeLib() { 78 | return typeLib; 79 | } 80 | 81 | /** The iunknown methods. */ 82 | private final static String[] IUNKNOWN_METHODS = { "QueryInterface", "AddRef", 83 | "Release" }; 84 | 85 | /** The idispatch methods. */ 86 | private final static String[] IDISPATCH_METHODS = { "GetTypeInfoCount", 87 | "GetTypeInfo", "GetIDsOfNames", "Invoke" }; 88 | 89 | private final static String[] IEnumVARIANT_METHODS = {"_NewEnum"}; 90 | 91 | private final static Set reservedMethods; 92 | 93 | static { 94 | Set reservedMethodsBuilder = new HashSet<>(); 95 | 96 | for (String method : IUNKNOWN_METHODS) { 97 | reservedMethodsBuilder.add(method.toLowerCase()); 98 | } 99 | 100 | for (String method : IDISPATCH_METHODS) { 101 | reservedMethodsBuilder.add(method.toLowerCase()); 102 | } 103 | 104 | for (String method : IEnumVARIANT_METHODS) { 105 | reservedMethodsBuilder.add(method.toLowerCase()); 106 | } 107 | reservedMethods = Collections.unmodifiableSet(reservedMethodsBuilder); 108 | } 109 | 110 | /** 111 | * Checks if is reserved method. 112 | * 113 | * @param method the method 114 | * @return true, if is reserved method 115 | */ 116 | public static boolean isReservedMethod(String method) { 117 | if(method == null) { 118 | return false; 119 | } 120 | return reservedMethods.contains(method.toLowerCase()); 121 | } 122 | 123 | @Override 124 | public String toString() { 125 | return "TlbEntry{" + "name=" + name + ", guid=" + guid + ", docString=" + 126 | docString + ", index=" + index + '}'; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbEnum.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.OaIdl; 29 | import java.util.Collections; 30 | import java.util.LinkedList; 31 | import java.util.List; 32 | 33 | public class TlbEnum extends TlbEntry { 34 | 35 | private final List members; 36 | 37 | public TlbEnum(TypeLib typeLib, int index) { 38 | super(typeLib, index); 39 | 40 | List membersBuilder = new LinkedList<>(); 41 | 42 | TypeInfoUtil typeInfoUtil = typeLib.getTypeLibUtil().getTypeInfoUtil(index); 43 | OaIdl.TYPEATTR typeAttr = typeInfoUtil.getTypeAttr(); 44 | int cVars = typeAttr.cVars.intValue(); 45 | for (int i = 0; i < cVars; i++) { 46 | membersBuilder.add(new TlbEnumMember(typeInfoUtil, i)); 47 | } 48 | 49 | members = Collections.unmodifiableList(membersBuilder); 50 | } 51 | 52 | public List getMembers() { 53 | return members; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "TlbEnum{" + super.toString() + ", members=" + members + '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbEnumMember.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.OaIdl; 29 | import com.sun.jna.platform.win32.Variant; 30 | 31 | public class TlbEnumMember { 32 | 33 | private final String name; 34 | private final long value; 35 | private final String documentation; 36 | 37 | public TlbEnumMember(TypeInfoUtil typeInfoUtil, int i) { 38 | // Get the property description 39 | OaIdl.VARDESC varDesc = typeInfoUtil.getVarDesc(i); 40 | Variant.VARIANT constValue = varDesc._vardesc.lpvarValue; 41 | Object valueString = constValue.getValue(); 42 | 43 | // Get the member ID 44 | OaIdl.MEMBERID memberID = varDesc.memid; 45 | 46 | // Get the name of the property 47 | TypeInfoUtil.TypeInfoDoc typeInfoDoc2 = typeInfoUtil.getDocumentation(memberID); 48 | documentation = typeInfoDoc2.getDocString(); 49 | name = typeInfoDoc2.getName(); 50 | value = Long.parseLong(valueString.toString()); 51 | 52 | // release the pointer 53 | typeInfoUtil.ReleaseVarDesc(varDesc); 54 | } 55 | 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | public long getValue() { 61 | return value; 62 | } 63 | 64 | public String getDocumentation() { 65 | return documentation; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "TlbEnumMember{" + "name=" + name + ", value=" + value + 71 | ", documentation=" + documentation + '}'; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbFunctionCall.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.Native; 28 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 29 | import com.sun.jna.platform.win32.COM.TypeInfoUtil.TypeInfoDoc; 30 | import com.sun.jna.platform.win32.OaIdl; 31 | import com.sun.jna.platform.win32.OaIdl.INVOKEKIND; 32 | import java.util.LinkedList; 33 | import java.util.List; 34 | 35 | public class TlbFunctionCall { 36 | private final static int FUNCFLAG_FSOURCE = 0x2; 37 | 38 | private final String methodName; 39 | private final String documentation; 40 | private final String returnType; 41 | private final boolean source; 42 | private final boolean property; 43 | private final boolean setter; 44 | private final Short vtableId; 45 | private final OaIdl.MEMBERID memberId; 46 | private final int typeIndex; 47 | private final List params = new LinkedList<>(); 48 | 49 | public TlbFunctionCall(TypeLib tl, int index, OaIdl.FUNCDESC funcDesc, TypeInfoUtil typeInfoUtil) { 50 | TypeInfoDoc typeInfoDoc = typeInfoUtil.getDocumentation(funcDesc.memid); 51 | methodName = typeInfoDoc.getName(); 52 | documentation = typeInfoDoc.getDocString(); 53 | if (funcDesc.invkind.value == INVOKEKIND.INVOKE_FUNC.value) { 54 | property = false; 55 | setter = false; 56 | } else if (funcDesc.invkind.value == INVOKEKIND.INVOKE_PROPERTYGET.value) { 57 | property = true; 58 | setter = false; 59 | } else if (funcDesc.invkind.value == INVOKEKIND.INVOKE_PROPERTYPUT.value 60 | || funcDesc.invkind.value == INVOKEKIND.INVOKE_PROPERTYPUTREF.value) { 61 | property = true; 62 | setter = true; 63 | } else { 64 | throw new RuntimeException(String.format("Failed to parse function '%s': %d", 65 | methodName, 66 | funcDesc.invkind 67 | )); 68 | } 69 | 70 | source = (funcDesc.wFuncFlags.intValue() & FUNCFLAG_FSOURCE) > 0; 71 | typeIndex = index; 72 | returnType = tl.getType(typeInfoUtil, funcDesc); 73 | if(funcDesc.oVft.shortValue() != 0) { 74 | vtableId = (short) (funcDesc.oVft.shortValue() / Native.POINTER_SIZE); 75 | } else { 76 | vtableId = null; 77 | } 78 | memberId = funcDesc.memid; 79 | 80 | short paramCount = funcDesc.cParams.shortValue(); 81 | String[] names = typeInfoUtil.getNames(funcDesc.memid, paramCount + 1); 82 | for (int i = 0; i < paramCount; i++) { 83 | String paramName; 84 | if(i < (names.length - 1)) { 85 | paramName = names[i + 1]; 86 | } else { 87 | paramName = "param" + i; 88 | } 89 | params.add(new TlbFunctionCallParam(tl, typeInfoUtil, funcDesc, i, paramName)); 90 | } 91 | } 92 | 93 | public String getMethodName() { 94 | return methodName; 95 | } 96 | 97 | public String getDocumentation() { 98 | return documentation; 99 | } 100 | 101 | public String getReturnType() { 102 | return returnType; 103 | } 104 | 105 | public boolean isProperty() { 106 | return property; 107 | } 108 | 109 | public boolean isSetter() { 110 | return setter; 111 | } 112 | 113 | public Short getVtableId() { 114 | return vtableId; 115 | } 116 | 117 | public OaIdl.MEMBERID getMemberId() { 118 | return memberId; 119 | } 120 | 121 | public int getTypeIndex() { 122 | return typeIndex; 123 | } 124 | 125 | public List getParams() { 126 | return params; 127 | } 128 | 129 | public boolean isSource() { 130 | return source; 131 | } 132 | 133 | @Override 134 | public String toString() { 135 | return "TlbFunctionCall{" + "methodName=" + methodName + ", returnType=" + 136 | returnType + ", property=" + property + ", params=" + params + 137 | '}'; 138 | } 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbFunctionCallParam.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.OaIdl; 29 | 30 | public class TlbFunctionCallParam { 31 | 32 | private static final int PARAMFLAG_NONE = 0; 33 | private static final int PARAMFLAG_FIN = 0x1; 34 | private static final int PARAMFLAG_FOUT = 0x2; 35 | private static final int PARAMFLAG_FLCID = 0x4; 36 | private static final int PARAMFLAG_FRETVAL = 0x8; 37 | private static final int PARAMFLAG_FOPT = 0x10; 38 | private static final int PARAMFLAG_FHASDEFAULT = 0x20; 39 | private static final int PARAMFLAG_FHASCUSTDATA = 0x40; 40 | 41 | private final String type; 42 | private final String name; 43 | private final int paramFlags; 44 | private final TypeLib tl; 45 | 46 | public TlbFunctionCallParam(TypeLib tl, TypeInfoUtil typeInfoUtil, OaIdl.FUNCDESC funcDesc, int paramIndex, String name) { 47 | OaIdl.ELEMDESC elemdesc = funcDesc.lprgelemdescParam.elemDescArg[paramIndex]; 48 | this.paramFlags = elemdesc._elemdesc.paramdesc.wParamFlags.intValue(); 49 | this.type = tl.getType(typeInfoUtil, elemdesc); 50 | this.name = name; 51 | this.tl = tl; 52 | } 53 | 54 | public String getType() { 55 | return type; 56 | } 57 | 58 | public String getJavaType() { 59 | if(tl.isMapOptionalToObject() && isOptional()) { 60 | return "Object"; 61 | } else { 62 | return getType(); 63 | } 64 | } 65 | 66 | public String getName() { 67 | return name; 68 | } 69 | 70 | public boolean isOut() { 71 | return (paramFlags & PARAMFLAG_FOUT) > 0; 72 | } 73 | 74 | public boolean isIn() { 75 | return (paramFlags & PARAMFLAG_FIN) > 0; 76 | } 77 | 78 | public boolean isOptional() { 79 | return (paramFlags & PARAMFLAG_FOPT) > 0; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "TlbFunctionCallParam{" + "type=" + type + ", name=" + name + '}'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbInterface.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.OaIdl; 29 | import static com.sun.jna.platform.win32.OaIdl.TYPEATTR.TYPEFLAGS_FDISPATCHABLE; 30 | import static com.sun.jna.platform.win32.OaIdl.TYPEATTR.TYPEFLAGS_FDUAL; 31 | import static com.sun.jna.platform.win32.OaIdl.TYPEATTR.TYPEFLAGS_FOLEAUTOMATION; 32 | import java.util.Collections; 33 | import java.util.LinkedList; 34 | import java.util.List; 35 | 36 | public class TlbInterface extends TlbEntry { 37 | private boolean usedAsSource; 38 | private boolean usedAsImplementation; 39 | private final boolean dispatch; 40 | private final int typeflags; 41 | private final List functions; 42 | private final List variables; 43 | 44 | public TlbInterface(TypeLib tl, int index) { 45 | super(tl, index); 46 | 47 | // Get the TypeAttributes 48 | TypeInfoUtil typeInfoUtil = tl.getTypeLibUtil().getTypeInfoUtil(index); 49 | OaIdl.TYPEATTR typeAttr = typeInfoUtil.getTypeAttr(); 50 | 51 | this.dispatch = typeAttr.typekind.value == OaIdl.TYPEKIND.TKIND_DISPATCH; 52 | this.typeflags = typeAttr.wTypeFlags.intValue(); 53 | 54 | List functionsBuilder = new LinkedList<>(); 55 | List variablesBuilder = new LinkedList<>(); 56 | 57 | int cFuncs = typeAttr.cFuncs.intValue(); 58 | int cVars = typeAttr.cVars.intValue(); 59 | 60 | for (int i = 0; i < cFuncs; i++) { 61 | // Get the function description 62 | OaIdl.FUNCDESC funcDesc = typeInfoUtil.getFuncDesc(i); 63 | 64 | // Get the member ID 65 | OaIdl.MEMBERID memberID = funcDesc.memid; 66 | 67 | // Get the name of the method 68 | TypeInfoUtil.TypeInfoDoc typeInfoDoc2 = typeInfoUtil.getDocumentation(memberID); 69 | String methodName = typeInfoDoc2.getName(); 70 | 71 | if ((!isReservedMethod(methodName)) 72 | // PROPERTYPUTREF is currently not correctly handled, so skip declarations 73 | && funcDesc.invkind.value != OaIdl.INVOKEKIND.INVOKE_PROPERTYPUTREF.value 74 | ) 75 | { 76 | functionsBuilder.add(new TlbFunctionCall(tl, index, funcDesc, typeInfoUtil)); 77 | } 78 | 79 | // Release our function description stuff 80 | typeInfoUtil.ReleaseFuncDesc(funcDesc); 81 | } 82 | 83 | for (int i = 0; i < cVars; i++) { 84 | // Get the function description 85 | OaIdl.VARDESC varDesc = typeInfoUtil.getVarDesc(i); 86 | 87 | // Get the member ID 88 | OaIdl.MEMBERID memberID = varDesc.memid; 89 | 90 | // Get the name of the method 91 | TypeInfoUtil.TypeInfoDoc typeInfoDoc2 = typeInfoUtil.getDocumentation(memberID); 92 | String name = typeInfoDoc2.getName(); 93 | 94 | if (!isReservedMethod(name)) { 95 | variablesBuilder.add(new TlbVariable(tl, index, varDesc, typeInfoUtil)); 96 | } 97 | 98 | // Release our variable description stuff 99 | typeInfoUtil.ReleaseVarDesc(varDesc); 100 | } 101 | 102 | functions = Collections.unmodifiableList(functionsBuilder); 103 | variables = Collections.unmodifiableList(variablesBuilder); 104 | } 105 | 106 | public List getFunctions() { 107 | return functions; 108 | } 109 | 110 | public List getVariables() { 111 | return variables; 112 | } 113 | 114 | public List getDispatchableVariables() { 115 | List result = new LinkedList<>(); 116 | for(TlbVariable var: variables) { 117 | if(var.getVarkind().value == OaIdl.VARKIND.VAR_DISPATCH) { 118 | result.add(var); 119 | } 120 | } 121 | return result; 122 | } 123 | 124 | @Override 125 | public String toString() { 126 | return "TlbDispInterface{" + super.toString() + ", functions=" + functions + '}'; 127 | } 128 | 129 | public boolean isUsedAsSource() { 130 | return usedAsSource; 131 | } 132 | 133 | void setUsedAsSource(boolean usedAsSource) { 134 | this.usedAsSource = usedAsSource; 135 | } 136 | 137 | public boolean isUsedAsImplementation() { 138 | return usedAsImplementation; 139 | } 140 | 141 | void setUsedAsImplementation(boolean usedAsImplementation) { 142 | this.usedAsImplementation = usedAsImplementation; 143 | } 144 | 145 | public boolean isDispatch() { 146 | return dispatch; 147 | } 148 | 149 | public boolean isDual() { 150 | return (typeflags & TYPEFLAGS_FDUAL) == TYPEFLAGS_FDUAL; 151 | } 152 | 153 | public boolean isDispatchable() { 154 | return (typeflags & TYPEFLAGS_FDISPATCHABLE) == TYPEFLAGS_FDISPATCHABLE; 155 | } 156 | 157 | public boolean isOleautomation() { 158 | return (typeflags & TYPEFLAGS_FOLEAUTOMATION) == TYPEFLAGS_FOLEAUTOMATION; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TlbVariable.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 28 | import com.sun.jna.platform.win32.COM.TypeInfoUtil.TypeInfoDoc; 29 | import com.sun.jna.platform.win32.OaIdl; 30 | 31 | public class TlbVariable { 32 | private final static int VARFLAG_READONLY = 0x1; 33 | private final static int VARFLAG_FSOURCE = 0x2; 34 | 35 | private final String name; 36 | private final String documentation; 37 | private final String type; 38 | private final int wVarFlags; 39 | private final OaIdl.MEMBERID memberId; 40 | private final int typeIndex; 41 | private final OaIdl.VARKIND varkind; 42 | 43 | public TlbVariable(TypeLib tl, int index, OaIdl.VARDESC varDesc, TypeInfoUtil typeInfoUtil) { 44 | TypeInfoDoc typeInfoDoc = typeInfoUtil.getDocumentation(varDesc.memid); 45 | name = typeInfoDoc.getName(); 46 | documentation = typeInfoDoc.getDocString(); 47 | wVarFlags = varDesc.wVarFlags.intValue(); 48 | typeIndex = index; 49 | type = tl.getType(typeInfoUtil, varDesc); 50 | memberId = varDesc.memid; 51 | this.varkind = varDesc.varkind; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public String getDocumentation() { 59 | return documentation; 60 | } 61 | 62 | public OaIdl.MEMBERID getMemberId() { 63 | return memberId; 64 | } 65 | 66 | public String getType() { 67 | return type; 68 | } 69 | 70 | public int getTypeIndex() { 71 | return typeIndex; 72 | } 73 | 74 | public boolean isSource() { 75 | return (wVarFlags & VARFLAG_FSOURCE) > 0; 76 | } 77 | 78 | public boolean isReadonly() { 79 | return (wVarFlags & VARFLAG_READONLY) > 0; 80 | } 81 | 82 | public OaIdl.VARKIND getVarkind() { 83 | return varkind; 84 | } 85 | } -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/imp/TypeLib.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.imp; 26 | 27 | import com.sun.jna.Pointer; 28 | import com.sun.jna.platform.win32.COM.COMUtils; 29 | import com.sun.jna.platform.win32.COM.ITypeInfo; 30 | import com.sun.jna.platform.win32.COM.TypeInfoUtil; 31 | import com.sun.jna.platform.win32.COM.TypeLibUtil; 32 | import com.sun.jna.platform.win32.COM.util.IDispatch; 33 | import com.sun.jna.platform.win32.COM.util.IUnknown; 34 | import com.sun.jna.platform.win32.Guid; 35 | import com.sun.jna.platform.win32.OaIdl; 36 | import com.sun.jna.platform.win32.Variant; 37 | import static com.sun.jna.platform.win32.Variant.VT_ARRAY; 38 | import static com.sun.jna.platform.win32.Variant.VT_BLOB_OBJECT; 39 | import static com.sun.jna.platform.win32.Variant.VT_BOOL; 40 | import static com.sun.jna.platform.win32.Variant.VT_BSTR; 41 | import static com.sun.jna.platform.win32.Variant.VT_BYREF; 42 | import static com.sun.jna.platform.win32.Variant.VT_CARRAY; 43 | import static com.sun.jna.platform.win32.Variant.VT_CF; 44 | import static com.sun.jna.platform.win32.Variant.VT_CLSID; 45 | import static com.sun.jna.platform.win32.Variant.VT_CY; 46 | import static com.sun.jna.platform.win32.Variant.VT_DATE; 47 | import static com.sun.jna.platform.win32.Variant.VT_DECIMAL; 48 | import static com.sun.jna.platform.win32.Variant.VT_DISPATCH; 49 | import static com.sun.jna.platform.win32.Variant.VT_EMPTY; 50 | import static com.sun.jna.platform.win32.Variant.VT_ERROR; 51 | import static com.sun.jna.platform.win32.Variant.VT_FILETIME; 52 | import static com.sun.jna.platform.win32.Variant.VT_HRESULT; 53 | import static com.sun.jna.platform.win32.Variant.VT_I1; 54 | import static com.sun.jna.platform.win32.Variant.VT_I2; 55 | import static com.sun.jna.platform.win32.Variant.VT_I4; 56 | import static com.sun.jna.platform.win32.Variant.VT_I8; 57 | import static com.sun.jna.platform.win32.Variant.VT_ILLEGAL; 58 | import static com.sun.jna.platform.win32.Variant.VT_INT; 59 | import static com.sun.jna.platform.win32.Variant.VT_INT_PTR; 60 | import static com.sun.jna.platform.win32.Variant.VT_LPSTR; 61 | import static com.sun.jna.platform.win32.Variant.VT_LPWSTR; 62 | import static com.sun.jna.platform.win32.Variant.VT_NULL; 63 | import static com.sun.jna.platform.win32.Variant.VT_PTR; 64 | import static com.sun.jna.platform.win32.Variant.VT_R4; 65 | import static com.sun.jna.platform.win32.Variant.VT_R8; 66 | import static com.sun.jna.platform.win32.Variant.VT_RECORD; 67 | import static com.sun.jna.platform.win32.Variant.VT_RESERVED; 68 | import static com.sun.jna.platform.win32.Variant.VT_SAFEARRAY; 69 | import static com.sun.jna.platform.win32.Variant.VT_STORAGE; 70 | import static com.sun.jna.platform.win32.Variant.VT_STORED_OBJECT; 71 | import static com.sun.jna.platform.win32.Variant.VT_STREAM; 72 | import static com.sun.jna.platform.win32.Variant.VT_STREAMED_OBJECT; 73 | import static com.sun.jna.platform.win32.Variant.VT_UI1; 74 | import static com.sun.jna.platform.win32.Variant.VT_UI2; 75 | import static com.sun.jna.platform.win32.Variant.VT_UI4; 76 | import static com.sun.jna.platform.win32.Variant.VT_UI8; 77 | import static com.sun.jna.platform.win32.Variant.VT_UINT; 78 | import static com.sun.jna.platform.win32.Variant.VT_UINT_PTR; 79 | import static com.sun.jna.platform.win32.Variant.VT_UNKNOWN; 80 | import static com.sun.jna.platform.win32.Variant.VT_USERDEFINED; 81 | import static com.sun.jna.platform.win32.Variant.VT_VARIANT; 82 | import static com.sun.jna.platform.win32.Variant.VT_VECTOR; 83 | import static com.sun.jna.platform.win32.Variant.VT_VERSIONED_STREAM; 84 | import static com.sun.jna.platform.win32.Variant.VT_VOID; 85 | import com.sun.jna.platform.win32.WTypes; 86 | import com.sun.jna.platform.win32.WinBase; 87 | import com.sun.jna.platform.win32.WinDef; 88 | import com.sun.jna.platform.win32.WinNT; 89 | import com.sun.jna.platform.win32.WinNT.HRESULT; 90 | import com.sun.jna.ptr.PointerByReference; 91 | import java.io.File; 92 | import java.io.IOException; 93 | import java.io.InputStream; 94 | import java.util.Arrays; 95 | import java.util.Collections; 96 | import java.util.Enumeration; 97 | import java.util.HashMap; 98 | import java.util.HashSet; 99 | import java.util.List; 100 | import java.util.Map; 101 | import java.util.Map.Entry; 102 | import java.util.Properties; 103 | import java.util.Set; 104 | import java.util.jar.JarEntry; 105 | import java.util.jar.JarFile; 106 | import java.util.logging.Logger; 107 | 108 | public class TypeLib { 109 | 110 | private static final Logger LOG = Logger.getLogger(TypeLib.class.getName()); 111 | 112 | private static final Set basicTypes; 113 | 114 | static { 115 | Set basicTypesBuilder = new HashSet<>(); 116 | basicTypesBuilder.addAll(Arrays.asList( 117 | "byte", "short", "int", "long", "float", "double", "boolean", "char", 118 | "Byte", "Short", "Integer", "Long", "Float", "Double", "Boolean", "Character", 119 | "String" 120 | )); 121 | basicTypes = Collections.unmodifiableSet(basicTypesBuilder); 122 | } 123 | 124 | private final Map guidPackageMap = new HashMap<>(); 125 | private final Map guidTypeMap = new HashMap<>(); 126 | private final Map entries; 127 | private final Map primitives; 128 | private final String name; 129 | private final String docString; 130 | private final String uuid; 131 | private final int majorVersion; 132 | private final int minorVersion; 133 | private final TypeLibUtil typeLibUtil; 134 | private boolean mapOptionalToNull; 135 | 136 | public TypeLib(List classpath, String clsid, int majorVersion, int minorVersion) { 137 | this(classpath, new TypeLibUtil(clsid, majorVersion, minorVersion)); 138 | } 139 | 140 | public TypeLib(List classpath, String file) { 141 | this(classpath, new TypeLibUtil(file)); 142 | } 143 | 144 | private TypeLib(List classpath, TypeLibUtil typeLibUtil) { 145 | addClasspathForTypeResolution(classpath); 146 | this.typeLibUtil = typeLibUtil; 147 | name = typeLibUtil.getName(); 148 | majorVersion = typeLibUtil.getLibAttr().wMajorVerNum.intValue(); 149 | minorVersion = typeLibUtil.getLibAttr().wMinorVerNum.intValue(); 150 | uuid = typeLibUtil.getLibAttr().guid.toGuidString(); 151 | docString = typeLibUtil.getDocString(); 152 | 153 | Map entriesBuilder = new HashMap<>(); 154 | Map primitivesBuilder = new HashMap<>(); 155 | 156 | int typeInfoCount = typeLibUtil.getTypeInfoCount(); 157 | for (int i = 0; i < typeInfoCount; ++i) { 158 | OaIdl.TYPEKIND typekind = typeLibUtil.getTypeInfoType(i); 159 | String name = typeLibUtil.getDocumentation(i).getName(); 160 | switch (typekind.value) { 161 | case OaIdl.TYPEKIND.TKIND_ENUM: 162 | entriesBuilder.put(name, new TlbEnum(this, i)); 163 | break; 164 | case OaIdl.TYPEKIND.TKIND_RECORD: 165 | LOG.fine("'TKIND_RECORD' objects are currently not supported! => " + name); 166 | break; 167 | case OaIdl.TYPEKIND.TKIND_MODULE: 168 | LOG.fine("'TKIND_MODULE' objects are currently not supported! => " + name); 169 | break; 170 | case OaIdl.TYPEKIND.TKIND_INTERFACE: 171 | entriesBuilder.put(name, new TlbInterface(this, i)); 172 | break; 173 | case OaIdl.TYPEKIND.TKIND_DISPATCH: 174 | entriesBuilder.put(name, new TlbInterface(this, i)); 175 | break; 176 | case OaIdl.TYPEKIND.TKIND_COCLASS: 177 | entriesBuilder.put(name, new TlbCoClass(this, i)); 178 | break; 179 | case OaIdl.TYPEKIND.TKIND_ALIAS: 180 | entriesBuilder.put(name, new TlbAlias(this, i)); 181 | break; 182 | case OaIdl.TYPEKIND.TKIND_UNION: 183 | LOG.fine("'TKIND_UNION' objects are currently not supported! => " + name); 184 | break; 185 | default: 186 | break; 187 | } 188 | } 189 | 190 | for(TlbEntry ent: entriesBuilder.values()) { 191 | if(ent instanceof TlbCoClass) { 192 | TlbCoClass entCoClass = (TlbCoClass) ent; 193 | for(String iface: entCoClass.getInterfaces()) { 194 | TlbEntry targetEntry = entriesBuilder.get(iface); 195 | if(targetEntry instanceof TlbInterface) { 196 | ((TlbInterface) targetEntry).setUsedAsImplementation(true); 197 | } 198 | } 199 | for(String iface: entCoClass.getSourceInterfaces()) { 200 | TlbEntry targetEntry = entriesBuilder.get(iface); 201 | if(targetEntry instanceof TlbInterface) { 202 | ((TlbInterface) targetEntry).setUsedAsSource(true); 203 | } 204 | } 205 | } else if (ent instanceof TlbAlias) { 206 | TlbAlias alias = (TlbAlias) ent; 207 | if(basicTypes.contains(alias.getReferencedType())) { 208 | primitivesBuilder.put(alias.getName(), alias.getReferencedType()); 209 | } 210 | } 211 | } 212 | 213 | entries = Collections.unmodifiableMap(entriesBuilder); 214 | primitives = Collections.unmodifiableMap(primitivesBuilder); 215 | } 216 | 217 | public String getName() { 218 | return name; 219 | } 220 | 221 | public String getDocString() { 222 | return docString; 223 | } 224 | 225 | public int getMajorVersion() { 226 | return majorVersion; 227 | } 228 | 229 | public int getMinorVersion() { 230 | return minorVersion; 231 | } 232 | 233 | public String getUUID() { 234 | return uuid; 235 | } 236 | 237 | public Map getEntries() { 238 | return entries; 239 | } 240 | 241 | public TlbEntry getEntry(String name) { 242 | return entries.get(name); 243 | } 244 | 245 | public String mapPrimitiveIfExists(String name) { 246 | String result = primitives.get(name); 247 | if(result == null){ 248 | return name; 249 | } else { 250 | return result; 251 | } 252 | } 253 | 254 | public TypeLibUtil getTypeLibUtil() { 255 | return typeLibUtil; 256 | } 257 | 258 | private void addClasspathForTypeResolution(List files) { 259 | for (File f : files) { 260 | try { 261 | JarFile jf = new JarFile(f); 262 | Enumeration entries = jf.entries(); 263 | while (entries.hasMoreElements()) { 264 | JarEntry je = entries.nextElement(); 265 | if (je.getName().startsWith("META-INF/typelib") 266 | && je.getName().endsWith("info.properties")) { 267 | Properties props = new Properties(); 268 | try (InputStream is = jf.getInputStream(je)) { 269 | props.load(is); 270 | if (props.containsKey("guid")) { 271 | guidPackageMap.put( 272 | props.getProperty("guid").toLowerCase(), 273 | props.getProperty("name")); 274 | } 275 | } 276 | } 277 | if (je.getName().startsWith("META-INF/typelib") 278 | && je.getName().endsWith("types.properties")) { 279 | Properties props = new Properties(); 280 | try (InputStream is = jf.getInputStream(je)) { 281 | props.load(is); 282 | for (Object key : props.keySet()) { 283 | guidTypeMap.put( 284 | ((String) key).toLowerCase(), 285 | (String) props.get(key)); 286 | } 287 | } 288 | } 289 | } 290 | } catch (IOException ex) { 291 | LOG.warning("Failed to parse file " + f.getAbsolutePath()); 292 | } 293 | } 294 | 295 | for (Entry e : guidTypeMap.entrySet()) { 296 | LOG.fine(String.format("Type: %s => %s", e.getKey(), e.getValue())); 297 | } 298 | for (Entry e : guidPackageMap.entrySet()) { 299 | LOG.fine(String.format("Package: %s => %s", e.getKey(), e.getValue())); 300 | } 301 | } 302 | 303 | /** 304 | * Gets the var type. 305 | * 306 | * @param vt the vt 307 | * @return the var type 308 | */ 309 | String getVarType(WTypes.VARTYPE vt) { 310 | switch (vt.intValue()) { 311 | case VT_EMPTY: 312 | return ""; 313 | case VT_NULL: 314 | return "null"; 315 | case VT_I1: 316 | case VT_UI1: 317 | return "Byte"; 318 | case VT_I2: 319 | return "Short"; 320 | case VT_UI2: 321 | return "Character"; 322 | case VT_UINT: 323 | case VT_INT: 324 | case VT_UI4: 325 | case VT_I4: 326 | return "Integer"; 327 | case VT_I8: 328 | case VT_UI8: 329 | return "Long"; 330 | case VT_R4: 331 | return "Float"; 332 | case VT_R8: 333 | return "Double"; 334 | case VT_CY: 335 | return OaIdl.CURRENCY.class.getCanonicalName(); 336 | case VT_DATE: 337 | return "java.util.Date"; 338 | case VT_BSTR: 339 | return "String"; 340 | case VT_DISPATCH: 341 | return IDispatch.class.getCanonicalName(); 342 | case VT_ERROR: 343 | return WinDef.SCODE.class.getCanonicalName(); 344 | case VT_BOOL: 345 | return "Boolean"; 346 | case VT_VARIANT: 347 | return "Object"; 348 | case VT_UNKNOWN: 349 | return IUnknown.class.getCanonicalName(); 350 | case VT_DECIMAL: 351 | return OaIdl.DECIMAL.class.getCanonicalName(); 352 | case VT_VOID: 353 | return "void"; 354 | case VT_HRESULT: 355 | return WinNT.HRESULT.class.getCanonicalName(); 356 | case VT_PTR: 357 | return Pointer.class.getCanonicalName(); 358 | case VT_SAFEARRAY: 359 | return "safearray"; 360 | case VT_CARRAY: 361 | return "carray"; 362 | case VT_USERDEFINED: 363 | return "userdefined"; 364 | case VT_LPSTR: 365 | return WTypes.LPSTR.class.getCanonicalName(); 366 | case VT_LPWSTR: 367 | return WTypes.LPWSTR.class.getCanonicalName(); 368 | case VT_RECORD: 369 | return "record"; 370 | case VT_INT_PTR: 371 | return WinDef.INT_PTR.class.getCanonicalName(); 372 | case VT_UINT_PTR: 373 | return WinDef.UINT_PTR.class.getCanonicalName(); 374 | case VT_FILETIME: 375 | return WinBase.FILETIME.class.getCanonicalName(); 376 | case VT_STREAM: 377 | return "steam"; 378 | case VT_STORAGE: 379 | return "storage"; 380 | case VT_STREAMED_OBJECT: 381 | return "steamed_object"; 382 | case VT_STORED_OBJECT: 383 | return "stored_object"; 384 | case VT_BLOB_OBJECT: 385 | return "blob_object"; 386 | case VT_CF: 387 | return "cf"; 388 | case VT_CLSID: 389 | return Guid.CLSID.class.getCanonicalName(); 390 | case VT_VERSIONED_STREAM: 391 | return ""; 392 | // case VT_BSTR_BLOB: 393 | // return ""; 394 | case VT_VECTOR: 395 | return ""; 396 | case VT_ARRAY: 397 | return "SAFEARRAY"; 398 | case VT_BYREF: 399 | return WinDef.PVOID.class.getCanonicalName(); 400 | case VT_RESERVED: 401 | return ""; 402 | case VT_ILLEGAL: 403 | return "illegal"; 404 | /* 405 | * case VT_ILLEGALMASKED: return "illegal_masked"; case VT_TYPEMASK: 406 | * return "typemask"; 407 | */ 408 | default: 409 | return null; 410 | } 411 | } 412 | 413 | String getUserdefinedType(TypeInfoUtil tiu, OaIdl.HREFTYPE hreftype) { 414 | ITypeInfo refTypeInfo = tiu.getRefTypeInfo(hreftype); 415 | TypeInfoUtil reftiu = new TypeInfoUtil(refTypeInfo); 416 | TypeInfoUtil.TypeInfoDoc documentation = reftiu 417 | .getDocumentation(OaIdl.MEMBERID_NIL); 418 | OaIdl.TYPEATTR refTypeAttr = reftiu.getTypeAttr(); 419 | if (OaIdl.TYPEKIND.TKIND_ALIAS == refTypeAttr.typekind.value) { 420 | OaIdl.TYPEDESC referenced = reftiu.getTypeAttr().tdescAlias; 421 | return getType(reftiu, referenced); 422 | } else { 423 | String guid1 = tiu.getTypeAttr().guid.toGuidString().toLowerCase(); 424 | String guid2 = reftiu.getTypeAttr().guid.toGuidString().toLowerCase(); 425 | if(guidTypeMap.containsKey(guid1)) { 426 | return guidTypeMap.get(guid1); 427 | } 428 | if(guidTypeMap.containsKey(guid2)) { 429 | return guidTypeMap.get(guid2); 430 | } 431 | 432 | PointerByReference pbr = new PointerByReference(); 433 | HRESULT hr = reftiu.GetContainingTypeLib().getTypeLib().GetLibAttr(pbr); 434 | if (COMUtils.SUCCEEDED(hr)) { 435 | OaIdl.TLIBATTR tlib = new OaIdl.TLIBATTR(pbr.getValue()); 436 | String lcGUID = tlib.guid.toGuidString().toLowerCase(); 437 | try { 438 | if(tlib.guid.toGuidString().equalsIgnoreCase(getUUID()) 439 | && tlib.wMajorVerNum.intValue() == getMajorVersion() 440 | && tlib.wMinorVerNum.intValue() == getMinorVersion()) { 441 | return documentation.getName(); 442 | } else { 443 | if(guidPackageMap.containsKey(lcGUID)) { 444 | return guidPackageMap.get(lcGUID) + "." + documentation.getName(); 445 | } else { 446 | return String.format("{%s-%d-%d}.%s", 447 | tlib.guid.toGuidString(), 448 | tlib.wMajorVerNum.intValue(), 449 | tlib.wMinorVerNum.intValue(), 450 | documentation.getName()); 451 | } 452 | } 453 | } finally { 454 | tiu.GetContainingTypeLib().getTypeLib().ReleaseTLibAttr(tlib); 455 | } 456 | } else { 457 | return documentation.getName(); 458 | } 459 | } 460 | } 461 | 462 | String getType(TypeInfoUtil tiu, OaIdl.VARDESC vardesc) { 463 | OaIdl.ELEMDESC elemDesc = vardesc.elemdescVar; 464 | return getType(tiu, elemDesc); 465 | } 466 | 467 | String getType(TypeInfoUtil tiu, OaIdl.FUNCDESC funcDesc) { 468 | OaIdl.ELEMDESC elemDesc = funcDesc.elemdescFunc; 469 | return getType(tiu, elemDesc); 470 | } 471 | 472 | String getType(TypeInfoUtil tiu, OaIdl.ELEMDESC elemDesc) { 473 | OaIdl.TYPEDESC _typeDesc = elemDesc.tdesc; 474 | return getType(tiu, _typeDesc); 475 | } 476 | 477 | String getType(TypeInfoUtil tiu, OaIdl.TYPEDESC typeDesc) { 478 | WTypes.VARTYPE vt = typeDesc.vt; 479 | String type = "not_defined"; 480 | 481 | if (vt.intValue() == Variant.VT_PTR) { 482 | OaIdl.TYPEDESC lptdesc = typeDesc._typedesc.getLptdesc(); 483 | type = getType(tiu, lptdesc); 484 | if("void".equals(type)) { 485 | type="Object"; 486 | } 487 | } else if (vt.intValue() == Variant.VT_SAFEARRAY 488 | || vt.intValue() == Variant.VT_CARRAY) { 489 | OaIdl.TYPEDESC tdescElem = typeDesc._typedesc.getLpadesc().tdescElem; 490 | type = getType(tiu, tdescElem); 491 | } else if (vt.intValue() == Variant.VT_USERDEFINED) { 492 | OaIdl.HREFTYPE hreftype = typeDesc._typedesc.hreftype; 493 | type = getUserdefinedType(tiu, hreftype); 494 | } else { 495 | type = getVarType(vt); 496 | } 497 | 498 | return type; 499 | } 500 | 501 | public boolean isMapOptionalToObject() { 502 | return mapOptionalToNull; 503 | } 504 | 505 | public void setMapOptionalToObject(boolean mapOptionalToObject) { 506 | this.mapOptionalToNull = mapOptionalToObject; 507 | } 508 | 509 | } 510 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/maven/Generator.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.maven; 26 | 27 | import eu.doppel_helix.jna.tlbcodegenerator.imp.FormatHelper; 28 | import eu.doppel_helix.jna.tlbcodegenerator.imp.TlbAlias; 29 | import eu.doppel_helix.jna.tlbcodegenerator.imp.TlbCoClass; 30 | import eu.doppel_helix.jna.tlbcodegenerator.imp.TlbEntry; 31 | import eu.doppel_helix.jna.tlbcodegenerator.imp.TlbEnum; 32 | import eu.doppel_helix.jna.tlbcodegenerator.imp.TlbInterface; 33 | import eu.doppel_helix.jna.tlbcodegenerator.imp.TypeLib; 34 | import eu.doppel_helix.jna.tlbcodegenerator.maven.util.JULBridge; 35 | import freemarker.core.ParseException; 36 | import freemarker.template.Configuration; 37 | import freemarker.template.DefaultObjectWrapper; 38 | import freemarker.template.MalformedTemplateNameException; 39 | import freemarker.template.Template; 40 | import freemarker.template.TemplateException; 41 | import freemarker.template.Version; 42 | import java.io.File; 43 | import java.io.FileOutputStream; 44 | import java.io.IOException; 45 | import java.io.OutputStream; 46 | import java.io.OutputStreamWriter; 47 | import java.nio.charset.Charset; 48 | import java.util.ArrayList; 49 | import java.util.HashMap; 50 | import java.util.Locale; 51 | import java.util.Map; 52 | import java.util.Properties; 53 | import java.util.Set; 54 | import org.apache.maven.artifact.Artifact; 55 | import org.apache.maven.artifact.versioning.ArtifactVersion; 56 | import org.apache.maven.artifact.versioning.DefaultArtifactVersion; 57 | import org.apache.maven.plugin.AbstractMojo; 58 | import org.apache.maven.plugin.MojoExecutionException; 59 | import org.apache.maven.plugin.MojoFailureException; 60 | import org.apache.maven.plugins.annotations.Mojo; 61 | import org.apache.maven.plugins.annotations.Parameter; 62 | import org.apache.maven.plugins.annotations.ResolutionScope; 63 | import org.apache.maven.project.MavenProject; 64 | 65 | /** 66 | * Generate JNA COM bindings for supplied typelibraries 67 | * 68 | *

69 | * Microsoft Shell Controls And Automation

70 | * 71 | * 72 | * 73 | *
Via file:
fileshell32.dll
74 | * 75 | * 76 | * 77 | * 78 | * 79 | * 80 | *
Via GUID, Major, Minor:
guid{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}
major1
minor0
81 | * 82 | * 83 | * 84 | * 85 | * 86 | * 87 | *
Sample: Microsoft Word 12.0 Object Library
guid{00020905-0000-0000-C000-000000000046}
major8
minor4
88 | * 89 | * @author Matthias Bläsing 90 | */ 91 | @Mojo(name = "generate", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) 92 | public class Generator extends AbstractMojo { 93 | 94 | @Parameter(defaultValue = "${project}", readonly = true) 95 | private MavenProject project; 96 | 97 | /** 98 | * Tlb file to use for code generation. If specified superseeds guid. 99 | */ 100 | @Parameter(property = "tlbcodegenerator.file") 101 | private String file; 102 | 103 | /** 104 | * GUID of typelibrary to analyse. 105 | */ 106 | @Parameter(property = "tlbcodegenerator.guid") 107 | private String guid; 108 | 109 | /** 110 | * Major version of typelibrary to analyse. If not specified, project major 111 | * version is used. 112 | */ 113 | @Parameter(property = "tlbcodegenerator.major") 114 | private Integer major; 115 | 116 | /** 117 | * Minor version of typelibrary to analyse. If not specified, project minor 118 | * version is used. 119 | */ 120 | @Parameter(property = "tlbcodegenerator.minor") 121 | private Integer minor; 122 | 123 | /** 124 | * Package for the generated sources. Defaults to artifactId. 125 | */ 126 | @Parameter(property = "tlbcodegenerator.packageName") 127 | private String packageName; 128 | 129 | /** 130 | * Prefix for the package. Defaults to groupId 131 | */ 132 | @Parameter(property = "tlbcodegenerator.basepackage") 133 | private String basepackage; 134 | 135 | /** 136 | * If set to true the parsing result will be displayed and not written. 137 | */ 138 | @Parameter(property = "tlbcodegenerator.displayonly", defaultValue = "false") 139 | private boolean displayonly; 140 | 141 | /** 142 | * If set to true option values are mapped to object, if false optional values are mapped to their "correct" type 143 | */ 144 | @Parameter(property = "tlbcodegenerator.mapOptionalToObject", defaultValue = "false") 145 | private boolean mapOptionalToObject; 146 | 147 | @Parameter(property = "tlbcodegenerator.skip") 148 | private boolean skip; 149 | 150 | @Override 151 | public void execute() throws MojoExecutionException, MojoFailureException { 152 | if(skip) { 153 | getLog().info("Skipping code generator"); 154 | return; 155 | } 156 | JULBridge bridge = new JULBridge(getLog()); 157 | try { 158 | initDefaults(); 159 | 160 | ArrayList dependencies = new ArrayList<>(); 161 | for(Artifact a: (Set) project.getArtifacts()) { 162 | dependencies.add(a.getFile()); 163 | } 164 | 165 | TypeLib typeLibrary; 166 | if (file != null) { 167 | typeLibrary = new TypeLib(dependencies, file); 168 | } else if (guid != null && major != null && minor != null) { 169 | typeLibrary = new TypeLib(dependencies, guid, major, minor); 170 | } else { 171 | throw new MojoFailureException("Either file or guid need to be specified"); 172 | } 173 | 174 | typeLibrary.setMapOptionalToObject(mapOptionalToObject); 175 | 176 | Configuration cfg = getFreemarkerConfig(); 177 | 178 | String packageName = getPackageName(typeLibrary); 179 | 180 | File srcOutputDir = null; 181 | File rsrcOutputDir = null; 182 | 183 | if (! displayonly) { 184 | srcOutputDir = createSourceDir(packageName); 185 | rsrcOutputDir = createResourceDir(packageName); 186 | writePackageInfo(typeLibrary, srcOutputDir, cfg, packageName); 187 | } 188 | 189 | int typesCount = 0; 190 | int writtenCount = 0; 191 | 192 | Properties packageData = new Properties(); 193 | Properties typeData = new Properties(); 194 | 195 | for (TlbEntry ent : typeLibrary.getEntries().values()) { 196 | typesCount++; 197 | String qualifiedName = packageName + "." + FormatHelper.replaceJavaKeyword(ent.getName()); 198 | if(ent.getGuid() != null) { 199 | typeData.put(ent.getGuid(), qualifiedName); 200 | } 201 | int written = writeEntry(typeLibrary, srcOutputDir, cfg, ent, packageName, null, displayonly); 202 | writtenCount += written; 203 | } 204 | 205 | packageData.put("guid", typeLibrary.getUUID()); 206 | packageData.put("name", packageName); 207 | packageData.put("nativename", typeLibrary.getName()); 208 | packageData.put("major", Integer.toString(typeLibrary.getMajorVersion())); 209 | packageData.put("minor", Integer.toString(typeLibrary.getMinorVersion())); 210 | 211 | try (OutputStream info = new FileOutputStream(new File(rsrcOutputDir, packageName + ".info.properties")); 212 | OutputStream types = new FileOutputStream(new File(rsrcOutputDir, packageName + ".types.properties")); 213 | ) { 214 | packageData.store(info, ""); 215 | typeData.store(types, ""); 216 | } 217 | 218 | 219 | if(srcOutputDir != null) { 220 | getLog().info(String.format("%d/%d types parsed and results written to: %s", typesCount, writtenCount, srcOutputDir.toString())); 221 | } else { 222 | getLog().info(String.format("%d/%d types parsed", typesCount, writtenCount)); 223 | } 224 | 225 | } catch (Exception e) { 226 | throw new MojoExecutionException("Faild to parse typelibrary", e); 227 | } finally { 228 | bridge.restore(); 229 | } 230 | } 231 | 232 | private String getPackageName(TypeLib tl) { 233 | String packageNameConst = packageName; 234 | if (packageNameConst == null) { 235 | packageNameConst = tl.getName().toLowerCase(); 236 | } 237 | if (basepackage != null && (!basepackage.isEmpty())) { 238 | packageNameConst = basepackage + "." 239 | + packageNameConst; 240 | } 241 | return packageNameConst; 242 | } 243 | 244 | private void initDefaults() { 245 | ArtifactVersion av = new DefaultArtifactVersion(project.getVersion()); 246 | if(major == null) { 247 | major = av.getMajorVersion(); 248 | } 249 | if(minor == null) { 250 | minor = av.getMinorVersion(); 251 | } 252 | if(packageName == null) { 253 | packageName = project.getArtifactId(); 254 | } 255 | if(basepackage == null) { 256 | basepackage = project.getGroupId(); 257 | } 258 | } 259 | 260 | private Configuration getFreemarkerConfig() { 261 | Configuration cfg = new Configuration(new Version("2.3.23")); 262 | cfg.setDefaultEncoding("UTF-8"); 263 | cfg.setLocale(Locale.ENGLISH); 264 | cfg.setDateFormat("yyyy-MM-dd"); 265 | cfg.setTimeFormat("HH:mm:ss"); 266 | cfg.setDateTimeFormat("yyyy-MM-dd HH:mm.ss"); 267 | cfg.setObjectWrapper(new DefaultObjectWrapper(new Version("2.3.23"))); 268 | if (displayonly) { 269 | cfg.setClassForTemplateLoading(Generator.class, "/eu/doppel_helix/jna/tlbcodegenerator/output"); 270 | } else { 271 | cfg.setClassForTemplateLoading(Generator.class, "/eu/doppel_helix/jna/tlbcodegenerator"); 272 | } 273 | return cfg; 274 | } 275 | 276 | private File createSourceDir(String packageName) { 277 | File _outputDir = new File(project.getBasedir(), "src/main/java"); 278 | 279 | String path = packageName.replace(".", "/"); 280 | 281 | _outputDir = new File(_outputDir, path); 282 | _outputDir.mkdirs(); 283 | 284 | return _outputDir; 285 | } 286 | 287 | private File createResourceDir(String packageName) { 288 | File _outputDir = new File(project.getBasedir(), "src/main/resources/META-INF/typelib"); 289 | _outputDir.mkdirs(); 290 | return _outputDir; 291 | } 292 | 293 | private void fillTemplate(Configuration cfg, String template, File target, Map data, boolean output) throws TemplateException, IOException { 294 | Template t = cfg.getTemplate(template); 295 | if (output) { 296 | t.process(data, new OutputStreamWriter(System.out)); 297 | } else { 298 | try (FileOutputStream fos = new FileOutputStream(target); 299 | OutputStreamWriter osw = new OutputStreamWriter(fos, Charset.forName("UTF-8"))) { 300 | t.process(data, osw); 301 | } 302 | } 303 | } 304 | 305 | private void writePackageInfo(TypeLib typeLibrary, File outputDirectory, Configuration cfg, String packageName) throws MalformedTemplateNameException, ParseException, IOException, TemplateException { 306 | File target = new File(outputDirectory, "package-info.java"); 307 | Map data = new HashMap<>(); 308 | data.put("fh", new FormatHelper()); 309 | data.put("package", packageName); 310 | data.put("name", typeLibrary.getName()); 311 | data.put("docString", typeLibrary.getDocString()); 312 | data.put("guid", typeLibrary.getUUID()); 313 | data.put("majorversion", typeLibrary.getMajorVersion()); 314 | data.put("minorversion", typeLibrary.getMinorVersion()); 315 | fillTemplate(cfg, "Package.ftl", target, data, false); 316 | } 317 | 318 | private int writeEntry(TypeLib typeLibrary, File outputDirectory, Configuration cfg, TlbEntry entry, String packageName, String overrideName, boolean output) throws MalformedTemplateNameException, ParseException, IOException, TemplateException { 319 | if(entry == null) { 320 | return 0; 321 | } 322 | Map data = new HashMap<>(); 323 | data.put("fh", new FormatHelper()); 324 | data.put("entry", entry); 325 | data.put("package", packageName); 326 | data.put("typeLib", typeLibrary); 327 | String javaName = FormatHelper.replaceJavaKeyword(entry.getName()); 328 | if(overrideName != null) { 329 | javaName = FormatHelper.replaceJavaKeyword(overrideName); 330 | } 331 | data.put("javaName", javaName); 332 | 333 | File target = new File(outputDirectory, javaName + ".java"); 334 | 335 | if (entry instanceof TlbAlias) { 336 | TlbEntry referenced = typeLibrary.getEntry(((TlbAlias) entry).getReferencedType()); 337 | return writeEntry(typeLibrary, outputDirectory, cfg, referenced, packageName, entry.getName(), output); 338 | } else if (entry instanceof TlbEnum) { 339 | fillTemplate(cfg, "Enum.ftl", target, data, output); 340 | return 1; 341 | } else if (entry instanceof TlbInterface) { 342 | TlbInterface tdi = (TlbInterface) entry; 343 | int res = 0; 344 | if (tdi.isDispatch() || tdi.isDispatchable() || tdi.isDual() || tdi.isOleautomation()) { 345 | fillTemplate(cfg, "Interface.ftl", target, data, output); 346 | res++; 347 | if (tdi.isUsedAsSource()) { 348 | data.put("javaName", javaName + "Listener"); 349 | target = new File(outputDirectory, javaName + "Listener.java"); 350 | fillTemplate(cfg, "InterfaceListener.ftl", target, data, output); 351 | res++; 352 | data.put("javaName", javaName + "Listener"); 353 | target = new File(outputDirectory, javaName + "ListenerHandler.java"); 354 | fillTemplate(cfg, "InterfaceListenerHandler.ftl", target, data, output); 355 | res++; 356 | } 357 | } 358 | return res; 359 | } else if (entry instanceof TlbCoClass) { 360 | TlbCoClass tcc = (TlbCoClass) entry; 361 | java.util.List implInterfaces = new ArrayList<>(tcc.getInterfaces()); 362 | implInterfaces.retainAll(typeLibrary.getEntries().keySet()); 363 | 364 | java.util.List interfaces = new ArrayList<>(); 365 | if(! implInterfaces.isEmpty()) { 366 | interfaces.add(implInterfaces.get(0)); 367 | } 368 | if(! tcc.getSourceInterfaces().isEmpty()) { 369 | interfaces.add("IConnectionPoint"); 370 | } 371 | data.put("interfaces", interfaces); 372 | fillTemplate(cfg, "CoClass.ftl", target, data, output); 373 | return 1; 374 | } 375 | 376 | return 0; 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/maven/List.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.maven; 26 | 27 | import com.sun.jna.platform.win32.Advapi32Util; 28 | import com.sun.jna.platform.win32.COM.COMException; 29 | import com.sun.jna.platform.win32.COM.TypeLibUtil; 30 | import com.sun.jna.platform.win32.Win32Exception; 31 | import com.sun.jna.platform.win32.WinReg; 32 | import java.util.LinkedList; 33 | import java.util.regex.Matcher; 34 | import java.util.regex.Pattern; 35 | import org.apache.maven.plugin.AbstractMojo; 36 | import org.apache.maven.plugin.MojoExecutionException; 37 | import org.apache.maven.plugin.MojoFailureException; 38 | import org.apache.maven.plugins.annotations.Mojo; 39 | import org.apache.maven.plugins.annotations.Parameter; 40 | 41 | @Mojo(name = "list") 42 | public class List extends AbstractMojo { 43 | 44 | /** 45 | * Report typelib GUIDs, that could not be resolved 46 | */ 47 | @Parameter(property = "tlbcodegenerator.reportedFailed") 48 | private Boolean reportedFailed; 49 | 50 | @Override 51 | public void execute() throws MojoExecutionException, MojoFailureException { 52 | java.util.List failedGUIDs = new LinkedList<>(); 53 | Pattern versionPattern = Pattern.compile("^(\\d).(\\d)$"); 54 | for (String guid : listTypeLibGUIDS()) { 55 | if (guid.trim().isEmpty()) { 56 | continue; 57 | } 58 | try { 59 | for (String version : listTypeLibVersions(guid)) { 60 | Matcher m = versionPattern.matcher(version); 61 | if (m.matches()) { 62 | int major = Integer.parseInt(m.group(1)); 63 | int minor = Integer.parseInt(m.group(2)); 64 | TypeLibUtil tlu = new TypeLibUtil(guid, major, minor); 65 | System.out.println(String.format("%s\t%d\t%d\t%s\t%s", 66 | guid, major, minor, tlu.getName().toLowerCase(), 67 | typelibGetName(guid, major, minor))); 68 | } 69 | } 70 | } catch (Win32Exception | COMException ex) { 71 | failedGUIDs.add(guid); 72 | } 73 | } 74 | 75 | if (reportedFailed != null && reportedFailed) { 76 | System.out.println("\nFailed GUIDs:"); 77 | for (String guid : failedGUIDs) { 78 | System.out.println(guid); 79 | } 80 | } 81 | } 82 | 83 | private String[] listTypeLibGUIDS() { 84 | return Advapi32Util.registryGetKeys(WinReg.HKEY_CLASSES_ROOT, "TypeLib"); 85 | } 86 | 87 | private String[] listTypeLibVersions(String guid) { 88 | return Advapi32Util.registryGetKeys(WinReg.HKEY_CLASSES_ROOT, "TypeLib\\" 89 | + guid); 90 | } 91 | 92 | private String typelibGetName(String guid, int major, int minor) { 93 | return Advapi32Util.registryGetStringValue(WinReg.HKEY_CLASSES_ROOT, 94 | String.format("TypeLib\\%s\\%d.%d", guid, major, minor), ""); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/eu/doppel_helix/jna/tlbcodegenerator/maven/util/JULBridge.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 2 | * 3 | * The contents of this file is dual-licensed under 2 4 | * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 | * Apache License 2.0. (starting with JNA version 4.0.0). 6 | * 7 | * You can freely decide which license you want to apply to 8 | * the project. 9 | * 10 | * You may obtain a copy of the LGPL License at: 11 | * 12 | * http://www.gnu.org/licenses/licenses.html 13 | * 14 | * A copy is also included in the downloadable source code package 15 | * containing JNA, in file "LGPL2.1". 16 | * 17 | * You may obtain a copy of the Apache License at: 18 | * 19 | * http://www.apache.org/licenses/ 20 | * 21 | * A copy is also included in the downloadable source code package 22 | * containing JNA, in file "AL2.0". 23 | */ 24 | 25 | package eu.doppel_helix.jna.tlbcodegenerator.maven.util; 26 | 27 | import java.util.LinkedList; 28 | import java.util.List; 29 | import java.util.logging.Formatter; 30 | import java.util.logging.Handler; 31 | import java.util.logging.Level; 32 | import java.util.logging.LogRecord; 33 | import java.util.logging.Logger; 34 | import java.util.logging.SimpleFormatter; 35 | import org.apache.maven.plugin.logging.Log; 36 | 37 | public class JULBridge extends Handler { 38 | 39 | private final Log mavenLogger; 40 | 41 | private final Formatter formatter = new SimpleFormatter(); 42 | 43 | private final Level originalLevel; 44 | private final List originalHandlers = new LinkedList<>(); 45 | 46 | 47 | public JULBridge(Log mavenLogger) { 48 | this.mavenLogger = mavenLogger; 49 | 50 | Logger rootLogger = Logger.getLogger(""); 51 | originalLevel = rootLogger.getLevel(); 52 | for(Handler h: rootLogger.getHandlers()) { 53 | originalHandlers.add(h); 54 | rootLogger.removeHandler(h); 55 | } 56 | 57 | if(mavenLogger.isDebugEnabled()) { 58 | rootLogger.setLevel(Level.FINE); 59 | } 60 | rootLogger.addHandler(this); 61 | } 62 | 63 | public void restore() { 64 | Logger rootLogger = Logger.getLogger(""); 65 | rootLogger.removeHandler(this); 66 | 67 | for(Handler h: originalHandlers) { 68 | rootLogger.addHandler(h); 69 | } 70 | 71 | rootLogger.setLevel(originalLevel); 72 | } 73 | 74 | @Override 75 | public void publish(LogRecord record) { 76 | String message = formatter.formatMessage(record); 77 | int level = record.getLevel().intValue(); 78 | if (level >= Level.SEVERE.intValue()) { 79 | if (record.getThrown() != null) { 80 | mavenLogger.error(message, record.getThrown()); 81 | } else { 82 | mavenLogger.error(message); 83 | } 84 | } else if (level >= Level.WARNING.intValue()) { 85 | if (record.getThrown() != null) { 86 | mavenLogger.warn(message, record.getThrown()); 87 | } else { 88 | mavenLogger.warn(message); 89 | } 90 | } else if (level >= Level.INFO.intValue()) { 91 | if (record.getThrown() != null) { 92 | mavenLogger.info(message, record.getThrown()); 93 | } else { 94 | mavenLogger.info(message); 95 | } 96 | } else if (record.getThrown() != null) { 97 | mavenLogger.debug(message, record.getThrown()); 98 | } else { 99 | mavenLogger.debug(message); 100 | } 101 | } 102 | 103 | @Override 104 | public void flush() { 105 | } 106 | 107 | @Override 108 | public void close() throws SecurityException { 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/CoClass.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | 27 | package ${package}; 28 | 29 | import com.sun.jna.platform.win32.COM.COMException; 30 | import com.sun.jna.platform.win32.COM.util.IComEventCallbackCookie; 31 | import com.sun.jna.platform.win32.COM.util.IComEventCallbackListener; 32 | import com.sun.jna.platform.win32.COM.util.IConnectionPoint; 33 | import com.sun.jna.platform.win32.COM.util.IUnknown; 34 | import com.sun.jna.platform.win32.COM.util.annotation.ComObject; 35 | import com.sun.jna.platform.win32.COM.util.IRawDispatchHandle; 36 | 37 | /** 38 | [#if (entry.docString)?has_content] * ${entry.docString!} 39 | * 40 | [/#if] *

uuid(${entry.guid})

41 | [#list entry.sourceInterfaces as iface] 42 | *

source(${fh.replaceJavaKeyword(iface)})

43 | [/#list] 44 | [#list interfaces as iface] 45 | *

interface(${fh.replaceJavaKeyword(iface)})

46 | [/#list] 47 | */ 48 | @ComObject(clsId = "${entry.guid}") 49 | public interface ${javaName} extends IUnknown[#list interfaces as iface] 50 | ,${fh.replaceJavaKeyword(iface)}[/#list] 51 | { 52 | 53 | } -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/Enum.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | 27 | package ${package}; 28 | 29 | import com.sun.jna.platform.win32.COM.util.IComEnum; 30 | 31 | [#if (entry.docString)?has_content || (entry.guid)?has_content] 32 | /** 33 | [#if (entry.docString)?has_content] * ${entry.docString!} 34 | * 35 | [/#if][#if (entry.guid)?has_content] *

uuid(${entry.guid})

36 | [/#if] */ 37 | [/#if] 38 | public enum ${javaName} implements IComEnum { 39 | [#list entry.members as member] 40 | 41 | /** 42 | * [#if (member.documentation)?has_content]${member.documentation!} [/#if](${member.value?c}) 43 | */ 44 | ${fh.replaceJavaKeyword(member.name)}(${member.value?c}), 45 | [/#list] 46 | ; 47 | 48 | private ${javaName}(long value) { 49 | this.value = value; 50 | } 51 | private long value; 52 | 53 | public long getValue() { 54 | return this.value; 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/Interface.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | 27 | [#macro paramList params][#list params as param] 28 | [#if param?index > 0] [/#if][#if (param.out)]VARIANT[#else]${typeLib.mapPrimitiveIfExists(param.javaType)}[/#if] ${param.name}[#sep], 29 | [/#sep][/#list][/#macro] 30 | [#macro paramListDoc params][#list params as param] 31 | * @param ${param.name} ${"["}[#if (param.in)]in[/#if][#if (param.out)]out[/#if][#if (param.optional)], optional[/#if]${"]"} {@code ${param.type}} 32 | [/#list][/#macro] 33 | 34 | package ${package}; 35 | 36 | import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; 37 | import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; 38 | import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; 39 | import com.sun.jna.platform.win32.COM.util.IDispatch; 40 | import com.sun.jna.platform.win32.COM.util.IUnknown; 41 | import com.sun.jna.platform.win32.COM.util.IRawDispatchHandle; 42 | import com.sun.jna.platform.win32.Variant.VARIANT; 43 | 44 | /** 45 | [#if (entry.docString)?has_content] * ${entry.docString!} 46 | * 47 | [/#if] *

uuid(${entry.guid})

48 | */ 49 | @ComInterface(iid="${entry.guid}") 50 | public interface ${javaName} extends IUnknown, IRawDispatchHandle[#if (entry.dual || entry.dispatch || entry.dispatchable)], IDispatch[/#if] { 51 | [#list entry.functions as function] 52 | /** 53 | [#if (function.documentation)?has_content] 54 | * ${function.documentation} 55 | * 56 | [/#if] 57 | *

id(${fh.formatHex(function.memberId)})

58 | [#if (function.vtableId)?has_content] 59 | *

vtableId(${function.vtableId})

60 | [/#if] 61 | [@paramListDoc params=function.params/] 62 | */ 63 | [#if function.property]@ComProperty[#else]@ComMethod[/#if](name = "${function.methodName}", dispId = ${fh.formatHex(function.memberId)}) 64 | ${typeLib.mapPrimitiveIfExists(function.returnType)} ${fh.prepareProperty(function.methodName, function.property, function.setter)}([@paramList params=function.params/]); 65 | 66 | [/#list] 67 | 68 | [#list entry.dispatchableVariables as variable] 69 | /** 70 | [#if (variable.documentation)?has_content] 71 | * ${variable.documentation} 72 | * 73 | [/#if] 74 | *

id(${fh.formatHex(variable.memberId)})

75 | */ 76 | @ComProperty(name = "${variable.name}", dispId = ${fh.formatHex(variable.memberId)}) 77 | ${typeLib.mapPrimitiveIfExists(variable.type)} ${fh.preparePropertyGetter(variable.name)}(); 78 | 79 | [#if ! variable.readonly] 80 | /** 81 | [#if (variable.documentation)?has_content] 82 | * ${variable.documentation} 83 | * 84 | [/#if] 85 | *

id(${fh.formatHex(variable.memberId)})

86 | */ 87 | @ComProperty(name = "${variable.name}", dispId = ${fh.formatHex(variable.memberId)}) 88 | void ${fh.preparePropertySetter(variable.name)}(${typeLib.mapPrimitiveIfExists(variable.type)} value); 89 | 90 | [/#if] 91 | [/#list] 92 | } -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/InterfaceListener.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | [#macro paramList params][#list params as param] 27 | [#if param?index > 0] [/#if][#if (param.out)]VARIANT[#else]${typeLib.mapPrimitiveIfExists(param.type)}[/#if] ${param.name}[#sep], 28 | [/#sep][/#list][/#macro] 29 | 30 | package ${package}; 31 | 32 | import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; 33 | import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; 34 | import com.sun.jna.platform.win32.COM.util.IDispatch; 35 | import com.sun.jna.platform.win32.Variant.VARIANT; 36 | 37 | /** 38 | [#if (entry.docString)?has_content] * ${entry.docString!} 39 | * 40 | [/#if] *

uuid(${entry.guid})

41 | */ 42 | @ComInterface(iid="${entry.guid}") 43 | public interface ${javaName} { 44 | [#list entry.functions as function] 45 | [#assign returnValue=typeLib.mapPrimitiveIfExists(function.returnType)] 46 | /** 47 | [#if (function.documentation)?has_content] 48 | * ${function.documentation} 49 | * 50 | [/#if] 51 | *

id(${fh.formatHex(function.memberId)})

52 | */ 53 | @ComMethod(name = "${function.methodName}", dispId = ${fh.formatHex(function.memberId)}) 54 | ${returnValue} ${fh.prepareProperty(function.methodName, function.property, function.setter)}([@paramList params=function.params/]); 55 | 56 | [/#list] 57 | 58 | } -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/InterfaceListenerHandler.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | [#macro paramList params][#list params as param] 27 | [#if param?index > 0] [/#if][#if (param.out)]VARIANT[#else]${typeLib.mapPrimitiveIfExists(param.type)}[/#if] ${param.name}[#sep], 28 | [/#sep][/#list][/#macro] 29 | 30 | package ${package}; 31 | 32 | import com.sun.jna.platform.win32.COM.util.AbstractComEventCallbackListener; 33 | import com.sun.jna.platform.win32.COM.util.annotation.ComEventCallback; 34 | import com.sun.jna.platform.win32.COM.util.annotation.ComInterface; 35 | import com.sun.jna.platform.win32.COM.util.IDispatch; 36 | import com.sun.jna.platform.win32.Variant.VARIANT; 37 | 38 | /** 39 | [#if (entry.docString)?has_content] * ${entry.docString!} 40 | * 41 | [/#if] *

uuid(${entry.guid})

42 | */ 43 | public abstract class ${javaName}Handler extends AbstractComEventCallbackListener implements ${javaName} { 44 | @Override 45 | public void errorReceivingCallbackEvent(java.lang.String string, java.lang.Exception excptn) { 46 | } 47 | 48 | [#list entry.functions as function] 49 | [#assign returnValue=typeLib.mapPrimitiveIfExists(function.returnType)] 50 | /** 51 | [#if (function.documentation)?has_content] 52 | * ${function.documentation} 53 | * 54 | [/#if] 55 | *

id(${fh.formatHex(function.memberId)})

56 | */ 57 | @Override 58 | public [#if returnValue != 'void']abstract [/#if]${returnValue} ${fh.prepareProperty(function.methodName, function.property, function.setter)}([@paramList params=function.params/])[#if returnValue != 'void'];[#else]{ 59 | }[/#if] 60 | 61 | [/#list] 62 | 63 | } -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/Package.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | 27 | /** 28 | * ${name} 29 | [#if (docString)?has_content] * 30 | *

${docString!}

31 | * 32 | [/#if] *

uuid(${guid})

33 | *

version(${majorversion?c}.${minorversion?c})

34 | */ 35 | package ${package}; -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/output/CoClass.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | ${package}.${javaName} (${entry.guid}) 27 | [#list entry.sourceInterfaces as iface] 28 | Source(${fh.replaceJavaKeyword(iface)}) 29 | [/#list] 30 | [#list interfaces as iface] 31 | Extends(${fh.replaceJavaKeyword(iface)}) 32 | [/#list] -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/output/Enum.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | ${package}.${javaName} (${entry.guid!}) 27 | [#list entry.members as member] 28 | ${fh.replaceJavaKeyword(member.name)}(${member.value?c}) 29 | [/#list] -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/output/Interface.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | [#macro paramList params][#list params as param] 27 | [#if param?index > 0] [/#if][#if (param.out)]VARIANT[#else]${typeLib.mapPrimitiveIfExists(param.javaType)} /* ${typeLib.mapPrimitiveIfExists(param.type)} */[/#if] ${param.name}[#sep], [/#sep][/#list][/#macro] 28 | 29 | ${package}.${javaName} (${entry.guid!}) 30 | [#list entry.functions as function] 31 | ${r"["}memberId=${function.memberId?c}, vtableID=${function.vtableId?c}${r"]"} 32 | ${typeLib.mapPrimitiveIfExists(function.returnType)} ${fh.prepareProperty(function.methodName, function.property, function.setter)}([@paramList params=function.params/]) 33 | [/#list] -------------------------------------------------------------------------------- /src/main/resources/eu/doppel_helix/jna/tlbcodegenerator/output/InterfaceListener.ftl: -------------------------------------------------------------------------------- 1 | [#ftl] 2 | [#-- 3 | Copyright (c) 2016 Matthias Bläsing, All Rights Reserved 4 | 5 | The contents of this file is dual-licensed under 2 6 | alternative Open Source/Free licenses: LGPL 2.1 or later and 7 | Apache License 2.0. 8 | 9 | You can freely decide which license you want to apply to 10 | the project. 11 | 12 | You may obtain a copy of the LGPL License at: 13 | 14 | http://www.gnu.org/licenses/licenses.html 15 | 16 | A copy is also included in the downloadable source code package 17 | containing JNA, in file "LGPL2.1". 18 | 19 | You may obtain a copy of the Apache License at: 20 | 21 | http://www.apache.org/licenses/ 22 | 23 | A copy is also included in the downloadable source code package 24 | containing JNA, in file "AL2.0". 25 | --] 26 | [#macro paramList params][#list params as param] 27 | [#if param?index > 0] [/#if][#if (param.out)]VARIANT[#else]${typeLib.mapPrimitiveIfExists(param.type)}[/#if] ${param.name}[#sep], [/#sep][/#list][/#macro] 28 | 29 | ${package}.${javaName} (${entry.guid!}) [SOURCE] 30 | [#list entry.functions as function] 31 | ${r"["}memberId=${function.memberId?c}, vtableID=${function.vtableId?c}${r"]"} 32 | ${typeLib.mapPrimitiveIfExists(function.returnType)} ${fh.prepareProperty(function.methodName, function.property, function.setter)}([@paramList params=function.params/]) 33 | [/#list] --------------------------------------------------------------------------------