including openisis 0.9.0 into webpac tree
[webpac] / openisis / org / openisis / Fdt.java
diff --git a/openisis/org/openisis/Fdt.java b/openisis/org/openisis/Fdt.java
new file mode 100644 (file)
index 0000000..5eac904
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+       openisis - an open implementation of the CDS/ISIS database
+       Version 0.8.x (patchlevel see file Version)
+       Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+       see README for more information
+EOH */
+
+package org.openisis;
+
+/**
+       Field description table.
+<p>
+       $Id: Fdt.java,v 1.5 2003/04/08 00:20:53 kripke Exp $
+       @version $Revision: 1.5 $
+       @author  $Author: kripke $
+*/
+public class Fdt {
+
+       /**     alphanum field type. */
+       public static final int FTX = 0;
+       /**     strictly alpha field type. */
+       public static final int FTA = 1;
+       /**     numeric field type. */
+       public static final int FTN = 2;
+       /**     pattern field type. */
+       public static final int FTP = 3;
+       /**     iso field type. */
+       public static final int FTI = 10;
+       /**     enum field type. */
+       public static final int FTE = 12;
+       /**     boolean field type. */
+       public static final int FTB = 13;
+       /**     table field type. */
+       public static final int FTT = 14;
+       /**     structure field type. */
+       public static final int FTS = 15;
+       /**     subfield field type. */
+       public static final int FTF = 16;
+       /**     enum value type. */
+       public static final int FTV = 31;
+
+       /**     field description. */
+       public static class Fd {
+               /** tag */
+               public final int id;
+               /** type */
+               public final int type;
+               /** max length or enum value */
+               public final int len;
+               /** repeated flag */
+               public final boolean rep;
+               /** name */
+               public final String name;
+               /** subfields/pattern */
+               public final String subf;
+               /** description */
+               public final String desc;
+
+               /**     @exception IllegalArgumentException if name is null or ""
+               */
+               public Fd (int id, int type, int len, boolean rep,
+                       String name, String subf, String desc) {
+                       this.id = id;
+                       this.type = type;
+                       this.len = len;
+                       this.rep = rep;
+                       this.name = name;
+                       this.subf = subf;
+                       this.desc = desc;
+                       if (null == name || 0 == name.length ()) {
+                               throw new IllegalArgumentException (
+                                       "illegal field desc: id " + id + ", name " + name);
+                       }
+               }
+
+               /**     shorthand for Fd (id, type, len, false, name, null, null)
+               */
+               public Fd (int id, int type, int len, String name) {
+                       this (id, type, len, false, name, null, null);
+               }
+
+               public String toString () {
+                       return name + ';' + id + ';' + type;
+               }
+       }
+
+       public final Fd[] _fd;
+
+       /**     @exception IllegalArgumentException if fd is null or has length 0
+       */
+       public Fdt (Fd[] fd) {
+               _fd = fd;
+               if (null == fd || 0 == fd.length) {
+                       throw new IllegalArgumentException ();
+               }
+       }
+
+       public Fd fdById (int id) {
+               for (int j = _fd.length; 0 <= --j; ) {
+                       if (id == _fd[j].id) {
+                               return _fd[j];
+                       }
+               }
+               return null;
+       }
+
+       public Fd fdByName (String name) {
+               if (null == name || 0 == name.length ()) {
+                       return null;
+               }
+               char c = name.charAt (0);
+               if ('0' <= c && '9' >= c) {
+                       try {
+                               int id = Integer.parseInt (name);
+                               return fdById (id);
+                       }
+                       catch (Exception ex) {
+                       }
+               }
+               for (int j = _fd.length; 0 <= --j; ) {
+                       if (name.equals (_fd[j].name)) {
+                               return _fd[j];
+                       }
+               }
+               return null;
+       }
+
+       public String dump() {
+               StringBuffer d=new StringBuffer();
+               for(int i=0;i<_fd.length;i++) {
+                       d.append(_fd[i].toString());
+                       if (_fd[i].subf!=null) {
+                               d.append(',');
+                               d.append(_fd[i].subf);
+                       }
+                       d.append('\n');
+               }
+               return d.toString();
+       }
+}
+