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    import java.util.Set;
029    import java.util.HashSet;
030    
031    /**
032     * Implementation of DatabaseDriver that contains database driver information
033     * contained in the console's deployment plan.
034     *
035     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
036     */
037    public class DatabaseDriverGBean implements DatabaseDriver {
038        private final static Pattern PARAM_PATTERN = Pattern.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 && !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    }