예제 #1
0
        private void OutputStatement(Statement exp, Object outer, bool isArgument)
        {
            Object target     = exp.Target;
            String methodName = exp.MethodName;

            if (target == null || methodName == null)
            {
                throw new NullPointerException((target == null ? "target" : "methodName") + " should not be null");
            }

            Object[] args       = exp.Arguments;
            bool     expression = exp.GetType() == typeof(Expression);
            Object   value      = (expression) ? GetValue((Expression)exp) : null;

            String    tag        = (expression && isArgument) ? "object" : "void";
            String    attributes = "";
            ValueData d          = GetValueData(value);

            // Special cases for targets.
            if (target == outer)
            {
            }
            else if (target == typeof(Array) && methodName.Equals("newInstance"))
            {
                tag        = "array";
                attributes = attributes + " class=" + Quote(((Class)args[0]).Name);
                attributes = attributes + " length=" + Quote(args[1].ToString());
                args       = new Object[] {};
            }
            else if (target.GetType() == typeof(Class))
            {
                attributes = attributes + " class=" + Quote(((Class)target).Name);
            }
            else
            {
                d.Refs = 2;
                if (d.Name == null)
                {
                    GetValueData(target).Refs++;
                    List <Statement> statements = StatementList(target);
                    if (!statements.Contains(exp))
                    {
                        statements.Add(exp);
                    }
                    OutputValue(target, outer, false);
                }
                if (expression)
                {
                    OutputValue(value, outer, isArgument);
                }
                return;
            }
            if (expression && (d.Refs > 1))
            {
                String instanceName = NameGenerator.InstanceName(value);
                d.Name     = instanceName;
                attributes = attributes + " id=" + Quote(instanceName);
            }

            // Special cases for methods.
            if ((!expression && methodName.Equals("set") && args.Length == 2 && args[0] is Integer) || (expression && methodName.Equals("get") && args.Length == 1 && args[0] is Integer))
            {
                attributes = attributes + " index=" + Quote(args[0].ToString());
                args       = (args.Length == 1) ? new Object[] {} : new Object[] { args[1] };
            }
            else if ((!expression && methodName.StartsWith("set") && args.Length == 1) || (expression && methodName.StartsWith("get") && args.Length == 0))
            {
                if (3 < methodName.Length())
                {
                    attributes = attributes + " property=" + Quote(Introspector.Decapitalize(methodName.Substring(3)));
                }
            }
            else if (!methodName.Equals("new") && !methodName.Equals("newInstance"))
            {
                attributes = attributes + " method=" + Quote(methodName);
            }
            OutputXML(tag, attributes, value, args);
        }