Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
ohair@286 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.tools.internal.jxc; |
ohair@286 | 27 | |
ohair@286 | 28 | import java.io.File; |
ohair@286 | 29 | import java.util.ArrayList; |
ohair@286 | 30 | import java.util.List; |
ohair@286 | 31 | import java.util.regex.Pattern; |
ohair@286 | 32 | |
ohair@286 | 33 | import com.sun.tools.internal.jxc.gen.config.NGCCRuntime; |
ohair@286 | 34 | |
ohair@286 | 35 | import org.xml.sax.ErrorHandler; |
ohair@286 | 36 | import org.xml.sax.SAXException; |
ohair@286 | 37 | import org.xml.sax.SAXParseException; |
ohair@286 | 38 | |
ohair@286 | 39 | |
ohair@286 | 40 | /** |
ohair@286 | 41 | * Controls the validating and converting of values obtained |
ohair@286 | 42 | * from the config file. |
ohair@286 | 43 | * |
ohair@286 | 44 | * @author |
ohair@286 | 45 | * Bhakti Mehta (bhakti.mehta@sun.com) |
ohair@286 | 46 | */ |
ohair@286 | 47 | public final class NGCCRuntimeEx extends NGCCRuntime { |
ohair@286 | 48 | /** |
ohair@286 | 49 | * All the errors shall be sent to this object. |
ohair@286 | 50 | */ |
ohair@286 | 51 | private final ErrorHandler errorHandler; |
ohair@286 | 52 | |
ohair@286 | 53 | public NGCCRuntimeEx(ErrorHandler errorHandler) { |
ohair@286 | 54 | this.errorHandler = errorHandler; |
ohair@286 | 55 | } |
ohair@286 | 56 | |
ohair@286 | 57 | /** |
ohair@286 | 58 | * This will check if the baseDir provided by the user |
ohair@286 | 59 | * in the config file exists. If not it throws an error |
ohair@286 | 60 | * @param baseDir |
ohair@286 | 61 | * The baseDir attribute passed by the user in the xml config file as a path |
ohair@286 | 62 | * @return |
ohair@286 | 63 | * The file representation of the path name |
ohair@286 | 64 | */ |
ohair@286 | 65 | public File getBaseDir(String baseDir) throws SAXException { |
ohair@286 | 66 | File dir = new File(baseDir); |
ohair@286 | 67 | if (dir.exists()) { |
ohair@286 | 68 | return dir; |
ohair@286 | 69 | } else { |
ohair@286 | 70 | SAXParseException e = new SAXParseException( |
ohair@286 | 71 | Messages.BASEDIR_DOESNT_EXIST.format(dir.getAbsolutePath()), |
ohair@286 | 72 | getLocator()); |
ohair@286 | 73 | errorHandler.error(e); |
ohair@286 | 74 | throw e; // we can't recover from this error |
ohair@286 | 75 | } |
ohair@286 | 76 | } |
ohair@286 | 77 | |
ohair@286 | 78 | /** |
ohair@286 | 79 | * This takes the include list provided by the user in the config file |
ohair@286 | 80 | * It converts the user values to {@link Pattern} |
ohair@286 | 81 | * @param includeContent |
ohair@286 | 82 | * The include list specified by the user |
ohair@286 | 83 | * @return |
ohair@286 | 84 | * A list of regular expression patterns {@link Pattern} |
ohair@286 | 85 | */ |
alanb@368 | 86 | public List<Pattern> getIncludePatterns(List<String> includeContent ) { |
ohair@286 | 87 | List<Pattern> includeRegexList = new ArrayList<Pattern>(); |
alanb@368 | 88 | for (String includes : includeContent) { |
ohair@286 | 89 | String regex = convertToRegex(includes); |
ohair@286 | 90 | Pattern pattern = Pattern.compile(regex); |
ohair@286 | 91 | includeRegexList.add(pattern); |
ohair@286 | 92 | } |
ohair@286 | 93 | return includeRegexList; |
ohair@286 | 94 | } |
ohair@286 | 95 | |
ohair@286 | 96 | |
ohair@286 | 97 | /** |
ohair@286 | 98 | * This takes the exclude list provided by the user in the config file |
ohair@286 | 99 | * It converts the user values to {@link Pattern} |
ohair@286 | 100 | * @param excludeContent |
ohair@286 | 101 | * The exclude list specified by the user |
ohair@286 | 102 | * @return |
ohair@286 | 103 | * A list of regular expression patterns {@link Pattern} |
ohair@286 | 104 | */ |
alanb@368 | 105 | public List getExcludePatterns(List<String> excludeContent ) { |
alanb@368 | 106 | List<Pattern> excludeRegexList = new ArrayList<Pattern>(); |
alanb@368 | 107 | for (String excludes : excludeContent) { |
ohair@286 | 108 | String regex = convertToRegex(excludes); |
ohair@286 | 109 | Pattern pattern = Pattern.compile(regex); |
ohair@286 | 110 | excludeRegexList.add(pattern); |
ohair@286 | 111 | } |
ohair@286 | 112 | return excludeRegexList; |
ohair@286 | 113 | } |
ohair@286 | 114 | |
ohair@286 | 115 | |
ohair@286 | 116 | /** |
ohair@286 | 117 | * This will tokenize the pattern and convert it into a regular expression |
ohair@286 | 118 | * @param pattern |
ohair@286 | 119 | */ |
ohair@286 | 120 | private String convertToRegex(String pattern) { |
ohair@286 | 121 | StringBuilder regex = new StringBuilder(); |
ohair@286 | 122 | char nc = ' '; |
ohair@286 | 123 | if (pattern.length() >0 ) { |
ohair@286 | 124 | |
ohair@286 | 125 | for ( int i = 0 ; i < pattern.length(); i ++ ) { |
ohair@286 | 126 | char c = pattern.charAt(i); |
ohair@286 | 127 | nc = ' '; |
alanb@368 | 128 | if ((i +1) != pattern.length()) { |
alanb@368 | 129 | nc = pattern.charAt(i +1); |
ohair@286 | 130 | } |
ohair@286 | 131 | //escape single '.' |
alanb@368 | 132 | if (c == '.' && nc != '.'){ |
ohair@286 | 133 | regex.append('\\'); |
ohair@286 | 134 | regex.append('.'); |
ohair@286 | 135 | //do not allow patterns like a..b |
alanb@368 | 136 | } else if (c == '.'){ |
ohair@286 | 137 | continue; |
ohair@286 | 138 | // "**" gets replaced by ".*" |
ohair@286 | 139 | } else if ((c=='*') && (nc == '*')) { |
ohair@286 | 140 | regex.append(".*"); |
ohair@286 | 141 | break; |
ohair@286 | 142 | //'*' replaced by anything but '.' i.e [^\\.]+ |
ohair@286 | 143 | } else if (c=='*') { |
ohair@286 | 144 | regex.append("[^\\.]+"); |
ohair@286 | 145 | continue; |
ohair@286 | 146 | //'?' replaced by anything but '.' i.e [^\\.] |
ohair@286 | 147 | } else if (c=='?') { |
ohair@286 | 148 | regex.append("[^\\.]"); |
ohair@286 | 149 | //else leave the chars as they occur in the pattern |
ohair@286 | 150 | } else |
ohair@286 | 151 | regex.append(c); |
ohair@286 | 152 | } |
ohair@286 | 153 | |
ohair@286 | 154 | } |
ohair@286 | 155 | |
ohair@286 | 156 | return regex.toString(); |
ohair@286 | 157 | } |
ohair@286 | 158 | |
ohair@286 | 159 | protected void unexpectedX(String token) throws SAXException { |
ohair@286 | 160 | errorHandler.error( |
ohair@286 | 161 | new SAXParseException(Messages.UNEXPECTED_NGCC_TOKEN.format( |
ohair@286 | 162 | token, getLocator().getLineNumber(), getLocator().getColumnNumber()), |
ohair@286 | 163 | getLocator())); |
ohair@286 | 164 | } |
ohair@286 | 165 | } |