summaryrefslogtreecommitdiff
path: root/src/com/memberwebs/ldapxml/map/LXBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/memberwebs/ldapxml/map/LXBase.java')
-rw-r--r--src/com/memberwebs/ldapxml/map/LXBase.java261
1 files changed, 261 insertions, 0 deletions
diff --git a/src/com/memberwebs/ldapxml/map/LXBase.java b/src/com/memberwebs/ldapxml/map/LXBase.java
new file mode 100644
index 0000000..82b3d09
--- /dev/null
+++ b/src/com/memberwebs/ldapxml/map/LXBase.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2004, Nate Nielsen
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ * * Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ * * The names of contributors to this software may not be
+ * used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ *
+ * CONTRIBUTORS
+ * Nate Nielsen <nielsen@memberwebs.com>
+ *
+ */
+
+package com.memberwebs.ldapxml.map;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * A base class for all objects in an LX map tree.
+ *
+ * @author nielsen@memberwebs.com
+ * @version 0.5
+ */
+public class LXBase
+{
+ /**
+ * Constructs an LXBase object.
+ *
+ * @param parent The parent object in the LX map tree.
+ */
+ LXBase(LXBase parent)
+ {
+ m_name = null;
+ m_xmlName = null;
+ m_nameSpace = null;
+ m_ns = null;
+ m_parent = parent;
+ m_isUseable = true;
+
+ // If we have a parent and it doesn't have any children set
+ // Then give it child capabilities.
+ if(parent != null && parent.m_children == null)
+ parent.m_children = new Hashtable();
+ }
+
+ /**
+ * Get the full XML name for this object. This includes any namespace
+ * prefixes prepended to the name.
+ *
+ * @return The XML name.
+ */
+ public String getXmlName()
+ {
+ String xmlName = m_xmlName;
+ if(xmlName == null)
+ xmlName = m_name;
+
+ if(xmlName != null)
+ {
+ String prefix = getPrefix();
+ if(prefix != null)
+ xmlName = prefix + ":" + xmlName;
+ }
+
+ return xmlName;
+ }
+
+
+ /**
+ * Get the name of this object.
+ *
+ * @return The name.
+ */
+ public final String getName()
+ {
+ return m_name;
+ }
+
+
+ /**
+ * Set the name of this object. Updates the parent (if any)
+ * to reflect this change in tree structure.
+ *
+ * @param name The new name
+ */
+ void setName(String name)
+ {
+ if(m_name != null && m_parent != null)
+ m_parent.m_children.remove(m_name);
+
+ if(name != null)
+ {
+ if(m_parent != null)
+ m_parent.m_children.put(name, this);
+
+ m_name = name;
+ }
+ }
+
+ /**
+ * Get the namespace prefix for this object. If this object has
+ * no namespaces info set, returns the parent objects namespace
+ * prefix.
+ *
+ * @return The namespace prefix, or null if there is no prefix.
+ */
+ public String getPrefix()
+ {
+ // If we have a namespace then return
+ // the ns value regardless
+ if(m_nameSpace != null)
+ return m_ns;
+
+ if(m_ns != null)
+ return m_ns;
+
+ if(m_parent != null)
+ return m_parent.getPrefix();
+
+ return null;
+ }
+
+ /**
+ * Get the full namespace URI for this object.
+ *
+ * @param here If set to true, then parent namespaces will
+ * be returned if none is set on this object.
+ * @return The namespace.
+ */
+ public String getNamespace(boolean here)
+ {
+ if(m_nameSpace != null || here)
+ return m_nameSpace;
+
+ if(m_parent != null)
+ return m_parent.getNamespace();
+
+ return null;
+ }
+
+ /**
+ * Get the full namespace URI for this node.
+ * If this object has no namespace, it's parent will
+ * be queried.
+ *
+ * @return The namespace.
+ */
+ public String getNamespace()
+ {
+ return getNamespace(false);
+ }
+
+ /**
+ * Get this object's parent in the LX map tree.
+ *
+ * @return The parent, or null if this object has no parent.
+ */
+ public final LXBase getParent()
+ {
+ return m_parent;
+ }
+
+ /**
+ * Get a child of this object in the LX map tree.
+ *
+ * @param name The child's name.
+ * @return The child, or null if no such child is present.
+ */
+ public final LXBase getChild(String name)
+ {
+ if(m_children == null)
+ return null;
+
+ return (LXBase)m_children.get(name);
+ }
+
+ /**
+ * Get the names of all the child objects.
+ *
+ * @return An enumeraton of the child attribute names.
+ */
+ public final Enumeration getChildNames()
+ {
+ if(m_children == null)
+ return null;
+
+ return m_children.keys();
+ }
+
+ /**
+ * Check whether this object has been marked unusable.
+ *
+ * @return Usability status.
+ */
+ public final boolean isUseable()
+ {
+ return m_isUseable;
+ }
+
+ /**
+ * Get the LX hook for this object. If this
+ * object has no hook, then the parent will be queried.
+ *
+ * @return The class name of the LX hook.
+ */
+ public String getHook()
+ {
+ if(m_hook == null && m_parent != null)
+ return m_parent.getHook();
+
+ return m_hook;
+ }
+
+ // The name to be used when creating XML for this object.
+ String m_xmlName;
+
+ // Namespace information for this object
+ String m_nameSpace;
+ String m_ns;
+
+ // The hook for this object and below
+ String m_hook;
+
+ // Is this object useable or not
+ boolean m_isUseable;
+
+ // This object's parent in the LX map
+ private LXBase m_parent;
+
+ // This object's name
+ private String m_name;
+
+ // Children in the LX map tree of this object.
+ private Hashtable m_children;
+};