View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   
8   package net.kwfgrid.gworkflowdl.structure;
9   
10  import org.jdom.Attribute;
11  import org.jdom.Element;
12  
13  /***
14   * User: hans
15   * Date: 05.04.2006
16   * Time: 13:02:10
17   */
18  public class OperationCandidateJdom {
19      private OperationCandidateJdom() {
20      }
21  
22      public static Element java2element(OperationCandidate clo) {
23          final Element cloe = new Element("operationCandidate", JdomString.ocSpace);
24  
25          // attribute type
26          final String type = clo.getType();
27          if (type != OperationCandidate.DEFAULT_TYPE) {
28              cloe.setAttribute("type", type);
29          }
30  
31          // attribute operationName
32          final String operationName = clo.getOperationName();
33          if (operationName != OperationCandidate.DEFAULT_OPERATIONNAME) {
34              cloe.setAttribute("operationName", operationName);
35          }
36  
37          // attribute resourceName
38          final String resourceName = clo.getResourceName();
39          if (resourceName != OperationCandidate.DEFAULT_RESOURCENAME) {
40              cloe.setAttribute("resourceName", resourceName);
41          }
42  
43          // attribute quality
44          cloe.setAttribute("quality", Float.toString(clo.getQuality()));
45  
46          // attribute selected
47          if (clo.isSelected()) {
48              cloe.setAttribute("selected", "true");
49          } else {
50              //pexe.setAttribute("selected", "false");
51          }
52  
53          // elements <owl>
54          OwlsJdom.java2ocElement(clo,cloe);
55  
56          return cloe;
57      }
58  
59      public static OperationCandidate element2java(Element cloe) {
60          final OperationCandidate clo = Factory.newOperationCandidate();
61  
62          // attribute type
63          final Attribute type = cloe.getAttribute("type");
64          if (type != null) {
65              clo.setType(type.getValue());
66          }
67  
68          // attribute operationName
69          final Attribute operationName = cloe.getAttribute("operationName");
70          if (operationName != null) {
71              clo.setOperationName(operationName.getValue());
72          }
73  
74          // attribute resourceName
75          final Attribute resourceName = cloe.getAttribute("resourceName");
76          if (resourceName != null) {
77              clo.setResourceName(resourceName.getValue());
78          }
79  
80          // attribute quality
81          final Attribute qual = cloe.getAttribute("quality");
82          if (qual != null) {
83              clo.setQuality(Float.valueOf(qual.getValue()));
84          }
85  
86          // attribute selected
87          final Attribute att = cloe.getAttribute("selected");
88          if (att != null) {
89              final String s = att.getValue();
90              clo.setSelected("true".equals(s));
91          }
92  
93          // elements <owl>
94          OwlsJdom.ocElement2java(cloe,clo);
95  
96          return clo;
97      }
98  }
99