001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.connector.deployment.jsr88;
018    
019    import javax.enterprise.deploy.model.DDBean;
020    import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
021    import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
022    import org.apache.xmlbeans.SchemaTypeLoader;
023    
024    /**
025     * Represents /connector/resourceadapter/resourceadapter-instance/config-property-setting
026     * or /connector/resourceadapter/outbound-resourceadapter/connection-definition/connectiondefinition-instance/config-property-setting
027     * or /connector/adminobject/adminobject-instance/config-property-setting in the
028     * Geronimo Connector deployment plan.
029     *
030     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
031     */
032    public class ConfigPropertySetting extends XmlBeanSupport {
033        private DDBean configProperty;
034        private String defaultValue;
035    
036        public ConfigPropertySetting() {
037            super(null);
038        }
039    
040        public ConfigPropertySetting(DDBean configProperty, GerConfigPropertySettingType property, boolean setDefault) {
041            super(null);
042            configure(configProperty, property, setDefault);
043        }
044    
045        protected GerConfigPropertySettingType getPropertySetting() {
046            return (GerConfigPropertySettingType) getXmlObject();
047        }
048    
049        DDBean getDDBean() {
050            return configProperty;
051        }
052    
053        void configure(DDBean configProperty, GerConfigPropertySettingType property, boolean setDefault) {
054            this.configProperty = configProperty;
055            setXmlObject(property);
056            final String name = configProperty.getText("config-property-name")[0];
057            getPropertySetting().setName(name);
058            String[] test = configProperty.getText("config-property-value");
059            if(test != null && test.length == 1) {
060                defaultValue = test[0];
061            } else {
062                defaultValue = null;
063            }
064            if(setDefault) {
065                getPropertySetting().setStringValue(defaultValue);
066            }
067        }
068    
069        boolean isSetToDefault() {
070            String value = getValue();
071            return (defaultValue == null && value == null) ||
072                    (defaultValue != null && value != null && defaultValue.equals(value));
073        }
074    
075        // ----------------------- JavaBean Properties for config-property-setting ----------------------
076    
077        public String getName() {
078            return getPropertySetting().getName();
079        }
080    
081        // Not public -- should always be kept in sync with matching config-property
082        void setName(String name) {
083            String old = getName();
084            getPropertySetting().setName(name);
085            pcs.firePropertyChange("name", old, name);
086        }
087    
088        public String getValue() {
089            return getPropertySetting().isNil() ? null : getPropertySetting().getStringValue();
090        }
091    
092        public void setValue(String value) {
093            String old = getValue();
094            getPropertySetting().setStringValue(value);
095            pcs.firePropertyChange("value", old, value);
096        }
097    
098        // ----------------------- End of JavaBean Properties ----------------------
099    
100        protected SchemaTypeLoader getSchemaTypeLoader() {
101            return Connector15DCBRoot.SCHEMA_TYPE_LOADER;
102        }
103    }