KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > ldif > container > LdifRecord


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
21 package org.apache.directory.ldapstudio.browser.core.model.ldif.container;
22
23
24 import java.util.Iterator JavaDoc;
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 JavaDoc( "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 JavaDoc( "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 JavaDoc( "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 JavaDoc it = this.parts.iterator(); it.hasNext(); )
80         {
81             Object JavaDoc 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 JavaDoc 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