View Javadoc

1   /*
2    * Copyright (c) 2008, the JUNG Project and the Regents of the University
3    * of California
4    * All rights reserved.
5    *
6    * This software is open-source under the BSD license; see either
7    * "license.txt" or
8    * http://jung.sourceforge.net/license.txt for a description.
9    */
10  
11  package edu.uci.ics.jung.io.graphml;
12  
13  import java.util.Map;
14  
15  /**
16   * GraphML key object that was parsed from the input stream.
17   *
18   * @author Nathan Mittler - nathan.mittler@gmail.com
19   */
20  public class Key {
21  
22      /**
23       * Enumeration for the 'for' type of this key.  The for property indicates 
24       * which elements (e.g. graph, node, edge) this key applies to.
25       */
26      public enum ForType {
27          ALL, GRAPH, NODE, EDGE, HYPEREDGE, PORT, ENDPOINT
28      }
29      
30      private String id;
31      private String description;
32      private String attributeName;
33      private String attributeType;
34      private String defaultValue;
35      private ForType forType = ForType.ALL;
36      
37      public String getDescription() {
38          return description;
39      }
40  
41      public void setDescription(String description) {
42          this.description = description;
43      }
44  
45      public String getAttributeName() {
46          return attributeName;
47      }
48  
49      public void setAttributeName(String attributeName) {
50          this.attributeName = attributeName;
51      }
52  
53      public String getAttributeType() {
54          return attributeType;
55      }
56  
57      public void setAttributeType(String attributeType) {
58          this.attributeType = attributeType;
59      }
60  
61      public String getDefaultValue() {
62          return defaultValue;
63      }
64  
65      public void setDefaultValue(String defaultValue) {
66          this.defaultValue = defaultValue;
67      }
68  
69      public void setId(String id) {
70          this.id = id;
71      }
72  
73      public void setForType(ForType forType) {
74          this.forType = forType;
75      }
76  
77      public String getId() {
78          return this.id;
79      }
80      
81      public String defaultValue() {
82          return this.defaultValue;
83      }
84      
85      public ForType getForType() {
86          return this.forType;
87      }
88  
89      public void applyKey( Metadata metadata ) {
90          Map<String,String> props = metadata.getProperties();                        
91          if( defaultValue != null && !props.containsKey(id) ) {
92              props.put(id, defaultValue);
93          }
94      }
95  }