1 17 18 package org.sape.carbon.core.config.node; 19 20 import org.sape.carbon.core.config.Config; 21 import org.sape.carbon.core.config.Configuration; 22 import org.sape.carbon.core.config.format.ConfigurationFormatException; 23 24 41 public class NestedConfigurationDocumentFactory implements NodeFactory { 42 43 46 public Node getInstance(Node parent, String name) 47 throws NodeCreationException { 48 49 try { 50 51 AbstractConfigurationDocument parentDoc = 52 (AbstractConfigurationDocument) parent; 53 Configuration parentConfig = parentDoc.readConfiguration(); 54 55 Configuration childConfig = 56 parentDoc.getFormatService().getChildConfiguration( 57 parentConfig, 58 name); 59 60 ConfigurationDocument nestedDoc; 61 62 if (childConfig != null) { 63 String childConfigName = childConfig.getConfigurationName(); 64 String parentConfigName = parentConfig.getConfigurationName(); 65 66 if (!childConfigName.startsWith(parentConfigName + Node.DELIMITER)) { 67 nestedDoc = 68 (ConfigurationDocument) Config.getInstance().fetchNode( 69 childConfigName); 70 } else { 71 nestedDoc = new NestedConfigurationDocument(parentDoc, name); 72 } 73 } else { 74 nestedDoc = new NestedConfigurationDocument(parentDoc, name); 75 } 76 77 return nestedDoc; 78 79 } catch (ClassCastException cce) { 80 throw new NodeCreationException( 81 this.getClass(), 82 parent, 83 name, 84 "parent must extend AbsractConfigurationDocument, it's class was [" 85 + parent.getClass().getName() 86 + "]", 87 cce); 88 89 } catch (NodeIOException nioe) { 90 throw new NodeCreationException( 91 this.getClass(), 92 parent, 93 name, 94 "could not read configuration", 95 nioe); 96 97 } catch (NodeNotFoundException nnfe) { 98 throw new NodeCreationException( 99 this.getClass(), 100 parent, 101 name, 102 "referenced node was not found", 103 nnfe); 104 105 } catch (ConfigurationFormatException cfe) { 106 throw new NodeCreationException( 107 this.getClass(), 108 parent, 109 name, 110 "could not read configuration", 111 cfe); 112 } 113 } 114 115 116 117 } | Popular Tags |