Source Code Cross Referenced for FileDataService.java in  » Portal » Open-Portal » com » sun » portal » rewriter » services » file » 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 » Portal » Open Portal » com.sun.portal.rewriter.services.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.rewriter.services.file;
006:
007:        import com.sun.portal.rewriter.RewriterModule;
008:        import com.sun.portal.rewriter.services.DataService;
009:        import com.sun.portal.rewriter.services.DataServiceException;
010:        import com.sun.portal.rewriter.services.DataServiceHelper;
011:        import com.sun.portal.rewriter.util.Constants;
012:        import com.sun.portal.rewriter.util.Debug;
013:        import com.sun.portal.rewriter.util.Resource;
014:        import com.sun.portal.rewriter.util.ConfigManager;
015:
016:        import java.io.File;
017:        import java.io.FileOutputStream;
018:        import java.io.FileReader;
019:        import java.util.Arrays;
020:        import java.util.HashSet;
021:        import java.util.Observable;
022:        import java.util.Properties;
023:        import java.util.Set;
024:        import java.util.logging.FileHandler;
025:
026:        /**
027:         * DataService implentation to store/retrive data to and from local filesystem
028:         * Used mainly for testing rewriter component, where IDSAME server does
029:         * not exist
030:         *
031:         * @version 1.0 12/15/2001
032:         * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
033:         */
034:        public final class FileDataService implements  DataService {
035:            public static final String[][] default_rulesets = {
036:                    /*{
037:                        RewriterModule.DEFAULT_RULESET_ID,
038:                        RewriterModule.RESOURCE_DEFAULT_RULESET_LOCATION,
039:                    },*/
040:
041:                    { RewriterModule.GENRIC_RULESET_ID,
042:                            RewriterModule.RESOURCE_GENERIC_RULESET_LOCATION, },
043:
044:                    {
045:                            "default_gateway_ruleset",
046:                            RewriterModule.RESOURCE_HOME
047:                                    + "/DefaultGatewayRuleSet.xml", }, };
048:
049:            private static final FileEventListenerImpl registar = new FileEventListenerImpl();
050:            private static final String FILE_BASE_DIR = DataService.PROPERTY_DATA_SERVICE_BASE;
051:
052:            static {
053:                DataServiceHelper.initLogSystem(FileHandler.class,
054:                        ConfigManager.getLogLocation(), ConfigManager
055:                                .getLogLevel());
056:            }
057:
058:            private String baseDir;
059:
060:            public FileDataService(final Properties aProps) {
061:                final String lBaseDir = aProps.getProperty(FILE_BASE_DIR, ".");
062:                if (!lBaseDir.endsWith(File.separator)) {
063:                    baseDir = lBaseDir + File.separator;
064:                }
065:
066:                //if the base directory does not exists, create one
067:                final File f = new File(baseDir);
068:                if (!f.exists()) {
069:                    f.mkdirs();
070:                }
071:            }//constructor
072:
073:            public String storeXML(final String aRuleSetID,
074:                    final String aXMLRuleSet) throws DataServiceException,
075:                    UnsupportedOperationException {
076:                String result = "";
077:                try {
078:                    result = retrieveXML(aRuleSetID);
079:                    File f = new File(baseDir + aRuleSetID);
080:                    f.createNewFile();
081:                    FileOutputStream fOut = new FileOutputStream(f);
082:                    fOut.write(aXMLRuleSet.getBytes());
083:                    fOut.flush();
084:                    fOut.close();
085:                    fOut = null;
086:                    fireEvent(aRuleSetID);
087:                } catch (Exception e) {
088:                    throw new DataServiceException(e.getMessage(), e);
089:                }//try/catch
090:                return result;
091:            }//storeXML()
092:
093:            public String deleteKey(final String aRuleSetID)
094:                    throws DataServiceException, UnsupportedOperationException {
095:                try {
096:                    String oldValue = readAndDelete(aRuleSetID);
097:                    fireEvent(aRuleSetID);
098:                    return oldValue;
099:                } catch (Exception e) {
100:                    throw new DataServiceException(e.getMessage(), e);
101:                }//try/catch
102:            }//deleteKey()
103:
104:            public String retrieveXML(final String aRuleSetID)
105:                    throws DataServiceException {
106:                Debug.message("Retrieve the RuleSet Located at: " + baseDir
107:                        + aRuleSetID);
108:                try {
109:                    for (int i = 0; i < default_rulesets.length; i++) {
110:                        if (aRuleSetID.equals(default_rulesets[i][0])) {
111:                            return Resource.readXML(default_rulesets[i][1]);
112:                        }
113:                    }
114:
115:                    return read(new File(baseDir + aRuleSetID));
116:                } catch (Exception e) {
117:                    throw new DataServiceException(e.getMessage(), e);
118:                }//try/catch
119:            }//retrieveXML()
120:
121:            public Set retrieveKeys() throws DataServiceException {
122:                try {
123:                    return new HashSet(Arrays
124:                            .asList((new File(baseDir)).list()));
125:                } catch (Exception e) {
126:                    throw new DataServiceException(e.getMessage(), e);
127:                }//try/catch
128:            }//retrieveKeys()
129:
130:            private String readAndDelete(final String aRuleSetIDKey)
131:                    throws Exception {
132:                final File f = new File(baseDir + aRuleSetIDKey);
133:                final String result = read(f);
134:                f.delete();
135:                return result;
136:            }//readAndDelete()
137:
138:            private static String read(final File f) throws Exception {
139:                final String result = "File Does Not Exisit: " + f.toURL();
140:                if (f.exists()) {
141:                    return Resource.read(new FileReader(f));
142:                }
143:                return result;
144:            }//read()
145:
146:            //dummy  not usefull in the case of file system
147:            public Observable getChangeNotifier() {
148:                return registar;
149:            }//getChangeNotifier()
150:
151:            private void fireEvent(final String aEventInfo) {
152:                ((FileEventListenerImpl) getChangeNotifier())
153:                        .dispatch(aEventInfo);
154:            }//fireEvent()
155:
156:            public String matchesWithID(final String aKey)
157:                    throws DataServiceException {
158:                if (retrieveKeys().contains(aKey)) {
159:                    return aKey;
160:                } else {
161:                    return null;
162:                }
163:            }//matchesWithID()
164:
165:            public static void main(String[] args) throws DataServiceException {
166:                //args[0] - base direcotry name
167:                //args[1] - file name
168:
169:                String lBaseDir = args[0];
170:                String lFileName = args[1];
171:                Properties props = new Properties();
172:                props.setProperty(Constants.PROPERTY_DATA_SOURCE_TYPE,
173:                        Constants.FILE);
174:                props.setProperty(DataService.PROPERTY_DATA_SERVICE_BASE,
175:                        lBaseDir);
176:
177:                DataService dataService = new FileDataService(props);
178:                Debug.println(dataService.storeXML(lFileName,
179:                        "one raja devaki devi"));
180:                Debug.println(dataService.retrieveKeys());
181:                Debug.println(dataService.storeXML(lFileName,
182:                        "two raja nagendra kumar"));
183:                Debug.println(dataService.storeXML(lFileName + lFileName,
184:                        "two raja nagendra kumar"));
185:                Debug.println(dataService.deleteKey(lFileName));
186:            }//main()
187:
188:        }//class FileDataService
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.