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.descriptors;
23 
24 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertyGetter;
25 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertySetter;
26 import org.apache.openoffice.comp.sdbc.dbtools.sdbcx.ODescriptor;
27 import org.apache.openoffice.comp.sdbc.dbtools.util.PropertyIds;
28 
29 import com.sun.star.lang.XServiceInfo;
30 import com.sun.star.uno.Type;
31 
32 public class SdbcxColumnDescriptor extends ODescriptor implements XServiceInfo {
33     private static final String[] services = {
34             "com.sun.star.sdbcx.ColumnDescriptor"
35     };
36 
37     protected int type;
38     protected String typeName = "";
39     protected int precision;
40     protected int scale;
41     protected int isNullable;
42     protected boolean isAutoIncrement;
43     protected boolean isRowVersion;
44     protected String description = "";
45     protected String defaultValue = "";
46     protected boolean isCurrency;
47 
SdbcxColumnDescriptor(boolean isCaseSensitive)48     public SdbcxColumnDescriptor(boolean isCaseSensitive) {
49         super("", isCaseSensitive, false);
50         registerProperties();
51     }
52 
registerProperties()53     private void registerProperties() {
54         registerProperty(PropertyIds.TYPE.name, PropertyIds.TYPE.id, Type.LONG, (short)0,
55                 new PropertyGetter() {
56                     @Override
57                     public Object getValue() {
58                         return type;
59 
60                     }
61                 },
62                 new PropertySetter() {
63                     @Override
64                     public void setValue(Object value) {
65                         type = (int) value;
66                     }
67                 });
68         registerProperty(PropertyIds.TYPENAME.name, PropertyIds.TYPENAME.id, Type.STRING, (short)0,
69                 new PropertyGetter() {
70                     @Override
71                     public Object getValue() {
72                         return typeName;
73 
74                     }
75                 },
76                 new PropertySetter() {
77                     @Override
78                     public void setValue(Object value) {
79                         typeName = (String) value;
80                     }
81                 });
82         registerProperty(PropertyIds.PRECISION.name, PropertyIds.PRECISION.id, Type.LONG, (short)0,
83                 new PropertyGetter() {
84                     @Override
85                     public Object getValue() {
86                         return precision;
87 
88                     }
89                 },
90                 new PropertySetter() {
91                     @Override
92                     public void setValue(Object value) {
93                         precision = (Integer) value;
94                     }
95                 });
96         registerProperty(PropertyIds.SCALE.name, PropertyIds.SCALE.id, Type.LONG, (short)0,
97                 new PropertyGetter() {
98                     @Override
99                     public Object getValue() {
100                         return scale;
101 
102                     }
103                 },
104                 new PropertySetter() {
105                     @Override
106                     public void setValue(Object value) {
107                         scale = (Integer) value;
108                     }
109                 });
110         registerProperty(PropertyIds.ISNULLABLE.name, PropertyIds.ISNULLABLE.id, Type.LONG, (short)0,
111                 new PropertyGetter() {
112                     @Override
113                     public Object getValue() {
114                         return isNullable;
115 
116                     }
117                 },
118                 new PropertySetter() {
119                     @Override
120                     public void setValue(Object value) {
121                         isNullable = (Integer) value;
122                     }
123                 });
124         registerProperty(PropertyIds.ISAUTOINCREMENT.name, PropertyIds.ISAUTOINCREMENT.id, Type.BOOLEAN, (short)0,
125                 new PropertyGetter() {
126                     @Override
127                     public Object getValue() {
128                         return isAutoIncrement;
129 
130                     }
131                 },
132                 new PropertySetter() {
133                     @Override
134                     public void setValue(Object value) {
135                         isAutoIncrement = (Boolean) value;
136                     }
137                 });
138         registerProperty(PropertyIds.ISROWVERSION.name, PropertyIds.ISROWVERSION.id, Type.BOOLEAN, (short)0,
139                 new PropertyGetter() {
140                     @Override
141                     public Object getValue() {
142                         return isRowVersion;
143 
144                     }
145                 },
146                 new PropertySetter() {
147                     @Override
148                     public void setValue(Object value) {
149                         isRowVersion = (Boolean) value;
150                     }
151                 });
152         registerProperty(PropertyIds.DESCRIPTION.name, PropertyIds.DESCRIPTION.id, Type.STRING, (short)0,
153                 new PropertyGetter() {
154                     @Override
155                     public Object getValue() {
156                         return description;
157 
158                     }
159                 },
160                 new PropertySetter() {
161                     @Override
162                     public void setValue(Object value) {
163                         description = (String) value;
164                     }
165                 });
166         registerProperty(PropertyIds.DEFAULTVALUE.name, PropertyIds.DEFAULTVALUE.id, Type.STRING, (short)0,
167                 new PropertyGetter() {
168                     @Override
169                     public Object getValue() {
170                         return defaultValue;
171 
172                     }
173                 },
174                 new PropertySetter() {
175                     @Override
176                     public void setValue(Object value) {
177                         defaultValue = (String) value;
178                     }
179                 });
180         registerProperty(PropertyIds.ISCURRENCY.name, PropertyIds.ISCURRENCY.id, Type.BOOLEAN, (short)0,
181                 new PropertyGetter() {
182                     @Override
183                     public Object getValue() {
184                         return isCurrency;
185 
186                     }
187                 },
188                 new PropertySetter() {
189                     @Override
190                     public void setValue(Object value) {
191                         isCurrency = (Boolean) value;
192                     }
193                 });
194     }
195 
196     // XServiceInfo
197 
198     @Override
getImplementationName()199     public String getImplementationName() {
200         return getClass().getName();
201     }
202 
203     @Override
getSupportedServiceNames()204     public String[] getSupportedServiceNames() {
205         return services.clone();
206     }
207 
208     @Override
supportsService(String serviceName)209     public boolean supportsService(String serviceName) {
210         for (String service : getSupportedServiceNames()) {
211             if (service.equals(serviceName)) {
212                 return true;
213             }
214         }
215         return false;
216     }
217 }
218