KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > config > core > ResinInclude


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.config.core;
31
32 import com.caucho.config.Config;
33 import com.caucho.config.ConfigException;
34 import com.caucho.config.SchemaBean;
35 import com.caucho.log.Log;
36 import com.caucho.util.L10N;
37 import com.caucho.vfs.Path;
38 import com.caucho.vfs.Vfs;
39 import com.caucho.xml.LooseXml;
40
41 import org.w3c.dom.Document JavaDoc;
42
43 import javax.annotation.PostConstruct;
44 import java.util.logging.Logger JavaDoc;
45
46 /**
47  * Imports values from a separate file.
48  */

49 public class ResinInclude extends ResinControl {
50   private static final L10N L = new L10N(ResinInclude.class);
51   private static final Logger JavaDoc log = Log.open(ResinInclude.class);
52
53   private Path _path;
54   private boolean _isOptional = true;
55   private String JavaDoc _systemId;
56
57   /**
58    * Sets the current location.
59    */

60   public void setConfigSystemId(String JavaDoc systemId)
61   {
62     _systemId = systemId;
63   }
64   
65   /**
66    * Sets the resin:import path.
67    */

68   public void setHref(String JavaDoc path)
69   {
70     if (_systemId != null)
71       _path = Vfs.lookup().lookup(_systemId).getParent().lookup(path);
72     else
73       _path = Vfs.lookup().lookup(path);
74   }
75   
76   /**
77    * Sets the resin:import path.
78    */

79   public void setPath(String JavaDoc path)
80   {
81     setHref(path);
82   }
83   
84   /**
85    * Sets true if the path is optional.
86    */

87   public void setOptional(boolean optional)
88   {
89     _isOptional = optional;
90   }
91
92   @PostConstruct
93   public void init()
94     throws Exception JavaDoc
95   {
96     if (_path == null)
97       throw new ConfigException(L.l("'href' attribute missing from resin:include."));
98
99     if (_path.canRead() && ! _path.isDirectory()) {
100     }
101     else {
102       throw new ConfigException(L.l("Required file '{0}' can not be read for resin:include.",
103                     _path.getNativePath()));
104     }
105     
106     Object JavaDoc object = getObject();
107
108     String JavaDoc schema = null;
109
110     // Use the relax schema for beans with schema.
111
if (object instanceof SchemaBean) {
112       schema = ((SchemaBean) object).getSchema();
113     }
114
115     log.config(L.l("resin:include '{0}'.\nresin:include is deprecated. Please use resin:import instead.", _path.getNativePath()));
116
117
118     LooseXml xml = new LooseXml();
119
120     Document JavaDoc doc = xml.parseDocument(_path);
121
122     new Config().configure(object, doc); // , schema);
123
}
124 }
125
126
Popular Tags