KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > admin > PartTypeUsesBinding


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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.outerj.daisy.frontend.admin;
17
18 import org.apache.cocoon.forms.binding.AbstractCustomBinding;
19 import org.apache.cocoon.forms.formmodel.Widget;
20 import org.apache.cocoon.forms.formmodel.Repeater;
21 import org.outerj.daisy.repository.schema.DocumentType;
22 import org.outerj.daisy.repository.schema.PartTypeUse;
23 import org.outerj.daisy.repository.schema.RepositorySchema;
24 import org.outerj.daisy.repository.schema.PartType;
25 import org.outerj.daisy.repository.Repository;
26
27 public class PartTypeUsesBinding extends AbstractCustomBinding {
28     protected void doLoad(Widget widget, org.apache.commons.jxpath.JXPathContext jxPathContext) throws Exception JavaDoc {
29         Repeater repeater = (Repeater)widget;
30
31         DocumentType documentType = (DocumentType)jxPathContext.getValue(".");
32         PartTypeUse[] partTypeUses = documentType.getPartTypeUses();
33         for (int i = 0; i < partTypeUses.length; i++) {
34           Repeater.RepeaterRow row = repeater.addRow();
35           row.getChild("id").setValue(new java.lang.Long JavaDoc(partTypeUses[i].getPartType().getId()));
36           row.getChild("name").setValue(partTypeUses[i].getPartType().getName());
37           row.getChild("required").setValue(Boolean.valueOf(partTypeUses[i].isRequired()));
38         }
39     }
40
41     protected void doSave(Widget widget, org.apache.commons.jxpath.JXPathContext jxPathContext) throws Exception JavaDoc {
42         Repeater repeater = (Repeater)widget;
43
44         DocumentType documentType = (DocumentType)jxPathContext.getValue(".");
45         documentType.clearPartTypeUses();
46         Repository repository = (Repository)widget.getForm().getAttribute("DaisyRepository");
47         RepositorySchema repositorySchema = repository.getRepositorySchema();
48         for (int i = 0; i < repeater.getSize(); i++) {
49           Long JavaDoc partTypeId = (Long JavaDoc)repeater.getRow(i).getChild("id").getValue();
50           PartType partType = repositorySchema.getPartTypeById(partTypeId.longValue(), false);
51           documentType.addPartType(partType, ((Boolean JavaDoc)repeater.getRow(i).getChild("required").getValue()).booleanValue());
52         }
53     }
54 }
55
Popular Tags