1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package org.apache.openoffice.comp.sdbc.dbtools.sdbcx;
23 
24 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.CompHelper;
25 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertyGetter;
26 import org.apache.openoffice.comp.sdbc.dbtools.sdbcx.descriptors.SdbcxKeyColumnDescriptor;
27 import org.apache.openoffice.comp.sdbc.dbtools.util.PropertyIds;
28 
29 import com.sun.star.beans.PropertyAttribute;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.lang.XServiceInfo;
32 import com.sun.star.uno.Type;
33 
34 public class OKeyColumn extends OColumn implements XServiceInfo {
35 
36     private static final String[] services = {
37             "com.sun.star.sdbcx.KeyColumn"
38     };
39 
40     protected String referencedColumn;
41 
OKeyColumn(boolean isCaseSensitive)42     protected OKeyColumn(boolean isCaseSensitive) {
43         super(isCaseSensitive);
44         registerProperties();
45     }
46 
OKeyColumn( final String referencedColumn, final String name, final String typeName, final String defaultValue, final String description, final int isNullable, final int precision, final int scale, final int type, final boolean isAutoIncrement, final boolean isRowVersion, final boolean isCurrency, final boolean isCaseSensitive)47     public OKeyColumn(
48             final String referencedColumn,
49             final String name,
50             final String typeName,
51             final String defaultValue,
52             final String description,
53             final int isNullable,
54             final int precision,
55             final int scale,
56             final int type,
57             final boolean isAutoIncrement,
58             final boolean isRowVersion,
59             final boolean isCurrency,
60             final boolean isCaseSensitive) {
61         super(name, typeName, defaultValue, description, isNullable,
62                 precision, scale, type, isAutoIncrement, isRowVersion, isCurrency, isCaseSensitive);
63         this.referencedColumn = referencedColumn;
64         registerProperties();
65     }
66 
registerProperties()67     private void registerProperties() {
68         registerProperty(PropertyIds.RELATEDCOLUMN.name, PropertyIds.RELATEDCOLUMN.id, Type.STRING, PropertyAttribute.READONLY,
69                 new PropertyGetter() {
70                     @Override
71                     public Object getValue() {
72                         return referencedColumn;
73 
74                     }
75                 }, null);
76     }
77 
78     // XServiceInfo
79 
getImplementationName()80     public String getImplementationName() {
81         return getClass().getName();
82     }
83 
84     @Override
getSupportedServiceNames()85     public String[] getSupportedServiceNames() {
86         return services.clone();
87     }
88 
89     @Override
supportsService(String serviceName)90     public boolean supportsService(String serviceName) {
91         for (String service : getSupportedServiceNames()) {
92             if (service.equals(serviceName)) {
93                 return true;
94             }
95         }
96         return false;
97     }
98 
99     // XDataDescriptorFactory
100 
101     @Override
createDataDescriptor()102     public XPropertySet createDataDescriptor() {
103         SdbcxKeyColumnDescriptor descriptor = new SdbcxKeyColumnDescriptor(isCaseSensitive());
104         synchronized (this) {
105             CompHelper.copyProperties(this, descriptor);
106         }
107         return descriptor;
108     }
109 }
110