summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/memberwebs/ldapxml/LXReader.java26
-rw-r--r--src/com/memberwebs/ldapxml/LXSpecs.java2
-rw-r--r--src/com/memberwebs/ldapxml/helpers/LXRoot.java74
-rw-r--r--src/com/memberwebs/ldapxml/map/LXAttribute.java (renamed from src/com/memberwebs/ldapxml/helpers/LXAttribute.java)3
-rw-r--r--src/com/memberwebs/ldapxml/map/LXBase.java (renamed from src/com/memberwebs/ldapxml/helpers/LXBase.java)6
-rw-r--r--src/com/memberwebs/ldapxml/map/LXClass.java (renamed from src/com/memberwebs/ldapxml/helpers/LXClass.java)3
-rw-r--r--src/com/memberwebs/ldapxml/map/LXEntry.java (renamed from src/com/memberwebs/ldapxml/helpers/LXEntry.java)55
-rw-r--r--src/com/memberwebs/ldapxml/map/LXMap.java (renamed from src/com/memberwebs/ldapxml/LXMap.java)166
-rw-r--r--src/com/memberwebs/ldapxml/map/LXMapException.java (renamed from src/com/memberwebs/ldapxml/LXMapException.java)4
-rw-r--r--src/com/memberwebs/ldapxml/map/LXSAXHandler.java (renamed from src/com/memberwebs/ldapxml/helpers/LXSAXHandler.java)50
10 files changed, 182 insertions, 207 deletions
diff --git a/src/com/memberwebs/ldapxml/LXReader.java b/src/com/memberwebs/ldapxml/LXReader.java
index 3e525f1..4f62c01 100644
--- a/src/com/memberwebs/ldapxml/LXReader.java
+++ b/src/com/memberwebs/ldapxml/LXReader.java
@@ -52,13 +52,13 @@ import java.util.Vector;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import com.memberwebs.ldapxml.helpers.LXAttribute;
-import com.memberwebs.ldapxml.helpers.LXBase;
-import com.memberwebs.ldapxml.helpers.LXClass;
import com.memberwebs.ldapxml.helpers.LXDefaultConvert;
import com.memberwebs.ldapxml.helpers.LXDefaultHook;
-import com.memberwebs.ldapxml.helpers.LXEntry;
-import com.memberwebs.ldapxml.helpers.LXRoot;
+import com.memberwebs.ldapxml.map.*;
+import com.memberwebs.ldapxml.map.LXAttribute;
+import com.memberwebs.ldapxml.map.LXBase;
+import com.memberwebs.ldapxml.map.LXClass;
+import com.memberwebs.ldapxml.map.LXEntry;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSchema;
import com.novell.ldap.LDAPCompareAttrNames;
@@ -122,7 +122,7 @@ public class LXReader
public final void setMap(LXMap map)
throws LXException
{
- if(map.getRoot() == null)
+ if(map == null)
throw new LXException("Must supply a valid loaded map");
m_map = map;
@@ -264,8 +264,7 @@ public class LXReader
}
// Create the root element etc...
- LXRoot lx = m_map.getRoot();
- Element root = createElement(doc, lx);
+ Element root = createElement(doc, m_map);
return new LXResults(doc, els, root);
}
@@ -280,11 +279,10 @@ public class LXReader
public LXResults retrieveBlank(Document doc)
throws LXException
{
- if(m_map == null || m_map.getRoot() == null)
+ if(m_map == null)
throw new LXException("Must supply a valid loaded map");
- LXRoot lx = m_map.getRoot();
- Element root = createElement(doc, lx);
+ Element root = createElement(doc, m_map);
return new LXResults(doc, new Vector(), root);
}
@@ -382,8 +380,6 @@ public class LXReader
// We retrieve the whole thing for efficiency
refreshSchema();
- LXRoot root = m_map.getRoot();
-
// Get all the classes we use them to determine a number
// of things
LDAPAttribute objectClasses = entry.getAttribute(CLASS);
@@ -398,7 +394,7 @@ public class LXReader
for(int i = 0; i < classes.length; i++)
{
- lxentry = root.getEntry(classes[i]);
+ lxentry = m_map.getEntry(classes[i]);
if(lxentry != null)
break;
}
@@ -737,7 +733,7 @@ public class LXReader
if(m_connection == null || !m_connection.isConnected())
throw new LXException("Must supply a valid open connection");
- if(m_map == null || m_map.getRoot() == null)
+ if(m_map == null)
throw new LXException("Must supply a valid loaded map");
}
diff --git a/src/com/memberwebs/ldapxml/LXSpecs.java b/src/com/memberwebs/ldapxml/LXSpecs.java
index 290e86d..b9bc68d 100644
--- a/src/com/memberwebs/ldapxml/LXSpecs.java
+++ b/src/com/memberwebs/ldapxml/LXSpecs.java
@@ -40,6 +40,8 @@ package com.memberwebs.ldapxml;
import java.util.Map;
+import com.memberwebs.ldapxml.map.*;
+
/**
* Additional specifications for retrieving data from an
* LDAP directory.
diff --git a/src/com/memberwebs/ldapxml/helpers/LXRoot.java b/src/com/memberwebs/ldapxml/helpers/LXRoot.java
deleted file mode 100644
index d4b9286..0000000
--- a/src/com/memberwebs/ldapxml/helpers/LXRoot.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.helpers;
-
-
-/**
- * Represents the root of an LX map
- *
- * @author nielsen@memberwebs.com
- * @version 0.5
- */
-public class LXRoot
- extends LXBase
-{
- /**
- * Constructs a new LXRoot object.
- */
- LXRoot()
- {
- super(null);
- }
-
- /**
- * Get an entry in this LX map by name.
- *
- * @param name The entry name.
- * @return The entry, or null if no such entry is present
- */
- public LXEntry getEntry(String name)
- {
- LXEntry entry = (LXEntry)getChild(name);
-
- if(entry != null && !entry.isUseable())
- entry = null;
-
- return entry;
- }
-};
diff --git a/src/com/memberwebs/ldapxml/helpers/LXAttribute.java b/src/com/memberwebs/ldapxml/map/LXAttribute.java
index a272470..8d95770 100644
--- a/src/com/memberwebs/ldapxml/helpers/LXAttribute.java
+++ b/src/com/memberwebs/ldapxml/map/LXAttribute.java
@@ -36,7 +36,8 @@
*
*/
-package com.memberwebs.ldapxml.helpers;
+package com.memberwebs.ldapxml.map;
+
/**
diff --git a/src/com/memberwebs/ldapxml/helpers/LXBase.java b/src/com/memberwebs/ldapxml/map/LXBase.java
index 34098cf..82b3d09 100644
--- a/src/com/memberwebs/ldapxml/helpers/LXBase.java
+++ b/src/com/memberwebs/ldapxml/map/LXBase.java
@@ -36,7 +36,7 @@
*
*/
-package com.memberwebs.ldapxml.helpers;
+package com.memberwebs.ldapxml.map;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -54,7 +54,7 @@ public class LXBase
*
* @param parent The parent object in the LX map tree.
*/
- public LXBase(LXBase parent)
+ LXBase(LXBase parent)
{
m_name = null;
m_xmlName = null;
@@ -109,7 +109,7 @@ public class LXBase
*
* @param name The new name
*/
- public void setName(String name)
+ void setName(String name)
{
if(m_name != null && m_parent != null)
m_parent.m_children.remove(m_name);
diff --git a/src/com/memberwebs/ldapxml/helpers/LXClass.java b/src/com/memberwebs/ldapxml/map/LXClass.java
index 435f2ea..94e0da9 100644
--- a/src/com/memberwebs/ldapxml/helpers/LXClass.java
+++ b/src/com/memberwebs/ldapxml/map/LXClass.java
@@ -36,7 +36,8 @@
*
*/
-package com.memberwebs.ldapxml.helpers;
+package com.memberwebs.ldapxml.map;
+
/**
diff --git a/src/com/memberwebs/ldapxml/helpers/LXEntry.java b/src/com/memberwebs/ldapxml/map/LXEntry.java
index ea244de..cf1760b 100644
--- a/src/com/memberwebs/ldapxml/helpers/LXEntry.java
+++ b/src/com/memberwebs/ldapxml/map/LXEntry.java
@@ -36,7 +36,12 @@
*
*/
-package com.memberwebs.ldapxml.helpers;
+package com.memberwebs.ldapxml.map;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+
/**
@@ -48,6 +53,9 @@ package com.memberwebs.ldapxml.helpers;
public class LXEntry
extends LXBase
{
+ private Map m_xmlMap;
+ private Map m_nameMap;
+
/**
* Constructs a new LXEntry object.
*
@@ -74,4 +82,49 @@ public class LXEntry
return cls;
}
+ /**
+ * Resolve an XML name to an attribute.
+ */
+ public LXAttribute resolveXMLName(String name)
+ {
+ loadNameMaps();
+ return (LXAttribute)m_xmlMap.get(name);
+ }
+
+ public LXAttribute resolveName(String name)
+ {
+ loadNameMaps();
+ return (LXAttribute)m_nameMap.get(name);
+ }
+
+ private void loadNameMaps()
+ {
+ // Note: This should never be called internally until the map
+ // is completely built. It relies on the map remaining static
+ // after this point, as there is no method for syncinc the
+ // cached map created below.
+
+ if(m_xmlMap == null || m_nameMap == null)
+ {
+ m_xmlMap = new Hashtable();
+ m_nameMap = new Hashtable();
+
+ Enumeration e = getChildNames();
+ while(e != null && e.hasMoreElements())
+ {
+ LXClass cls = getClass((String)e.nextElement());
+
+ Enumeration e2 = cls.getChildNames();
+ while(e2 != null && e2.hasMoreElements())
+ {
+ LXAttribute attr = cls.getAttribute((String)e2.nextElement());
+ if(attr != null)
+ {
+ m_xmlMap.put(attr.getXmlName(), attr);
+ m_nameMap.put(attr.getName(), attr);
+ }
+ }
+ }
+ }
+ }
};
diff --git a/src/com/memberwebs/ldapxml/LXMap.java b/src/com/memberwebs/ldapxml/map/LXMap.java
index 5dd9018..2676f18 100644
--- a/src/com/memberwebs/ldapxml/LXMap.java
+++ b/src/com/memberwebs/ldapxml/map/LXMap.java
@@ -36,7 +36,7 @@
*
*/
-package com.memberwebs.ldapxml;
+package com.memberwebs.ldapxml.map;
import java.io.IOException;
import java.util.Map;
@@ -47,8 +47,6 @@ import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
-import com.memberwebs.ldapxml.helpers.LXRoot;
-import com.memberwebs.ldapxml.helpers.LXSAXHandler;
/**
* The in memory representation of an LX map.
@@ -57,83 +55,40 @@ import com.memberwebs.ldapxml.helpers.LXSAXHandler;
* @version 0.5
*/
public class LXMap
+ extends LXBase
{
- /**
+ // Cache of the name map
+ private Map m_nameMap;
+
+ // Cache of the name set
+ private Set m_nameSet;
+
+ /**
* Constructs a new LXMap object.
*/
- public LXMap()
+ LXMap(Map nameMap, Set nameSet)
{
- m_root = null;
- m_nameMap = null;
- m_nameSet = null;
+ super(null);
+ m_nameMap = nameMap;
+ m_nameSet = nameSet;
}
- /**
- * Get the root node of the LX map.
- *
- * @return The root.
- */
- protected final LXRoot getRoot()
- {
- return m_root;
- }
+ /**
+ * Get an entry in this LX map by name.
+ *
+ * @param name The entry name.
+ * @return The entry, or null if no such entry is present
+ */
+ public LXEntry getEntry(String name)
+ {
+ LXEntry entry = (LXEntry)getChild(name);
- /**
- * Load an LX map from an XML data stream
- *
- * @param source The source of the XML data.
- */
- public void loadMap(InputSource source)
- throws LXMapException, IOException
- {
- try
- {
- XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
-
- // We require some form of validation on the document
- // as our internal checks are lax
- xr.setFeature("http://xml.org/sax/features/validation", true);
-
- // Parse and load the map.
- LXSAXHandler handler = new LXSAXHandler();
- xr.setContentHandler(handler);
- xr.setErrorHandler(handler);
- xr.parse(source);
-
- m_root = handler.getRoot();
- m_nameMap = handler.getNameMap();
- m_nameSet = handler.getNameSet();
- }
- catch(SAXException e)
- {
- Exception inside = e.getException();
-
- if(inside != null)
- {
- inside.printStackTrace();
- if(inside instanceof LXMapException)
- throw (LXMapException)inside;
- else if(inside.getMessage() != null)
- throw new LXMapException(inside.getMessage());
- else
- throw new LXMapException(inside.getClass().getName());
- }
-
- throw new LXMapException(e.getMessage());
- }
- }
+ if(entry != null && !entry.isUseable())
+ entry = null;
- /**
- * Load an LX map from a uri.
- *
- * @param uri The fully qualified uri of the file.
- */
- public void loadMap(String uri)
- throws LXMapException, IOException
- {
- loadMap(new InputSource(uri));
- }
+ return entry;
+ }
/**
* Get public (XML) to private (LDAP) name mappings
@@ -150,22 +105,63 @@ public class LXMap
* Get the minimum set of LDAP attributes required
* to retrieve items via this map.
*/
- protected final Set getNameSet()
+ public final Set getNameSet()
{
return m_nameSet;
}
- public final boolean isLoaded()
- {
- return m_root != null;
- }
-
- // The root of the LX map
- private LXRoot m_root;
-
- // Cache of the name map
- private Map m_nameMap;
-
- // Cache of the name set
- private Set m_nameSet;
+ /**
+ * Load an LX map from an XML data stream
+ *
+ * @param source The source of the XML data.
+ */
+ public static LXMap loadMap(InputSource source)
+ throws LXMapException, IOException
+ {
+ try
+ {
+ XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+
+ // We require some form of validation on the document
+ // as our internal checks are lax
+ xr.setFeature("http://xml.org/sax/features/validation", true);
+
+ // Parse and load the map.
+ LXSAXHandler handler = new LXSAXHandler();
+ xr.setContentHandler(handler);
+ xr.setErrorHandler(handler);
+ xr.parse(source);
+
+ LXMap map = handler.getMap();
+ return map;
+ }
+ catch(SAXException e)
+ {
+ Exception inside = e.getException();
+
+ if(inside != null)
+ {
+ inside.printStackTrace();
+ if(inside instanceof LXMapException)
+ throw (LXMapException)inside;
+ else if(inside.getMessage() != null)
+ throw new LXMapException(inside.getMessage());
+ else
+ throw new LXMapException(inside.getClass().getName());
+ }
+
+ throw new LXMapException(e.getMessage());
+ }
+ }
+
+ /**
+ * Load an LX map from a uri.
+ *
+ * @param uri The fully qualified uri of the file.
+ */
+ public static LXMap loadMap(String uri)
+ throws LXMapException, IOException
+ {
+ return loadMap(new InputSource(uri));
+ }
}
diff --git a/src/com/memberwebs/ldapxml/LXMapException.java b/src/com/memberwebs/ldapxml/map/LXMapException.java
index 21ac9e0..4dd24b4 100644
--- a/src/com/memberwebs/ldapxml/LXMapException.java
+++ b/src/com/memberwebs/ldapxml/map/LXMapException.java
@@ -36,7 +36,9 @@
*
*/
-package com.memberwebs.ldapxml;
+package com.memberwebs.ldapxml.map;
+
+import com.memberwebs.ldapxml.LXException;
/**
* Thrown when an error occurs parsing an LX map file.
diff --git a/src/com/memberwebs/ldapxml/helpers/LXSAXHandler.java b/src/com/memberwebs/ldapxml/map/LXSAXHandler.java
index 9c36534..d81c240 100644
--- a/src/com/memberwebs/ldapxml/helpers/LXSAXHandler.java
+++ b/src/com/memberwebs/ldapxml/map/LXSAXHandler.java
@@ -36,7 +36,7 @@
*
*/
-package com.memberwebs.ldapxml.helpers;
+package com.memberwebs.ldapxml.map;
import java.util.HashSet;
import java.util.Hashtable;
@@ -48,7 +48,6 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
-import com.memberwebs.ldapxml.LXMapException;
/**
* Parses an XML file into an in memory LX map representation.
@@ -56,7 +55,7 @@ import com.memberwebs.ldapxml.LXMapException;
* @author nielsen@memberwebs.com
* @version 0.5
*/
-public class LXSAXHandler
+class LXSAXHandler
extends DefaultHandler
{
private static final String EL_ROOT = "lxmap";
@@ -83,6 +82,20 @@ public class LXSAXHandler
private static final String INTERNAL_ERROR = "LX Map parser invalid internal state";
+ // The root of the map being built
+ private LXMap m_map;
+
+ // The current LX map object being acted on.
+ private LXBase m_cur;
+
+ // Stack of LX objects
+ private Stack m_elStack;
+
+ // public (XML) to private (LDAP) name mappings
+ private Hashtable m_nameMap;
+
+ // All the LDAP attributes required for this map
+ private HashSet m_nameSet;
/**
* Constructs a new LXSAXHandler object.
@@ -101,7 +114,7 @@ public class LXSAXHandler
throws SAXException
{
m_cur = null;
- m_root = null;
+ m_map = null;
m_nameMap.clear();
m_nameSet = new HashSet();
}
@@ -149,7 +162,7 @@ public class LXSAXHandler
{
rootHandler(uri, localName, qName, attributes);
}
- else if(m_cur instanceof LXRoot)
+ else if(m_cur instanceof LXMap)
{
entryHandler(uri, localName, qName, attributes);
}
@@ -222,8 +235,8 @@ public class LXSAXHandler
if(!attributes.getValue(AT_VERSION).equals(VAL_VERSION))
throw new LXMapException("Invalid LX Map version");
- m_root = new LXRoot();
- m_cur = m_root;
+ m_map = new LXMap(m_nameMap, m_nameSet);
+ m_cur = m_map;
nameAttrHandler(attributes, AT_ROOT);
commonAttrHandler(attributes);
@@ -424,13 +437,13 @@ public class LXSAXHandler
}
/**
- * Get the root of the resulting LX map.
+ * Get the resulting LX Map.
*
- * @return The root of the map.
+ * @return The map.
*/
- public final LXRoot getRoot()
+ public final LXMap getMap()
{
- return m_root;
+ return m_map;
}
/**
@@ -472,19 +485,4 @@ public class LXSAXHandler
if(m_nameSet != null)
m_nameSet.add(name);
}
-
- // The root of the map being built
- private LXRoot m_root;
-
- // The current LX map object being acted on.
- private LXBase m_cur;
-
- // Stack of LX objects
- private Stack m_elStack;
-
- // public (XML) to private (LDAP) name mappings
- private Hashtable m_nameMap;
-
- // All the LDAP attributes required for this map
- private HashSet m_nameSet;
}