Source Code Cross Referenced for JNDIFolderFactory.java in  » Inversion-of-Control » carbon » org » sape » carbon » services » config » jndi » 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 » Inversion of Control » carbon » org.sape.carbon.services.config.jndi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Sapient Public License
003:         * Version 1.0 (the "License"); you may not use this file except in compliance
004:         * with the License. You may obtain a copy of the License at
005:         * http://carbon.sf.net/License.html.
006:         *
007:         * Software distributed under the License is distributed on an "AS IS" basis,
008:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009:         * the specific language governing rights and limitations under the License.
010:         *
011:         * The Original Code is The Carbon Component Framework.
012:         *
013:         * The Initial Developer of the Original Code is Sapient Corporation
014:         *
015:         * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016:         */
017:
018:        package org.sape.carbon.services.config.jndi;
019:
020:        import javax.naming.Name;
021:        import javax.naming.NameNotFoundException;
022:        import javax.naming.NamingException;
023:        import javax.naming.directory.Attributes;
024:        import javax.naming.directory.BasicAttributes;
025:        import javax.naming.directory.DirContext;
026:
027:        import org.sape.carbon.core.config.node.Node;
028:        import org.sape.carbon.core.config.node.NodeCreationException;
029:        import org.sape.carbon.core.config.node.NodeFactory;
030:        import org.sape.carbon.core.exception.InvalidParameterException;
031:
032:        /**
033:         * This class provides the functionality for creating JNDIFolderFactory nodes.
034:         *
035:         * <br>Copyright 2003 Sapient
036:         * @since carbon 2.0
037:         * @author Douglas Voet, March 2003
038:         * @version $Revision: 1.7 $($Author: dvoet $ / $Date: 2003/05/05 21:21:10 $)
039:         */
040:        public class JNDIFolderFactory implements  NodeFactory {
041:
042:            private JNDILinkNodeConfiguration config;
043:
044:            /**
045:             * Constructs a new factory
046:             * @param config configuration used to get the names of the attributes
047:             * that hold node name, node and document type, and document content as well
048:             * as valid attribute values for node and document type.
049:             */
050:            public JNDIFolderFactory(JNDILinkNodeConfiguration config) {
051:                if (config == null) {
052:                    throw new InvalidParameterException(this .getClass(),
053:                            "config cannot be null");
054:                }
055:
056:                this .config = config;
057:            }
058:
059:            /**
060:             * Creates JNDIConfigurationDocument objects only as children
061:             * of JNDIFolders.
062:             *
063:             * @param parent the parent node of the folder to be created, must be of
064:             * type JNDIFolder
065:             * @param name the name of the node to create
066:             * @throws InvalidParameterExcpetion if parent is not
067:             * assignable from JNDIFolder or name is null
068:             */
069:            public Node getInstance(Node parent, String name)
070:                    throws NodeCreationException {
071:
072:                // these constants are defined in order to make the code below readable
073:                final String NAME = this .config.getNodeNameAttributeName();
074:                final String EQUALS = this .config
075:                        .getAttributeNameValueSeparator();
076:                final String NODE_TYPE = this .config.getNodeTypeAttributeName();
077:                final String FOLDER = this .config
078:                        .getFolderNodeTypeAttributeValue();
079:
080:                JNDIFolder parentJNDIFolder;
081:                try {
082:                    parentJNDIFolder = (JNDIFolder) parent;
083:                } catch (ClassCastException cce) {
084:                    throw new InvalidParameterException(this .getClass(),
085:                            "parent is not assignable from JNDIFolder", cce);
086:                }
087:
088:                if (name == null) {
089:                    throw new InvalidParameterException(this .getClass(),
090:                            "name cannot be null");
091:                }
092:
093:                try {
094:                    // create the context name for the new node
095:                    Name nodeContextName = (Name) parentJNDIFolder
096:                            .getNodeContextName().clone();
097:                    nodeContextName.add(NAME + EQUALS + name);
098:
099:                    DirContext initialContext = parentJNDIFolder
100:                            .getInitialContext();
101:
102:                    try {
103:                        // lookup the folder's attributes and validate them
104:                        Attributes folderAttributes = initialContext
105:                                .getAttributes(nodeContextName,
106:                                        new String[] { NODE_TYPE });
107:
108:                        if (!folderAttributes.get(NODE_TYPE).contains(FOLDER)) {
109:                            // the backing data was not the correct node type
110:                            throw new NodeCreationException(
111:                                    this .getClass(),
112:                                    parent,
113:                                    name,
114:                                    "Context ["
115:                                            + nodeContextName.toString()
116:                                            + "] exists, but is missing required folder attribute ["
117:                                            + NODE_TYPE + EQUALS + FOLDER + "]");
118:                        }
119:
120:                    } catch (NameNotFoundException nnfe) {
121:                        // context was not found, so create it
122:                        Attributes folderAttributes = new BasicAttributes(
123:                                NODE_TYPE, FOLDER);
124:
125:                        folderAttributes.put(NAME, name);
126:
127:                        initialContext.createSubcontext(nodeContextName,
128:                                folderAttributes);
129:                    }
130:
131:                    // create the new JNDIFolder and return it
132:                    return new JNDIFolder(parent, name, parentJNDIFolder
133:                            .getSubFolderFactory(), parentJNDIFolder
134:                            .getConfigurationDocumentFactory(),
135:                            parentJNDIFolder.getLinkNodeFactory(),
136:                            initialContext, nodeContextName, this .config);
137:
138:                } catch (NamingException ne) {
139:                    throw new NodeCreationException(this .getClass(), parent,
140:                            name, "Problem reading JNDI directory", ne);
141:                }
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.