Beispiel #1
0
 public virtual T Create(InvocationHandler handler)
 {
     try
     {
         return(Constructor.newInstance(handler));
     }
     catch (Exception e)
     {
         throw new LinkageError("Failed to create proxy instance", e);
     }
 }
Beispiel #2
0
        protected internal static T generateException <T>(Type exceptionClass, string message, string variableName, string description) where T : org.camunda.bpm.engine.ProcessEngineException
        {
            exceptionClass = typeof(T);
            string formattedMessage = formatMessage(message, variableName, description);

            try
            {
                System.Reflection.ConstructorInfo <T> constructor = exceptionClass.GetConstructor(typeof(string));

                return(constructor.newInstance(formattedMessage));
            }
            catch (Exception e)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw LOG.exceptionWhileInstantiatingClass(exceptionClass.FullName, e);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Create an ExpressionFactory instance.
        /// </summary>
        /// <param name="properties">
        ///            Properties passed to the constructor of the implementation. </param>
        /// <returns> an instance of ExpressionFactory </returns>
        /// <param name="className">
        ///            The name of the ExpressionFactory class. </param>
        /// <param name="classLoader">
        ///            The class loader to be used to load the class. </param>
        /// <returns> An instance of ExpressionFactory. </returns>
        /// <exception cref="ELException">
        ///             if the class could not be found or if it is not a subclass of ExpressionFactory
        ///             or if the class could not be instantiated. </exception>
        private static ExpressionFactory newInstance(Properties properties, string className, ClassLoader classLoader)
        {
            Type clazz = null;

            try
            {
                clazz = classLoader.loadClass(className.Trim());
                if (!clazz.IsAssignableFrom(typeof(ExpressionFactory)))
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new ELException("Invalid expression factory class: " + clazz.FullName);
                }
            }
            catch (ClassNotFoundException e)
            {
                throw new ELException("Could not find expression factory class", e);
            }
            try
            {
                if (properties != null)
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Constructor<?> constructor = null;
                    System.Reflection.ConstructorInfo <object> constructor = null;
                    try
                    {
                        constructor = clazz.GetConstructor(typeof(Properties));
                    }
                    catch (Exception)
                    {
                        // do nothing
                    }
                    if (constructor != null)
                    {
                        return((ExpressionFactory)constructor.newInstance(properties));
                    }
                }
                return((ExpressionFactory)System.Activator.CreateInstance(clazz));
            }
            catch (Exception e)
            {
                throw new ELException("Could not create expression factory instance", e);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance of a class within one of the plug-ins
        /// </summary>
        /// <param name="classname"> The fully qualified name of the desired class </param>
        /// <param name="argTypes"> An array of classes (fully qualified name) that specify the arguments to the constructor </param>
        /// <param name="args"> An array of objects that will be the actual parameters to the constructor (the type should corresponds to the argTypes). </param>
        /// <returns> a reference to the created instance. </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object newInstance(String classname, Class[] argTypes, Object[] args) throws org.maltparser.core.exception.MaltChainedException
        public virtual object newInstance(string classname, Type[] argTypes, object[] args)
        {
            try
            {
                if (jarLoader == null)
                {
                    return(null);
                }
                Type   clazz = jarLoader.getClass(classname);
                object o     = null;
                if (clazz == null)
                {
                    return(null);
                }
                if (argTypes != null)
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Constructor<?> constructor = clazz.getConstructor(argTypes);
                    System.Reflection.ConstructorInfo <object> constructor = clazz.GetConstructor(argTypes);
                    o = constructor.newInstance(args);
                }
                else
                {
                    o = Activator.CreateInstance(clazz);
                }
                return(o);
            }
            catch (NoSuchMethodException e)
            {
                throw new PluginException("The plugin loader was not able to create an instance of the class '" + classname + "'. ", e);
            }
            catch (InstantiationException e)
            {
                throw new PluginException("The plugin loader was not able to create an instance of the class '" + classname + "'. ", e);
            }
            catch (IllegalAccessException e)
            {
                throw new PluginException("The plugin loader was not able to create an instance of the class '" + classname + "'. ", e);
            }
            catch (InvocationTargetException e)
            {
                throw new PluginException("The plugin loader was not able to create an instance of the class '" + classname + "'. ", e);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Create the factory's builder. This implementation takes the
        /// <code>de.odysseus.el.tree.TreeBuilder</code> property as a name of a class implementing the
        /// <code>de.odysseus.el.tree.TreeBuilder</code> interface. If the property is not set, a plain
        /// <code>de.odysseus.el.tree.impl.Builder</code> is used. If the configured class is a subclass
        /// of <code>de.odysseus.el.tree.impl.Builder</code> and which provides a constructor taking an
        /// array of <code>Builder.Feature</code>, this constructor will be invoked. Otherwise, the
        /// default constructor will be used.
        /// </summary>
        protected internal virtual TreeBuilder createTreeBuilder(Properties properties, params Feature[] features)
        {
            Type clazz = load(typeof(TreeBuilder), properties);

            if (clazz == null)
            {
                return(new Builder(features));
            }
            try
            {
                if (clazz.IsAssignableFrom(typeof(Builder)))
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Constructor<?> constructor = clazz.getConstructor(org.camunda.bpm.engine.impl.juel.Builder.Feature[].class);
                    System.Reflection.ConstructorInfo <object> constructor = clazz.GetConstructor(typeof(Feature[]));
                    if (constructor == null)
                    {
                        if (features == null || features.Length == 0)
                        {
                            return(typeof(TreeBuilder).cast(System.Activator.CreateInstance(clazz)));
                        }
                        else
                        {
                            throw new ELException("Builder " + clazz + " is missing constructor (can't pass features)");
                        }
                    }
                    else
                    {
                        return(typeof(TreeBuilder).cast(constructor.newInstance((object)features)));
                    }
                }
                else
                {
                    return(typeof(TreeBuilder).cast(System.Activator.CreateInstance(clazz)));
                }
            }
            catch (Exception e)
            {
                throw new ELException("TreeBuilder " + clazz + " could not be instantiated", e);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Create a new instance of the provided type
        /// </summary>
        /// <param name="type"> the class to create a new instance of </param>
        /// <param name="parameters"> the parameters to pass to the constructor </param>
        /// <returns> the created instance </returns>
        public static T createInstance <T>(Type type, params object[] parameters)
        {
            type = typeof(T);

            // get types for parameters
            Type[] parameterTypes = new Type[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                object parameter = parameters[i];
                parameterTypes[i] = parameter.GetType();
            }

            try
            {
                // create instance
                System.Reflection.ConstructorInfo <T> constructor = type.GetConstructor(parameterTypes);
                return(constructor.newInstance(parameters));
            }
            catch (Exception e)
            {
                throw new ModelException("Exception while creating an instance of type " + type, e);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Constructs an atomic model.
        /// </summary>
        /// <param name="index"> the index of the atomic model (-1..n), where -1 is special value (used by a single model
        /// or the master divide model) and n is number of divide models. </param>
        /// <param name="parent"> the parent guide model. </param>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public AtomicModel(int index, org.maltparser.parser.guide.Model parent) throws org.maltparser.core.exception.MaltChainedException
        public AtomicModel(int index, Model parent)
        {
            this.parent = parent;
            this.index  = index;
            if (index == -1)
            {
                modelName = parent.ModelName + ".";
            }
            else
            {
                modelName = parent.ModelName + "." + (new Formatter()).format("%03d", index) + ".";
            }
            //		this.featureVector = featureVector;
            frequency = 0;
            int?learnerMode = null;

            if (Guide.GuideMode == ClassifierGuide_GuideMode.CLASSIFY)
            {
                learnerMode = LearningMethod_Fields.CLASSIFY;
            }
            else if (Guide.GuideMode == ClassifierGuide_GuideMode.BATCH)
            {
                learnerMode = LearningMethod_Fields.BATCH;
            }

            // start init learning method
            Type clazz = (Type)Guide.Configuration.getOptionValue("guide", "learner");

            if (clazz == typeof(LibSvm))
            {
                method = new LibSvm(this, learnerMode);
            }
            else if (clazz == typeof(LibLinear))
            {
                method = new LibLinear(this, learnerMode);
            }
            else
            {
                object[] arguments = new object[] { this, learnerMode };
                try
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Constructor<?> constructor = clazz.getConstructor(argTypes);
                    System.Reflection.ConstructorInfo <object> constructor = clazz.GetConstructor(argTypes);
                    method = (LearningMethod)constructor.newInstance(arguments);
                }
                catch (NoSuchMethodException e)
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new GuideException("The learner class '" + clazz.FullName + "' cannot be initialized. ", e);
                }
                catch (InstantiationException e)
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new GuideException("The learner class '" + clazz.FullName + "' cannot be initialized. ", e);
                }
                catch (IllegalAccessException e)
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new GuideException("The learner class '" + clazz.FullName + "' cannot be initialized. ", e);
                }
                catch (InvocationTargetException e)
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new GuideException("The learner class '" + clazz.FullName + "' cannot be initialized. ", e);
                }
            }
            // end init learning method

            if (learnerMode.Value == LearningMethod_Fields.BATCH && index == -1 && Guide.Configuration != null)
            {
                Guide.Configuration.writeInfoToConfigFile(method.ToString());
            }
        }