01: /*
02: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * 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 Emil Ong, Adam Megacz
28: */
29:
30: package com.caucho.jaxb.accessor;
31:
32: import static javax.xml.XMLConstants.*;
33:
34: import javax.xml.bind.JAXBException;
35: import javax.xml.bind.ValidationEvent;
36: import javax.xml.bind.ValidationEventHandler;
37: import javax.xml.bind.helpers.ValidationEventImpl;
38: import javax.xml.bind.helpers.ValidationEventLocatorImpl;
39: import javax.xml.namespace.QName;
40:
41: import java.lang.annotation.Annotation;
42: import java.lang.reflect.Type;
43:
44: import com.caucho.util.L10N;
45:
46: /** an Accessor is either a getter/setter pair or a field */
47: public abstract class Accessor {
48: public static final L10N L = new L10N(Accessor.class);
49:
50: protected int _order = -1;
51: protected String _name;
52:
53: public void setOrder(int order) {
54: _order = order;
55: }
56:
57: public int getOrder() {
58: return _order;
59: }
60:
61: public boolean checkOrder(int order, ValidationEventHandler handler) {
62: if (_order < 0 || _order == order)
63: return true;
64:
65: ValidationEvent event = new ValidationEventImpl(
66: ValidationEvent.ERROR, L.l("ordering error"),
67: new ValidationEventLocatorImpl());
68:
69: return handler.handleEvent(event);
70: }
71:
72: public abstract Object get(Object o) throws JAXBException;
73:
74: public abstract void set(Object o, Object value)
75: throws JAXBException;
76:
77: public abstract String getName();
78:
79: public abstract Class getType();
80:
81: public abstract Type getGenericType();
82:
83: public abstract Package getPackage();
84:
85: public abstract <A extends Annotation> A getAnnotation(Class<A> c);
86:
87: public abstract <A extends Annotation> A getPackageAnnotation(
88: Class<A> c);
89: }
|