//	private final HashSet<SyntaxGraphReader> supportedReaders;
        //	private final HashSet<SyntaxGraphWriter> supportedWriters;

        public DataFormatSpecification()
        {
            entries = new LinkedHashMap <string, DataFormatEntry>();
            //		entryPositionCounter = 0;
            dependencies = new Helper.HashSet <Dependency>();
            //		supportedReaders = new HashSet<SyntaxGraphReader>();
            //		supportedWriters = new HashSet<SyntaxGraphWriter>();
        }
Пример #2
0
        /// <summary>
        /// Loads the content of a jar file that comply with a MaltParser Plugin
        /// </summary>
        /// <param name="jarUrl"> The URL to the jar file </param>
        /// <exception cref="PluginException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean readJarFile(java.net.URL jarUrl) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool readJarFile(URL jarUrl)
        {
            JarInputStream jis;
            JarEntry       je;
            ISet <URL>     pluginXMLs = new Helper.HashSet <URL>();

            /*if (logger.isDebugEnabled()) {
             *      logger.debug("Loading jar " + jarUrl+"\n");
             * }*/
            JarFile jarFile;

            try
            {
                jarFile = new JarFile(jarUrl.File);
            }
            catch (IOException e)
            {
                throw new PluginException("Could not open jar file " + jarUrl + ". ", e);
            }
            try
            {
                Manifest manifest = jarFile.Manifest;
                if (manifest != null)
                {
                    Attributes manifestAttributes = manifest.MainAttributes;
                    if (!(manifestAttributes.getValue("MaltParser-Plugin") != null && manifestAttributes.getValue("MaltParser-Plugin").Equals("true")))
                    {
                        return(false);
                    }
                    if (manifestAttributes.getValue("Class-Path") != null)
                    {
                        string[] classPathItems = manifestAttributes.getValue("Class-Path").Split(" ");
                        for (int i = 0; i < classPathItems.Length; i++)
                        {
                            URL u;
                            try
                            {
                                u = new URL(jarUrl.Protocol + ":" + (new File(jarFile.Name)).ParentFile.Path + "/" + classPathItems[i]);
                            }
                            catch (MalformedURLException e)
                            {
                                throw new PluginException("The URL to the plugin jar-class-path '" + jarUrl.Protocol + ":" + (new File(jarFile.Name)).ParentFile.Path + "/" + classPathItems[i] + "' is wrong. ", e);
                            }
                            URLClassLoader sysloader            = (URLClassLoader)ClassLoader.SystemClassLoader;
                            Type           sysclass             = typeof(URLClassLoader);
                            System.Reflection.MethodInfo method = sysclass.getDeclaredMethod("addURL", new Type[] { typeof(URL) });
                            method.Accessible = true;
                            method.invoke(sysloader, new object[] { u });
                        }
                    }
                }
            }
            catch (PatternSyntaxException e)
            {
                throw new PluginException("Could not split jar-class-path entries in the jar-file '" + jarFile.Name + "'. ", e);
            }
            catch (IOException e)
            {
                throw new PluginException("Could not read the manifest file in the jar-file '" + jarFile.Name + "'. ", e);
            }
            catch (NoSuchMethodException e)
            {
                throw new PluginException("", e);
            }
            catch (IllegalAccessException e)
            {
                throw new PluginException("", e);
            }
            catch (InvocationTargetException e)
            {
                throw new PluginException("", e);
            }

            try
            {
                jis = new JarInputStream(jarUrl.openConnection().InputStream);

                while ((je = jis.NextJarEntry) != null)
                {
                    string jarName = je.Name;
                    if (jarName.EndsWith(".class", StringComparison.Ordinal))
                    {
                        /* if (logger.isDebugEnabled()) {
                         *      logger.debug("  Loading class: " + jarName+"\n");
                         * }*/
                        loadClassBytes(jis, jarName);
                        Type clazz = findClass(jarName.Substring(0, jarName.Length - 6));
                        classes[jarName.Substring(0, jarName.Length - 6).Replace('/', '.')] = clazz;
                        loadClass(jarName.Substring(0, jarName.Length - 6).Replace('/', '.'));
                    }
                    if (jarName.EndsWith("plugin.xml", StringComparison.Ordinal))
                    {
                        pluginXMLs.Add(new URL("jar:" + jarUrl.Protocol + ":" + jarUrl.Path + "!/" + jarName));
                    }
                    jis.closeEntry();
                }
                foreach (URL url in pluginXMLs)
                {
                    /* if (logger.isDebugEnabled()) {
                     *      logger.debug("  Loading "+url+"\n");
                     * }*/
                    OptionManager.instance().loadOptionDescriptionFile(url);
                }
            }
            catch (MalformedURLException e)
            {
                throw new PluginException("The URL to the plugin.xml is wrong. ", e);
            }
            catch (IOException e)
            {
                throw new PluginException("cannot open jar file " + jarUrl + ". ", e);
            }
            catch (ClassNotFoundException e)
            {
                throw new PluginException("The class " + e.Message + " can't be found. ", e);
            }
            return(true);
        }