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 org.apache.geronimo.deployment.plugin.DConfigBeanSupport; 020 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType; 021 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType; 022 import org.apache.xmlbeans.SchemaTypeLoader; 023 024 import javax.enterprise.deploy.model.DDBean; 025 026 /** 027 * Represents /connector/adminobject in a Geronimo Connector deployment plan. 028 * Corresponds to /connector/resourceadapter/adminobject in the J2EE deployment plan. 029 * Note that in an arbitrary Geronimo connector plan, there can be multiple 030 * adminobject entries per adminobject from the J2EE plan. When we load such 031 * a plan, we combine all the adminobject-instances from those adminobjects 032 * into a single Geronimo adminobject per J2EE adminobject, so if we write it 033 * out again it'll be a little different, but that way this can be a DConfigBean 034 * instead of a POJO (the loading code is in ConnectorDCB). 035 * 036 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $ 037 */ 038 public class AdminObjectDCB extends DConfigBeanSupport { 039 private AdminObjectInstance[] adminObjectInstance = new AdminObjectInstance[0]; 040 041 public AdminObjectDCB(DDBean adminobjectDDBean, final GerAdminobjectType adminobject) { 042 super(adminobjectDDBean, adminobject); 043 //todo: listen for property changes on the admin object 044 configure(adminobjectDDBean, adminobject); 045 } 046 047 private void configure(DDBean adminDDBean, GerAdminobjectType adminXml) { 048 adminXml.setAdminobjectClass(adminDDBean.getText("adminobject-class")[0]); 049 adminXml.setAdminobjectInterface(adminDDBean.getText("adminobject-interface")[0]); 050 GerAdminobjectInstanceType[] xmls = adminXml.getAdminobjectInstanceArray(); 051 adminObjectInstance = new AdminObjectInstance[xmls.length]; 052 for (int i = 0; i < xmls.length; i++) { 053 adminObjectInstance[i] = new AdminObjectInstance(adminDDBean, xmls[i]); 054 } 055 } 056 057 GerAdminobjectType getAdminObject() { 058 return (GerAdminobjectType) getXmlObject(); 059 } 060 061 void addAdminObjectInstance(GerAdminobjectInstanceType xml) { 062 AdminObjectInstance instance = new AdminObjectInstance(getDDBean(), xml); 063 AdminObjectInstance[] result = new AdminObjectInstance[adminObjectInstance.length+1]; 064 System.arraycopy(adminObjectInstance, 0, result, 0, adminObjectInstance.length); 065 result[adminObjectInstance.length] = instance; 066 setAdminObjectInstance(result); 067 } 068 069 // ----------------------- JavaBean Properties for /adminobject ---------------------- 070 071 public String getAdminObjectInterface() { 072 return getAdminObject().getAdminobjectInterface(); 073 } 074 075 public String getAdminObjectClass() { 076 return getAdminObject().getAdminobjectClass(); 077 } 078 079 public AdminObjectInstance[] getAdminObjectInstance() { 080 return adminObjectInstance; 081 } 082 083 public void setAdminObjectInstance(AdminObjectInstance[] adminObjectInstance) { 084 AdminObjectInstance[] old = getAdminObjectInstance(); 085 //todo: whack all the old ones 086 for (int i = 0; i < adminObjectInstance.length; i++) { 087 AdminObjectInstance instance = adminObjectInstance[i]; 088 if(instance.getAdminInstance() == null) { 089 instance.configure(getDDBean(), getAdminObject().addNewAdminobjectInstance()); 090 } 091 } 092 this.adminObjectInstance = adminObjectInstance; 093 pcs.firePropertyChange("adminObjectInstance", old, adminObjectInstance); 094 } 095 096 public AdminObjectInstance getAdminObjectInstance(int index) { 097 return adminObjectInstance[index]; 098 } 099 100 public void setAdminObjectInstance(int index, AdminObjectInstance adminObjectInstance) { 101 AdminObjectInstance[] old = getAdminObjectInstance(); 102 //todo: whack the old one 103 if(adminObjectInstance.getAdminInstance() == null) { 104 adminObjectInstance.configure(getDDBean(), getAdminObject().addNewAdminobjectInstance()); 105 } 106 this.adminObjectInstance[index] = adminObjectInstance; 107 //todo: deep copy of array for "old" 108 pcs.firePropertyChange("adminObjectInstance", old, adminObjectInstance); 109 } 110 111 // ----------------------- End of JavaBean Properties ---------------------- 112 113 protected SchemaTypeLoader getSchemaTypeLoader() { 114 return Connector15DCBRoot.SCHEMA_TYPE_LOADER; 115 } 116 }