KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > ldif > lines > LdifModSpecTypeLine


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.lines;
22
23
24 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
25
26
27 public class LdifModSpecTypeLine extends LdifValueLineBase
28 {
29
30     private static final long serialVersionUID = 82623220224991909L;
31
32
33     protected LdifModSpecTypeLine()
34     {
35     }
36
37
38     public LdifModSpecTypeLine( int offset, String JavaDoc rawModType, String JavaDoc rawValueType, String JavaDoc rawAttributeDescription,
39         String JavaDoc rawNewLine )
40     {
41         super( offset, rawModType, rawValueType, rawAttributeDescription, rawNewLine );
42     }
43
44
45     public String JavaDoc getRawModType()
46     {
47         return super.getRawLineStart();
48     }
49
50
51     public String JavaDoc getUnfoldedModType()
52     {
53         return super.getUnfoldedLineStart();
54     }
55
56
57     public String JavaDoc getRawAttributeDescription()
58     {
59         return super.getRawValue();
60     }
61
62
63     public String JavaDoc getUnfoldedAttributeDescription()
64     {
65         return super.getUnfoldedValue();
66     }
67
68
69     public String JavaDoc toRawString()
70     {
71         return super.toRawString();
72     }
73
74
75     public boolean isAdd()
76     {
77         return this.getUnfoldedModType().equals( "add" );
78     }
79
80
81     public boolean isReplace()
82     {
83         return this.getUnfoldedModType().equals( "replace" );
84     }
85
86
87     public boolean isDelete()
88     {
89         return this.getUnfoldedModType().equals( "delete" );
90     }
91
92
93     public boolean isValid()
94     {
95         return super.isValid() && ( this.isAdd() || this.isReplace() || this.isDelete() );
96     }
97
98
99     public String JavaDoc getInvalidString()
100     {
101         if ( this.getUnfoldedModType().length() == 0 )
102         {
103             return "Missing modification type 'add', 'replace' or 'delete'";
104         }
105         else if ( !this.isAdd() && !this.isReplace() && !this.isDelete() )
106         {
107             return "Invalid modification type, expected 'add', 'replace' or 'delete'";
108         }
109         else if ( this.getUnfoldedAttributeDescription().length() == 0 )
110         {
111             return "Missing attribute";
112         }
113         else
114         {
115             return super.getInvalidString();
116         }
117     }
118
119
120     public static LdifModSpecTypeLine createAdd( String JavaDoc attributeName )
121     {
122         return new LdifModSpecTypeLine( 0, "add", ":", attributeName, BrowserCoreConstants.LINE_SEPARATOR );
123     }
124
125
126     public static LdifModSpecTypeLine createReplace( String JavaDoc attributeName )
127     {
128         return new LdifModSpecTypeLine( 0, "replace", ":", attributeName, BrowserCoreConstants.LINE_SEPARATOR );
129     }
130
131
132     public static LdifModSpecTypeLine createDelete( String JavaDoc attributeName )
133     {
134         return new LdifModSpecTypeLine( 0, "delete", ":", attributeName, BrowserCoreConstants.LINE_SEPARATOR );
135     }
136
137 }
138
Popular Tags