%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.util.ojb.ACLFieldConversion |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.util.ojb; |
|
18 | ||
19 | import java.util.ArrayList; |
|
20 | import java.util.Iterator; |
|
21 | import java.util.List; |
|
22 | import java.util.StringTokenizer; |
|
23 | ||
24 | import org.apache.ojb.broker.accesslayer.conversions.ConversionException; |
|
25 | import org.apache.ojb.broker.accesslayer.conversions.FieldConversion; |
|
26 | ||
27 | /** |
|
28 | * ACLFieldConversion |
|
29 | * |
|
30 | * OJB field conversion: Helps transparently map ACL List members |
|
31 | * to/from database table column that that contains an ordered |
|
32 | * CSV list of strings. |
|
33 | */ |
|
34 | 0 | public class ACLFieldConversion implements FieldConversion |
35 | { |
|
36 | private static final String DELIM = ","; |
|
37 | ||
38 | /** |
|
39 | * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object) |
|
40 | */ |
|
41 | public Object javaToSql(Object arg0) throws ConversionException |
|
42 | { |
|
43 | 0 | if (arg0 instanceof List) |
44 | { |
|
45 | 0 | List csvList = (List) arg0; |
46 | 0 | if (csvList.size() > 1) |
47 | { |
|
48 | 0 | StringBuffer buffer = null; |
49 | 0 | Iterator values = csvList.iterator(); |
50 | 0 | while (values.hasNext()) |
51 | { |
|
52 | 0 | String value = (String)values.next(); |
53 | 0 | if (value.length() > 0) |
54 | { |
|
55 | 0 | if (buffer == null) |
56 | { |
|
57 | 0 | buffer = new StringBuffer(255); |
58 | } |
|
59 | else |
|
60 | { |
|
61 | 0 | buffer.append(DELIM); |
62 | } |
|
63 | 0 | buffer.append(value); |
64 | } |
|
65 | 0 | } |
66 | 0 | if (buffer != null) |
67 | { |
|
68 | 0 | return buffer.toString(); |
69 | } |
|
70 | 0 | } |
71 | 0 | else if (!csvList.isEmpty()) |
72 | { |
|
73 | 0 | String value = (String)csvList.get(0); |
74 | 0 | if (value.length() > 0) |
75 | { |
|
76 | 0 | return value; |
77 | } |
|
78 | } |
|
79 | 0 | return ""; |
80 | } |
|
81 | 0 | return arg0; |
82 | } |
|
83 | ||
84 | /** |
|
85 | * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object) |
|
86 | */ |
|
87 | public Object sqlToJava(Object arg0) throws ConversionException |
|
88 | { |
|
89 | 0 | if (arg0 instanceof String) |
90 | { |
|
91 | 0 | List aclList = new ArrayList(4); |
92 | 0 | StringTokenizer tokens = new StringTokenizer((String) arg0, DELIM); |
93 | 0 | while (tokens.hasMoreTokens()) |
94 | { |
|
95 | 0 | String value = tokens.nextToken().trim(); |
96 | 0 | if (value.length() > 0) |
97 | { |
|
98 | 0 | aclList.add(value); |
99 | } |
|
100 | 0 | } |
101 | 0 | return aclList; |
102 | } |
|
103 | 0 | return arg0; |
104 | } |
|
105 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |