001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.geronimo.console.databasemanager.wizard;
019
020 import org.apache.geronimo.kernel.repository.Artifact;
021 import org.apache.geronimo.gbean.GBeanInfo;
022 import org.apache.geronimo.gbean.GBeanInfoBuilder;
023
024 import java.util.regex.Pattern;
025 import java.util.regex.Matcher;
026 import java.util.List;
027 import java.util.ArrayList;
028
029 /**
030 * Implementation of DatabaseDriver that contains database driver information
031 * contained in the console's deployment plan.
032 *
033 * @version $Rev: 472167 $ $Date: 2006-11-07 12:00:18 -0500 (Tue, 07 Nov 2006) $
034 */
035 public class DatabaseDriverGBean implements DatabaseDriver {
036 private final static Pattern PARAM_PATTERN = Pattern.compile("\\{.+?\\}");
037 private String name;
038 private String URLPrototype;
039 private String driverClassName;
040 private int defaultPort;
041 private boolean XA;
042 private Artifact RAR;
043
044 public String getName() {
045 return name;
046 }
047
048 public void setName(String name) {
049 this.name = name;
050 }
051
052 public String getURLPrototype() {
053 return URLPrototype;
054 }
055
056 public void setURLPrototype(String URLPrototype) {
057 this.URLPrototype = URLPrototype;
058 }
059
060 public String getDriverClassName() {
061 return driverClassName;
062 }
063
064 public void setDriverClassName(String driverClassName) {
065 this.driverClassName = driverClassName;
066 }
067
068 public int getDefaultPort() {
069 return defaultPort;
070 }
071
072 public void setDefaultPort(int defaultPort) {
073 this.defaultPort = defaultPort;
074 }
075
076 public boolean isXA() {
077 return XA;
078 }
079
080 public void setXA(boolean XA) {
081 this.XA = XA;
082 }
083
084 public Artifact getRAR() {
085 return RAR;
086 }
087
088 public void setRARName(String name) {
089 RAR = Artifact.create(name);
090 }
091
092 public String[] getURLParameters() {
093 Matcher m = PARAM_PATTERN.matcher(URLPrototype);
094 List list = new ArrayList();
095 while(m.find()) {
096 list.add(URLPrototype.substring(m.start()+1, m.end()-1));
097 }
098 return (String[]) list.toArray(new String[list.size()]);
099 }
100
101 public static final GBeanInfo GBEAN_INFO;
102
103 static {
104 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Database Driver Info", DatabaseDriverGBean.class);
105 infoFactory.addAttribute("name", String.class, true, true);
106 infoFactory.addAttribute("URLPrototype", String.class, true, true);
107 infoFactory.addAttribute("driverClassName", String.class, true, true);
108 infoFactory.addAttribute("defaultPort", int.class, true, true);
109 infoFactory.addAttribute("XA", boolean.class, true, true);
110 infoFactory.addAttribute("RARName", String.class, true, true);
111 infoFactory.addInterface(DatabaseDriver.class);
112
113 infoFactory.setConstructor(new String[0]);
114
115 GBEAN_INFO = infoFactory.getBeanInfo();
116 }
117
118 public static GBeanInfo getGBeanInfo() {
119 return GBEAN_INFO;
120 }
121 }