码迷,mamicode.com
首页 > 其他好文 > 详细

6.4 xml part4

时间:2014-06-05 15:00:53      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

1.DiagramModel

bubuko.com,布布扣
注意:是继承自AbstractModel功能:监听)
public class DiagramModel extends AbstractModel {
bubuko.com,布布扣
bubuko.com,布布扣
public DiagramModel() {
        super();        
        name="";        
        initModel();  见下面:
    }
bubuko.com,布布扣
bubuko.com,布布扣
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。??
bubuko.com,布布扣

1.1 doSaveXML()

bubuko.com,布布扣
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();
        }
    }
bubuko.com,布布扣

1.1.1  addDiagramAttribute(ModelType.ATR_NAME, name);

bubuko.com,布布扣
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);
        }
    }
bubuko.com,布布扣

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了。

bubuko.com,布布扣
public abstract class PortElementModel extends ElementModel {
bubuko.com,布布扣
bubuko.com,布布扣
定义一些属性:
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"), };
bubuko.com,布布扣
bubuko.com,布布扣
初始化:
public
PortElementModel(String label, String modelID, Dimension size) { super(label, modelID, size); // TODO Auto-generated constructor stub name=""; type=""; }
bubuko.com,布布扣
bubuko.com,布布扣
保存:
public
void doSaveXML() { // TODO Auto-generated method stub super.doSaveXML(); this.addXMLElementAttribute(ModelType.ELE_NAME, name); this.addXMLElementAttribute(ModelType.ELE_TYPE, type); }
bubuko.com,布布扣

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

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

1.2 DiagramModel中定义的变量

bubuko.com,布布扣
    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()
bubuko.com,布布扣
public ComponentInstanceModel getComponent() {
        return component;
    }
public void setComponent(ComponentInstanceModel component) {
        this.component = component;
    }
bubuko.com,布布扣
private DiagramHeadingModel diagramHead;     doSaveXML()
bubuko.com,布布扣
public void setDiagramHead(DiagramHeadingModel diagramHead) {
        this.diagramHead = diagramHead;
    }
public DiagramHeadingModel getDiagramHead() {
        return diagramHead;
    }
bubuko.com,布布扣
 private String name; 
bubuko.com,布布扣
public String getName() {
        return name;
    }
public void setName(String name) {
        this.name = name;
    }
bubuko.com,布布扣
 private Document diagramDoc; 
bubuko.com,布布扣
public void setDiagramDoc(Document diagramDoc) {
        this.diagramDoc = diagramDoc;
    }

public Document getDiagramDoc() {
        return diagramDoc;
    }
bubuko.com,布布扣
 private Element rootElement,diagramElement,diagramExElement;
bubuko.com,布布扣
public void setDiagramElement(Element diagramElement) {
        this.diagramElement = diagramElement;
    }
public Element getDiagramElement() {
        return diagramElement;
    }
bubuko.com,布布扣
bubuko.com,布布扣
public void setDiagramExElement(Element diagramExElement) {
        this.diagramExElement = diagramExElement;
    }
public Element getDiagramExElement() {
        return diagramExElement;
    }
bubuko.com,布布扣
bubuko.com,布布扣
public void setRootElement(Element rootElement) {
        this.rootElement = rootElement;
    }
public Element getRootElement() {
        return rootElement;
    }
bubuko.com,布布扣

 

bubuko.com,布布扣

 

  

  

  

  

  

  

6.4 xml part4,布布扣,bubuko.com

6.4 xml part4

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/liyuhui20093357/p/3768944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!