1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javamaker.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_codemaker.hxx"
38 #include "codemaker/typemanager.hxx"
39 #include "codemaker/generatedtypeset.hxx"
40 #include "javaoptions.hxx"
41 #include "javatype.hxx"
45 sal_Bool
produceAllTypes(RegistryKey
& rTypeKey
, sal_Bool bIsExtraType
,
46 TypeManager
const & typeMgr
,
47 codemaker::GeneratedTypeSet
& generated
,
48 JavaOptions
* pOptions
,
50 throw( CannotDumpException
)
52 OString typeName
= typeMgr
.getTypeName(rTypeKey
);
54 if (!produceType(rTypeKey
, bIsExtraType
, typeMgr
, generated
, pOptions
))
56 fprintf(stderr
, "%s ERROR: %s\n",
57 pOptions
->getProgramName().getStr(),
58 OString("cannot dump Type '" + typeName
+ "'").getStr());
62 RegistryKeyList typeKeys
= typeMgr
.getTypeKeys(typeName
);
63 RegistryKeyList::const_iterator iter
= typeKeys
.begin();
64 RegistryKey key
, subKey
;
65 RegistryKeyArray subKeys
;
67 while (iter
!= typeKeys
.end())
71 if (!(*iter
).second
&& !key
.openSubKeys(OUString(), subKeys
))
73 for (sal_uInt32 i
= 0; i
< subKeys
.getLength(); i
++)
75 subKey
= subKeys
.getElement(i
);
79 subKey
, (*iter
).second
,
80 typeMgr
, generated
, pOptions
, sal_True
))
84 if (!produceType(subKey
, (*iter
).second
,
85 typeMgr
, generated
, pOptions
))
97 sal_Bool
produceAllTypes(const OString
& typeName
,
98 TypeManager
const & typeMgr
,
99 codemaker::GeneratedTypeSet
& generated
,
100 JavaOptions
* pOptions
,
102 throw( CannotDumpException
)
104 if (!produceType(typeName
, typeMgr
, generated
, pOptions
))
106 fprintf(stderr
, "%s ERROR: %s\n",
107 pOptions
->getProgramName().getStr(),
108 OString("cannot dump Type '" + typeName
+ "'").getStr());
112 RegistryKeyList typeKeys
= typeMgr
.getTypeKeys(typeName
);
113 RegistryKeyList::const_iterator iter
= typeKeys
.begin();
114 RegistryKey key
, subKey
;
115 RegistryKeyArray subKeys
;
117 while (iter
!= typeKeys
.end())
120 if (!(*iter
).second
&& !key
.openSubKeys(OUString(), subKeys
))
122 for (sal_uInt32 i
= 0; i
< subKeys
.getLength(); i
++)
124 subKey
= subKeys
.getElement(i
);
127 if (!produceAllTypes(
128 subKey
, (*iter
).second
,
129 typeMgr
, generated
, pOptions
, sal_True
))
133 if (!produceType(subKey
, (*iter
).second
,
134 typeMgr
, generated
, pOptions
))
146 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
152 if (!options
.initOptions(argc
, argv
))
157 catch( IllegalArgument
& e
)
159 fprintf(stderr
, "Illegal option: %s\n", e
.m_message
.getStr());
163 RegistryTypeManager typeMgr
;
165 if (!typeMgr
.init(options
.getInputFiles(), options
.getExtraInputFiles()))
167 fprintf(stderr
, "%s : init registries failed, check your registry files.\n", options
.getProgramName().getStr());
171 if (options
.isValid("-B"))
173 typeMgr
.setBase(options
.getOption("-B"));
178 if (options
.isValid("-T"))
180 OString
tOption(options
.getOption("-T"));
181 sal_Int32 nIndex
= 0;
183 codemaker::GeneratedTypeSet generated
;
184 OString typeName
, tmpName
;
185 sal_Bool ret
= sal_False
;
188 typeName
= tOption
.getToken(0, ';', nIndex
);
190 sal_Int32 nPos
= typeName
.lastIndexOf( '.' );
191 tmpName
= typeName
.copy( nPos
!= -1 ? nPos
+1 : 0 );
194 // produce this type and his scope.
195 if (typeName
.equals("*"))
200 tmpName
= typeName
.copy(0, typeName
.lastIndexOf('.')).replace('.', '/');
201 if (tmpName
.getLength() == 0)
204 tmpName
.replace('.', '/');
206 // related to task #116780# the scope is recursively
207 // generated. bFullScope = true
208 ret
= produceAllTypes(
209 tmpName
, typeMgr
, generated
, &options
, sal_True
);
212 // produce only this type
214 typeName
.replace('.', '/'), typeMgr
, generated
,
220 fprintf(stderr
, "%s ERROR: %s\n",
221 options
.getProgramName().getStr(),
222 OString("cannot dump Type '" + typeName
+ "'").getStr());
225 } while( nIndex
!= -1 );
229 codemaker::GeneratedTypeSet generated
;
230 if (!produceAllTypes("/", typeMgr
, generated
, &options
, sal_True
))
232 fprintf(stderr
, "%s ERROR: %s\n",
233 options
.getProgramName().getStr(),
234 "an error occurs while dumping all types.");
239 catch( CannotDumpException
& e
)
241 fprintf(stderr
, "%s ERROR: %s\n",
242 options
.getProgramName().getStr(),
243 e
.m_message
.getStr());