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.MutableDisplayNameSet;
026: import org.apache.jetspeed.util.JetspeedLocale;
027: import org.apache.pluto.om.common.DisplayName;
028:
029: /**
030: * DisplayNameSetImpl
031: *
032: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
033: * @version $Id: DisplayNameSetImpl.java 517121 2007-03-12 07:45:49Z ate $
034: *
035: */
036: public class DisplayNameSetImpl implements MutableDisplayNameSet,
037: Serializable {
038:
039: /** Specifies the type Description we are storing */
040: protected String displayNameType;
041:
042: protected Collection innerCollection;
043:
044: public DisplayNameSetImpl() {
045: super ();
046: this .innerCollection = new ArrayList();
047: }
048:
049: public DisplayNameSetImpl(Collection collection) {
050: super ();
051: this .innerCollection = collection;
052: }
053:
054: /**
055: * @see org.apache.pluto.om.common.DisplayNameSet#get(java.util.Locale)
056: */
057: public DisplayName get(Locale arg0) {
058:
059: DisplayName fallBack = null;
060: Iterator searchItr = innerCollection.iterator();
061: while (searchItr.hasNext()) {
062: DisplayName aDName = (DisplayName) searchItr.next();
063: if (aDName.getLocale().equals(arg0)) {
064: return aDName;
065: } else if (aDName.getLocale().getLanguage().equals(
066: arg0.getLanguage())) {
067: fallBack = aDName;
068: } else if (fallBack == null
069: && aDName.getLocale().equals(
070: JetspeedLocale.getDefaultLocale())) {
071: fallBack = aDName;
072: }
073: }
074:
075: return fallBack;
076: }
077:
078: public void addDisplayName(DisplayName name) {
079: if (name == null) {
080: throw new IllegalArgumentException(
081: "DisplayName argument cannot be null");
082: }
083:
084: add(name);
085: }
086:
087: /**
088: * @see java.util.Collection#add(java.lang.Object)
089: */
090: public boolean add(Object o) {
091: return innerCollection.add(o);
092: }
093:
094: /**
095: * @see java.util.Collection#remove(java.lang.Object)
096: */
097: public boolean remove(Object o) {
098: return innerCollection.remove(o);
099: }
100:
101: /**
102: * @see org.apache.pluto.om.common.DisplayNameSet#iterator()
103: */
104: public Iterator iterator() {
105: return this .innerCollection.iterator();
106: }
107:
108: /**
109: * @return
110: */
111: public Collection getInnerCollection() {
112: return innerCollection;
113: }
114:
115: /**
116: * @param collection
117: */
118: public void setInnerCollection(Collection collection) {
119: innerCollection = collection;
120: }
121:
122: }
|