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 018 package org.apache.geronimo.connector.deployment.dconfigbean; 019 020 import javax.enterprise.deploy.model.DDBean; 021 import javax.enterprise.deploy.model.XpathListener; 022 023 import org.apache.geronimo.deployment.plugin.XmlBeanSupport; 024 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType; 025 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType; 026 import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType; 027 import org.apache.xmlbeans.SchemaTypeLoader; 028 import org.apache.xmlbeans.XmlBeans; 029 030 /** 031 * @version $Revision 1.0$ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $ 032 */ 033 public class ConnectionDefinitionInstance extends XmlBeanSupport { 034 private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.getContextTypeLoader(); 035 private ConfigPropertySettings[] configs = new ConfigPropertySettings[0]; 036 private ConnectionDefinitionDConfigBean parent; 037 private XpathListener configListener; 038 039 public ConnectionDefinitionInstance() { 040 super(null); 041 } 042 043 void initialize(GerConnectiondefinitionInstanceType xmlObject, ConnectionDefinitionDConfigBean parent) { 044 setXmlObject(xmlObject); 045 this.parent = parent; 046 DDBean parentDDBean = parent.getDDBean(); 047 configListener = ConfigPropertiesHelper.initialize(parentDDBean, new ConfigPropertiesHelper.ConfigPropertiesSource() { 048 public GerConfigPropertySettingType[] getConfigPropertySettingArray() { 049 return getConnectiondefinitionInstance().getConfigPropertySettingArray(); 050 } 051 052 public GerConfigPropertySettingType addNewConfigPropertySetting() { 053 return getConnectiondefinitionInstance().addNewConfigPropertySetting(); 054 } 055 056 public void removeConfigPropertySetting(int j) { 057 getConnectiondefinitionInstance().removeConfigPropertySetting(j); 058 } 059 060 public ConfigPropertySettings[] getConfigPropertySettings() { 061 return configs; 062 } 063 064 public void setConfigPropertySettings(ConfigPropertySettings[] configs) { 065 setConfigProperty(configs); 066 } 067 068 }, "config-property", "config-property-name"); 069 } 070 071 072 boolean hasParent() { 073 return parent != null; 074 } 075 076 void dispose() { 077 if (configs != null) { 078 for (int i = 0; i < configs.length; i++) { 079 configs[i].dispose(); 080 } 081 } 082 if (parent != null) { 083 parent.getDDBean().removeXpathListener("config-property", configListener); 084 } 085 configs = null; 086 configListener = null; 087 parent = null; 088 } 089 090 // JavaBean properties for this object (with a couple helper methods) 091 092 GerConnectiondefinitionInstanceType getConnectiondefinitionInstance() { 093 return (GerConnectiondefinitionInstanceType) getXmlObject(); 094 } 095 096 GerConnectionmanagerType getConnectionManager() { 097 return getConnectiondefinitionInstance().getConnectionmanager(); 098 } 099 100 public ConfigPropertySettings[] getConfigProperty() { 101 return configs; 102 } 103 104 private void setConfigProperty(ConfigPropertySettings[] configs) { // can only be changed by adding a new DDBean 105 ConfigPropertySettings[] old = getConfigProperty(); 106 this.configs = configs; 107 pcs.firePropertyChange("configProperty", old, configs); 108 } 109 110 public String getName() { 111 return getConnectiondefinitionInstance().getName(); 112 } 113 114 public void setName(String name) { 115 String old = getName(); 116 getConnectiondefinitionInstance().setName(name); 117 pcs.firePropertyChange("name", old, name); 118 } 119 120 // public String getGlobalJNDIName() { 121 // return getConnectiondefinitionInstance().getGlobalJndiName(); 122 // } 123 // 124 // public void setGlobalJNDIName(String globalJNDIName) { 125 // String old = getGlobalJNDIName(); 126 // getConnectiondefinitionInstance().setGlobalJndiName(globalJNDIName); 127 // pcs.firePropertyChange("globalJNDIName", old, globalJNDIName); 128 // } 129 130 // public boolean isUseConnectionRequestInfo() { 131 // return getConnectionManager().getUseConnectionRequestInfo(); 132 // } 133 // 134 // public void setUseConnectionRequestInfo(boolean useConnectionRequestInfo) { 135 // boolean old = isUseConnectionRequestInfo(); 136 // getConnectionManager().setUseConnectionRequestInfo(useConnectionRequestInfo); 137 // pcs.firePropertyChange("useConnectionRequestInfo", old, useConnectionRequestInfo); 138 // } 139 // 140 // public boolean isUseSubject() { 141 // return getConnectionManager().getUseSubject(); 142 // } 143 // 144 // public void setUseSubject(boolean useSubject) { 145 // boolean old = isUseSubject(); 146 // getConnectionManager().setUseSubject(useSubject); 147 // pcs.firePropertyChange("useSubject", old, useSubject); 148 // } 149 // 150 // public boolean isUseTransactionCaching() { 151 // return getConnectionManager().getUseTransactionCaching(); 152 // } 153 // 154 // public void setUseTransactionCaching(boolean useTransactionCaching) { 155 // boolean old = isUseTransactionCaching(); 156 // getConnectionManager().setUseTransactionCaching(useTransactionCaching); 157 // pcs.firePropertyChange("useTransactionCaching", old, useTransactionCaching); 158 // } 159 // 160 // public boolean isUseLocalTransactions() { 161 // return getConnectionManager().getUseLocalTransactions(); 162 // } 163 // 164 // public void setUseLocalTransactions(boolean useLocalTransactions) { 165 // boolean old = isUseLocalTransactions(); 166 // getConnectionManager().setUseLocalTransactions(useLocalTransactions); 167 // pcs.firePropertyChange("useLocalTransactions", old, useLocalTransactions); 168 // } 169 // 170 // public boolean isUseTransactions() { 171 // return getConnectionManager().getUseTransactions(); 172 // } 173 // 174 // public void setUseTransactions(boolean useTransactions) { 175 // boolean old = isUseTransactions(); 176 // getConnectionManager().setUseTransactions(useTransactions); 177 // pcs.firePropertyChange("useTransactions", old, useTransactions); 178 // } 179 // 180 // public int getMaxSize() { 181 // BigInteger test = getConnectionManager().getMaxSize(); 182 // return test == null ? 0 : test.intValue(); 183 // } 184 // 185 // public void setMaxSize(int maxSize) { 186 // int old = getMaxSize(); 187 // getConnectionManager().setMaxSize(BigInteger.valueOf(maxSize)); 188 // pcs.firePropertyChange("maxSize", old, maxSize); 189 // } 190 // 191 // public int getBlockingTimeout() { 192 // BigInteger test = getConnectionManager().getBlockingTimeout(); 193 // return test == null ? 0 : test.intValue(); 194 // } 195 // 196 // public void setBlockingTimeout(int blockingTimeout) { 197 // int old = getBlockingTimeout(); 198 // getConnectionManager().setBlockingTimeout(BigInteger.valueOf(blockingTimeout)); 199 // pcs.firePropertyChange("blockingTimeout", old, blockingTimeout); 200 // } 201 202 public boolean isContainerManagedSecurity() { 203 return getConnectionManager().isSetContainerManagedSecurity(); 204 } 205 206 public void setContainerManagedSecurity(boolean containerManagedSecurity) { 207 boolean old = isContainerManagedSecurity(); 208 if (old && !containerManagedSecurity) { 209 getConnectionManager().setContainerManagedSecurity(null); 210 } else if (!old && containerManagedSecurity) { 211 getConnectionManager().addNewContainerManagedSecurity(); 212 } 213 pcs.firePropertyChange("containerManagedSecurity", old, containerManagedSecurity); 214 } 215 216 public String toString() { 217 return "Connection "+getName(); 218 } 219 }