001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2004-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.registry.xml;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.List;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.java.plugin.registry.Documentation;
028: import org.java.plugin.registry.Identity;
029:
030: /**
031: * @version $Id$
032: */
033: class DocumentationImpl<T extends Identity> implements Documentation<T> {
034: /**
035: * Logger object.
036: */
037: protected static Log log = LogFactory
038: .getLog(DocumentationImpl.class);
039:
040: private final T identity;
041: private final ModelDocumentation model;
042: private List<Reference<T>> references;
043:
044: DocumentationImpl(final T anIdentity,
045: final ModelDocumentation aModel) {
046: identity = anIdentity;
047: model = aModel;
048: if ((model.getCaption() == null)
049: || (model.getCaption().trim().length() == 0)) {
050: model.setCaption(""); //$NON-NLS-1$
051: }
052: references = new ArrayList<Reference<T>>(model.getReferences()
053: .size());
054: for (ModelDocumentationReference reference : model
055: .getReferences())
056: references.add(new ReferenceImpl(reference));
057:
058: references = Collections.unmodifiableList(references);
059: if (model.getText() == null) {
060: model.setText(""); //$NON-NLS-1$
061: }
062: if (log.isDebugEnabled()) {
063: log.debug("object instantiated: " + this ); //$NON-NLS-1$
064: }
065: }
066:
067: /**
068: * @see org.java.plugin.registry.Documentation#getCaption()
069: */
070: public String getCaption() {
071: return model.getCaption();
072: }
073:
074: /**
075: * @see org.java.plugin.registry.Documentation#getText()
076: */
077: public String getText() {
078: return model.getText();
079: }
080:
081: /**
082: * @see org.java.plugin.registry.Documentation#getReferences()
083: */
084: public Collection<Reference<T>> getReferences() {
085: return references;
086: }
087:
088: /**
089: * @see org.java.plugin.registry.Documentation#getDeclaringIdentity()
090: */
091: public T getDeclaringIdentity() {
092: return identity;
093: }
094:
095: private class ReferenceImpl implements Reference<T> {
096: private final ModelDocumentationReference modelRef;
097:
098: ReferenceImpl(final ModelDocumentationReference aModel) {
099: modelRef = aModel;
100: if ((modelRef.getCaption() == null)
101: || (modelRef.getCaption().trim().length() == 0)) {
102: modelRef.setCaption(""); //$NON-NLS-1$
103: }
104: if ((modelRef.getPath() == null)
105: || (modelRef.getPath().trim().length() == 0)) {
106: modelRef.setPath(""); //$NON-NLS-1$
107: }
108: if (log.isDebugEnabled()) {
109: log.debug("object instantiated: " + this ); //$NON-NLS-1$
110: }
111: }
112:
113: /**
114: * @see org.java.plugin.registry.Documentation.Reference#getCaption()
115: */
116: public String getCaption() {
117: return modelRef.getCaption();
118: }
119:
120: /**
121: * @see org.java.plugin.registry.Documentation.Reference#getRef()
122: */
123: public String getRef() {
124: return modelRef.getPath();
125: }
126:
127: /**
128: * @see org.java.plugin.registry.Documentation.Reference#getDeclaringIdentity()
129: */
130: public T getDeclaringIdentity() {
131: return DocumentationImpl.this.getDeclaringIdentity();
132: }
133: }
134: }
|