1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.schema.parsers; 21 22 23 import java.text.ParseException; 24 25 import org.apache.directory.api.i18n.I18n; 26 import org.apache.directory.api.ldap.model.schema.MutableObjectClass; 27 import org.apache.directory.api.ldap.model.schema.ObjectClass; 28 import org.slf4j.Logger; 29 import org.slf4j.LoggerFactory; 30 31 import antlr.RecognitionException; 32 import antlr.TokenStreamException; 33 34 35 /** 36 * A parser for RFC 4512 object class descriptons 37 * 38 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 39 */ 40 public class ObjectClassDescriptionSchemaParser extends AbstractSchemaParser 41 { 42 /** The LoggerFactory used by this class */ 43 protected static final Logger LOG = LoggerFactory.getLogger( ObjectClassDescriptionSchemaParser.class ); 44 45 46 /** 47 * Creates a schema parser instance. 48 */ 49 public ObjectClassDescriptionSchemaParser() 50 { 51 // Nothing to do 52 } 53 54 55 /** 56 * Parses a object class definition according to RFC 4512: 57 * 58 * <pre> 59 * ObjectClassDescription = LPAREN WSP 60 * numericoid ; object identifier 61 * [ SP "NAME" SP qdescrs ] ; short names (descriptors) 62 * [ SP "DESC" SP qdstring ] ; description 63 * [ SP "OBSOLETE" ] ; not active 64 * [ SP "SUP" SP oids ] ; superior object classes 65 * [ SP kind ] ; kind of class 66 * [ SP "MUST" SP oids ] ; attribute types 67 * [ SP "MAY" SP oids ] ; attribute types 68 * extensions WSP RPAREN 69 * 70 * kind = "ABSTRACT" / "STRUCTURAL" / "AUXILIARY" 71 * 72 * extensions = *( SP xstring SP qdstrings ) 73 * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 74 * </pre> 75 * 76 * @param objectClassDescription the object class description to be parsed 77 * @return the parsed ObjectClassDescription bean 78 * @throws ParseException if there are any recognition errors (bad syntax) 79 */ 80 public synchronized MutableObjectClass parseObjectClassDescription( String objectClassDescription ) 81 throws ParseException 82 { 83 LOG.debug( "Parsing an ObjectClass : {}", objectClassDescription ); 84 85 if ( objectClassDescription == null ) 86 { 87 LOG.error( I18n.err( I18n.ERR_04254 ) ); 88 throw new ParseException( "Null", 0 ); 89 } 90 91 reset( objectClassDescription ); // reset and initialize the parser / lexer pair 92 93 try 94 { 95 MutableObjectClass objectClass = parser.objectClassDescription(); 96 97 // Update the schemaName 98 updateSchemaName( objectClass ); 99 100 return objectClass; 101 } 102 catch ( RecognitionException re ) 103 { 104 String msg = I18n.err( I18n.ERR_04255, objectClassDescription, re.getMessage(), re.getColumn() ); 105 LOG.error( msg ); 106 throw new ParseException( msg, re.getColumn() ); 107 } 108 catch ( TokenStreamException tse ) 109 { 110 String msg = I18n.err( I18n.ERR_04256, objectClassDescription, tse.getMessage() ); 111 LOG.error( msg ); 112 throw new ParseException( msg, 0 ); 113 } 114 115 } 116 117 118 /** 119 * Parses a ObjectClass description. 120 * 121 * @param schemaDescription The ObjectClass description to parse 122 * @return An instance of ObjectClass 123 * @throws ParseException {@inheritDoc} 124 */ 125 public ObjectClass parse( String schemaDescription ) throws ParseException 126 { 127 return parseObjectClassDescription( schemaDescription ); 128 } 129 130 }