001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.wsdl.codegen;
021:
022: import org.apache.axis2.description.AxisService;
023: import org.apache.axis2.util.CommandLineOptionConstants;
024: import org.apache.axis2.util.URLProcessor;
025: import org.apache.axis2.wsdl.databinding.TypeMapper;
026: import org.apache.axis2.wsdl.util.ConfigPropertyFileLoader;
027:
028: import javax.wsdl.Definition;
029: import java.io.File;
030: import java.util.ArrayList;
031: import java.util.HashMap;
032: import java.util.Iterator;
033: import java.util.List;
034: import java.util.Map;
035:
036: public class CodeGenConfiguration implements CommandLineOptionConstants {
037:
038: /** Axis Services reference */
039: private List axisServices;
040:
041: /** Axis service to use */
042: private AxisService axisService;
043:
044: /** Base URI */
045: private String baseURI;
046: /** path to the repository - used for evaluating policy */
047: private String repositoryPath;
048: /** Mapping file including the qname to type map */
049: private File typeMappingFile;
050:
051: /** keeps the WSDL version - default is 1.1 */
052: private String WSDLVersion = WSDL2JavaConstants.WSDL_VERSION_1;
053:
054: public String getWSDLVersion() {
055: return WSDLVersion;
056: }
057:
058: public void setWSDLVersion(String WSDLVersion) {
059: this .WSDLVersion = WSDLVersion;
060: }
061:
062: public File getTypeMappingFile() {
063: return typeMappingFile;
064: }
065:
066: public void setTypeMappingFile(File typeMappingFile) {
067: this .typeMappingFile = typeMappingFile;
068: }
069:
070: /** A map to keep the custom namespace and package name mappings */
071: private Map uri2PackageNameMap;
072:
073: public Map getUri2PackageNameMap() {
074: return uri2PackageNameMap;
075: }
076:
077: public void setUri2PackageNameMap(Map uri2PackageNameMap) {
078: if (this .uri2PackageNameMap == null) {
079: this .uri2PackageNameMap = uri2PackageNameMap;
080: } else {
081: this .uri2PackageNameMap.putAll(uri2PackageNameMap);
082: }
083: }
084:
085: /** Full path and name of XMLBeans xsdconfig file to use */
086: private String xsdConfigFile = null;
087:
088: /**
089: * Returns the xsdconfig file to use for XMLBeans data binding.
090: *
091: * @return Full path and name of XMLBeans xsdconfig file to use
092: * @deprecated
093: */
094: public String getXsdConfigFile() {
095: return xsdConfigFile;
096: }
097:
098: /**
099: * Sets the xsdconfig file to use for XMLBeans data binding.
100: *
101: * @param xsdConfigFile Full path and name of XMLBeans xsdconfig file to use
102: * @deprecated
103: */
104: public void setXsdConfigFile(String xsdConfigFile) {
105: this .xsdConfigFile = xsdConfigFile;
106: }
107:
108: /** Says whether to flatten the files or put them in specific folders */
109: private boolean flattenFiles = false;
110:
111: public boolean isFlattenFiles() {
112: return flattenFiles;
113: }
114:
115: public void setFlattenFiles(boolean flattenFiles) {
116: this .flattenFiles = flattenFiles;
117: }
118:
119: /** Folder name for the resource files */
120: private String resourceLocation = ConfigPropertyFileLoader
121: .getResourceFolderName();
122:
123: public String getResourceLocation() {
124: return resourceLocation;
125: }
126:
127: public void setResourceLocation(String resourceLocation) {
128: this .resourceLocation = resourceLocation;
129: }
130:
131: /** Folder name for the source files */
132: private String sourceLocation = ConfigPropertyFileLoader
133: .getSrcFolderName();
134:
135: public String getSourceLocation() {
136: return sourceLocation;
137: }
138:
139: public void setSourceLocation(String sourceLocation) {
140: this .sourceLocation = sourceLocation;
141: }
142:
143: /** Determines whether the parameters are wrapped or unwrapped true by default */
144: private boolean parametersWrapped = true;
145:
146: public boolean isParametersWrapped() {
147: return parametersWrapped;
148: }
149:
150: public void setParametersWrapped(boolean parametersWrapped) {
151: this .parametersWrapped = parametersWrapped;
152: }
153:
154: public String getBaseURI() {
155: return baseURI;
156: }
157:
158: public void setBaseURI(String baseURI) {
159: this .baseURI = baseURI;
160: }
161:
162: public Map getConfigurationProperties() {
163: return configurationProperties;
164: }
165:
166: public void setConfigurationProperties(Map configurationProperties) {
167: this .configurationProperties = configurationProperties;
168: }
169:
170: public void setOutputLanguage(String outputLanguage) {
171: this .outputLanguage = outputLanguage;
172: }
173:
174: public void setAdvancedCodeGenEnabled(boolean advancedCodeGenEnabled) {
175: this .advancedCodeGenEnabled = advancedCodeGenEnabled;
176: }
177:
178: public void setAsyncOn(boolean asyncOn) {
179: this .asyncOn = asyncOn;
180: }
181:
182: public void setSyncOn(boolean syncOn) {
183: this .syncOn = syncOn;
184: }
185:
186: public void setServerSide(boolean serverSide) {
187: this .serverSide = serverSide;
188: }
189:
190: public void setGenerateDeployementDescriptor(
191: boolean generateDeployementDescriptor) {
192: this .generateDeployementDescriptor = generateDeployementDescriptor;
193: }
194:
195: public void setWriteTestCase(boolean writeTestCase) {
196: this .writeTestCase = writeTestCase;
197: }
198:
199: public void setOutputLocation(File outputLocation) {
200: this .outputLocation = outputLocation;
201: }
202:
203: private File outputLocation;
204:
205: //get the defaults for these from the property file
206: private String outputLanguage = ConfigPropertyFileLoader
207: .getDefaultLanguage();
208: private String databindingType = ConfigPropertyFileLoader
209: .getDefaultDBFrameworkName();
210: private boolean advancedCodeGenEnabled = false;
211:
212: private boolean asyncOn = true;
213: private boolean syncOn = true;
214: private boolean serverSide = false;
215: private boolean generateDeployementDescriptor = true;
216: private boolean writeTestCase = false;
217: private boolean skipMessageReceiver = false;
218: private boolean skipWriteWSDLs = false;
219: private boolean skipBuildXML = false;
220: private String packageName = URLProcessor.DEFAULT_PACKAGE;
221:
222: // Default packClasses is true, which means the classes generated
223: // by default are wrapped. The effect of this setting will be controlled
224: // to some extent, by the other settings as well.
225: private boolean packClasses = true;
226:
227: private boolean generateAll = false;
228:
229: //user selected portname
230: private String portName;
231: //user selected servicename
232: private String serviceName;
233:
234: //option to generate server side interface or not
235: private boolean serverSideInterface = false;
236:
237: public boolean isServerSideInterface() {
238: return serverSideInterface;
239: }
240:
241: public void setServerSideInterface(boolean serverSideInterface) {
242: this .serverSideInterface = serverSideInterface;
243: }
244:
245: public String getPortName() {
246: return portName;
247: }
248:
249: public void setPortName(String portName) {
250: this .portName = portName;
251: }
252:
253: public String getServiceName() {
254: return serviceName;
255: }
256:
257: public void setServiceName(String serviceName) {
258: this .serviceName = serviceName;
259: }
260:
261: /** A hashmap to hang the property objects */
262: private Map policyMap = new HashMap();
263:
264: /*
265: * A hashmap of properties that may be populated on the way. extensions can populate it
266: * This can be used to keep non specific information
267: */
268: private Map configurationProperties = new HashMap();
269:
270: public boolean isGenerateAll() {
271: return generateAll;
272: }
273:
274: public void setGenerateAll(boolean generateAll) {
275: this .generateAll = generateAll;
276: }
277:
278: /**
279: * Gets the wrap classes flag.
280: *
281: * @return Returns true if it is a wrap class, else returns false.
282: */
283: public boolean isPackClasses() {
284: return packClasses;
285: }
286:
287: /**
288: * Sets the wrap classes flag.
289: *
290: * @param packClasses
291: */
292: public void setPackClasses(boolean packClasses) {
293: this .packClasses = packClasses;
294: }
295:
296: /**
297: * Gets the policy map.
298: *
299: * @return Returns Map.
300: */
301: public Map getPolicyMap() {
302: return policyMap;
303: }
304:
305: /**
306: * Sets the policy map.
307: *
308: * @param policyMap
309: */
310: public void setPolicyMap(Map policyMap) {
311: this .policyMap = policyMap;
312: }
313:
314: /**
315: * Puts a property into the configuration.
316: *
317: * @param key
318: * @param value
319: */
320: public void putProperty(Object key, Object value) {
321: configurationProperties.put(key, value);
322: }
323:
324: /**
325: * Gets the property from the configuration.
326: *
327: * @param key
328: * @return Returns the property as Object.
329: */
330: public Object getProperty(Object key) {
331: return configurationProperties.get(key);
332: }
333:
334: /**
335: * Gets all property objects.
336: *
337: * @return Returns Map of all properties.
338: */
339: public Map getProperties() {
340: return configurationProperties;
341: }
342:
343: private TypeMapper typeMapper;
344:
345: /** @return Returns TypeMapper. */
346: public TypeMapper getTypeMapper() {
347: return typeMapper;
348: }
349:
350: /** @param typeMapper */
351: public void setTypeMapper(TypeMapper typeMapper) {
352: this .typeMapper = typeMapper;
353: }
354:
355: /** @return Returns String. */
356: public String getDatabindingType() {
357: return databindingType;
358: }
359:
360: /** @param databindingType */
361: public void setDatabindingType(String databindingType) {
362: this .databindingType = databindingType;
363: }
364:
365: /**
366: * Constructor for the configuration. It populates the values using the options map.
367: *
368: * @param optionMap
369: */
370: public CodeGenConfiguration(Map optionMap) {
371: CodegenConfigLoader.loadConfig(this , optionMap);
372: this .axisServices = new ArrayList();
373: this .outputXmlFileNamesList = new ArrayList();
374: }
375:
376: /** @return Returns the outputLocation. */
377: public File getOutputLocation() {
378: return outputLocation;
379: }
380:
381: public String getOutputLanguage() {
382: return outputLanguage;
383: }
384:
385: public boolean isAdvancedCodeGenEnabled() {
386: return advancedCodeGenEnabled;
387: }
388:
389: /** @return Returns the packageName. */
390: public String getPackageName() {
391: return packageName;
392: }
393:
394: /** @param packageName The packageName to set. */
395: public void setPackageName(String packageName) {
396: this .packageName = packageName;
397: }
398:
399: public boolean isAsyncOn() {
400: return asyncOn;
401: }
402:
403: public boolean isSyncOn() {
404: return syncOn;
405: }
406:
407: public boolean isServerSide() {
408: return serverSide;
409: }
410:
411: public boolean isGenerateDeployementDescriptor() {
412: return generateDeployementDescriptor;
413: }
414:
415: public boolean isSkipBuildXML() {
416: return skipBuildXML;
417: }
418:
419: public void setSkipBuildXML(boolean skipBuildXML) {
420: this .skipBuildXML = skipBuildXML;
421: }
422:
423: public boolean isWriteTestCase() {
424: return writeTestCase;
425: }
426:
427: public boolean isSkipWriteWSDLs() {
428: return skipWriteWSDLs;
429: }
430:
431: public void setSkipWriteWSDLs(boolean writeWriteWSDLs) {
432: this .skipWriteWSDLs = writeWriteWSDLs;
433: }
434:
435: public boolean isSkipMessageReceiver() {
436: return skipMessageReceiver;
437: }
438:
439: public void setSkipMessageReceiver(boolean skipMessageReceiver) {
440: this .skipMessageReceiver = skipMessageReceiver;
441: }
442:
443: public void setRepositoryPath(String repositoryPath) {
444: this .repositoryPath = repositoryPath;
445: }
446:
447: public String getRepositoryPath() {
448: return repositoryPath;
449: }
450:
451: public List getAxisServices() {
452: return axisServices;
453: }
454:
455: public void setAxisServices(List axisServices) {
456: this .axisServices = axisServices;
457: }
458:
459: public void addAxisService(AxisService axisService) {
460: this .axisServices.add(axisService);
461: }
462:
463: public AxisService getAxisService() {
464: // return the first element of the axis services
465: if (axisService != null) {
466: return axisService;
467: } else if ((axisServices != null) && (axisServices.size() > 0)) {
468: return (AxisService) axisServices.get(0);
469: } else {
470: return null;
471: }
472: }
473:
474: public void setAxisService(AxisService axisService) {
475: this .axisService = axisService;
476: }
477:
478: /**
479: * This flag determines whether the generated classes are expected to be backword compatible
480: * with Axis 1.x
481: */
482: private boolean backwordCompatibilityMode = false;
483:
484: public boolean isBackwordCompatibilityMode() {
485: return backwordCompatibilityMode;
486: }
487:
488: public void setBackwordCompatibilityMode(
489: boolean backwordCompatibilityMode) {
490: this .backwordCompatibilityMode = backwordCompatibilityMode;
491: }
492:
493: /** Should we suppress namespace prefixes */
494: private boolean suppressPrefixesMode = false;
495:
496: public boolean isSuppressPrefixesMode() {
497: return suppressPrefixesMode;
498: }
499:
500: public void setSuppressPrefixesMode(boolean suppressPrefixesMode) {
501: this .suppressPrefixesMode = suppressPrefixesMode;
502: }
503:
504: public String getTargetNamespace() {
505: String targetNamespace = null;
506: if ((this .axisServices != null)
507: && (this .axisServices.size() > 0)) {
508: targetNamespace = ((AxisService) this .axisServices.get(0))
509: .getTargetNamespace();
510: }
511: return targetNamespace;
512: }
513:
514: public List getSchemaListForAllServices() {
515: List schemas = new ArrayList();
516: AxisService axisService;
517: for (Iterator iter = this .axisServices.iterator(); iter
518: .hasNext();) {
519: axisService = (AxisService) iter.next();
520: schemas.addAll(axisService.getSchema());
521: }
522: return schemas;
523: }
524:
525: /** keep this wsdl definition to write the wsdl file later */
526: private Definition wsdlDefinition;
527:
528: public Definition getWsdlDefinition() {
529: return wsdlDefinition;
530: }
531:
532: public void setWsdlDefinition(Definition wsdlDefinition) {
533: this .wsdlDefinition = wsdlDefinition;
534: }
535:
536: private boolean isAllPorts;
537: private boolean isOverride;
538:
539: public boolean isAllPorts() {
540: return isAllPorts;
541: }
542:
543: public void setAllPorts(boolean allPorts) {
544: isAllPorts = allPorts;
545: }
546:
547: public boolean isOverride() {
548: return isOverride;
549: }
550:
551: public void setOverride(boolean override) {
552: isOverride = override;
553: }
554:
555: // this is used to keep the generated xml file list to pretty print.
556: private List outputXmlFileNamesList;
557:
558: public List getOutputXmlFileNamesList() {
559: return outputXmlFileNamesList;
560: }
561:
562: public void setOutputXmlFileNamesList(List outputXmlFileNamesList) {
563: this .outputXmlFileNamesList = outputXmlFileNamesList;
564: }
565:
566: public void addXmlFileName(String fileName) {
567: this.outputXmlFileNamesList.add(fileName);
568: }
569: }
|