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: */package org.apache.geronimo.console.databasemanager.wizard;
018:
019: import org.apache.geronimo.kernel.repository.Artifact;
020: import org.apache.geronimo.gbean.GBeanInfo;
021: import org.apache.geronimo.gbean.GBeanInfoBuilder;
022:
023: import java.util.regex.Pattern;
024: import java.util.regex.Matcher;
025: import java.util.List;
026: import java.util.ArrayList;
027: import java.util.Set;
028: import java.util.HashSet;
029:
030: /**
031: * Implementation of DatabaseDriver that contains database driver information
032: * contained in the console's deployment plan.
033: *
034: * @version $Rev: 567194 $ $Date: 2007-08-17 17:48:48 -0700 (Fri, 17 Aug 2007) $
035: */
036: public class DatabaseDriverGBean implements DatabaseDriver {
037: private final static Pattern PARAM_PATTERN = Pattern
038: .compile("\\{.+?\\}");
039: private String name;
040: private String URLPrototype;
041: private String driverClassName;
042: private int defaultPort;
043: private boolean specific;
044: private Artifact RAR;
045: private Set<Artifact> dependencyFilters;
046:
047: public String getName() {
048: return name;
049: }
050:
051: public void setName(String name) {
052: this .name = name;
053: }
054:
055: public String getURLPrototype() {
056: return URLPrototype;
057: }
058:
059: public void setURLPrototype(String URLPrototype) {
060: this .URLPrototype = URLPrototype;
061: }
062:
063: public String getDriverClassName() {
064: return driverClassName;
065: }
066:
067: public void setDriverClassName(String driverClassName) {
068: this .driverClassName = driverClassName;
069: }
070:
071: public int getDefaultPort() {
072: return defaultPort;
073: }
074:
075: public void setDefaultPort(int defaultPort) {
076: this .defaultPort = defaultPort;
077: }
078:
079: public boolean isSpecific() {
080: return specific;
081: }
082:
083: public void setSpecific(boolean specific) {
084: this .specific = specific;
085: }
086:
087: public Artifact getRAR() {
088: return RAR;
089: }
090:
091: public void setDependencyFilterStrings(List<String> filterStrings) {
092: dependencyFilters = new HashSet<Artifact>();
093: for (String filterString : filterStrings) {
094: Artifact filter = Artifact.createPartial(filterString);
095: dependencyFilters.add(filter);
096: }
097: }
098:
099: public Set<Artifact> getDependencyFilters() {
100: return dependencyFilters != null
101: && !dependencyFilters.isEmpty() ? dependencyFilters
102: : null;
103: }
104:
105: public void setRARName(String name) {
106: RAR = Artifact.create(name);
107: }
108:
109: public List<String> getURLParameters() {
110: Matcher m = PARAM_PATTERN.matcher(URLPrototype);
111: List<String> list = new ArrayList<String>();
112: while (m.find()) {
113: list
114: .add(URLPrototype.substring(m.start() + 1,
115: m.end() - 1));
116: }
117: return list;
118: }
119:
120: public static final GBeanInfo GBEAN_INFO;
121:
122: static {
123: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
124: "Database Driver Info", DatabaseDriverGBean.class);
125: infoFactory.addAttribute("name", String.class, true, true);
126: infoFactory.addAttribute("URLPrototype", String.class, true,
127: true);
128: infoFactory.addAttribute("driverClassName", String.class, true,
129: true);
130: infoFactory.addAttribute("defaultPort", int.class, true, true);
131: infoFactory.addAttribute("specific", boolean.class, true, true);
132: infoFactory.addAttribute("RARName", String.class, true, true);
133: infoFactory.addAttribute("dependencyFilterStrings", List.class,
134: true, true);
135: infoFactory.addAttribute("dependencyFilters", Set.class, false,
136: false);
137: infoFactory.addInterface(DatabaseDriver.class);
138:
139: GBEAN_INFO = infoFactory.getBeanInfo();
140: }
141:
142: public static GBeanInfo getGBeanInfo() {
143: return GBEAN_INFO;
144: }
145: }
|