6.4 xml part4

1.DiagramModel


注意:是继承自AbstractModel(功能:监听)
public class DiagramModel extends AbstractModel {


public DiagramModel() {
super();
name="";
initModel(); 见下面:
}


public void initModel(){
setName("Diagram");
setDiagramDoc(DocumentHelper.createDocument()); 创建document
setRootElement(getDiagramDoc().addElement(ModelType.ELE_ROOT));
setDiagramElement(getRootElement().addElement(ModelType.ELE_DIAGRAM));
setDiagramExElement(getRootElement().addElement(ModelType.ELE_DIAGRAMEX));
}
添加根元素root,并且添加root的子元素diagram和diagramex。??

1.1 doSaveXML()


public void doSaveXML() {
// TODO Auto-generated method stub
this.addDiagramAttribute(ModelType.ATR_NAME, name); 先添加属性NAME和属性值name。

getDiagramHead().doSaveXML();
getComponent().doSaveXML();

for(int i=0;i<getPorts().size();i++){
((ElementModel)getPorts().get(i)).doSaveXML();
}

for(int i=0;i<getTexts().size();i++){
((ElementModel)getTexts().get(i)).doSaveXML();
}
}

1.1.1  addDiagramAttribute(ModelType.ATR_NAME, name);


protected void addDiagramAttribute(String name,String value){
if(getDiagramElement()==null){
return;
}
getDiagramElement().addAttribute(name, value);
}

protected void removeDiagramAttribute(String name){
if(getDiagramElement()==null){
return;
}
Attribute atr = getDiagramElement().attribute(name);
if(atr != null){
getDiagramElement().remove(atr);
}
}

1.1.2 getDiagramHead().doSaveXML();

?





1

2

3

public<span style="color: rgb(255, 0, 0);"> DiagramHeadingModel</span> getDiagramHead() {

        return
diagramHead;

    }

?





1

public class DiagramHeadingModel extends
ElementModel {

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

先定义一些属性,并且定义一个结构体

        private
String definition,myCtype,myReturn,mySystem,diagramType;

    private
boolean isRetShow,isSysShow,isRunsOnShow;

    public
static final String SELECT_DEF = "select_def";

    public
static final String SELECT_CTYPE = "select_ctype";

    public
static final String SELECT_RETURN = "select_return";

    public
static final String SELECT_SYSTEM = "select_system";

    public
static final String SELECT_DIAGRAM = "select_diagram";

    

    private
IPropertyDescriptor[] descriptor;

    private
List<IPropertyDescriptor> descriptorList = new
ArrayList<IPropertyDescriptor>();

    private
static final

    TextPropertyDescriptor definitionDescriptor = new
TextPropertyDescriptor(SELECT_DEF,"Definition");

    private
static final

    TextPropertyDescriptor ctypeDescriptor = new
TextPropertyDescriptor(SELECT_CTYPE,"runs On");

    private
static final

    TextPropertyDescriptor returnDescriptor = new
TextPropertyDescriptor(SELECT_RETURN,"return");

    private
static final

    TextPropertyDescriptor systemDescriptor = new
TextPropertyDescriptor(SELECT_SYSTEM,"system");

    private
static final

    PropertyDescriptor diagramDescriptor = new
PropertyDescriptor(SELECT_DIAGRAM,"Diagram Type");

    

    public
DiagramHeadingModel() {

        super(ConstantResourceFactory.LABEL_DIAGRAMHEAD_MODEL,

                ConstantResourceFactory.ID_DIAGRAMHEAD_MODEL,

                ConstantResourceFactory.SIZE_DIAGRAMHEAD);

        // TODO Auto-generated constructor stub

        definition="";

        myCtype="";

        myReturn="";

        mySystem="";

        diagramType="";

        isRetShow=false;

        isSysShow=false;

        isRunsOnShow=false;

    }

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

public IPropertyDescriptor[] getPropertyDescriptors() {

        // TODO Auto-generated method stub

        if(descriptor == null){

            descriptorList.add(definitionDescriptor);

            descriptorList.add(diagramDescriptor);

            if(isRunsOnShow()){

                descriptorList.add(ctypeDescriptor);

            }

            if(isRetShow()){

                descriptorList.add(returnDescriptor);

            }

            if(isSysShow()){

                descriptorList.add(systemDescriptor);

            }

            descriptor = (IPropertyDescriptor[]) descriptorList

                            .toArray(new
IPropertyDescriptor[1]);

        }          

        

        return
descriptor;

    }

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

<span style="color: rgb(255, 0, 0);">然后保存,过程就是两步:首先继承elementModel的dosaveXML,然后添加自己的属性。</span>

public void doSaveXML() {

        // TODO Auto-generated method stub

        super.doSaveXML();

        

        this.addXMLElementAttribute(ModelType.ATR_DIAGRAM,diagramType);

        this.addXMLElementAttribute(ModelType.ATR_DEFINITION,definition);

        if(isRunsOnShow()){

            this.addXMLElementAttribute(ModelType.ATR_RUNSON,myCtype);

        }

        else{

            this.removeXMLElementAttribute(ModelType.ATR_RUNSON);

        }

        

        if(isRetShow()){

            this.addXMLElementAttribute(ModelType.ATR_RETURN,myReturn);

        }

        else{

            this.removeXMLElementAttribute(ModelType.ATR_RETURN);

        }

        

        if(isSysShow()){

            this.addXMLElementAttribute(ModelType.ATR_SYSTEM,mySystem);

        }

        else{

            this.removeXMLElementAttribute(ModelType.ATR_SYSTEM);

        }

    }

1.1.3 getComponent().doSaveXML();

?





1

2

3

public <span style="color: rgb(255, 0, 0);">ComponentInstanceModel</span> getComponent() {

        return
component;

    }

?





1

2

3

4

5

6

7

8

9

10

11

public void doSaveXML() {

        // TODO Auto-generated method stub

        super.doSaveXML();     

        

        for(int
i=0;i<children.size();i++){

            <span style="background-color: rgb(0, 255, 0);">((ElementModel)children.get(i)).doSaveXML();</span>

        }

        

        if(tail!=null)

             tail.doSaveXML();

    }

1.1.4 ((ElementModel)getPorts().get(i)).doSaveXML();

到了最重要的portelementmodel了。


public abstract class PortElementModel extends ElementModel {


定义一些属性:
private static final
IPropertyDescriptor[] descriptorPort = new IPropertyDescriptor[]{
new PropertyDescriptor(SELECT_LABEL,"Model Label"),
new TextPropertyDescriptor(SELECT_NAME,"Port Name"),
new TextPropertyDescriptor(SELECT_TYPE,"Port Type"),
};


初始化:
public PortElementModel(String label, String modelID, Dimension size) {
super(label, modelID, size);
// TODO Auto-generated constructor stub
name="";
type="";
}


保存:
public void doSaveXML() {
// TODO Auto-generated method stub
super.doSaveXML();
this.addXMLElementAttribute(ModelType.ELE_NAME, name);
this.addXMLElementAttribute(ModelType.ELE_TYPE, type);
}

1.1.5 ((ElementModel)getTexts().get(i)).doSaveXML();


public abstract class LiteralElementModel extends ElementModel {
public void doSaveXML() {
// TODO Auto-generated method stub
super.doSaveXML();
}
}

1.2 DiagramModel中定义的变量


    private List<Object> children = new ArrayList<Object>();
private List<Object> ports = new ArrayList<Object>(); doSaveXML()
private List<Object> texts = new ArrayList<Object>(); doSaveXML()
private List<Object> containers = new ArrayList<Object>();
private List<Object> portOps = new ArrayList<Object>();
private List<Object> refers = new ArrayList<Object>();

private ComponentInstanceModel component; doSaveXML()


public ComponentInstanceModel getComponent() {
return component;
}
public void setComponent(ComponentInstanceModel component) {
this.component = component;
}

private DiagramHeadingModel diagramHead;     doSaveXML()


public void setDiagramHead(DiagramHeadingModel diagramHead) {
this.diagramHead = diagramHead;
}
public DiagramHeadingModel getDiagramHead() {
return diagramHead;
}

 private String name; 


public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

 private Document diagramDoc; 


public void setDiagramDoc(Document diagramDoc) {
this.diagramDoc = diagramDoc;
}

public Document getDiagramDoc() {
return diagramDoc;
}

 private Element rootElement,diagramElement,diagramExElement;


public void setDiagramElement(Element diagramElement) {
this.diagramElement = diagramElement;
}
public Element getDiagramElement() {
return diagramElement;
}


public void setDiagramExElement(Element diagramExElement) {
this.diagramExElement = diagramExElement;
}
public Element getDiagramExElement() {
return diagramExElement;
}


public void setRootElement(Element rootElement) {
this.rootElement = rootElement;
}
public Element getRootElement() {
return rootElement;
}

  

  

  

  

  

  

6.4 xml part4,布布扣,bubuko.com

时间: 2024-10-15 02:26:22

6.4 xml part4的相关文章

Maven中,pom.xml文件报错

一:错误消息,如下图: aus 原因是本地仓库在org.codehaus.plexus:plexus-uils:pom:3.0.20下面没有jar文件,只有一个plexus-utils-3.0.20.pom.lastUpdated,如下图: 解决:将该文件夹删掉,然后右击项目:Maven->Update Project就可以了 若pom.xml里面还有类型的报错,就像这样解决就OK了

微信5.4 AndroidManifest.xml

1 <?xml version="1.0" encoding="utf-8" ?> 2 - <manifest android:versionCode="462" android:versionName="5.4.0.48_r794734" android:installLocation="auto" package="com.tencent.mm" xmlns:and

C#中XML与对象之间的序列化、反序列化

using System; using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; namespace Xml.Utility { public static class XmlUtil { /// <summary> /// 将一个对象序列化为XML字符串 /// </summary> /// <param name="o">要序列化

logback-spring.xml的schema

<?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd"> </configuration>

Web.xml 中 metadata-complete 介绍

Servlet 3.0 的部署描述文件 web.xml 的顶层标签 <web-app> 有一个 metadata-complete 属性, 该属性指定当前的部署描述文件是否是完全的. 如果设置为 true,则容器在部署时将只依赖部署描述文件,忽略所有的注解(同时也会跳过 web-fragment.xml 的扫描,亦即禁用可插性支持,具体请看后文关于 可插性支持的讲解): 如果不配置该属性,或者将其设置为 false,则表示启用注解支持(和可插性支持).

关于java解析xml文件出现的问题

问题1:导入javax.xml.parsers.DocumentBuilderFactory出现问题,如图: 解决办法是:由于创建工程时有个默认的jre,重新创建工程改掉就解决了,如图: 问题2:出现1 字节的 UTF-8 序列的字节 1 无效,解决办法: 使用记事本打开xml文件--点击文件-另存为-修改编码方式为UTF-8 -覆盖保存,如图: 以后出现问题还会补充

XML

一.XML概述     定义:Extensible Makeup Language(可扩展标记语言);     作用:         1.存储数据,有良好的存储格式,多种语言通用         2.作为配置文件,许多框架都使用xml作为配置文件     语法:         1.文件后缀名必须为.xml;         2.文档声明必须写在第一行,且前面不能空格,一般写法:<?xml version="1.0" encoding="UTF-8"?>

Android 编译错误——布局 Error parsing XML: not well-formed (invalid token)

在修改了Android布局文件后,编译出现Error parsing XML: not well-formed (invalid token). 首先先排查xml文件的编码格式是否为UTF-8, <?xml version="1.0" encoding="utf-8"?> ,注意,从别处copy的要留意编码格式! 还有各个标签是否有遗漏,把鼠标箭头移到出错误的layout上 点击鼠标右键选择Source然后再选Format. 都没有问题,结果发现报错处(

MyBatis应用开发(2)应用之开发方式XML文件篇

1.1. 开发方法 有三种使用MyBatis的方法: (1)使用XML配置文件的方式. (2)使用注解方式. (3)使用API方式. 1.2. XML方式 1.2.1. 开发步骤 目标:使用MyBatis从数据库中查询t_person表的全部记录. MyBatis使用XML文件来配置数据库中的记录与Java对象之间的映射关系,实现了SQL语句和Java代码的分离. 使用MyBatis 的XML配置方式开发数据库应用的步骤如下所示: (1)编写POJO类Person. (2)编写Mapper接口P