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.xbeans.geronimo.GerConnectiondefinitionInstanceType; 021 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType; 022 import org.apache.geronimo.naming.deployment.jsr88.GBeanLocator; 023 import org.apache.xmlbeans.SchemaTypeLoader; 024 025 /** 026 * Represents connection-definition/connectiondefinition-instance in the 027 * Geronimo Connector deployment plan. 028 * 029 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $ 030 */ 031 public class ConnectionDefinitionInstance extends ConfigHolder { 032 private DDBean connectionDefinition; 033 private ConnectionManager manager; 034 035 public ConnectionDefinitionInstance() { 036 } 037 038 public ConnectionDefinitionInstance(DDBean connectionDefinition, GerConnectiondefinitionInstanceType instance) { 039 configure(connectionDefinition, instance); 040 } 041 042 protected GerConnectiondefinitionInstanceType getConnectionInstance() { 043 return (GerConnectiondefinitionInstanceType) getXmlObject(); 044 } 045 046 public void reconfigure() { 047 configure(connectionDefinition, getConnectionInstance()); 048 } 049 050 void configure(DDBean connectionDefinition, GerConnectiondefinitionInstanceType definition) { 051 this.connectionDefinition = connectionDefinition; 052 super.configure(connectionDefinition, definition); 053 if(connectionDefinition != null) { 054 DDBean parent = connectionDefinition.getChildBean("..")[0]; 055 ConnectionManager oldMgr = manager; 056 if(oldMgr == null) { 057 if(definition.getConnectionmanager() != null) { 058 manager = new ConnectionManager(parent, definition.getConnectionmanager()); 059 } else { 060 manager = new ConnectionManager(parent, definition.addNewConnectionmanager()); 061 } 062 } else { 063 if(definition.getConnectionmanager() != null) { 064 manager.configure(parent, definition.getConnectionmanager()); 065 } else { 066 manager.configure(parent, definition.addNewConnectionmanager()); 067 } 068 } 069 pcs.firePropertyChange("connectionManager", oldMgr, manager); 070 } 071 } 072 073 DDBean getDDBean() { 074 return connectionDefinition; 075 } 076 077 protected GerConfigPropertySettingType createConfigProperty() { 078 return getConnectionInstance().addNewConfigPropertySetting(); 079 } 080 081 protected GerConfigPropertySettingType[] getConfigProperties() { 082 return getConnectionInstance().getConfigPropertySettingArray(); 083 } 084 085 protected void removeConfigProperty(int index) { 086 getConnectionInstance().removeConfigPropertySetting(index); 087 } 088 089 // ----------------------- JavaBean Properties for /connectiondefinition-instance ---------------------- 090 091 public String getName() { 092 return getConnectionInstance().getName(); 093 } 094 095 public void setName(String name) { 096 String old = getName(); 097 getConnectionInstance().setName(name); 098 pcs.firePropertyChange("name", old, name); 099 } 100 101 public String[] getImplementedInterface() { 102 return getConnectionInstance().getImplementedInterfaceArray(); 103 } 104 105 public String getImplementedInterface(int index) { 106 return getConnectionInstance().getImplementedInterfaceArray(index); 107 } 108 109 public void setImplementedInterface(String[] list) { 110 String[] old = getImplementedInterface(); 111 getConnectionInstance().setImplementedInterfaceArray(list); 112 pcs.firePropertyChange("implementedInterface", old, list); 113 } 114 115 public void setImplementedInterface(int index, String iface) { 116 String[] old = getImplementedInterface(); 117 getConnectionInstance().setImplementedInterfaceArray(index, iface); 118 pcs.firePropertyChange("implementedInterface", old, getImplementedInterface()); 119 } 120 121 public ConnectionManager getConnectionManager() { 122 return manager; 123 } 124 125 // ----------------------- End of JavaBean Properties ---------------------- 126 127 protected SchemaTypeLoader getSchemaTypeLoader() { 128 return Connector15DCBRoot.SCHEMA_TYPE_LOADER; 129 } 130 }