View Javadoc

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.server.schema.bootstrap;
21  
22  
23  import org.apache.directory.server.constants.ServerDNConstants;
24  import org.apache.directory.shared.ldap.util.ArrayUtils;
25  import org.apache.directory.shared.ldap.util.ClassUtils;
26  
27  
28  /**
29   * Abstract bootstrap schema implementation.
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   * @version $Rev: 602753 $
33   */
34  public class AbstractBootstrapSchema implements BootstrapSchema
35  {
36      protected static final String[] DEFAULT_DEPS = ArrayUtils.EMPTY_STRING_ARRAY;
37      private static final String DEFAULT_OWNER = ServerDNConstants.ADMIN_SYSTEM_DN;
38      private static final String DEFAULT_SCHEMA_NAME = "default";
39      private static final String DEFAULT_PACKAGE_NAME = AbstractBootstrapSchema.class.getPackage().getName();
40  
41      private final String owner;
42      private final String schemaName;
43      private final String packageName;
44      private String[] dependencies;
45  
46      private transient String baseName;
47      private transient String defaultBaseName;
48  
49      private transient String schemaNameCapped;
50  
51  
52      // ------------------------------------------------------------------------
53      // C O N S T R U C T O R S
54      // ------------------------------------------------------------------------
55  
56      protected AbstractBootstrapSchema(String schemaName)
57      {
58          this( null, schemaName, null, null );
59      }
60  
61  
62      protected AbstractBootstrapSchema(String owner, String schemaName)
63      {
64          this( owner, schemaName, null, null );
65      }
66  
67  
68      protected AbstractBootstrapSchema(String owner, String schemaName, String packageName)
69      {
70          this( owner, schemaName, packageName, null );
71      }
72  
73  
74      protected AbstractBootstrapSchema(String owner, String schemaName, String packageName, String[] dependencies)
75      {
76          if ( owner == null )
77          {
78              this.owner = DEFAULT_OWNER;
79          }
80          else
81          {
82              this.owner = owner;
83          }
84  
85          if ( schemaName == null )
86          {
87              this.schemaName = DEFAULT_SCHEMA_NAME;
88          }
89          else
90          {
91              this.schemaName = schemaName;
92          }
93  
94          if ( packageName == null )
95          {
96              this.packageName = DEFAULT_PACKAGE_NAME;
97          }
98          else
99          {
100             this.packageName = packageName;
101         }
102 
103         if ( dependencies == null )
104         {
105             this.dependencies = ArrayUtils.EMPTY_STRING_ARRAY;
106         }
107         else
108         {
109             this.dependencies = dependencies;
110         }
111 
112         StringBuffer buf = new StringBuffer();
113         buf.append( Character.toUpperCase( schemaName.charAt( 0 ) ) );
114         buf.append( schemaName.substring( 1, schemaName.length() ) );
115         schemaNameCapped = buf.toString();
116 
117         buf.setLength( 0 );
118         buf.append( DEFAULT_PACKAGE_NAME );
119         buf.append( ClassUtils.PACKAGE_SEPARATOR_CHAR );
120         buf.append( schemaNameCapped );
121         defaultBaseName = buf.toString();
122 
123         buf.setLength( 0 );
124         buf.append( packageName );
125         buf.append( ClassUtils.PACKAGE_SEPARATOR_CHAR );
126         buf.append( schemaNameCapped );
127         baseName = buf.toString();
128     }
129 
130 
131     public final String getOwner()
132     {
133         return owner;
134     }
135 
136 
137     public final String getSchemaName()
138     {
139         return schemaName;
140     }
141 
142 
143     public final String[] getDependencies()
144     {
145         return dependencies;
146     }
147 
148 
149     protected final void setDependencies( String[] dependencies )
150     {
151         this.dependencies = dependencies;
152     }
153 
154 
155     public String getBaseClassName()
156     {
157         return baseName;
158     }
159 
160 
161     public String getDefaultBaseClassName()
162     {
163         return defaultBaseName;
164     }
165 
166 
167     public String getFullClassName( ProducerTypeEnum type )
168     {
169         return baseName + type.getName();
170     }
171 
172 
173     public String getFullDefaultBaseClassName( ProducerTypeEnum type )
174     {
175         return defaultBaseName + type.getName();
176     }
177 
178 
179     public String getUnqualifiedClassName( ProducerTypeEnum type )
180     {
181         return schemaNameCapped + type.getName();
182     }
183 
184 
185     public String getPackageName()
186     {
187         return packageName;
188     }
189 
190 
191     public String getUnqualifiedClassName()
192     {
193         return schemaNameCapped + "Schema";
194     }
195 
196 
197     public boolean isDisabled()
198     {
199         return false;
200     }
201 }