Source Code Cross Referenced for JavaCondition.java in  » Installer » IzPack » com » izforge » izpack » rules » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » IzPack » com.izforge.izpack.rules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         *
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         *
007:         * Copyright 2007 Dennis Reil
008:         *
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:        package com.izforge.izpack.rules;
022:
023:        import java.lang.reflect.Field;
024:        import java.lang.reflect.Method;
025:        import java.util.Properties;
026:
027:        import net.n3.nanoxml.XMLElement;
028:        import com.izforge.izpack.util.Debug;
029:
030:        /**
031:         * A condition based on the value of a static java field or static java method.
032:         *
033:         * @author Dennis Reil, <Dennis.Reil@reddot.de>
034:         */
035:        public class JavaCondition extends Condition {
036:            /**
037:             * 
038:             */
039:            private static final long serialVersionUID = -7649870719815066537L;
040:            protected String classname;
041:            protected String methodname;
042:            protected String fieldname;
043:            protected boolean complete;
044:            protected String returnvalue;
045:            protected String returnvaluetype;
046:
047:            protected Class usedclass;
048:            protected Field usedfield;
049:            protected Method usedmethod;
050:
051:            public JavaCondition() {
052:
053:            }
054:
055:            private boolean isTrue(Properties variables) {
056:                if (!this .complete) {
057:                    return false;
058:                } else {
059:                    if (this .usedclass == null) {
060:                        ClassLoader loader = ClassLoader.getSystemClassLoader();
061:                        try {
062:                            this .usedclass = loader.loadClass(this .classname);
063:                        } catch (ClassNotFoundException e) {
064:                            Debug.log("Can't find class " + this .classname);
065:                            return false;
066:                        }
067:                    }
068:                    if ((this .usedfield == null) && (this .fieldname != null)) {
069:                        try {
070:                            this .usedfield = this .usedclass
071:                                    .getField(this .fieldname);
072:                        } catch (SecurityException e) {
073:                            Debug
074:                                    .log("No permission to access specified field: "
075:                                            + this .fieldname);
076:                            return false;
077:                        } catch (NoSuchFieldException e) {
078:                            Debug.log("No such field: " + this .fieldname);
079:                            return false;
080:                        }
081:                    }
082:                    if ((this .usedmethod == null) && (this .methodname != null)) {
083:                        Debug.log("not implemented yet.");
084:                        return false;
085:                    }
086:
087:                    if (this .usedfield != null) {
088:                        // access field
089:                        if ("boolean".equals(this .returnvaluetype)) {
090:                            try {
091:                                boolean returnval = this .usedfield
092:                                        .getBoolean(null);
093:                                boolean expectedreturnval = Boolean
094:                                        .valueOf(this .returnvalue);
095:                                return returnval == expectedreturnval;
096:                            } catch (IllegalArgumentException e) {
097:                                Debug.log("IllegalArgumentexeption "
098:                                        + this .fieldname);
099:                            } catch (IllegalAccessException e) {
100:                                Debug.log("IllegalAccessException "
101:                                        + this .fieldname);
102:                            }
103:                        } else {
104:                            Debug.log("not implemented yet.");
105:                            return false;
106:                        }
107:                    }
108:                    return false;
109:                }
110:            }
111:
112:            public void readFromXML(XMLElement xmlcondition) {
113:                if (xmlcondition.getChildrenCount() != 2) {
114:                    Debug
115:                            .log("Condition of type java needs (java,returnvalue)");
116:                    return;
117:                }
118:                XMLElement javael = xmlcondition.getFirstChildNamed("java");
119:                XMLElement classel = javael.getFirstChildNamed("class");
120:                if (classel != null) {
121:                    this .classname = classel.getContent();
122:                } else {
123:                    Debug.log("Java-Element needs (class,method?,field?)");
124:                    return;
125:                }
126:                XMLElement methodel = javael.getFirstChildNamed("method");
127:                if (methodel != null) {
128:                    this .methodname = methodel.getContent();
129:                }
130:                XMLElement fieldel = javael.getFirstChildNamed("field");
131:                if (fieldel != null) {
132:                    this .fieldname = fieldel.getContent();
133:                }
134:                if ((this .methodname == null) && (this .fieldname == null)) {
135:                    Debug.log("java element needs (class, method?,field?)");
136:                    return;
137:                }
138:                XMLElement returnvalel = xmlcondition
139:                        .getFirstChildNamed("returnvalue");
140:                if (returnvalel != null) {
141:                    this .returnvalue = returnvalel.getContent();
142:                    this .returnvaluetype = returnvalel.getAttribute("type");
143:                } else {
144:                    Debug.log("no returnvalue-element specified.");
145:                    return;
146:                }
147:                this .complete = true;
148:            }
149:
150:            public boolean isTrue() {
151:                return this .isTrue(this .installdata.getVariables());
152:            }
153:
154:            /* (non-Javadoc)
155:             * @see com.izforge.izpack.rules.Condition#getDependenciesDetails()
156:             */
157:            public String getDependenciesDetails() {
158:                StringBuffer details = new StringBuffer();
159:                details.append(this .id);
160:                details.append(" depends on the ");
161:                if (this .fieldname != null) {
162:                    details.append("value of field <b>");
163:                    details.append(this .fieldname);
164:                    details.append("</b>");
165:                } else {
166:                    details.append("return value of method <b>");
167:                    details.append(this .methodname);
168:                    details.append("</b>");
169:                }
170:                details.append(" on an instance of class <b>");
171:                details.append(this .classname);
172:                details.append("</b> which should be <b>");
173:                details.append(this .returnvalue);
174:                details.append("</b><br/>");
175:                return details.toString();
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.