1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * 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, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.geronimo.console.databasemanager.wizard; 19 20 import org.apache.geronimo.kernel.repository.Artifact; 21 import org.apache.geronimo.gbean.GBeanInfo; 22 import org.apache.geronimo.gbean.GBeanInfoBuilder; 23 24 import java.util.regex.Pattern; 25 import java.util.regex.Matcher; 26 import java.util.List; 27 import java.util.ArrayList; 28 import java.util.Set; 29 import java.util.HashSet; 30 31 /** 32 * Implementation of DatabaseDriver that contains database driver information 33 * contained in the console's deployment plan. 34 * 35 * @version $Rev: 567194 $ $Date: 2007-08-17 17:48:48 -0700 (Fri, 17 Aug 2007) $ 36 */ 37 public class DatabaseDriverGBean implements DatabaseDriver { 38 private final static Pattern PARAM_PATTERN = Pattern.compile("\\{.+?\\}"); 39 private String name; 40 private String URLPrototype; 41 private String driverClassName; 42 private int defaultPort; 43 private boolean specific; 44 private Artifact RAR; 45 private Set<Artifact> dependencyFilters; 46 47 public String getName() { 48 return name; 49 } 50 51 public void setName(String name) { 52 this.name = name; 53 } 54 55 public String getURLPrototype() { 56 return URLPrototype; 57 } 58 59 public void setURLPrototype(String URLPrototype) { 60 this.URLPrototype = URLPrototype; 61 } 62 63 public String getDriverClassName() { 64 return driverClassName; 65 } 66 67 public void setDriverClassName(String driverClassName) { 68 this.driverClassName = driverClassName; 69 } 70 71 public int getDefaultPort() { 72 return defaultPort; 73 } 74 75 public void setDefaultPort(int defaultPort) { 76 this.defaultPort = defaultPort; 77 } 78 79 public boolean isSpecific() { 80 return specific; 81 } 82 83 public void setSpecific(boolean specific) { 84 this.specific = specific; 85 } 86 87 public Artifact getRAR() { 88 return RAR; 89 } 90 91 public void setDependencyFilterStrings(List<String> filterStrings) { 92 dependencyFilters = new HashSet<Artifact>(); 93 for (String filterString: filterStrings) { 94 Artifact filter = Artifact.createPartial(filterString); 95 dependencyFilters.add(filter); 96 } 97 } 98 99 public Set<Artifact> getDependencyFilters() { 100 return dependencyFilters != null && !dependencyFilters.isEmpty()? dependencyFilters : null; 101 } 102 103 public void setRARName(String name) { 104 RAR = Artifact.create(name); 105 } 106 107 public List<String> getURLParameters() { 108 Matcher m = PARAM_PATTERN.matcher(URLPrototype); 109 List<String> list = new ArrayList<String>(); 110 while(m.find()) { 111 list.add(URLPrototype.substring(m.start()+1, m.end()-1)); 112 } 113 return list; 114 } 115 116 public static final GBeanInfo GBEAN_INFO; 117 118 static { 119 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Database Driver Info", DatabaseDriverGBean.class); 120 infoFactory.addAttribute("name", String.class, true, true); 121 infoFactory.addAttribute("URLPrototype", String.class, true, true); 122 infoFactory.addAttribute("driverClassName", String.class, true, true); 123 infoFactory.addAttribute("defaultPort", int.class, true, true); 124 infoFactory.addAttribute("specific", boolean.class, true, true); 125 infoFactory.addAttribute("RARName", String.class, true, true); 126 infoFactory.addAttribute("dependencyFilterStrings", List.class, true, true); 127 infoFactory.addAttribute("dependencyFilters", Set.class, false, false); 128 infoFactory.addInterface(DatabaseDriver.class); 129 130 GBEAN_INFO = infoFactory.getBeanInfo(); 131 } 132 133 public static GBeanInfo getGBeanInfo() { 134 return GBEAN_INFO; 135 } 136 }