1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.axis2.schema;
21
22 import org.apache.axis2.AxisFault;
23 import org.apache.axis2.description.AxisMessage;
24 import org.apache.axis2.description.AxisOperation;
25 import org.apache.axis2.description.AxisService;
26 import org.apache.axis2.description.Parameter;
27 import org.apache.axis2.schema.typemap.JavaTypeMap;
28 import org.apache.axis2.schema.typemap.TypeMap;
29 import org.apache.axis2.wsdl.WSDLConstants;
30 import org.apache.axis2.wsdl.WSDLUtil;
31 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
32 import org.apache.axis2.wsdl.databinding.CTypeMapper;
33 import org.apache.axis2.wsdl.databinding.DefaultTypeMapper;
34 import org.apache.axis2.wsdl.databinding.JavaTypeMapper;
35 import org.apache.axis2.wsdl.databinding.TypeMapper;
36 import org.apache.axis2.wsdl.util.Constants;
37 import org.apache.ws.commons.schema.XmlSchema;
38 import org.apache.ws.commons.schema.XmlSchemaAny;
39 import org.apache.ws.commons.schema.XmlSchemaAttribute;
40 import org.apache.ws.commons.schema.XmlSchemaComplexContent;
41 import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
42 import org.apache.ws.commons.schema.XmlSchemaComplexType;
43 import org.apache.ws.commons.schema.XmlSchemaContent;
44 import org.apache.ws.commons.schema.XmlSchemaContentModel;
45 import org.apache.ws.commons.schema.XmlSchemaElement;
46 import org.apache.ws.commons.schema.XmlSchemaImport;
47 import org.apache.ws.commons.schema.XmlSchemaInclude;
48 import org.apache.ws.commons.schema.XmlSchemaObject;
49 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
50 import org.apache.ws.commons.schema.XmlSchemaParticle;
51 import org.apache.ws.commons.schema.XmlSchemaSequence;
52 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
53 import org.apache.ws.commons.schema.XmlSchemaType;
54
55 import javax.xml.namespace.QName;
56 import java.io.File;
57 import java.util.ArrayList;
58 import java.util.HashMap;
59 import java.util.Iterator;
60 import java.util.List;
61 import java.util.Map;
62
63 /**
64 * This is the utility for the extension to call by reflection.
65 */
66 public class ExtensionUtility {
67
68
69 public static void invoke(CodeGenConfiguration configuration) throws Exception {
70 List schemaList = new ArrayList();
71 // add all the schemas to the list
72 List services = configuration.getAxisServices();
73 for (Iterator iter = services.iterator();iter.hasNext();){
74 schemaList.addAll(((AxisService)iter.next()).getSchema());
75 }
76
77 //hashmap that keeps the targetnamespace and the xmlSchema object
78 //this is a convenience to locate the relevant schema quickly
79 //by looking at the target namespace
80 Map schemaMap = new HashMap();
81 populateSchemaMap(schemaMap, schemaList);
82
83 if (schemaList == null || schemaList.isEmpty()) {
84 //there are no types to be code generated
85 //However if the type mapper is left empty it will be a problem for the other
86 //processes. Hence the default type mapper is set to the configuration
87 configuration.setTypeMapper(new DefaultTypeMapper());
88 return;
89 }
90 //call the schema compiler
91 CompilerOptions options = new CompilerOptions();
92
93 //set the default options
94 populateDefaultOptions(options, configuration);
95
96 //set the user parameters. the user parameters get the preference over
97 //the default ones. But the user better know what he's doing if he
98 //used module specific parameters
99 populateUserparameters(options, configuration);
100
101 SchemaCompiler schemaCompiler = new SchemaCompiler(options);
102 // run the schema compiler
103 schemaCompiler.compile(schemaList);
104
105 //create the type mapper
106 //First try to take the one that is already there
107 TypeMapper mapper = configuration.getTypeMapper();
108 if (mapper == null) {
109 if (configuration.getOutputLanguage() != null &&
110 !configuration.getOutputLanguage().trim().equals("") &&
111 configuration.getOutputLanguage().toLowerCase().equals("c")) {
112 mapper = new CTypeMapper();
113
114 } else {
115 mapper = new JavaTypeMapper();
116 }
117
118 }
119
120 if (options.isWriteOutput()) {
121 //get the processed element map and transfer it to the type mapper
122 Map processedMap = schemaCompiler.getProcessedElementMap();
123 Iterator processedkeys = processedMap.keySet().iterator();
124 QName qNameKey;
125 while (processedkeys.hasNext()) {
126 qNameKey = (QName) processedkeys.next();
127 mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
128 }
129
130 } else {
131 //get the processed model map and transfer it to the type mapper
132 //since the options mentiond that its not writable, it should have
133 //populated the model map
134 Map processedModelMap = schemaCompiler.getProcessedModelMap();
135 Iterator processedkeys = processedModelMap.keySet().iterator();
136 QName qNameKey;
137 while (processedkeys.hasNext()) {
138 qNameKey = (QName) processedkeys.next();
139 mapper.addTypeMappingObject(qNameKey, processedModelMap.get(qNameKey));
140 }
141
142 Map processedMap = schemaCompiler.getProcessedElementMap();
143 processedkeys = processedMap.keySet().iterator();
144 while (processedkeys.hasNext()) {
145 qNameKey = (QName) processedkeys.next();
146 mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
147 }
148
149 //get the ADB template from the schema compilers property bag and set the
150 //template
151 configuration.putProperty(Constants.EXTERNAL_TEMPLATE_PROPERTY_KEY,
152 schemaCompiler.getCompilerProperties().getProperty(
153 SchemaConstants.SchemaPropertyNames.BEAN_WRITER_TEMPLATE_KEY));
154
155 }
156
157 //process the unwrapped parameters
158 if (!configuration.isParametersWrapped()) {
159 //figure out the unwrapped operations
160 List axisServices = configuration.getAxisServices();
161 AxisService axisService;
162 for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
163 axisService = (AxisService) servicesIter.next();
164 for (Iterator operations = axisService.getOperations();
165 operations.hasNext();) {
166 AxisOperation op = (AxisOperation) operations.next();
167 if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
168 walkSchema(op.getMessage(
169 WSDLConstants.MESSAGE_LABEL_IN_VALUE),
170 mapper,
171 schemaMap,
172 op.getName().getLocalPart(),
173 WSDLConstants.INPUT_PART_QNAME_SUFFIX);
174 }
175
176 // TODO: support for xml beans
177 if (configuration.getDatabindingType().equals("adb")) {
178 if (WSDLUtil.isOutputPresentForMEP(op.getMessageExchangePattern())) {
179 walkSchema(op.getMessage(
180 WSDLConstants.MESSAGE_LABEL_OUT_VALUE),
181 mapper,
182 schemaMap,
183 op.getName().getLocalPart(),
184 WSDLConstants.OUTPUT_PART_QNAME_SUFFIX);
185 }
186 }
187
188 }
189 }
190
191 }
192
193 //put the complext types for the top level elements having them
194 // this is needed in unwrapping and to provide backwordCompatibility
195 if (!configuration.isParametersWrapped() || configuration.isBackwordCompatibilityMode()) {
196 List axisServices = configuration.getAxisServices();
197 AxisService axisService;
198 for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
199 axisService = (AxisService) servicesIter.next();
200 AxisOperation axisOperation;
201 AxisMessage axisMessage;
202 for (Iterator operators = axisService.getOperations(); operators.hasNext();) {
203 axisOperation = (AxisOperation) operators.next();
204 if (WSDLUtil.isInputPresentForMEP(axisOperation.getMessageExchangePattern())) {
205 axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
206 setComplexTypeName(axisMessage);
207 }
208 if (WSDLUtil.isOutputPresentForMEP(axisOperation.getMessageExchangePattern())) {
209 axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
210 setComplexTypeName(axisMessage);
211 }
212 }
213 }
214
215 }
216
217 //set the type mapper to the config
218 configuration.setTypeMapper(mapper);
219
220 }
221
222 /**
223 * set the complext type class name as an message parameter if it exits
224 * @param axisMessage
225 */
226 private static void setComplexTypeName(AxisMessage axisMessage) throws AxisFault {
227
228 if (axisMessage.getSchemaElement() != null){
229
230 XmlSchemaElement schemaElement = axisMessage.getSchemaElement();
231 XmlSchemaType schemaType = schemaElement.getSchemaType();
232 QName schemaTypeQname = schemaElement.getSchemaTypeName();
233
234 if (schemaType == null) {
235 if (schemaTypeQname != null) {
236 // find the schema type from all the schemas
237 // now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
238 // the parent schema
239 AxisService axisService = axisMessage.getAxisOperation().getAxisService();
240 ArrayList schemasList = axisService.getSchema();
241 XmlSchema schema = null;
242 for (Iterator iter = schemasList.iterator(); iter.hasNext();) {
243 schema = (XmlSchema) iter.next();
244 schemaType = getSchemaType(schema, schemaTypeQname);
245 if (schemaType != null) {
246 break;
247 }
248 }
249 }
250 }
251
252 if (schemaType instanceof XmlSchemaComplexType){
253 XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
254 if ((complexType.getName() != null) && (complexType.getQName() != null)) {
255 Map metaInfo = complexType.getMetaInfoMap();
256 String complexTypeName = (String)
257 metaInfo.get(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY);
258 if (complexTypeName.endsWith("[]")){
259 complexTypeName = complexTypeName.substring(0,complexTypeName.length() -2);
260 }
261 // store the complext type name to process later
262 axisMessage.addParameter(new Parameter(Constants.COMPLEX_TYPE, complexTypeName));
263 }
264 }
265 }
266
267
268 }
269
270 /**
271 * Populate the schema objects into the
272 *
273 * @param schemaMap
274 * @param schemaList
275 */
276 private static void populateSchemaMap(Map schemaMap, List schemaList) {
277 for (int i = 0; i < schemaList.size(); i++) {
278 XmlSchema xmlSchema = (XmlSchema) schemaList.get(i);
279 schemaMap.put(xmlSchema.getTargetNamespace(), xmlSchema);
280 }
281 }
282
283 /**
284 * @param message
285 * @param mapper
286 */
287 private static void walkSchema(AxisMessage message,
288 TypeMapper mapper,
289 Map schemaMap,
290 String opName,
291 String qnameSuffix) {
292
293 if (message.getParameter(Constants.UNWRAPPED_KEY) != null) {
294
295 XmlSchemaElement schemaElement = message.getSchemaElement();
296 XmlSchemaType schemaType = schemaElement.getSchemaType();
297 QName schemaTypeQname = schemaElement.getSchemaTypeName();
298
299 if (schemaType == null) {
300 if (schemaTypeQname != null) {
301 // find the schema type from all the schemas
302 // now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
303 // the parent schema
304 AxisService axisService = message.getAxisOperation().getAxisService();
305 ArrayList schemasList = axisService.getSchema();
306
307 XmlSchema schema = null;
308 for (Iterator iter = schemasList.iterator(); iter.hasNext();) {
309 schema = (XmlSchema) iter.next();
310 schemaType = getSchemaType(schema, schemaTypeQname);
311 if (schemaType != null) {
312 break;
313 }
314 }
315 }
316 }
317
318 //create a type mapper
319 TypeMap basicTypeMap = new JavaTypeMap();
320 if (schemaType instanceof XmlSchemaComplexType) {
321 processXMLSchemaComplexType(schemaType, mapper, opName, schemaMap, qnameSuffix);
322 } else if ((schemaTypeQname != null) && basicTypeMap.getTypeMap().containsKey(schemaTypeQname)){
323 QName partQName = WSDLUtil.getPartQName(opName,
324 qnameSuffix,
325 message.getElementQName().getLocalPart());
326 mapper.addTypeMappingName(partQName, (String)basicTypeMap.getTypeMap().get(schemaTypeQname));
327 } else if (schemaType instanceof XmlSchemaSimpleType) {
328 XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) schemaType;
329 populateClassName(xmlSchemaSimpleType.getMetaInfoMap(),
330 mapper,
331 opName,
332 false,
333 message.getElementQName().getLocalPart(),
334 qnameSuffix);
335 // handle xsd:anyType
336 }
337
338 }
339 }
340
341 private static void processXMLSchemaComplexType(XmlSchemaType schemaType,
342 TypeMapper mapper,
343 String opName,
344 Map schemaMap,
345 String qnameSuffix) {
346 if (schemaType instanceof XmlSchemaComplexType) {
347 XmlSchemaComplexType cmplxType = (XmlSchemaComplexType) schemaType;
348 if (cmplxType.getContentModel() == null) {
349 processSchemaSequence(cmplxType.getParticle(), mapper, opName, schemaMap, qnameSuffix);
350 } else {
351 processComplexContentModel(cmplxType, mapper, opName, schemaMap, qnameSuffix);
352 }
353 processAttributes(cmplxType, opName, qnameSuffix, mapper);
354 }
355 }
356
357 private static void processAttributes(XmlSchemaComplexType complexType,
358 String opName,
359 String qnameSuffix,
360 TypeMapper typeMap) {
361 XmlSchemaObjectCollection xmlObjectCollection = complexType.getAttributes();
362 XmlSchemaObject item;
363 for (Iterator iter = xmlObjectCollection.getIterator(); iter.hasNext();) {
364 item = (XmlSchemaObject) iter.next();
365 XmlSchemaAttribute xmlSchemaAttribute;
366 if (item instanceof XmlSchemaAttribute) {
367 xmlSchemaAttribute = (XmlSchemaAttribute) item;
368 populateClassName(xmlSchemaAttribute.getMetaInfoMap(),
369 typeMap,
370 opName,
371 false,
372 xmlSchemaAttribute.getName(),
373 qnameSuffix);
374 }
375
376 }
377
378 }
379
380 private static XmlSchemaType getSchemaType(XmlSchema schema, QName typeName) {
381 XmlSchemaType xmlSchemaType = null;
382 if (schema != null) {
383 xmlSchemaType = schema.getTypeByName(typeName);
384 if (xmlSchemaType == null) {
385 // try to find in an import or an include
386 XmlSchemaObjectCollection includes = schema.getIncludes();
387 if (includes != null) {
388 Iterator includesIter = includes.getIterator();
389 Object object = null;
390 while (includesIter.hasNext()) {
391 object = includesIter.next();
392 if (object instanceof XmlSchemaImport) {
393 XmlSchema schema1 = ((XmlSchemaImport) object).getSchema();
394 xmlSchemaType = getSchemaType(schema1,typeName);
395 }
396 if (object instanceof XmlSchemaInclude) {
397 XmlSchema schema1 = ((XmlSchemaInclude) object).getSchema();
398 xmlSchemaType = getSchemaType(schema1,typeName);
399 }
400 if (xmlSchemaType != null){
401 break;
402 }
403 }
404 }
405 }
406 }
407 return xmlSchemaType;
408 }
409
410
411 private static void processComplexContentModel(XmlSchemaComplexType cmplxType,
412 TypeMapper mapper,
413 String opName,
414 Map schemaMap,
415 String qnameSuffix) {
416 XmlSchemaContentModel contentModel = cmplxType.getContentModel();
417 if (contentModel instanceof XmlSchemaComplexContent) {
418 XmlSchemaComplexContent xmlSchemaComplexContent = (XmlSchemaComplexContent) contentModel;
419 XmlSchemaContent content = xmlSchemaComplexContent.getContent();
420 if (content instanceof XmlSchemaComplexContentExtension) {
421 XmlSchemaComplexContentExtension schemaExtension = (XmlSchemaComplexContentExtension) content;
422
423 // process particles inside this extension, if any
424 processSchemaSequence(schemaExtension.getParticle(), mapper, opName, schemaMap, qnameSuffix);
425
426 XmlSchema xmlSchema = null;
427 XmlSchemaType extensionSchemaType = null;
428 for (Iterator iter = schemaMap.values().iterator();iter.hasNext();){
429 xmlSchema = (XmlSchema) iter.next();
430 extensionSchemaType = getSchemaType(xmlSchema,schemaExtension.getBaseTypeName());
431 if (extensionSchemaType != null){
432 break;
433 }
434 }
435
436 processXMLSchemaComplexType(extensionSchemaType, mapper, opName, schemaMap, qnameSuffix);
437 }
438 }
439 }
440
441 private static void processSchemaSequence(XmlSchemaParticle particle,
442 TypeMapper mapper,
443 String opName,
444 Map schemaMap,
445 String qnameSuffix) {
446 if (particle instanceof XmlSchemaSequence) {
447 XmlSchemaObjectCollection items = ((XmlSchemaSequence) particle).getItems();
448 for (Iterator i = items.getIterator(); i.hasNext();) {
449 Object item = i.next();
450 // get each and every element in the sequence and
451 // traverse through them
452 if (item instanceof XmlSchemaElement) {
453 //populate the map with the partname - class name
454 //attached to the schema element
455 XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) item;
456 boolean isArray = xmlSchemaElement.getMaxOccurs() > 1;
457
458 XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
459 String partName = null;
460 if (xmlSchemaElement.getRefName() != null) {
461 partName = xmlSchemaElement.getRefName().getLocalPart();
462 } else {
463 partName = xmlSchemaElement.getName();
464 }
465
466
467 // get the element class name from the element and populate the mapper
468 populateClassName(xmlSchemaElement.getMetaInfoMap(),
469 mapper,
470 opName,
471 isArray,
472 partName,
473 qnameSuffix);
474 } else if (item instanceof XmlSchemaAny) {
475
476 // if this is an instance of xs:any, then there is no part name for it. Using ANY_ELEMENT_FIELD_NAME
477 // for it for now
478
479 XmlSchemaAny xmlSchemaAny = (XmlSchemaAny) item;
480 boolean isArray = xmlSchemaAny.getMaxOccurs() > 1;
481
482 QName partQName = WSDLUtil.getPartQName(opName,
483 qnameSuffix,
484 Constants.ANY_ELEMENT_FIELD_NAME);
485
486 if (isArray) {
487 mapper.addTypeMappingName(partQName, "org.apache.axiom.om.OMElement[]");
488 } else {
489 mapper.addTypeMappingName(partQName, "org.apache.axiom.om.OMElement");
490 }
491 }
492 }
493 }
494 }
495
496 // private static void
497
498 /**
499 * Util method to populate the class name into the typeMap
500 *
501 */
502 private static void populateClassName(Map metaInfoMap,
503 TypeMapper typeMap,
504 String opName,
505 boolean isArray,
506 String partName,
507 String qnameSuffix) {
508
509
510
511 if (metaInfoMap != null) {
512 String className = (String) metaInfoMap.
513 get(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY);
514
515 // this is a temporary patch
516 // the acual problem is keeping the class name details on the schemaType in
517 // XmlSchema compiler.
518 // we have to store them in XmlElement
519 if (isArray && !className.endsWith("[]")) {
520 className += "[]";
521 } else if (!isArray && className.endsWith("[]")) {
522 className = className.substring(0, className.length() - 2);
523 }
524
525
526 QName partQName = WSDLUtil.getPartQName(opName,
527 qnameSuffix,
528 partName);
529 typeMap.addTypeMappingName(partQName, className);
530 if (Boolean.TRUE.equals(
531 metaInfoMap.get(SchemaConstants.
532 SchemaCompilerInfoHolder.CLASSNAME_PRIMITVE_KEY))) {
533
534 //this type is primitive - add that to the type mapper status
535 //for now lets add a boolean
536 typeMap.addTypeMappingStatus(partQName, Boolean.TRUE);
537 }
538 }
539 }
540
541
542 /**
543 * Look for a given schema type given the schema type Qname
544 *
545 * @param schemaMap
546 * @return null if the schema is not found
547 */
548 private static XmlSchemaType findSchemaType(Map schemaMap, QName schemaTypeName) {
549 //find the schema
550 XmlSchema schema = (XmlSchema) schemaMap.get(schemaTypeName.getNamespaceURI());
551 if (schema != null) {
552 return schema.getTypeByName(schemaTypeName);
553 }
554 return null;
555 }
556
557 /**
558 * populate parameters from the user
559 *
560 * @param options
561 */
562 private static void populateUserparameters(CompilerOptions options, CodeGenConfiguration configuration) {
563 Map propertyMap = configuration.getProperties();
564 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES)) {
565 if (Boolean.valueOf(
566 propertyMap.get(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES).toString()).
567 booleanValue()) {
568 options.setWrapClasses(true);
569 } else {
570 options.setWrapClasses(false);
571 }
572 }
573
574 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.WRITE_SCHEMA_CLASSES)) {
575 if (Boolean.valueOf(
576 propertyMap.get(SchemaConstants.SchemaCompilerArguments.WRITE_SCHEMA_CLASSES).toString()).
577 booleanValue()) {
578 options.setWriteOutput(true);
579 } else {
580 options.setWriteOutput(false);
581 }
582 }
583
584
585 // add the custom package name
586 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.PACKAGE)) {
587 String packageName = (String) propertyMap.get(SchemaConstants.SchemaCompilerArguments.PACKAGE);
588 if (packageName != null || !"".equals(packageName)) {
589 options.setPackageName(packageName);
590 }
591
592 }
593
594 // set the package namespace to uri details
595 options.setNs2PackageMap(configuration.getUri2PackageNameMap());
596
597 //add custom mapper package name
598 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.MAPPER_PACKAGE)) {
599 String packageName = (String) propertyMap.get(SchemaConstants.SchemaCompilerArguments.MAPPER_PACKAGE);
600 if (packageName != null || !"".equals(packageName)) {
601 options.setMapperClassPackage(packageName);
602 }
603
604 }
605
606 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.OFF_STRICT_VALIDATION)){
607 options.setOffStrictValidation(true);
608 }
609
610 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.USE_WRAPPER_CLASSES)){
611 options.setUseWrapperClasses(true);
612 }
613
614 //set helper mode
615 //this becomes effective only if the classes are unpacked
616 if (!options.isWrapClasses()) {
617 if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.HELPER_MODE)) {
618 options.setHelperMode(true);
619 }
620 }
621 }
622
623
624 /**
625 * populate the default options - called before the applying of user parameters
626 *
627 * @param options
628 */
629 private static void populateDefaultOptions(CompilerOptions options,
630 CodeGenConfiguration configuration) {
631 //create the output directory
632 File outputDir = configuration.isFlattenFiles() ?
633 configuration.getOutputLocation() :
634 new File(configuration.getOutputLocation(), configuration.getSourceLocation());
635
636 if (!outputDir.exists()) {
637 outputDir.mkdirs();
638 }
639
640 /// these options need to be taken from the command line
641 options.setOutputLocation(outputDir);
642 options.setNs2PackageMap(configuration.getUri2PackageNameMap() == null ?
643 new HashMap() :
644 configuration.getUri2PackageNameMap());
645
646 //default setting is to set the wrap status depending on whether it's
647 //the server side or the client side
648 if (configuration.isServerSide()) {
649 //for the serverside we generate unwrapped by default
650 options.setWrapClasses(false);
651 //for the serverside we write the output by default
652 options.setWriteOutput(true);
653 } else {
654 // for the client let the users preference be the word here
655 options.setWrapClasses(configuration.isPackClasses());
656 //for the client side the default setting is not to write the
657 //output
658 options.setWriteOutput(!configuration.isPackClasses());
659 }
660
661 if (configuration.isGenerateAll()) {
662 options.setGenerateAll(true);
663 }
664
665 if (configuration.isBackwordCompatibilityMode()) {
666 options.setBackwordCompatibilityMode(true);
667 }
668
669 if (configuration.isSuppressPrefixesMode()) {
670 options.setSuppressPrefixesMode(true);
671 }
672 }
673
674 }