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.wicket.markup;
018:
019: import java.lang.ref.WeakReference;
020: import java.util.Locale;
021:
022: import org.apache.wicket.MarkupContainer;
023:
024: /**
025: * Because a Component has reference to its parents, which eventually is the
026: * Page, and because the Page contains a reference to the Session, keeping a
027: * "copy" of a component is very expensive. ContainerInfo shall be used instead
028: * of MarkupContainer whenever a small subset of the container's information is
029: * required.
030: *
031: * @author Juergen Donnerstag
032: */
033: public class ContainerInfo {
034: private final WeakReference/* <Class> */containerClassRef;
035: private final Locale locale;
036: private final String style;
037: private final String variation;
038: private final String fileExtension;
039:
040: /**
041: * Construct.
042: *
043: * @param container
044: * The container to create the information from
045: */
046: public ContainerInfo(final MarkupContainer container) {
047: this (container.getClass(), container.getLocale(), container
048: .getStyle(), null, container.getMarkupType());
049: }
050:
051: /**
052: * Construct.
053: *
054: * @param containerClass
055: * @param locale
056: * @param style
057: * @param variation
058: * @param fileExtension
059: */
060: public ContainerInfo(final Class containerClass,
061: final Locale locale, final String style,
062: final String variation, final String fileExtension) {
063: super ();
064: this .containerClassRef = new WeakReference(containerClass);
065: this .locale = locale;
066: this .style = style;
067: this .variation = variation;
068: this .fileExtension = fileExtension;
069: }
070:
071: /**
072: *
073: * @return The container class
074: */
075: public Class getContainerClass() {
076: return (Class) containerClassRef.get();
077: }
078:
079: /**
080: *
081: * @return The container markup type (== file extension)
082: */
083: public String getFileExtension() {
084: return fileExtension;
085: }
086:
087: /**
088: *
089: * @return The container locale
090: */
091: public Locale getLocale() {
092: return locale;
093: }
094:
095: /**
096: *
097: * @return The container style
098: */
099: public String getStyle() {
100: return style;
101: }
102:
103: /**
104: *
105: * @return The containers variation
106: */
107: public String getVariation() {
108: return variation;
109: }
110:
111: /**
112: *
113: * @see java.lang.Object#toString()
114: */
115: public String toString() {
116: return ((Class) containerClassRef.get()).getName() + ":"
117: + locale + ":" + style + ":" + fileExtension;
118: }
119: }
|