KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > deployment > jsr88 > HasPattern


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.naming.deployment.jsr88;
18
19 import javax.xml.namespace.QName JavaDoc;
20 import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
21 import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
22 import org.apache.xmlbeans.XmlObject;
23 import org.apache.xmlbeans.impl.values.XmlObjectBase;
24
25 /**
26  * Represents an element in a Geronimo dployment plan that has a child
27  * of type Pattern. This handles patterns that are a member of a choice as
28  * well as singleton patterns.
29  * <p>
30  * Has 1 JavaBean Properties <br />
31  * - pattern (type Pattern) </p>
32  *
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 public class HasPattern extends XmlBeanSupport {
36     public HasPattern() {
37         super(null);
38     }
39
40     public HasPattern(XmlObject xmlObject) {
41         super(xmlObject);
42     }
43
44     /**
45      * JavaBean getter for the Pattern property. Gets a JavaBean of type
46      * Pattern for the pattern child of this element, or null if there is no
47      * pattern child.
48      */

49     public Pattern getPattern() {
50         GerPatternType patternType = findPattern();
51         if(patternType == null) return null;
52         Pattern group = new Pattern();
53         group.setGroupId(patternType.getGroupId());
54         group.setArtifactId(patternType.getArtifactId());
55         group.setVersion(patternType.getVersion());
56         group.setModule(patternType.getModule());
57         group.setName(patternType.getName());
58         return group.empty() ? null : group;
59     }
60
61     /**
62      * JavaBean setter for the Pattern property. Calls the helper
63      * clearNonPatternFromChoice if a non-null Pattern is set.
64      */

65     public void setPattern(Pattern group) {
66         Pattern old = getPattern();
67         if(group != null) {
68             GerPatternType patternType;
69             if(old == null) {
70                 patternType = (GerPatternType) ((XmlObjectBase)getXmlObject()).get_store().add_element_user(new QName JavaDoc("http://geronimo.apache.org/xml/ns/naming-1.2", "pattern"));
71             } else {
72                 patternType = findPattern();
73             }
74             if(!isEmpty(group.getGroupId())) {
75                 patternType.setGroupId(group.getGroupId());
76             } else {
77                 if(patternType.isSetGroupId()) patternType.unsetGroupId();
78             }
79             if(!isEmpty(group.getArtifactId())) {
80                 patternType.setArtifactId(group.getArtifactId());
81             } else {
82                 if(patternType.isSetArtifactId()) patternType.unsetArtifactId();
83             }
84             if(!isEmpty(group.getModule())) {
85                 patternType.setModule(group.getModule());
86             } else {
87                 if(patternType.isSetModule()) patternType.unsetModule();
88             }
89             patternType.setName(group.getName());
90             if(!isEmpty(group.getVersion())) {
91                 patternType.setVersion(group.getVersion());
92             } else {
93                 if(patternType.isSetVersion()) patternType.unsetVersion();
94             }
95             clearNonPatternFromChoice();
96         } else {
97             if(old != null) {
98                 ((XmlObjectBase)getXmlObject()).get_store().remove_element(new QName JavaDoc("http://geronimo.apache.org/xml/ns/naming-1.2", "pattern"), 0);
99             }
100         }
101         pcs.firePropertyChange("objectNameComponents", old, group);
102     }
103
104     /**
105      * Should be overridden to remove any non-pattern elements if this
106      * element has a pattern that's part of a choice. If this is called, it
107      * means a non-null Pattern is in the process of being set. This method
108      * should fire property change events on any elements it removes.
109      */

110     protected void clearNonPatternFromChoice() {}
111
112     /**
113      * Should be called to remove any pattern child element if the pattern is
114      * part of a choice and some other element in the choice was set to a
115      * non-null value. This will clear the pattern and send a property change
116      * event on the "pattern" property if the pattern was set.
117      */

118     protected void clearPatternFromChoice() {
119         Pattern pattern = getPattern();
120         if(pattern != null) {
121             ((XmlObjectBase)getXmlObject()).get_store().remove_element(new QName JavaDoc("http://geronimo.apache.org/xml/ns/naming-1.2", "pattern"), 0);
122             pcs.firePropertyChange("pattern", pattern, null);
123         }
124     }
125
126     /**
127      * Gets the pattern child of this element, or null if there is none.
128      */

129     protected GerPatternType findPattern() {
130         XmlObject[] patterns = getXmlObject().selectChildren(new QName JavaDoc(GerPatternType.type.getName().getNamespaceURI(), "pattern"));
131         if(patterns.length == 0) {
132             return null;
133         }
134         return (GerPatternType)patterns[0];
135     }
136 }
137
Popular Tags