KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > util > CopletDataReferenceFieldHandler


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.util;
17
18 import org.apache.cocoon.portal.coplet.CopletData;
19 import org.apache.cocoon.portal.coplet.CopletInstanceData;
20
21 /**
22  * Field handler for external CopletData references.
23  *
24  * @author <a HREF="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
25  *
26  * @version CVS $Id: CopletDataReferenceFieldHandler.java 123407 2004-12-27 13:51:59Z cziegeler $
27  */

28 public class CopletDataReferenceFieldHandler extends ReferenceFieldHandler {
29
30     public Object JavaDoc getValue(Object JavaDoc object) {
31         CopletData copletData = ((CopletInstanceData) object).getCopletData();
32         if (copletData != null) {
33             return copletData.getId();
34         }
35         return null;
36     }
37
38     public Object JavaDoc newInstance(Object JavaDoc parent) {
39         return new CopletData();
40     }
41
42     public void resetValue(Object JavaDoc object) {
43         ((CopletInstanceData) object).setCopletData(null);
44     }
45
46     public void setValue(Object JavaDoc object, Object JavaDoc value) {
47         CopletData copletData = (CopletData) getObjectMap().get(value);
48         if (copletData == null) {
49             throw new ProfileException(
50                 "Referenced Coplet Data " + value + " does not exist.");
51         }
52         ((CopletInstanceData) object).setCopletData(copletData);
53     }
54 }
55
Popular Tags