English 中文(简体)
简单的XML(Java Lib)产生的原始格式
原标题:Pretty format of XML generated by Simple (Java Lib)

I am facing a problem regarding readability and cross-platform issues.

我们正在利用某些班级和子级,在飞机上制造我们的国歌。 例如,我将使用一些基本要素(而不是统一原则),但我认为“问题”应当显而易见。

我要求综合框架在简单(http://simple.sourceforge.net/home.php)上实现预期成果。 正如已经说过的那样,如果我只想把联阿特派团作为目标,那么它对于另一个平台的可读性,我将不关心十大运动的眼光和感觉。

So, in my example, I serialize a simple class, the result is:

<GuiElementExamples>
   <LastCreated>2012-04-15 16:48:59.813 CEST</LastCreated>
   <NonGuiObject>
      <objectBase class="objects.single.simple.StringObject" _value="">
         <_readonly>false</_readonly>
      </objectBase>
      <objectBase class="objects.single.simple.StringProperty">
         <_items>
            <object class="objects.single.simple.StringObject" _value="Label">
               <_readonly>true</_readonly>
            </object>
            <object class="objects.single.simple.StringObject" _value="">
               <_readonly>false</_readonly>
            </object>
         </_items>
         <_readonly>false</_readonly>
      </objectBase>
   </NonGuiObject>
</GuiElementExamples>

我所热心的是(我会以举手方式创建它),这就是:

<GuiElementExamples>
   <LastCreated>2012-04-15 16:48:59.813 CEST</LastCreated>
   <NonGuiObject>
      <StringObject _value="">
         <_readonly>false</_readonly>
      </StringObject>
      <StringProperty>
         <_items>
            <StringObject _value="Label">
               <_readonly>true</_readonly>
            </StringObject>
            <StringObject _value="">
               <_readonly>false</_readonly>
            </StringObject>
         </_items>
         <_readonly>false</_readonly>
      </StringProperty>
   </NonGuiObject>
</GuiElementExamples>

I KNOW将出现班级名称上的无分冲突,而我可以采用的一种选择是简单搜索和替换文字,但也许可以选择以上文所示的方式将“简单”混为一谈。

我知道,在不使用前面提到的文字的情况下,再也不能以上述格式来限制残疾人的地位,因为没有完全合格的班级名称,便可以知道什么是反对制造的。

Thanks for any help or workaround ideas, Chris

问题回答

Like always, after writing it, and going back to the docs, I found it :-)
It is the last entry on the tutorial page, in my example this does the trick:
EDIT This does not work with more then one element, dont ask me why EDIT

  @ElementListUnion({@ElementList(entry = "StringObject", type = StringObject.class)})
  private ArrayList<T> _items = new ArrayList<T>();

我所用的解决办法稍微复杂,但取得了一些成就。 我将在此请来文方向您指出正确的方向(标本是我想要“重新命名”上述方式的所有物体的基本类别):

public class FormatVisitor implements Visitor
{
    private static ILogger _logger = LogManager.GetLogger(FormatVisitor.class);
    @Override
    public void read(Type type, NodeMap<InputNode> strings) throws Exception
    {

    }

    public void write(Type type, NodeMap<OutputNode> node)
    {
        OutputNode element = node.getNode();


        Class javaType = type.getType();

        if (ObjectBase.class.isAssignableFrom(javaType))
        {
            _logger.Verbose("Old name was " + element.getName());
            element.setName(javaType.getSimpleName());
            _logger.Verbose("Changing name to " + javaType.getSimpleName());
        }

        try
        {
            String className =  element.getAttributes().get("class").getValue();
            Class localClass = Class.forName(className);
            boolean shouldShortenName = ObjectBase.class.isAssignableFrom(localClass);
            if (shouldShortenName)
            {
                element.getAttributes().remove("class");
                element.setName(localClass.getSimpleName());
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();  
        }


        if (ObjectBase.class.isAssignableFrom(javaType))
        {
            element.setName(type.getType().getSimpleName());
        }

    }


}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签