1
2
3
4
5
6
7 package org.lcsim.material;
8
9 import org.jdom.JDOMException;
10
11
12
13
14
15 public class MaterialDefinitionType
16 {
17 String _tagname;
18
19 public static final MaterialDefinitionType COMPOSITE = new MaterialDefinitionType("composite");
20 public static final MaterialDefinitionType FRACTION = new MaterialDefinitionType("fraction");
21 public static final MaterialDefinitionType ATOM = new MaterialDefinitionType("atom");
22 public static final MaterialDefinitionType INVALID = new MaterialDefinitionType("");
23
24
25 public MaterialDefinitionType(String tagname)
26 {
27 _tagname = tagname;
28 }
29
30 public String getTagName()
31 {
32 return _tagname;
33 }
34
35 static MaterialDefinitionType getMaterialDefinitionType(org.jdom.Element materialElement) throws JDOMException
36 {
37 boolean gotOne = false;
38 MaterialDefinitionType mdt = MaterialDefinitionType.INVALID;
39
40 if ( materialElement.getChild("atom") != null )
41 {
42 mdt = MaterialDefinitionType.ATOM;
43 gotOne = true;
44 }
45
46 if ( materialElement.getChild("composite") != null )
47 {
48 if ( gotOne )
49 {
50 throw new JDOMException("Already got atom tag for material: " + materialElement.getAttributeValue("name"));
51 }
52 else
53 {
54 gotOne = true;
55 mdt = MaterialDefinitionType.COMPOSITE;
56 }
57 }
58
59 if ( materialElement.getChild("fraction") != null )
60 {
61 if ( gotOne )
62 {
63 throw new JDOMException("Already got atom or composite tag for material: " + materialElement.getAttributeValue("name"));
64 }
65 else
66 {
67 mdt = MaterialDefinitionType.FRACTION;
68 gotOne = true;
69 }
70 }
71
72 if ( !gotOne )
73 {
74 throw new JDOMException("One of atom, composite or fraction was not found for material: " + materialElement.getAttributeValue("name"));
75 }
76
77 return mdt;
78 }
79 }