Source code: joelib/io/types/cml/CDKConvention.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: CDKConvention.java,v $
3 // Purpose: Chemical Markup Language.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: steinbeck@ice.mpg.de, gezelter@maul.chem.nd.edu,
7 // egonw@sci.kun.nl, wegnerj@informatik.uni-tuebingen.de
8 // Version: $Revision: 1.6 $
9 // $Date: 2003/08/22 15:56:18 $
10 // $Author: wegner $
11 //
12 // Copyright (C) 1997-2003 The Chemistry Development Kit (CDK) project
13 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
14 //
15 // This program is free software; you can redistribute it and/or
16 // modify it under the terms of the GNU Lesser General Public License
17 // as published by the Free Software Foundation; either version 2.1
18 // of the License, or (at your option) any later version.
19 // All we ask is that proper credit is given for our work, which includes
20 // - but is not limited to - adding the above copyright notice to the beginning
21 // of your source code files, and to any copyright notice that you may distribute
22 // with programs based on this work.
23 //
24 // This program is distributed in the hope that it will be useful,
25 // but WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 // GNU Lesser General Public License for more details.
28 //
29 // You should have received a copy of the GNU Lesser General Public License
30 // along with this program; if not, write to the Free Software
31 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 ///////////////////////////////////////////////////////////////////////////////
33 package joelib.io.types.cml;
34
35 import java.util.*;
36
37 import org.apache.log4j.*;
38
39 import org.xml.sax.*;
40
41
42 /**
43 * This is an implementation for the CDK convention.
44 *
45 * @author egonw
46 * @author c.steinbeck@uni-koeln.de
47 * @author gezelter@maul.chem.nd.edu
48 * @author wegnerj
49 * @license LGPL
50 * @cvsversion $Revision: 1.6 $, $Date: 2003/08/22 15:56:18 $
51 */
52 public class CDKConvention extends CMLCoreModule
53 {
54 //~ Static fields/initializers /////////////////////////////////////////////
55
56 // Obtain a suitable logger.
57 private static Category logger = Category.getInstance(
58 "joelib.io.types.cml.CDKConvention");
59
60 //~ Instance fields ////////////////////////////////////////////////////////
61
62 private boolean isBond;
63
64 //~ Constructors ///////////////////////////////////////////////////////////
65
66 public CDKConvention(CDOInterface cdo)
67 {
68 super(cdo);
69 }
70
71 public CDKConvention(ModuleInterface conv)
72 {
73 super(conv);
74 }
75
76 //~ Methods ////////////////////////////////////////////////////////////////
77
78 public void characterData(char[] ch, int start, int length)
79 {
80 String s = new String(ch, start, length).trim();
81
82 if (isBond)
83 {
84 logger.debug("CharData (bond): " + s);
85
86 StringTokenizer st = new StringTokenizer(s);
87
88 while (st.hasMoreElements())
89 {
90 String border = (String) st.nextElement();
91
92 if (logger.isDebugEnabled())
93 {
94 logger.debug("new bond order: " + border);
95 }
96
97 // assume cdk bond object has already started
98 cdo.setObjectProperty("Bond", "order", border);
99 }
100 }
101 else
102 {
103 super.characterData(ch, start, length);
104 }
105 }
106
107 public void endDocument()
108 {
109 super.endDocument();
110 }
111
112 public void endElement(String uri, String local, String raw)
113 {
114 super.endElement(uri, local, raw);
115 }
116
117 public CDOInterface returnCDO()
118 {
119 return this.cdo;
120 }
121
122 public void startDocument()
123 {
124 super.startDocument();
125 isBond = false;
126 }
127
128 public void startElement(String uri, String local, String raw,
129 Attributes atts)
130 {
131 String name = raw;
132 setCurrentElement(name);
133 isBond = false;
134
135 if (currentElement == STRING)
136 {
137 for (int i = 0; i < atts.getLength(); i++)
138 {
139 if (atts.getQName(i).equals("buildin") &&
140 atts.getValue(i).equals("order"))
141 {
142 isBond = true;
143 }
144 }
145 }
146 else
147 {
148 super.startElement(uri, local, raw, atts);
149 }
150 }
151 }
152 ///////////////////////////////////////////////////////////////////////////////
153 // END OF FILE.
154 ///////////////////////////////////////////////////////////////////////////////