KickJava   Java API By Example, From Geeks To Geeks.

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


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.lines.LdifChangeTypeLine;
27 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDeloldrdnLine;
28 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDnLine;
29 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewrdnLine;
30 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewsuperiorLine;
31
32
33 public class LdifChangeModDnRecord extends LdifChangeRecord
34 {
35
36     private static final long serialVersionUID = 4439094400671169207L;
37
38
39     protected LdifChangeModDnRecord()
40     {
41     }
42
43
44     public LdifChangeModDnRecord( LdifDnLine dn )
45     {
46         super( dn );
47     }
48
49
50     public void setNewrdn( LdifNewrdnLine newrdn )
51     {
52         if ( newrdn == null )
53             throw new IllegalArgumentException JavaDoc( "null argument" );
54         this.parts.add( newrdn );
55     }
56
57
58     public void setDeloldrdn( LdifDeloldrdnLine deloldrdn )
59     {
60         if ( deloldrdn == null )
61             throw new IllegalArgumentException JavaDoc( "null argument" );
62         this.parts.add( deloldrdn );
63     }
64
65
66     public void setNewsuperior( LdifNewsuperiorLine newsuperior )
67     {
68         if ( newsuperior == null )
69             throw new IllegalArgumentException JavaDoc( "null argument" );
70         this.parts.add( newsuperior );
71     }
72
73
74     public LdifNewrdnLine getNewrdnLine()
75     {
76         for ( Iterator JavaDoc it = this.parts.iterator(); it.hasNext(); )
77         {
78             Object JavaDoc o = it.next();
79             if ( o instanceof LdifNewrdnLine )
80             {
81                 return ( LdifNewrdnLine ) o;
82             }
83         }
84
85         return null;
86     }
87
88
89     public LdifDeloldrdnLine getDeloldrdnLine()
90     {
91         for ( Iterator JavaDoc it = this.parts.iterator(); it.hasNext(); )
92         {
93             Object JavaDoc o = it.next();
94             if ( o instanceof LdifDeloldrdnLine )
95             {
96                 return ( LdifDeloldrdnLine ) o;
97             }
98         }
99
100         return null;
101     }
102
103
104     public LdifNewsuperiorLine getNewsuperiorLine()
105     {
106         for ( Iterator JavaDoc it = this.parts.iterator(); it.hasNext(); )
107         {
108             Object JavaDoc o = it.next();
109             if ( o instanceof LdifNewsuperiorLine )
110             {
111                 return ( LdifNewsuperiorLine ) o;
112             }
113         }
114
115         return null;
116     }
117
118
119     public static LdifChangeModDnRecord create( String JavaDoc dn )
120     {
121         LdifChangeModDnRecord record = new LdifChangeModDnRecord( LdifDnLine.create( dn ) );
122         record.setChangeType( LdifChangeTypeLine.createModDn() );
123         return record;
124     }
125
126
127     public boolean isValid()
128     {
129         if ( !super.isAbstractValid() )
130         {
131             return false;
132         }
133
134         return this.getNewrdnLine() != null && this.getDeloldrdnLine() != null;
135     }
136
137
138     public String JavaDoc getInvalidString()
139     {
140         if ( this.getNewrdnLine() == null )
141         {
142             return "Missing new RDN";
143         }
144         else if ( this.getDeloldrdnLine() == null )
145         {
146             return "Missing delete old RDN";
147         }
148         else
149         {
150             return super.getInvalidString();
151         }
152     }
153
154 }
155
Popular Tags