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: package org.apache.axis2.schema;
020:
021: import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
022:
023: import java.io.File;
024: import java.util.regex.Matcher;
025: import java.util.regex.Pattern;
026: import java.util.Map;
027: import java.util.HashMap;
028:
029: /**
030: * This is a bean class that captures all the compiler options.
031: * Right now the compiler options consist of the following
032: * 1. output file location - A folder with necessary rights for the
033: * schema compiler to write the files
034: * 2.package name
035: * 3.namespace to package map
036: * 4.boolean flag marking whether to wrap or unwrap
037: * 4.boolean flag marking whether to write classes or not
038: */
039: public class CompilerOptions {
040:
041: /**
042: * Generated output file
043: */
044: private File outputLocation;
045: private String packageName = null;
046: private boolean generateAll = false;
047:
048: private boolean offStrictValidation = false;
049:
050: /**
051: * Package for the mapper
052: */
053: private String mapperClassPackage = null;
054:
055: public String getMapperClassPackage() {
056: return mapperClassPackage;
057: }
058:
059: public void setMapperClassPackage(String mapperClassPackage) {
060: this .mapperClassPackage = mapperClassPackage;
061: }
062:
063: /**
064: * get whether the mapper class package
065: * name is present
066: */
067: public boolean isMapperClassPackagePresent() {
068: return (mapperClassPackage != null && !""
069: .equals(mapperClassPackage));
070: }
071:
072: /**
073: * The flag keeping whether seperate helpers
074: * need to be generated or not
075: */
076: private boolean helperMode = false;
077:
078: public boolean isHelperMode() {
079: return helperMode;
080: }
081:
082: public void setHelperMode(boolean helperMode) {
083: this .helperMode = helperMode;
084: }
085:
086: /**
087: * Keep track of the namespace and packages mapping
088: */
089: private Map ns2PackageMap = new HashMap();
090:
091: public Map getNs2PackageMap() {
092: return ns2PackageMap;
093: }
094:
095: public void setNs2PackageMap(Map ns2PackageMap) {
096: this .ns2PackageMap = ns2PackageMap;
097: }
098:
099: /**
100: * This flag tells the databinder to either write the output or
101: * not. if this is set to true it will write the output at once.
102: * if not the outputter will populate the
103: */
104: private boolean writeOutput = false;
105:
106: /**
107: * This flag determines whether the generated classes are wrapped or not
108: * if the wrapper flag is true, then only a single file will be generated
109: */
110: private boolean wrapClasses = false;
111:
112: public boolean isWriteOutput() {
113: return writeOutput;
114: }
115:
116: public void setWriteOutput(boolean writeOutput) {
117: this .writeOutput = writeOutput;
118: }
119:
120: public boolean isWrapClasses() {
121: return wrapClasses;
122: }
123:
124: public void setWrapClasses(boolean wrapClasses) {
125: this .wrapClasses = wrapClasses;
126: }
127:
128: public String getPackageName() {
129: return packageName;
130: }
131:
132: public CompilerOptions setPackageName(String packageName) {
133: // Validate the package name.
134: if (packageName != null && testValue(packageName)) {
135: this .packageName = packageName;
136: } else {
137: throw new RuntimeException(SchemaCompilerMessages
138: .getMessage("schema.unsupportedvalue"));
139: }
140: return this ;
141: }
142:
143: public File getOutputLocation() {
144: return outputLocation;
145: }
146:
147: public CompilerOptions setOutputLocation(File outputLocation) {
148: this .outputLocation = outputLocation;
149: return this ;
150: }
151:
152: private boolean testValue(String wordToMatch) {
153: Pattern pat = Pattern.compile("^(\\w+\\.)+$");
154: Matcher m = pat.matcher(wordToMatch);
155: return m.matches();
156: }
157:
158: public boolean isGenerateAll() {
159: return generateAll;
160: }
161:
162: public void setGenerateAll(boolean generateAll) {
163: this .generateAll = generateAll;
164: }
165:
166: /**
167: * This flag determines whether the generated classes are expected to be
168: * backword compatible with Axis 1.x
169: */
170: private boolean backwordCompatibilityMode = false;
171:
172: public boolean isBackwordCompatibilityMode() {
173: return backwordCompatibilityMode;
174: }
175:
176: public void setBackwordCompatibilityMode(
177: boolean backwordCompatibilityMode) {
178: this .backwordCompatibilityMode = backwordCompatibilityMode;
179: }
180:
181: /**
182: * Should we suppress namespace prefixes
183: */
184: private boolean suppressPrefixesMode = false;
185:
186: public boolean isSuppressPrefixesMode() {
187: return suppressPrefixesMode;
188: }
189:
190: public void setSuppressPrefixesMode(boolean suppressPrefixesMode) {
191: this .suppressPrefixesMode = suppressPrefixesMode;
192: }
193:
194: public boolean isOffStrictValidation() {
195: return offStrictValidation;
196: }
197:
198: public void setOffStrictValidation(boolean offStrictValidation) {
199: this.offStrictValidation = offStrictValidation;
200: }
201:
202: }
|