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.naming.deployment.jsr88;
018    
019    import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
020    
021    /**
022     * Represents an element of the resource-refType in a Geronimo deployment
023     * plan.
024     *                                          <p>
025     * Has 4 JavaBean Properties                <br />
026     *  - refName (type String)                 <br />
027     *  - pattern (type Pattern)                <br />
028     *  - url (type String)                     <br />
029     *  - resourceLink (type String)            </p>
030     *
031     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
032     */
033    public class ResourceRef extends HasPattern {
034        public ResourceRef() {
035            super(null);
036        }
037    
038        public ResourceRef(GerResourceRefType xmlObject) {
039            super(xmlObject);
040        }
041    
042        public void setRefName(String name) {
043            String old = getResourceRef().getRefName();
044            getResourceRef().setRefName(name);
045            pcs.firePropertyChange("refName", old, name);
046        }
047    
048        public String getRefName() {
049            return getResourceRef().getRefName();
050        }
051    
052        public String getResourceLink() {
053            return getResourceRef().getResourceLink();
054        }
055    
056        public void setResourceLink(String link) {
057            GerResourceRefType ref = getResourceRef();
058            if(link != null) {
059                if(ref.isSetPattern()) {
060                    clearPatternFromChoice();
061                }
062                if(ref.isSetUrl()) {
063                    String old = getUrl();
064                    ref.unsetUrl();
065                    pcs.firePropertyChange("url", old, null);
066                }
067            }
068            String old = getResourceLink();
069            ref.setResourceLink(link);
070            pcs.firePropertyChange("resourceLink", old, link);
071        }
072    
073        public String getUrl() {
074            return getResourceRef().getResourceLink();
075        }
076    
077        public void setUrl(String link) {
078            GerResourceRefType ref = getResourceRef();
079            if(link != null) {
080                if(ref.isSetPattern()) {
081                    clearPatternFromChoice();
082                }
083                if(ref.isSetResourceLink()) {
084                    String old = getResourceLink();
085                    ref.unsetResourceLink();
086                    pcs.firePropertyChange("resourceLink", old, null);
087                }
088            }
089            String old = getUrl();
090            ref.setUrl(link);
091            pcs.firePropertyChange("url", old, link);
092        }
093    
094    
095        protected void clearNonPatternFromChoice() {
096            GerResourceRefType ref = getResourceRef();
097            if(ref.isSetResourceLink()) {
098                String temp = ref.getResourceLink();
099                ref.unsetResourceLink();
100                pcs.firePropertyChange("resourceLink", temp, null);
101            }
102            if(ref.isSetUrl()) {
103                String temp = ref.getUrl();
104                ref.unsetUrl();
105                pcs.firePropertyChange("url", temp, null);
106            }
107        }
108    
109        protected GerResourceRefType getResourceRef() {
110            return (GerResourceRefType) getXmlObject();
111        }
112    
113        public void configure(GerResourceRefType xml) {
114            setXmlObject(xml);
115        }
116    }