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.wsdl.codegen.writer;
020:
021: import org.apache.axis2.util.XSLTTemplateProcessor;
022: import org.apache.axis2.wsdl.util.ConfigPropertyFileLoader;
023: import org.w3c.dom.Document;
024:
025: import javax.xml.transform.URIResolver;
026: import java.io.File;
027: import java.io.FileOutputStream;
028: import java.util.Iterator;
029: import java.util.Map;
030:
031: public class AntBuildWriter extends FileWriter {
032:
033: private String databindingFramework = ConfigPropertyFileLoader
034: .getDefaultDBFrameworkName();
035:
036: public AntBuildWriter(String outputFileLocation) {
037: this .outputFileLocation = new File(outputFileLocation);
038: }
039:
040: public AntBuildWriter(File outputFileLocation, String language) {
041: this .outputFileLocation = outputFileLocation;
042: this .language = language;
043: }
044:
045: public void setDatabindingFramework(String databindingFramework) {
046: this .databindingFramework = databindingFramework;
047: }
048:
049: public void createOutFile(String packageName, String fileName)
050: throws Exception {
051: outputFile = org.apache.axis2.util.FileWriter.createClassFile(
052: outputFileLocation, "", "build", ".xml");
053: //set the existing flag
054: fileExists = outputFile.exists();
055: if (!fileExists) {
056: this .stream = new FileOutputStream(outputFile);
057: }
058: }
059:
060: //overridden to get the correct behavior
061: protected String findTemplate(Map languageSpecificPropertyMap) {
062: String ownClazzName = this .getClass().getName();
063: String key;
064: String propertyValue;
065: String templateName = null;
066: Iterator keys = languageSpecificPropertyMap.keySet().iterator();
067:
068: while (keys.hasNext()) {
069: //check for template entries
070: key = keys.next().toString();
071: if (key.endsWith(TEMPLATE_SUFFIX)) {
072: // check if the class name is there
073: propertyValue = languageSpecificPropertyMap.get(key)
074: .toString();
075: if (propertyValue.startsWith(ownClazzName)) {
076: if (key.indexOf(databindingFramework) != -1) {
077: templateName = propertyValue
078: .substring(propertyValue
079: .indexOf(SEPARATOR_STRING) + 1);
080: break;
081: }
082: }
083: }
084:
085: }
086:
087: return templateName;
088: }
089:
090: /**
091: * Writes the output file.
092: *
093: * @param doc
094: * @throws Exception
095: */
096: public void parse(Document doc, URIResolver resolver)
097: throws Exception {
098: if (!fileExists) {
099: XSLTTemplateProcessor.parse(this.stream, doc,
100: this.xsltStream, resolver);
101: this.stream.flush();
102: this.stream.close();
103: }
104: }
105: }
|