001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.om.impl;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023: import java.util.Locale;
024:
025: import org.apache.jetspeed.om.common.MutableDescriptionSet;
026: import org.apache.jetspeed.util.JetspeedLocale;
027: import org.apache.pluto.om.common.Description;
028:
029: /**
030: * BaseDescriptionSet
031: *
032: * Supports
033: *
034: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
035: * @version $Id: DescriptionSetImpl.java 516448 2007-03-09 16:25:47Z ate $
036: *
037: */
038: public class DescriptionSetImpl implements MutableDescriptionSet,
039: Serializable {
040: /** Specifies the type Description we are storing */
041: protected String descriptionType;
042: protected Collection innerCollection;
043:
044: /**
045: *
046: */
047: public DescriptionSetImpl() {
048: super ();
049: this .innerCollection = new ArrayList();
050: }
051:
052: /**
053: * @param c
054: */
055: public DescriptionSetImpl(Collection c) {
056: this .innerCollection = c;
057: }
058:
059: public DescriptionSetImpl(String descriptionType) {
060: super ();
061: this .descriptionType = descriptionType;
062: this .innerCollection = new ArrayList();
063: }
064:
065: /**
066: * @see org.apache.pluto.om.common.DescriptionSet#get(java.util.Locale)
067: */
068: public Description get(Locale arg0) {
069: if (arg0 == null) {
070: throw new IllegalArgumentException(
071: "The Locale argument cannot be null");
072: }
073:
074: // TODO: This may cause concurrent modification exceptions
075: Iterator itr = iterator();
076: Description fallBack = null;
077: while (itr.hasNext()) {
078: Description desc = (Description) itr.next();
079: if (desc.getLocale().equals(arg0)) {
080: return desc;
081: }
082: // set fall back if we have a Locale that only has
083: // language set.
084: else if (desc.getLocale().getLanguage().equals(
085: arg0.getLanguage())) {
086: fallBack = desc;
087: } else if (fallBack == null
088: && desc.getLocale().equals(
089: JetspeedLocale.getDefaultLocale())) {
090: fallBack = desc;
091: }
092: }
093: return fallBack;
094: }
095:
096: /**
097: * @see org.apache.jetspeed.om.common.MutableDescriptionSet#addDescription(java.lang.String)
098: */
099: public void addDescription(Description description) {
100: innerCollection.add(description);
101: }
102:
103: /**
104: * @see org.apache.pluto.om.common.DescriptionSet#iterator()
105: */
106: public Iterator iterator() {
107: return innerCollection.iterator();
108: }
109:
110: /**
111: * @return
112: */
113: public Collection getInnerCollection() {
114: return innerCollection;
115: }
116:
117: /**
118: * @param collection
119: */
120: public void setInnerCollection(Collection collection) {
121: innerCollection = collection;
122: }
123:
124: }
|