01: /*
02: * (C) Copyright 2006 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package com.nabhinc.condition;
22:
23: import java.io.StringReader;
24:
25: import javax.xml.bind.JAXBContext;
26: import javax.xml.bind.JAXBException;
27: import javax.xml.bind.Unmarshaller;
28:
29: import org.apache.commons.logging.Log;
30: import org.apache.commons.logging.LogFactory;
31: import org.w3c.dom.Element;
32:
33: import com.nabhinc.core.Constants;
34:
35: /**
36: *
37: *
38: * @author Padmanabh Dabke
39: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
40: */
41: public class ConditionFactory {
42: private static Log cfLogger = LogFactory
43: .getLog(ConditionFactory.class);
44: public static Condition OWNER_CONDITION = null;
45: public static Condition ADMIN_CONDITION = null;
46: public static Condition OWNER_OR_ADMIN_CONDITION = null;
47: private static JAXBContext cfJAXBContext = null;
48:
49: static {
50: try {
51: OWNER_CONDITION = new OwnerCondition();
52: ADMIN_CONDITION = new AllowRoles(
53: new String[] { Constants.ADMIN_ROLE });
54: Or cond = new Or();
55: cond.children = new Condition[] { OWNER_CONDITION,
56: ADMIN_CONDITION };
57: OWNER_OR_ADMIN_CONDITION = cond;
58: cfJAXBContext = JAXBContext
59: .newInstance("com.nabhinc.condition");
60: } catch (JAXBException e) {
61: cfLogger.error(
62: "Failed to create JAXBContext for conditions.", e);
63: }
64: }
65:
66: public static Condition create(Element xmlConfig)
67: throws JAXBException {
68: Unmarshaller um = cfJAXBContext.createUnmarshaller();
69: return (Condition) um.unmarshal(xmlConfig);
70: }
71:
72: public static Condition create(String xmlConfig)
73: throws JAXBException {
74: Unmarshaller um = cfJAXBContext.createUnmarshaller();
75: return (Condition) um.unmarshal(new StringReader(xmlConfig));
76: }
77: }
|