KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > transform > elements > Property


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Element.java
26  *
27  * Created on August 4, 2003, 2:04 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.transform.elements;
31
32 /**
33  *
34  * @author prakash
35  */

36 import org.w3c.dom.Document JavaDoc;
37 import org.w3c.dom.Element JavaDoc;
38 import org.w3c.dom.NodeList JavaDoc;
39 import org.w3c.dom.Node JavaDoc;
40 import com.sun.enterprise.tools.upgrade.transform.ElementToObjectMapper;
41
42 public class Property extends BaseElement {
43     
44     /** Creates a new instance of Element */
45     public Property() {
46     }
47     /**
48      * element - Property
49      * parentSource - parent of Property
50      * parentResult - result element that need to be updated.
51      */

52     public void transform(Element JavaDoc element, Element JavaDoc parentSource, Element JavaDoc parentResult){
53         // Property has name and value. and possible description element.
54
if(!canTransferAttributes(element, parentSource, parentResult))
55             return;
56         NodeList JavaDoc resultProperties = parentResult.getElementsByTagName("property");
57         Element JavaDoc resultProperty = null;
58         if(resultProperties != null){
59             for(int index=0; index < resultProperties.getLength(); index++){
60                 if(element.getAttribute("name").equals(((Element JavaDoc)resultProperties.item(index)).getAttribute("name"))){
61                     resultProperty = (Element JavaDoc)resultProperties.item(index);
62                     resultProperty.getAttributeNode("value").setValue(element.getAttributeNode("value").getValue());
63                     this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
64                     break;
65                 }
66             }
67         }
68         if(resultProperty == null){
69             resultProperty = parentResult.getOwnerDocument().createElement("property");
70             this.transferAttributes(element, resultProperty, null);
71             this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
72             parentResult.appendChild(resultProperty);
73         }
74         super.transform(element, parentSource, resultProperty);
75     }
76     
77     // This method is used to avoid transferring certain property elements.
78
private boolean canTransferAttributes(Element JavaDoc element, Element JavaDoc parentSource, Element JavaDoc parentResult){
79         /*if(parentSource.getTagName().equals("virtual-server")){
80             if(this.commonInfoModel.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
81                 if(element.getAttribute("name").equals("docroot") || element.getAttribute("name").equals("accesslog")){
82                     return false;
83                 }
84             }
85         }*/

86         return true;
87     }
88     private void handleSpecialCases(Element JavaDoc source, Element JavaDoc target, Element JavaDoc parentSource, Element JavaDoc targetParent){
89         if(parentSource.getTagName().equals("jms-resource") && targetParent.getTagName().equals("admin-object-resource")){
90             if(source.getAttribute("name").equals("imqDestinationName")){
91                 target.setAttribute("name", "Name");
92             }
93         }
94         if(parentSource.getTagName().equals("virtual-server")){
95             if(source.getAttribute("name").equals("docroot")){
96                 target.setAttribute("value", "${com.sun.aas.instanceRoot}/docroot");
97             }
98             if(source.getAttribute("name").equals("accesslog")){
99                 target.setAttribute("value", "${com.sun.aas.instanceRoot}/logs/access");
100             }
101         }
102     }
103     
104 }
105
Popular Tags