1 20 21 package org.apache.directory.ldapstudio.browser.core.model.ldif.container; 22 23 24 import java.util.Iterator ; 25 26 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEOFPart; 27 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart; 28 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifCommentLine; 29 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDnLine; 30 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine; 31 32 33 public abstract class LdifRecord extends LdifContainer 34 { 35 36 protected LdifRecord() 37 { 38 } 39 40 41 protected LdifRecord( LdifDnLine dn ) 42 { 43 super( dn ); 44 } 45 46 47 public void addComment( LdifCommentLine comment ) 48 { 49 if ( comment == null ) 50 throw new IllegalArgumentException ( "null argument" ); 51 this.parts.add( comment ); 52 } 53 54 55 public void finish( LdifSepLine sep ) 56 { 57 if ( sep == null ) 58 throw new IllegalArgumentException ( "null argument" ); 59 this.parts.add( sep ); 60 } 61 62 63 public void finish( LdifEOFPart eof ) 64 { 65 if ( eof == null ) 66 throw new IllegalArgumentException ( "null argument" ); 67 this.parts.add( eof ); 68 } 69 70 71 public LdifDnLine getDnLine() 72 { 73 return ( LdifDnLine ) this.parts.get( 0 ); 74 } 75 76 77 public LdifSepLine getSepLine() 78 { 79 for ( Iterator it = this.parts.iterator(); it.hasNext(); ) 80 { 81 Object o = it.next(); 82 if ( o instanceof LdifSepLine ) 83 { 84 return ( LdifSepLine ) o; 85 } 86 } 87 88 return null; 89 } 90 91 92 public String getInvalidString() 93 { 94 LdifDnLine dnLine = getDnLine(); 95 LdifSepLine sepLine = getSepLine(); 96 97 if ( dnLine == null ) 98 return "Record must start with DN"; 99 else if ( !dnLine.isValid() ) 100 return dnLine.getInvalidString(); 101 102 if ( sepLine == null ) 103 return "Record must end with an empty line"; 104 else if ( !sepLine.isValid() ) 105 return sepLine.getInvalidString(); 106 107 return super.getInvalidString(); 108 } 109 110 111 protected boolean isAbstractValid() 112 { 113 if ( !super.isAbstractValid() ) 114 { 115 return false; 116 } 117 118 LdifPart lastPart = getLastPart(); 119 return this.getDnLine().isValid() && ( lastPart instanceof LdifSepLine || lastPart instanceof LdifEOFPart ) 120 && lastPart.isValid(); 121 } 122 123 } 124 | Popular Tags |