You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/07/10 16:07:51 UTC
svn commit: r554953 - in
/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io:
XMLSchemaFileExporter.java XMLSchemaFileImportException.java
XMLSchemaFileImporter.java
Author: pamarcelot
Date: Tue Jul 10 07:07:50 2007
New Revision: 554953
URL: http://svn.apache.org/viewvc?view=rev&rev=554953
Log:
Added a new XMLSchemaImporter.
Added:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImportException.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
Modified:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java?view=diff&rev=554953&r1=554952&r2=554953
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java Tue Jul 10 07:07:50 2007
@@ -73,6 +73,7 @@
private static final String OID_TAG = "oid";
private static final String OPTIONAL_TAG = "optional";
private static final String ORDERING_TAG = "ordering";
+ private static final String SCHEMA_TAG = "schema";
private static final String SINGLE_VALUE_TAG = "singlevalue";
private static final String SUBSTRING_TAG = "substring";
private static final String SUPERIOR_TAG = "superior";
@@ -98,7 +99,7 @@
{
// Creating the Document and the 'root' Element
Document document = DocumentHelper.createDocument();
- Element element = document.addElement( "schema" );
+ Element element = document.addElement( SCHEMA_TAG );
// Name
String name = schema.getName();
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImportException.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImportException.java?view=auto&rev=554953
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImportException.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImportException.java Tue Jul 10 07:07:50 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.model.io;
+
+
+/**
+ * This class represents the XMLSchemaFileImportException.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class XMLSchemaFileImportException extends Exception
+{
+ private static final long serialVersionUID = 1L;
+
+
+ /**
+ * Creates a new instance of XMLSchemaFileImportException.
+ *
+ * @param message
+ * the message
+ */
+ public XMLSchemaFileImportException( String message )
+ {
+ super( message );
+ }
+}
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java?view=auto&rev=554953
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java Tue Jul 10 07:07:50 2007
@@ -0,0 +1,712 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.model.io;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.SchemaImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+
+/**
+ * This class is used to import a Schema file from the XML Format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class XMLSchemaFileImporter
+{
+ // The Tags
+ private static final String ALIAS_TAG = "alias";
+ private static final String ALIASES_TAG = "aliases";
+ private static final String ATTRIBUTE_TYPE_TAG = "attributetype";
+ private static final String ATTRIBUTE_TYPES_TAG = "attributetypes";
+ private static final String BOOLEAN_FALSE = "true";
+ private static final String BOOLEAN_TRUE = "true";
+ private static final String COLLECTIVE_TAG = "collective";
+ private static final String DESCRIPTION_TAG = "description";
+ private static final String EQUALITY_TAG = "equality";
+ private static final String HUMAN_READIBLE_TAG = "humanreadible";
+ private static final String MANDATORY_TAG = "mandatory";
+ private static final String MATCHING_RULE_TAG = "matchingrule";
+ private static final String MATCHING_RULES_TAG = "matchingrules";
+ private static final String NAME_TAG = "name";
+ private static final String NO_USER_MODIFICATION_TAG = "nousermodification";
+ private static final String OBJECT_CLASS_TAG = "objectclass";
+ private static final String OBJECT_CLASSES_TAG = "objectclasses";
+ private static final String OBSOLETE_TAG = "obsolete";
+ private static final String OID_TAG = "oid";
+ private static final String OPTIONAL_TAG = "optional";
+ private static final String ORDERING_TAG = "ordering";
+ private static final String SCHEMA_TAG = "schema";
+ private static final String SINGLE_VALUE_TAG = "singlevalue";
+ private static final String SUBSTRING_TAG = "substring";
+ private static final String SUPERIOR_TAG = "superior";
+ private static final String SUPERIORS_TAG = "superiors";
+ private static final String SYNTAX_LENGTH_TAG = "syntaxlength";
+ private static final String SYNTAX_OID_TAG = "syntaxoid";
+ private static final String SYNTAX_TAG = "syntax";
+ private static final String SYNTAXES_TAG = "syntaxes";
+ private static final String TYPE_TAG = "type";
+ private static final String USAGE_TAG = "usage";
+
+
+ /**
+ * Extracts the Schema from the given path.
+ *
+ * @param path
+ * the path of the file.
+ * @return
+ * the corresponding schema
+ * @throws XMLSchemaFileImportException
+ * if an error occurs when importing the schema
+ */
+ public static Schema getSchema( String path ) throws XMLSchemaFileImportException
+ {
+ // Creating the schema with an empty name
+ Schema schema = new SchemaImpl( null );
+
+ SAXReader reader = new SAXReader();
+ Document document = null;
+ try
+ {
+ document = reader.read( path );
+ }
+ catch ( DocumentException e )
+ {
+ throw new XMLSchemaFileImportException( "The file '" + path + "' can not be read correctly." );
+ }
+
+ // Name
+ schema.setName( getSchemaName( document, path ) );
+
+ // Attribute Types
+ readAttributeTypes( document, schema );
+
+ // Object Classes
+ readObjectClasses( document, schema );
+
+ // Matching Rules
+ readMatchingRules( document, schema );
+
+ // Syntaxes
+ readSyntaxes( document, schema );
+
+ return schema;
+ }
+
+
+ /**
+ * Gets the name of the schema.
+ *
+ * @param document
+ * the Document
+ * @param path
+ * the path
+ * @return
+ * the name of the schema
+ * @throws XMLSchemaFileImportException
+ * if an error occurs when reading the file
+ */
+ private static String getSchemaName( Document document, String path ) throws XMLSchemaFileImportException
+ {
+ Element schemaElement = document.getRootElement();
+ if ( !schemaElement.getName().equals( SCHEMA_TAG ) )
+ {
+ throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem to be a valid Schema file." );
+ }
+
+ Attribute nameAttribute = schemaElement.attribute( NAME_TAG );
+ if ( ( nameAttribute != null ) && ( !nameAttribute.getValue().equals( "" ) ) )
+ {
+ return nameAttribute.getValue();
+ }
+ else
+ {
+ return getNameFromPath( path );
+ }
+ }
+
+
+ /**
+ * Gets the name of the file.
+ *
+ * @param path
+ * the path
+ * @return
+ * the name of the file.
+ */
+ private static final String getNameFromPath( String path )
+ {
+ String separator = File.separator;
+
+ String[] splFileName = path.split( separator );
+ String fileNoPath = splFileName[splFileName.length - 1];
+
+ if ( fileNoPath.endsWith( ".xml" ) ) //$NON-NLS-1$
+ {
+ String[] fileName = fileNoPath.split( "\\." ); //$NON-NLS-1$
+ return fileName[0];
+ }
+
+ return fileNoPath;
+ }
+
+
+ /**
+ * Reads the attribute types.
+ *
+ * @param document
+ * the document
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readAttributeTypes( Document document, Schema schema ) throws XMLSchemaFileImportException
+ {
+ for ( Iterator<?> i = document.getRootElement().elementIterator( ATTRIBUTE_TYPES_TAG ); i.hasNext(); )
+ {
+ Element attributesTypesElement = ( Element ) i.next();
+ for ( Iterator<?> i2 = attributesTypesElement.elementIterator( ATTRIBUTE_TYPE_TAG ); i2.hasNext(); )
+ {
+ readAttributeType( ( Element ) i2.next(), schema );
+ }
+ }
+ }
+
+
+ /**
+ * Reads an attribute type.
+ *
+ * @param element
+ * the element
+ * @param schema
+ * the schema
+ */
+ private static void readAttributeType( Element element, Schema schema ) throws XMLSchemaFileImportException
+ {
+ AttributeTypeImpl at = null;
+
+ // OID
+ Attribute oidAttribute = element.attribute( OID_TAG );
+ if ( ( oidAttribute != null ) && ( !oidAttribute.getValue().equals( "" ) ) )
+ {
+ at = new AttributeTypeImpl( oidAttribute.getValue() );
+ }
+ else
+ {
+ throw new XMLSchemaFileImportException(
+ "An attribute type definition must contain an attribute for the OID." );
+ }
+
+ // Schema
+ at.setSchema( schema.getName() );
+
+ // Aliases
+ Element aliasesElement = element.element( ALIASES_TAG );
+ if ( aliasesElement != null )
+ {
+ List<String> aliases = new ArrayList<String>();
+ for ( Iterator<?> i = aliasesElement.elementIterator( ALIAS_TAG ); i.hasNext(); )
+ {
+ Element aliasElement = ( Element ) i.next();
+ aliases.add( aliasElement.getText() );
+ }
+ if ( aliases.size() >= 1 )
+ {
+ at.setNames( aliases.toArray( new String[0] ) );
+ }
+ }
+
+ // Description
+ Element descriptionElement = element.element( DESCRIPTION_TAG );
+ if ( ( descriptionElement != null ) && ( !descriptionElement.getText().equals( "" ) ) )
+ {
+ at.setDescription( descriptionElement.getText() );
+ }
+
+ // Superior
+ Element superiorElement = element.element( SUPERIOR_TAG );
+ if ( ( superiorElement != null ) && ( !superiorElement.getText().equals( "" ) ) )
+ {
+ at.setSuperiorName( superiorElement.getText() );
+ }
+
+ // Usage
+ Element usageElement = element.element( USAGE_TAG );
+ if ( ( usageElement != null ) && ( !usageElement.getText().equals( "" ) ) )
+ {
+ try
+ {
+ at.setUsage( UsageEnum.valueOf( usageElement.getText() ) );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ throw new XMLSchemaFileImportException(
+ "The parser was not able to convert the usage value of the attribute type." );
+ }
+ }
+
+ // Syntax
+ Element syntaxElement = element.element( SYNTAX_TAG );
+ if ( ( syntaxElement != null ) && ( !syntaxElement.getText().equals( "" ) ) )
+ {
+ at.setSyntaxOid( syntaxElement.getText() );
+ }
+
+ // Syntax Length
+ Element syntaxLengthElement = element.element( SYNTAX_LENGTH_TAG );
+ if ( ( syntaxLengthElement != null ) && ( !syntaxLengthElement.getText().equals( "" ) ) )
+ {
+ try
+ {
+ at.setLength( Integer.parseInt( syntaxLengthElement.getText() ) );
+ }
+ catch ( NumberFormatException e )
+ {
+ throw new XMLSchemaFileImportException(
+ "The parser was not able to convert the syntax length value of the attribute type to an integer." );
+ }
+ }
+
+ // Obsolete
+ Attribute obsoleteAttribute = element.attribute( OBSOLETE_TAG );
+ if ( ( obsoleteAttribute != null ) && ( !obsoleteAttribute.getValue().equals( "" ) ) )
+ {
+ at.setObsolete( readBoolean( obsoleteAttribute.getValue() ) );
+ }
+
+ // Single Value
+ Attribute singleValueAttribute = element.attribute( SINGLE_VALUE_TAG );
+ if ( ( singleValueAttribute != null ) && ( !singleValueAttribute.getValue().equals( "" ) ) )
+ {
+ at.setSingleValue( readBoolean( singleValueAttribute.getValue() ) );
+ }
+
+ // Collective
+ Attribute collectiveAttribute = element.attribute( COLLECTIVE_TAG );
+ if ( ( collectiveAttribute != null ) && ( !collectiveAttribute.getValue().equals( "" ) ) )
+ {
+ at.setCollective( readBoolean( collectiveAttribute.getValue() ) );
+ }
+
+ // No User Modification
+ Attribute noUserModificationAttribute = element.attribute( NO_USER_MODIFICATION_TAG );
+ if ( ( noUserModificationAttribute != null ) && ( !noUserModificationAttribute.getValue().equals( "" ) ) )
+ {
+ at.setCanUserModify( !readBoolean( noUserModificationAttribute.getValue() ) );
+ }
+
+ // Equality
+ Element equalityElement = element.element( EQUALITY_TAG );
+ if ( ( equalityElement != null ) && ( !equalityElement.getText().equals( "" ) ) )
+ {
+ at.setEqualityName( equalityElement.getText() );
+ }
+
+ // Ordering
+ Element orderingElement = element.element( ORDERING_TAG );
+ if ( ( orderingElement != null ) && ( !orderingElement.getText().equals( "" ) ) )
+ {
+ at.setOrderingName( orderingElement.getText() );
+ }
+
+ // Substring
+ Element substringElement = element.element( SUBSTRING_TAG );
+ if ( ( substringElement != null ) && ( !substringElement.getText().equals( "" ) ) )
+ {
+ at.setSubstrName( substringElement.getText() );
+ }
+
+ // Adding the attribute type to the schema
+ schema.addAttributeType( at );
+ }
+
+
+ /**
+ * Reads the object classes
+ *
+ * @param document
+ * the document
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readObjectClasses( Document document, Schema schema ) throws XMLSchemaFileImportException
+ {
+ for ( Iterator<?> i = document.getRootElement().elementIterator( OBJECT_CLASSES_TAG ); i.hasNext(); )
+ {
+ Element objectClassesElement = ( Element ) i.next();
+ for ( Iterator<?> i2 = objectClassesElement.elementIterator( OBJECT_CLASS_TAG ); i2.hasNext(); )
+ {
+ readObjectClass( ( Element ) i2.next(), schema );
+ }
+ }
+ }
+
+
+ /**
+ * Reads an object class
+ *
+ * @param element
+ * the element
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readObjectClass( Element element, Schema schema ) throws XMLSchemaFileImportException
+ {
+ ObjectClassImpl oc = null;
+
+ // OID
+ Attribute oidAttribute = element.attribute( OID_TAG );
+ if ( ( oidAttribute != null ) && ( !oidAttribute.getValue().equals( "" ) ) )
+ {
+ oc = new ObjectClassImpl( oidAttribute.getValue() );
+ }
+ else
+ {
+ throw new XMLSchemaFileImportException( "An object class definition must contain an attribute for the OID." );
+ }
+
+ // Schema
+ oc.setSchema( schema.getName() );
+
+ // Aliases
+ Element aliasesElement = element.element( ALIASES_TAG );
+ if ( aliasesElement != null )
+ {
+ List<String> aliases = new ArrayList<String>();
+ for ( Iterator<?> i = aliasesElement.elementIterator( ALIAS_TAG ); i.hasNext(); )
+ {
+ Element aliasElement = ( Element ) i.next();
+ aliases.add( aliasElement.getText() );
+ }
+ if ( aliases.size() >= 1 )
+ {
+ oc.setNames( aliases.toArray( new String[0] ) );
+ }
+ }
+
+ // Description
+ Element descriptionElement = element.element( DESCRIPTION_TAG );
+ if ( ( descriptionElement != null ) && ( !descriptionElement.getText().equals( "" ) ) )
+ {
+ oc.setDescription( descriptionElement.getText() );
+ }
+
+ // Superiors
+ Element superiorsElement = element.element( SUPERIORS_TAG );
+ if ( superiorsElement != null )
+ {
+ List<String> superiors = new ArrayList<String>();
+ for ( Iterator<?> i = superiorsElement.elementIterator( SUPERIOR_TAG ); i.hasNext(); )
+ {
+ Element superiorElement = ( Element ) i.next();
+ superiors.add( superiorElement.getText() );
+ }
+ if ( superiors.size() >= 1 )
+ {
+ oc.setSuperClassesNames( superiors.toArray( new String[0] ) );
+ }
+ }
+
+ // Class Type
+ Element classTypeElement = element.element( TYPE_TAG );
+ if ( ( classTypeElement != null ) && ( !classTypeElement.getText().equals( "" ) ) )
+ {
+ try
+ {
+ oc.setType( ObjectClassTypeEnum.valueOf( classTypeElement.getText() ) );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ throw new XMLSchemaFileImportException(
+ "The parser was not able to convert the usage value of the attribute type." );
+ }
+ }
+
+ // Obsolete
+ Attribute obsoleteAttribute = element.attribute( OBSOLETE_TAG );
+ if ( ( obsoleteAttribute != null ) && ( !obsoleteAttribute.getValue().equals( "" ) ) )
+ {
+ oc.setObsolete( readBoolean( obsoleteAttribute.getValue() ) );
+ }
+
+ // Mandatory Attribute Types
+ Element mandatoryElement = element.element( MANDATORY_TAG );
+ if ( mandatoryElement != null )
+ {
+ List<String> mandatoryATs = new ArrayList<String>();
+ for ( Iterator<?> i = mandatoryElement.elementIterator( ATTRIBUTE_TYPE_TAG ); i.hasNext(); )
+ {
+ Element attributeTypeElement = ( Element ) i.next();
+ mandatoryATs.add( attributeTypeElement.getText() );
+ }
+ if ( mandatoryATs.size() >= 1 )
+ {
+ oc.setMustNamesList( mandatoryATs.toArray( new String[0] ) );
+ }
+ }
+
+ // Optional Attribute Types
+ Element optionalElement = element.element( OPTIONAL_TAG );
+ if ( optionalElement != null )
+ {
+ List<String> optionalATs = new ArrayList<String>();
+ for ( Iterator<?> i = optionalElement.elementIterator( ATTRIBUTE_TYPE_TAG ); i.hasNext(); )
+ {
+ Element attributeTypeElement = ( Element ) i.next();
+ optionalATs.add( attributeTypeElement.getText() );
+ }
+ if ( optionalATs.size() >= 1 )
+ {
+ oc.setMayNamesList( optionalATs.toArray( new String[0] ) );
+ }
+ }
+
+ // Adding the object class to the schema
+ schema.addObjectClass( oc );
+ }
+
+
+ /**
+ * Reads the matching rules.
+ *
+ * @param document
+ * the document
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readMatchingRules( Document document, Schema schema ) throws XMLSchemaFileImportException
+ {
+ for ( Iterator<?> i = document.getRootElement().elementIterator( MATCHING_RULES_TAG ); i.hasNext(); )
+ {
+ Element matchingRulesElement = ( Element ) i.next();
+ for ( Iterator<?> i2 = matchingRulesElement.elementIterator( MATCHING_RULE_TAG ); i2.hasNext(); )
+ {
+ readMatchingRule( ( Element ) i2.next(), schema );
+ }
+ }
+ }
+
+
+ /**
+ * Reads a matching rule.
+ *
+ * @param element
+ * the element
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readMatchingRule( Element element, Schema schema ) throws XMLSchemaFileImportException
+ {
+ MatchingRuleImpl mr = null;
+
+ // OID
+ Attribute oidAttribute = element.attribute( OID_TAG );
+ if ( ( oidAttribute != null ) && ( !oidAttribute.getValue().equals( "" ) ) )
+ {
+ mr = new MatchingRuleImpl( oidAttribute.getValue() );
+ }
+ else
+ {
+ throw new XMLSchemaFileImportException( "A matching rule definition must contain an attribute for the OID." );
+ }
+
+ // Schema
+ mr.setSchema( schema.getName() );
+
+ // Aliases
+ Element aliasesElement = element.element( ALIASES_TAG );
+ if ( aliasesElement != null )
+ {
+ List<String> aliases = new ArrayList<String>();
+ for ( Iterator<?> i = aliasesElement.elementIterator( ALIAS_TAG ); i.hasNext(); )
+ {
+ Element aliasElement = ( Element ) i.next();
+ aliases.add( aliasElement.getText() );
+ }
+ if ( aliases.size() >= 1 )
+ {
+ mr.setNames( aliases.toArray( new String[0] ) );
+ }
+ }
+
+ // Description
+ Element descriptionElement = element.element( DESCRIPTION_TAG );
+ if ( ( descriptionElement != null ) && ( !descriptionElement.getText().equals( "" ) ) )
+ {
+ mr.setDescription( descriptionElement.getText() );
+ }
+
+ // Obsolete
+ Attribute obsoleteAttribute = element.attribute( OBSOLETE_TAG );
+ if ( ( obsoleteAttribute != null ) && ( !obsoleteAttribute.getValue().equals( "" ) ) )
+ {
+ mr.setObsolete( readBoolean( obsoleteAttribute.getValue() ) );
+ }
+
+ // Syntax OID
+ Element syntaxOidElement = element.element( SYNTAX_OID_TAG );
+ if ( ( syntaxOidElement != null ) && ( !syntaxOidElement.getText().equals( "" ) ) )
+ {
+ mr.setSyntaxOid( syntaxOidElement.getText() );
+ }
+
+ // Adding the matching rule to the schema
+ schema.addMatchingRule( mr );
+ }
+
+
+ /**
+ * Reads the syntaxes
+ *
+ * @param document
+ * the document
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readSyntaxes( Document document, Schema schema ) throws XMLSchemaFileImportException
+ {
+ for ( Iterator<?> i = document.getRootElement().elementIterator( SYNTAXES_TAG ); i.hasNext(); )
+ {
+ Element syntaxElement = ( Element ) i.next();
+ for ( Iterator<?> i2 = syntaxElement.elementIterator( SYNTAX_TAG ); i2.hasNext(); )
+ {
+ readSyntax( ( Element ) i2.next(), schema );
+ }
+ }
+ }
+
+
+ /**
+ * Reads a syntax.
+ *
+ * @param element
+ * the element
+ * @param schema
+ * the schema
+ * @throws XMLSchemaFileImportException
+ */
+ private static void readSyntax( Element element, Schema schema ) throws XMLSchemaFileImportException
+ {
+ SyntaxImpl syntax = null;
+
+ // OID
+ Attribute oidAttribute = element.attribute( OID_TAG );
+ if ( ( oidAttribute != null ) && ( !oidAttribute.getValue().equals( "" ) ) )
+ {
+ syntax = new SyntaxImpl( oidAttribute.getValue() );
+ }
+ else
+ {
+ throw new XMLSchemaFileImportException( "A syntax definition must contain an attribute for the OID." );
+ }
+
+ // Schema
+ syntax.setSchema( schema.getName() );
+
+ // Aliases
+ Element aliasesElement = element.element( ALIASES_TAG );
+ if ( aliasesElement != null )
+ {
+ List<String> aliases = new ArrayList<String>();
+ for ( Iterator<?> i = aliasesElement.elementIterator( ALIAS_TAG ); i.hasNext(); )
+ {
+ Element aliasElement = ( Element ) i.next();
+ aliases.add( aliasElement.getText() );
+ }
+ if ( aliases.size() >= 1 )
+ {
+ syntax.setNames( aliases.toArray( new String[0] ) );
+ }
+ }
+
+ // Description
+ Element descriptionElement = element.element( DESCRIPTION_TAG );
+ if ( ( descriptionElement != null ) && ( !descriptionElement.getText().equals( "" ) ) )
+ {
+ syntax.setDescription( descriptionElement.getText() );
+ }
+
+ // Obsolete
+ Attribute obsoleteAttribute = element.attribute( OBSOLETE_TAG );
+ if ( ( obsoleteAttribute != null ) && ( !obsoleteAttribute.getValue().equals( "" ) ) )
+ {
+ syntax.setObsolete( readBoolean( obsoleteAttribute.getValue() ) );
+ }
+
+ // Human Readible
+ Attribute humanReadibleAttribute = element.attribute( HUMAN_READIBLE_TAG );
+ if ( ( humanReadibleAttribute != null ) && ( !humanReadibleAttribute.getValue().equals( "" ) ) )
+ {
+ syntax.setHumanReadible( readBoolean( humanReadibleAttribute.getValue() ) );
+ }
+
+ // Adding the syntax to the schema
+ schema.addSyntax( syntax );
+ }
+
+
+ /**
+ * Reads a boolean value
+ *
+ * @param value
+ * the value
+ * @return
+ * the boolean value
+ * @throws XMLSchemaFileImportException
+ * if the boolean could not be read
+ */
+ private static boolean readBoolean( String value ) throws XMLSchemaFileImportException
+ {
+ if ( value.equals( BOOLEAN_TRUE ) )
+ {
+ return true;
+ }
+ else if ( value.equals( BOOLEAN_FALSE ) )
+ {
+ return false;
+ }
+ else
+ {
+ throw new XMLSchemaFileImportException( "The parser was not able to convert a boolean value." );
+ }
+ }
+}