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 package org.apache.openoffice.comp.sdbc.dbtools.sdbcx;
22 
23 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertyGetter;
24 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.PropertySetAdapter.PropertySetter;
25 import org.apache.openoffice.comp.sdbc.dbtools.util.PropertyIds;
26 
27 import com.sun.star.beans.PropertyAttribute;
28 import com.sun.star.container.XNamed;
29 import com.sun.star.lang.XServiceInfo;
30 import com.sun.star.uno.Type;
31 
32 public class OView extends ODescriptor
33         implements XNamed, XServiceInfo {
34 
35     private static String[] services = {
36             "com.sun.star.sdbcx.View"
37     };
38 
39     protected String catalogName;
40     protected String schemaName;
41     protected String command;
42     protected int checkOption;
43 
OView(String catalog, String schema, String name, boolean isCaseSensitive, String command, int checkOption)44     public OView(String catalog, String schema, String name, boolean isCaseSensitive, String command, int checkOption) {
45         super(name, isCaseSensitive, true);
46         this.catalogName = catalog;
47         this.schemaName = schema;
48         this.command = command;
49         this.checkOption = checkOption;
50         registerProperties();
51     }
52 
registerProperties()53     private void registerProperties() {
54         registerProperty(PropertyIds.CATALOGNAME.name, PropertyIds.CATALOGNAME.id, Type.STRING, PropertyAttribute.READONLY,
55                 new PropertyGetter() {
56                     @Override
57                     public Object getValue() {
58                         return catalogName;
59 
60                     }
61                 },
62                 new PropertySetter() {
63                     @Override
64                     public void setValue(Object value) {
65                         catalogName = (String) value;
66                     }
67                 });
68         registerProperty(PropertyIds.SCHEMANAME.name, PropertyIds.SCHEMANAME.id, Type.STRING, PropertyAttribute.READONLY,
69                 new PropertyGetter() {
70                     @Override
71                     public Object getValue() {
72                         return schemaName;
73 
74                     }
75                 },
76                 new PropertySetter() {
77                     @Override
78                     public void setValue(Object value) {
79                         schemaName = (String) value;
80                     }
81                 });
82         registerProperty(PropertyIds.COMMAND.name, PropertyIds.COMMAND.id, Type.STRING, PropertyAttribute.READONLY,
83                 new PropertyGetter() {
84                     @Override
85                     public Object getValue() {
86                         return command;
87 
88                     }
89                 },
90                 new PropertySetter() {
91                     @Override
92                     public void setValue(Object value) {
93                         command = (String) value;
94                     }
95                 });
96         registerProperty(PropertyIds.CHECKOPTION.name, PropertyIds.CHECKOPTION.id, Type.LONG, PropertyAttribute.READONLY,
97                 new PropertyGetter() {
98                     @Override
99                     public Object getValue() {
100                         return checkOption;
101 
102                     }
103                 },
104                 new PropertySetter() {
105                     @Override
106                     public void setValue(Object value) {
107                         checkOption = (int) value;
108                     }
109                 });
110     }
111 
112     // XServiceInfo
113 
getImplementationName()114     public String getImplementationName() {
115         return getClass().getName();
116     }
117 
118     @Override
getSupportedServiceNames()119     public String[] getSupportedServiceNames() {
120         return services.clone();
121     }
122 
123     @Override
supportsService(String serviceName)124     public boolean supportsService(String serviceName) {
125         for (String service : getSupportedServiceNames()) {
126             if (service.equals(serviceName)) {
127                 return true;
128             }
129         }
130         return false;
131     }
132 }
133