File Source: WeblogCategoryWrapper.java
/*
P/P * Method: org.apache.roller.weblogger.pojos.wrapper.WeblogCategoryWrapper__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.pojos.wrapper;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Set;
25 import org.apache.roller.weblogger.WebloggerException;
26 import org.apache.roller.weblogger.business.URLStrategy;
27 import org.apache.roller.weblogger.pojos.WeblogCategory;
28 import org.apache.roller.weblogger.pojos.WeblogEntry;
29
30
31 /**
32 * Pojo safety wrapper for WeblogCategory objects.
33 */
34 public class WeblogCategoryWrapper {
35
36 // keep a reference to the wrapped pojo
37 private final WeblogCategory pojo;
38
39 // url strategy to use for any url building
40 private final URLStrategy urlStrategy;
41
42
43 // this is private so that we can force the use of the .wrap(pojo) method
/*
P/P * Method: void org.apache.roller.weblogger.pojos.wrapper.WeblogCategoryWrapper(WeblogCategory, URLStrategy)
*
* Postconditions:
* this.pojo == toWrap
* init'ed(this.pojo)
* this.urlStrategy == strat
* init'ed(this.urlStrategy)
*/
44 private WeblogCategoryWrapper(WeblogCategory toWrap, URLStrategy strat) {
45 this.pojo = toWrap;
46 this.urlStrategy = strat;
47 }
48
49
50 // wrap the given pojo if it is not null
51 public static WeblogCategoryWrapper wrap(WeblogCategory toWrap, URLStrategy strat) {
/*
P/P * Method: WeblogCategoryWrapper wrap(WeblogCategory, URLStrategy)
*
* Postconditions:
* return_value == One-of{&new WeblogCategoryWrapper(wrap#1), null}
* return_value in Addr_Set{null,&new WeblogCategoryWrapper(wrap#1)}
* new WeblogCategoryWrapper(wrap#1) num objects <= 1
* new WeblogCategoryWrapper(wrap#1).pojo == toWrap
* new WeblogCategoryWrapper(wrap#1).pojo != null
* new WeblogCategoryWrapper(wrap#1).urlStrategy == strat
* init'ed(new WeblogCategoryWrapper(wrap#1).urlStrategy)
*
* Test Vectors:
* toWrap: Addr_Set{null}, Inverse{null}
*/
52 if(toWrap != null)
53 return new WeblogCategoryWrapper(toWrap, strat);
54
55 return null;
56 }
57
58
59 public String getId() {
/*
P/P * Method: String getId()
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
60 return this.pojo.getId();
61 }
62
63
64 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
65 return this.pojo.getName();
66 }
67
68
69 public String getDescription() {
/*
P/P * Method: String getDescription()
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
70 return this.pojo.getDescription();
71 }
72
73
74 public String getImage() {
/*
P/P * Method: String getImage()
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
75 return this.pojo.getImage();
76 }
77
78
79 public String getPath() {
/*
P/P * Method: String getPath()
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
80 return this.pojo.getPath();
81 }
82
83
84 public WeblogWrapper getWebsite() {
/*
P/P * Method: WeblogWrapper getWebsite()
*
* Preconditions:
* this.pojo != null
*
* Presumptions:
* org.apache.roller.weblogger.pojos.WeblogCategory:getWebsite(...)@85 != null
*
* Postconditions:
* return_value == &new WeblogWrapper(wrap#1)
* new WeblogWrapper(wrap#1) num objects == 1
* new WeblogWrapper(wrap#1).pojo != null
* new WeblogWrapper(wrap#1).urlStrategy == this.urlStrategy
* init'ed(new WeblogWrapper(wrap#1).urlStrategy)
*/
85 return WeblogWrapper.wrap(this.pojo.getWebsite(), urlStrategy);
86 }
87
88
89 public WeblogCategoryWrapper getParent() {
/*
P/P * Method: WeblogCategoryWrapper getParent()
*
* Preconditions:
* this.pojo != null
*
* Presumptions:
* org.apache.roller.weblogger.pojos.WeblogCategory:getParent(...)@90 != null
*
* Postconditions:
* return_value == &new WeblogCategoryWrapper(wrap#1)
* new WeblogCategoryWrapper(wrap#1) num objects == 1
* new WeblogCategoryWrapper(wrap#1).pojo != null
* new WeblogCategoryWrapper(wrap#1).urlStrategy == this.urlStrategy
* init'ed(new WeblogCategoryWrapper(wrap#1).urlStrategy)
*/
90 return WeblogCategoryWrapper.wrap(this.pojo.getParent(), urlStrategy);
91 }
92
93
94 public List getWeblogCategories() {
/*
P/P * Method: List getWeblogCategories()
*
* Preconditions:
* this.pojo != null
*
* Presumptions:
* org.apache.roller.weblogger.pojos.WeblogCategory:getWeblogCategories(...)@95 != null
*
* Postconditions:
* return_value == &new ArrayList(getWeblogCategories#1)
* new ArrayList(getWeblogCategories#1) num objects == 1
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@103: {0}, {1}
*/
95 Set initialCollection = this.pojo.getWeblogCategories();
96
97 // iterate through and wrap
98 // we force the use of an ArrayList because it should be good enough to cover
99 // for any Collection type we encounter.
100 ArrayList wrappedCollection = new ArrayList(initialCollection.size());
101 Iterator it = initialCollection.iterator();
102 int i = 0;
103 while(it.hasNext()) {
104 wrappedCollection.add(i,WeblogCategoryWrapper.wrap((WeblogCategory) it.next(), urlStrategy));
+ 105 i++;
106 }
107
108 return wrappedCollection;
109 }
110
111
112 public List retrieveWeblogEntries(boolean subcats)
113 throws WebloggerException {
114
/*
P/P * Method: List retrieveWeblogEntries(bool)
*
* Preconditions:
* this.pojo != null
*
* Presumptions:
* org.apache.roller.weblogger.pojos.WeblogCategory:retrieveWeblogEntries(...)@115 != null
*
* Postconditions:
* return_value == &new ArrayList(retrieveWeblogEntries#1)
* new ArrayList(retrieveWeblogEntries#1) num objects == 1
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@123: {0}, {1}
*/
115 List initialCollection = this.pojo.retrieveWeblogEntries(subcats);
116
117 // iterate through and wrap
118 // we force the use of an ArrayList because it should be good enough to cover
119 // for any Collection type we encounter.
120 ArrayList wrappedCollection = new ArrayList(initialCollection.size());
121 Iterator it = initialCollection.iterator();
122 int i = 0;
123 while(it.hasNext()) {
124 wrappedCollection.add(i,WeblogEntryWrapper.wrap((WeblogEntry) it.next(), urlStrategy));
+ 125 i++;
126 }
127
128 return wrappedCollection;
129 }
130
131
132 // TODO: this method doesn't work and propably doesn't need to be here anyways?
133 public boolean descendentOf(WeblogCategory ancestor) {
/*
P/P * Method: bool descendentOf(WeblogCategory)
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
134 return this.pojo.descendentOf(ancestor);
135 }
136
137
138 public boolean isInUse() {
/*
P/P * Method: bool isInUse()
*
* Preconditions:
* this.pojo != null
*
* Postconditions:
* init'ed(return_value)
*/
139 return this.pojo.isInUse();
140 }
141
142 }
SofCheck Inspector Build Version : 2.18479
| WeblogCategoryWrapper.java |
2009-Jan-02 14:25:40 |
| WeblogCategoryWrapper.class |
2009-Sep-04 03:12:32 |