|
From: <sta...@us...> - 2007-05-06 09:49:29
|
Revision: 187
http://jsmiparser.svn.sourceforge.net/jsmiparser/?rev=187&view=rev
Author: stappend
Date: 2007-05-06 02:49:24 -0700 (Sun, 06 May 2007)
Log Message:
-----------
Removed the FileParserOptions class, and replaced it with a simple List<URL> in the FileParserPhase.
Added several utility classes (ClassPathURLListFactory, FileURLListFactory) to easily create such a list.
Modified Paths:
--------------
trunk/jsmiparser-api/src/main/java/org/jsmiparser/parser/SmiDefaultParser.java
trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/Phase.java
trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserPhase.java
trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserProblemReporter.java
trunk/jsmiparser-api/src/test/java/org/jsmiparser/AbstractMibTestCase.java
trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/CyclicDepsTest.java
trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/SmiDefaultParserTest.java
Added Paths:
-----------
trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/
trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/AbstractURLListFactory.java
trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/ClassPathURLListFactory.java
trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/CompositeURLListFactory.java
trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/FileURLListFactory.java
trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/URLListFactory.java
Removed Paths:
-------------
trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserOptions.java
Modified: trunk/jsmiparser-api/src/main/java/org/jsmiparser/parser/SmiDefaultParser.java
===================================================================
--- trunk/jsmiparser-api/src/main/java/org/jsmiparser/parser/SmiDefaultParser.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/main/java/org/jsmiparser/parser/SmiDefaultParser.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -34,9 +34,9 @@
protected boolean m_failOnError = false;
protected ProblemEventHandler m_problemEventHandler;
protected ProblemReporterFactory m_problemReporterFactory;
- protected Phase m_fileParserPhase;
- protected Phase m_xRefPhase;
- protected Phase m_errorCheckPhase;
+ protected FileParserPhase m_fileParserPhase;
+ protected XRefPhase m_xRefPhase;
+ protected ErrorCheckPhase m_errorCheckPhase;
public SmiMib parse() throws SmiException {
SmiMib mib = new SmiMib(new SmiJavaCodeNamingStrategy("org.jsmiparser.mib")); // TODO
@@ -52,15 +52,15 @@
return mib;
}
- protected Phase createFileParserPhase() {
+ protected FileParserPhase createFileParserPhase() {
return new FileParserPhase(getProblemReporterFactory().create(FileParserProblemReporter.class));
}
- protected Phase createXRefPhase() {
+ protected XRefPhase createXRefPhase() {
return new XRefPhase(getProblemReporterFactory().create(XRefProblemReporter.class));
}
- private Phase createErrorCheckPhase() {
+ private ErrorCheckPhase createErrorCheckPhase() {
return new ErrorCheckPhase();
}
@@ -86,36 +86,36 @@
m_problemReporterFactory = problemReporterFactory;
}
- public Phase getFileParserPhase() {
+ public FileParserPhase getFileParserPhase() {
if (m_fileParserPhase == null) {
m_fileParserPhase = createFileParserPhase();
}
return m_fileParserPhase;
}
- public void setFileParserPhase(Phase fileParserPhase) {
+ public void setFileParserPhase(FileParserPhase fileParserPhase) {
m_fileParserPhase = fileParserPhase;
}
- public Phase getXRefPhase() {
+ public XRefPhase getXRefPhase() {
if (m_xRefPhase == null) {
m_xRefPhase = createXRefPhase();
}
return m_xRefPhase;
}
- public void setXRefPhase(Phase xrefPhase) {
+ public void setXRefPhase(XRefPhase xrefPhase) {
m_xRefPhase = xrefPhase;
}
- public Phase getErrorCheckPhase() {
+ public ErrorCheckPhase getErrorCheckPhase() {
if (m_errorCheckPhase == null) {
m_errorCheckPhase = createErrorCheckPhase();
}
return m_errorCheckPhase;
}
- public void setErrorCheckPhase(Phase errorCheckPhase) {
+ public void setErrorCheckPhase(ErrorCheckPhase errorCheckPhase) {
m_errorCheckPhase = errorCheckPhase;
}
Modified: trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/Phase.java
===================================================================
--- trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/Phase.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/Phase.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -20,7 +20,6 @@
public interface Phase {
- Object getOptions();
-
SmiMib process(SmiMib mib) throws SmiException;
+
}
Deleted: trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserOptions.java
===================================================================
--- trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserOptions.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserOptions.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -1,205 +0,0 @@
-/*
- * Copyright 2005 Davy Verstappen.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jsmiparser.phase.file;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedHashSet;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-import org.jsmiparser.util.TextUtil;
-
-public class FileParserOptions {
-
- private static final Logger m_log = Logger.getLogger(FileParserOptions.class);
-
- private Set<File> m_usedDirSet = new LinkedHashSet<File>();
- private Set<File> m_inputDirSet = new LinkedHashSet<File>();
-
- private Set<String> m_usedResourceSet = new LinkedHashSet<String>();
- private Set<String> m_inputResourceSet = new LinkedHashSet<String>();
-
- private Set<String> m_extensions = new LinkedHashSet<String>();
-
- public FileParserOptions() {
- m_extensions.add(".mib");
- m_extensions.add(".smi");
- m_extensions.add(".asn");
- }
-
- public Set<File> getUsedDirSet() {
- return m_usedDirSet;
- }
-
- public void setUsedDirSet(Set<File> usedDirSet) {
- m_usedDirSet = usedDirSet;
- }
-
- public Set<File> getInputDirSet() {
- return m_inputDirSet;
- }
-
- public void setInputDirSet(Set<File> inputDirSet) {
- m_inputDirSet = inputDirSet;
- }
-
- public Set<String> getUsedResourceSet() {
- return m_usedResourceSet;
- }
-
- public void setUsedResourceSet(Set<String> usedFileSet) {
- m_usedResourceSet = usedFileSet;
- }
-
- public Set<String> getInputResourceSet() {
- return m_inputResourceSet;
- }
-
- public void setInputResourceSet(Set<String> inputResourceSet) {
- m_inputResourceSet = inputResourceSet;
- }
-
- public void addFile(File file) {
- m_inputResourceSet.add(file.getAbsolutePath());
- }
-
- public void addResource(String path) {
- m_inputResourceSet.add(path);
- }
-
- public Set<String> getExtensions() {
- return m_extensions;
- }
-
- public void setExtensions(Set<String> extensions) {
- m_extensions = extensions;
- }
-
- public File findFile(final String moduleName) {
- boolean itf = false;
- if ("ITF-MIB".equals(moduleName)) {
- itf = true;
- }
-
- File result = findModuleFile(moduleName, null);
- if (result != null) {
- return result;
- }
-
- for (String ext : m_extensions) {
- result = findModuleFile(moduleName, ext);
- if (result != null) {
- return result;
- }
- }
-
- if (!moduleName.equals(moduleName.toLowerCase())) {
- result = findFile(moduleName.toLowerCase());
- if (result != null) {
- return result;
- }
- }
-
- if (moduleName.contains("-")) {
- result = findFile(moduleName.replace('-', '_'));
- if (result != null) {
- return result;
- }
-
- result = findFile(TextUtil.deleteChar(moduleName, '-'));
- if (result != null) {
- return result;
- }
- }
-
- if (moduleName.endsWith("-MIB") || moduleName.endsWith("-SMI")) {
- result = findFile(moduleName.substring(0, moduleName.length() - 4));
- if (result != null) {
- return result;
- }
- }
-
- if (itf) {
- m_log.debug("trying itf");
- }
- Properties props = getModuleFileNameProperties();
- if (props != null) {
- if (itf) {
- m_log.debug("found properties for itf");
- }
- String fileName = (String) props.get(moduleName);
- if (itf) {
- m_log.debug("itf fileName: " + fileName);
- }
- if (fileName != null) {
- result = doFindFile(fileName);
- if (result != null) {
- return result;
- }
- } else {
- m_log.debug(moduleName + " not found in properties file");
- }
- }
-
- return result;
- }
-
- private Properties getModuleFileNameProperties() {
- try {
- String fileName = System.getenv("MIBS_MODULE_FILE");
- if (fileName != null) {
- Properties p = new Properties();
- InputStream is = new BufferedInputStream(new FileInputStream(fileName));
- p.load(is);
- //m_log.debug("properties file size: " + p.size());
- is.close();
- return p;
- } else {
- m_log.debug("MIBS_MODULE_FILE not set");
- }
- return null;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private File findModuleFile(final String moduleName, final String extension) {
- String fileName = moduleName;
- if (extension != null) {
- fileName += extension;
- }
-
- return doFindFile(fileName);
- }
-
- private File doFindFile(String fileName) {
- for (File dir : m_usedDirSet) {
- File file = new File(dir, fileName);
- if (file.exists()) {
- return file;
- } else {
- //m_log.debug(file.getPath() + " does not exist.");
- }
- }
-
- return null;
- }
-}
Modified: trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserPhase.java
===================================================================
--- trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserPhase.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserPhase.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -18,8 +18,8 @@
import antlr.RecognitionException;
import antlr.TokenStreamException;
import org.apache.log4j.Logger;
+import org.jsmiparser.exception.SmiException;
import org.jsmiparser.phase.Phase;
-import org.jsmiparser.exception.SmiException;
import org.jsmiparser.phase.file.antlr.SMILexer;
import org.jsmiparser.phase.file.antlr.SMIParser;
import org.jsmiparser.smi.SmiMib;
@@ -28,11 +28,10 @@
import org.jsmiparser.util.location.Location;
import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
import java.util.Set;
// TODO allow any URL's
@@ -42,8 +41,9 @@
private static final Logger m_log = Logger.getLogger(FileParserPhase.class);
private FileParserProblemReporter m_reporter;
- private FileParserOptions m_options = new FileParserOptions();
+ private List<URL> m_inputUrls;
+
public FileParserPhase(FileParserProblemReporter reporter) {
m_reporter = reporter;
}
@@ -52,9 +52,17 @@
return m_reporter;
}
+ public List<URL> getInputUrls() {
+ return m_inputUrls;
+ }
+
+ public void setInputUrls(List<URL> inputUrls) {
+ m_inputUrls = inputUrls;
+ }
+
public SmiMib process(SmiMib mib) throws SmiException {
- for (String resourceLocation : m_options.getInputResourceSet()) {
- parse(mib, resourceLocation);
+ for (URL url : getInputUrls()) {
+ parse(mib, url, determineResourceLocation(url));
}
if (m_log.isDebugEnabled()) {
@@ -64,24 +72,19 @@
return mib;
}
- public void parse(SmiMib mib, String resourceLocation) {
+ private String determineResourceLocation(URL url) {
+ if ("file".equals(url.getProtocol())) {
+ return "file://" + url.getPath();
+ }
+ return url.toString();
+ }
+
+ public void parse(SmiMib mib, URL url, String resourceLocation) {
InputStream is = null;
try {
- m_log.debug("Parsing :" + resourceLocation);
- // ResourceLocation could be either a classpath location or a file location
- // First try as a classpath location
- InputStream resourceStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceLocation);
- if (resourceStream == null) {
- // Attempt to interpret as a File
- File inputFile = null;
- try {
- inputFile = new File(resourceLocation);
- resourceStream = new FileInputStream(inputFile);
- } catch (FileNotFoundException e) {
- m_reporter.reportFileNotFound(inputFile);
- }
- }
- is = new BufferedInputStream(resourceStream);
+ m_log.debug("Parsing :" + url);
+ is = url.openStream();
+ is = new BufferedInputStream(is);
SMILexer lexer = new SMILexer(is);
SMIParser parser = new SMIParser(lexer);
@@ -98,6 +101,9 @@
} catch (RecognitionException e) {
m_log.debug(e.getMessage(), e);
m_reporter.reportParseError(new Location(resourceLocation, e.getLine(), e.getColumn()), e.getMessage());
+ } catch (IOException e) {
+ m_log.debug(e.getMessage(), e);
+ m_reporter.reportIoException(new Location(resourceLocation, 0, 0), e.getMessage());
} finally {
m_log.debug("Finished parsing :" + resourceLocation);
if (is != null) {
@@ -129,8 +135,8 @@
}
}
- public FileParserOptions getOptions() {
- return m_options;
- }
+// public FileParserOptions getOptions() {
+// return m_options;
+// }
}
Modified: trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserProblemReporter.java
===================================================================
--- trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserProblemReporter.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/main/java/org/jsmiparser/phase/file/FileParserProblemReporter.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -30,5 +30,8 @@
@ProblemMethod(message = "File not found: %s")
void reportFileNotFound(File file);
+
+ @ProblemMethod(message="IO error: %s")
+ void reportIoException(Location location, String message);
}
Modified: trunk/jsmiparser-api/src/test/java/org/jsmiparser/AbstractMibTestCase.java
===================================================================
--- trunk/jsmiparser-api/src/test/java/org/jsmiparser/AbstractMibTestCase.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/test/java/org/jsmiparser/AbstractMibTestCase.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -16,25 +16,25 @@
package org.jsmiparser;
import junit.framework.TestCase;
+import org.apache.log4j.Logger;
import org.jsmiparser.parser.SmiDefaultParser;
import org.jsmiparser.parser.SmiParser;
-import org.jsmiparser.phase.file.FileParserOptions;
import org.jsmiparser.smi.SmiConstants;
import org.jsmiparser.smi.SmiMib;
import org.jsmiparser.smi.SmiModule;
import org.jsmiparser.smi.SmiObjectType;
+import org.jsmiparser.smi.SmiOidNode;
import org.jsmiparser.smi.SmiOidValue;
import org.jsmiparser.smi.SmiPrimitiveType;
import org.jsmiparser.smi.SmiSymbol;
import org.jsmiparser.smi.SmiType;
import org.jsmiparser.smi.SmiVersion;
-import org.jsmiparser.smi.SmiOidNode;
-import org.apache.log4j.Logger;
+import org.jsmiparser.util.url.AbstractURLListFactory;
+import org.jsmiparser.util.url.ClassPathURLListFactory;
import org.springframework.util.StopWatch;
-import java.io.File;
-import java.net.URISyntaxException;
import java.net.URL;
+import java.util.List;
import java.util.Set;
public abstract class AbstractMibTestCase extends TestCase {
@@ -71,7 +71,7 @@
SmiMib mib = parser.parse();
stopWatch.stop();
m_log.info("Parsing time: " + stopWatch.getTotalTimeSeconds() + " s");
-
+
m_mib.set(mib);
m_testClass.set(getClass());
} catch (Exception e) {
@@ -82,36 +82,25 @@
}
protected SmiParser createParser() throws Exception {
- m_parser = new SmiDefaultParser();
- FileParserOptions options = (FileParserOptions) m_parser.getFileParserPhase().getOptions();
+ ClassPathURLListFactory urlListFactory = new ClassPathURLListFactory("libsmi-0.4.5/mibs/ietf/");
- URL mibsURL = getClass().getClassLoader().getResource("libsmi-0.4.5/mibs/ietf");
- File mibsDir = null;
- try {
- mibsDir = new File(mibsURL.toURI());
- } catch (URISyntaxException e) {
- fail(e.getMessage());
- }
-
if (m_version == null || m_version == SmiVersion.V1) {
- options.addFile(new File(mibsDir, "RFC1155-SMI"));
+ urlListFactory.add("RFC1155-SMI");
}
if (m_version == null || m_version == SmiVersion.V2) {
- options.addFile(new File(mibsDir, "SNMPv2-SMI"));
- options.addFile(new File(mibsDir, "SNMPv2-TC"));
- options.addFile(new File(mibsDir, "SNMPv2-CONF"));
- options.addFile(new File(mibsDir, "SNMPv2-MIB"));
+ urlListFactory.add("SNMPv2-SMI");
+ urlListFactory.add("SNMPv2-TC");
+ urlListFactory.add("SNMPv2-CONF");
+ urlListFactory.add("SNMPv2-MIB");
}
+ List<URL> urls = urlListFactory.create();
for (String resource : getResources()) {
- URL mibURL = getClass().getClassLoader().getResource(resource);
- try {
- File mibFile = new File(mibURL.toURI());
- options.addFile(mibFile);
- } catch (URISyntaxException e) {
- fail(e.getMessage());
- }
+ urls.add(getClass().getClassLoader().getResource(resource));
}
+
+ m_parser = new SmiDefaultParser();
+ m_parser.getFileParserPhase().setInputUrls(urls);
return m_parser;
}
Modified: trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/CyclicDepsTest.java
===================================================================
--- trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/CyclicDepsTest.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/CyclicDepsTest.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -1,14 +1,3 @@
-package org.jsmiparser.parser;
-
-import org.jsmiparser.phase.file.FileParserOptions;
-import org.jsmiparser.exception.SmiException;
-
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.io.File;
-
-import junit.framework.TestCase;
-
/*
* Copyright 2007 Davy Verstappen.
*
@@ -24,15 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.jsmiparser.parser;
+
+import junit.framework.TestCase;
+import org.jsmiparser.exception.SmiException;
+import org.jsmiparser.util.url.ClassPathURLListFactory;
+
+import java.net.URISyntaxException;
+
+
public class CyclicDepsTest extends TestCase {
public void testCyclicDeps() throws URISyntaxException {
- URL mibURL = getClass().getClassLoader().getResource("cyclic_deps.txt");
- File mibFile = new File(mibURL.toURI());
+ ClassPathURLListFactory urlListFactory = new ClassPathURLListFactory();
+ urlListFactory.add("cyclic_deps.txt");
SmiDefaultParser parser = new SmiDefaultParser();
- FileParserOptions options = (FileParserOptions) parser.getFileParserPhase().getOptions();
- options.addFile(mibFile);
+ parser.getFileParserPhase().setInputUrls(urlListFactory.create());
try {
parser.parse();
Modified: trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/SmiDefaultParserTest.java
===================================================================
--- trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/SmiDefaultParserTest.java 2007-05-01 11:03:10 UTC (rev 186)
+++ trunk/jsmiparser-api/src/test/java/org/jsmiparser/parser/SmiDefaultParserTest.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -16,8 +16,6 @@
package org.jsmiparser.parser;
import org.jsmiparser.AbstractMibTestCase;
-import org.jsmiparser.util.token.HexStringToken;
-import org.jsmiparser.phase.file.FileParserOptions;
import org.jsmiparser.smi.SmiConstants;
import org.jsmiparser.smi.SmiIndex;
import org.jsmiparser.smi.SmiMib;
@@ -26,6 +24,7 @@
import org.jsmiparser.smi.SmiOidValue;
import org.jsmiparser.smi.SmiPrimitiveType;
import org.jsmiparser.smi.SmiProtocolType;
+import org.jsmiparser.smi.SmiRange;
import org.jsmiparser.smi.SmiReferencedType;
import org.jsmiparser.smi.SmiRow;
import org.jsmiparser.smi.SmiSymbol;
@@ -34,14 +33,16 @@
import org.jsmiparser.smi.SmiType;
import org.jsmiparser.smi.SmiVarBindField;
import org.jsmiparser.smi.SmiVariable;
-import org.jsmiparser.smi.SmiRange;
+import org.jsmiparser.util.token.HexStringToken;
+import org.jsmiparser.util.url.FileURLListFactory;
import java.io.File;
+import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.math.BigInteger;
public class SmiDefaultParserTest extends AbstractMibTestCase {
@@ -55,8 +56,8 @@
File mibsDir = new File(mibsURL.toURI());
SmiDefaultParser parser = new SmiDefaultParser();
- FileParserOptions options = (FileParserOptions) parser.getFileParserPhase().getOptions();
- initFileParserOptions(options, mibsDir, "iana", "ietf", "site", "tubs");
+ List<URL> inputUrls = initFileParserOptions(mibsDir, "iana", "ietf", "site", "tubs");
+ parser.getFileParserPhase().setInputUrls(inputUrls);
return parser;
}
@@ -180,10 +181,10 @@
checkType(type.getBaseType());
} else if (type.getFields() == null && !(type instanceof SmiProtocolType)) {
assertTrue(type.getId(),
- type == SmiConstants.BITS_TYPE
- || type == SmiConstants.INTEGER_TYPE
- || type == SmiConstants.OBJECT_IDENTIFIER_TYPE
- || type == SmiConstants.OCTET_STRING_TYPE);
+ type == SmiConstants.BITS_TYPE
+ || type == SmiConstants.INTEGER_TYPE
+ || type == SmiConstants.OBJECT_IDENTIFIER_TYPE
+ || type == SmiConstants.OCTET_STRING_TYPE);
}
}
@@ -357,13 +358,15 @@
}
- private void initFileParserOptions(FileParserOptions options, File mibsDir, String... subDirNames) {
+ private List<URL> initFileParserOptions(File mibsDir, String... subDirNames) throws Exception {
+ List<URL> result = new ArrayList<URL>();
+
for (String subDirName : subDirNames) {
File dir = new File(mibsDir, subDirName);
assertTrue(dir.toString(), dir.exists());
assertTrue(dir.toString(), dir.isDirectory());
- options.getUsedDirSet().add(dir);
+ FileURLListFactory urlListFactory = new FileURLListFactory(dir);
File[] files = dir.listFiles();
for (File file : files) {
if (file.isFile()
@@ -374,10 +377,12 @@
&& !file.getName().endsWith("~")
//&& !v1mibs.contains(file.getName())
&& !file.getName().endsWith("-orig")) { // TODO parsing -orig should give more errors!
- options.addFile(file);
+ urlListFactory.add(file.getName());
}
}
+ result.addAll(urlListFactory.create());
}
+ return result;
}
Added: trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/AbstractURLListFactory.java
===================================================================
--- trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/AbstractURLListFactory.java (rev 0)
+++ trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/AbstractURLListFactory.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 Davy Verstappen.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jsmiparser.util.url;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public abstract class AbstractURLListFactory implements URLListFactory {
+
+ protected String m_rootPath;
+ protected List<String> m_children;
+
+ public AbstractURLListFactory() {
+ this("");
+ }
+
+ public AbstractURLListFactory(String rootPath) {
+ this(rootPath, new ArrayList<String>());
+ }
+
+ public AbstractURLListFactory(String rootPath, List<String> children) {
+ m_rootPath = rootPath;
+ m_children = children;
+ }
+
+ public String getRootPath() {
+ return m_rootPath;
+ }
+
+ public void setRootPath(String rootPath) {
+ m_rootPath = rootPath;
+ }
+
+ public List<String> getChildren() {
+ return m_children;
+ }
+
+ public void setChildren(List<String> children) {
+ m_children = children;
+ }
+
+ public void add(String child) {
+ getChildren().add(child);
+ }
+
+}
Added: trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/ClassPathURLListFactory.java
===================================================================
--- trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/ClassPathURLListFactory.java (rev 0)
+++ trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/ClassPathURLListFactory.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 Davy Verstappen.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jsmiparser.util.url;
+
+import java.net.URL;
+import java.util.List;
+import java.util.ArrayList;
+
+public class ClassPathURLListFactory extends AbstractURLListFactory {
+ protected ClassLoader m_classLoader;
+
+ public ClassPathURLListFactory() {
+ super();
+ }
+
+ public ClassPathURLListFactory(String rootPath) {
+ super(rootPath);
+ }
+
+ public ClassPathURLListFactory(String rootPath, List<String> children) {
+ super(rootPath, children);
+ }
+
+
+ public ClassLoader getClassLoader() {
+ if (m_classLoader != null) {
+ return m_classLoader;
+ }
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ m_classLoader = classLoader;
+ }
+
+ public List<URL> create() {
+ List<URL> result = new ArrayList<URL>();
+ for (String child : m_children) {
+ String path = getRootPath() + child; // explicitly no
+ URL url = getClassLoader().getResource(path);
+ if (url == null) {
+ throw new IllegalStateException("Classpath resource doesn't exist (perhaps you are missing a slash or have one too much at the beginning?): " + path);
+ }
+ result.add(url);
+ }
+ return result;
+ }
+}
Added: trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/CompositeURLListFactory.java
===================================================================
--- trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/CompositeURLListFactory.java (rev 0)
+++ trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/CompositeURLListFactory.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2007 Davy Verstappen.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jsmiparser.util.url;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class CompositeURLListFactory implements URLListFactory {
+
+ private List<URLListFactory> m_children;
+
+ public CompositeURLListFactory() {
+ this(new ArrayList<URLListFactory>());
+ }
+
+ public CompositeURLListFactory(List<URLListFactory> children) {
+ m_children = children;
+ }
+
+ public CompositeURLListFactory(URLListFactory... urlListFactories) {
+ this(Arrays.asList(urlListFactories));
+ }
+
+ public List<URLListFactory> getChildren() {
+ return m_children;
+ }
+
+ public void setChildren(List<URLListFactory> children) {
+ m_children = children;
+ }
+
+ public List<URL> create() throws Exception {
+ List<URL> result = new ArrayList<URL>();
+ for (URLListFactory child : m_children) {
+ result.addAll(child.create());
+ }
+ return result;
+ }
+}
Added: trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/FileURLListFactory.java
===================================================================
--- trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/FileURLListFactory.java (rev 0)
+++ trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/FileURLListFactory.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2007 Davy Verstappen.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jsmiparser.util.url;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.net.URL;
+import java.io.File;
+
+public class FileURLListFactory extends AbstractURLListFactory {
+
+ public FileURLListFactory() {
+ super();
+ }
+
+ public FileURLListFactory(File rootDir) {
+ this(rootDir.getAbsolutePath());
+ }
+
+ public FileURLListFactory(String rootPath) {
+ super(rootPath);
+ }
+
+ public FileURLListFactory(File rootDir, List<String> children) {
+ super(rootDir.getAbsolutePath(), children);
+ }
+
+ public FileURLListFactory(String rootPath, List<String> children) {
+ super(rootPath, children);
+ }
+
+
+ public List<URL> create() throws Exception {
+ List<URL> result = new ArrayList<URL>();
+ File dir = new File(m_rootPath);
+ for (String child : m_children) {
+ File file = new File(dir, child);
+ if (!file.exists()) {
+ throw new IllegalStateException("File doesn't exist: " + file);
+ }
+ result.add(file.toURL());
+ }
+ return result;
+ }
+}
Added: trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/URLListFactory.java
===================================================================
--- trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/URLListFactory.java (rev 0)
+++ trunk/jsmiparser-util/src/main/java/org/jsmiparser/util/url/URLListFactory.java 2007-05-06 09:49:24 UTC (rev 187)
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2007 Davy Verstappen.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jsmiparser.util.url;
+
+import java.net.URL;
+import java.util.List;
+
+/**
+ * Utility interface to create a List<URL> for input to the FileParserPhase of the jsmiparser.
+ */
+public interface URLListFactory {
+
+ /**
+ * @return The URL List.
+ */
+ List<URL> create() throws Exception;
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|