update dev300-m58
[ooovba.git] / codemaker / source / javamaker / javamaker.cxx
blob813fee03603cb8855ebbe59123757883e60c0d67
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javamaker.cxx,v $
10 * $Revision: 1.10 $
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"
34 #include <stdio.h>
36 #include "sal/main.h"
38 #include "codemaker/typemanager.hxx"
39 #include "codemaker/generatedtypeset.hxx"
40 #include "javaoptions.hxx"
41 #include "javatype.hxx"
43 using namespace rtl;
45 sal_Bool produceAllTypes(RegistryKey& rTypeKey, sal_Bool bIsExtraType,
46 TypeManager const & typeMgr,
47 codemaker::GeneratedTypeSet & generated,
48 JavaOptions* pOptions,
49 sal_Bool bFullScope)
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());
59 exit(99);
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())
69 key = (*iter).first;
71 if (!(*iter).second && !key.openSubKeys(OUString(), subKeys))
73 for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
75 subKey = subKeys.getElement(i);
76 if (bFullScope)
78 if (!produceAllTypes(
79 subKey, (*iter).second,
80 typeMgr, generated, pOptions, sal_True))
81 return sal_False;
82 } else
84 if (!produceType(subKey, (*iter).second,
85 typeMgr, generated, pOptions))
86 return sal_False;
91 ++iter;
94 return sal_True;
97 sal_Bool produceAllTypes(const OString& typeName,
98 TypeManager const & typeMgr,
99 codemaker::GeneratedTypeSet & generated,
100 JavaOptions* pOptions,
101 sal_Bool bFullScope)
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());
109 exit(99);
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())
119 key = (*iter).first;
120 if (!(*iter).second && !key.openSubKeys(OUString(), subKeys))
122 for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
124 subKey = subKeys.getElement(i);
125 if (bFullScope)
127 if (!produceAllTypes(
128 subKey, (*iter).second,
129 typeMgr, generated, pOptions, sal_True))
130 return sal_False;
131 } else
133 if (!produceType(subKey, (*iter).second,
134 typeMgr, generated, pOptions))
135 return sal_False;
140 ++iter;
143 return sal_True;
146 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
148 JavaOptions options;
150 try
152 if (!options.initOptions(argc, argv))
154 exit(1);
157 catch( IllegalArgument& e)
159 fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr());
160 exit(99);
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());
168 exit(99);
171 if (options.isValid("-B"))
173 typeMgr.setBase(options.getOption("-B"));
176 try
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 );
192 if (tmpName == "*")
194 // produce this type and his scope.
195 if (typeName.equals("*"))
197 tmpName = "/";
198 } else
200 tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/');
201 if (tmpName.getLength() == 0)
202 tmpName = "/";
203 else
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);
210 } else
212 // produce only this type
213 ret = produceType(
214 typeName.replace('.', '/'), typeMgr, generated,
215 &options);
218 if (!ret)
220 fprintf(stderr, "%s ERROR: %s\n",
221 options.getProgramName().getStr(),
222 OString("cannot dump Type '" + typeName + "'").getStr());
223 exit(99);
225 } while( nIndex != -1 );
226 } else
228 // produce all types
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.");
235 exit(99);
239 catch( CannotDumpException& e)
241 fprintf(stderr, "%s ERROR: %s\n",
242 options.getProgramName().getStr(),
243 e.m_message.getStr());
244 exit(99);
247 return 0;