* @throws OpenLdapSchemaFileImportException
* if an error occurrs when importing the schema
*/
public static Schema getSchema( InputStream inputStream, String path ) throws OpenLdapSchemaFileImportException
{
OpenLdapSchemaParser parser = null;
try
{
parser = new OpenLdapSchemaParser();
}
catch ( IOException e )
{
throw new OpenLdapSchemaFileImportException( "The file '" + path + "' can not be read correctly." );
}
try
{
parser.parse( inputStream );
}
catch ( IOException e )
{
throw new OpenLdapSchemaFileImportException( "The file '" + path + "' can not be read correctly." );
}
catch ( ParseException e )
{
ExceptionMessage exceptionMessage = parseExceptionMessage( e.getMessage() );
throw new OpenLdapSchemaFileImportException( "The file '"
+ path
+ "' can not be read correctly."
+ ( exceptionMessage == null ? "" : "\nLine: " + exceptionMessage.lineNumber + ", Column: "
+ exceptionMessage.columnNumber + ", Cause: " + exceptionMessage.cause ) );
}
String schemaName = getNameFromPath( path );
Schema schema = new SchemaImpl( schemaName );
List<?> ats = parser.getAttributeTypes();
for ( int i = 0; i < ats.size(); i++ )
{
AttributeTypeImpl at = convertAttributeType( ( AttributeTypeLiteral ) ats.get( i ) );
at.setSchema( schemaName );
schema.addAttributeType( at );
}
List<?> ocs = parser.getObjectClassTypes();
for ( int i = 0; i < ocs.size(); i++ )
{
ObjectClassImpl oc = convertObjectClass( ( ObjectClassLiteral ) ocs.get( i ) );
oc.setSchema( schemaName );
schema.addObjectClass( oc );