001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/query/virtualmetainfo/LinkMetaPropertyAnnotationHelper.java,v 1.1.1.1 2004/03/25 12:08:37 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:37 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruņa
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruņa nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040: package es.udc.mypersonalizer.kernel.model.query.virtualmetainfo;
041:
042: import java.util.Arrays;
043: import java.util.HashSet;
044: import java.util.Set;
045:
046: import es.udc.mypersonalizer.kernel.conventions.ServiceConventions;
047: import es.udc.mypersonalizer.kernel.model.annotators.AnnotatedObject;
048: import es.udc.mypersonalizer.kernel.model.annotators.AnnotationHelper;
049:
050: /**
051: * Utility class to simplify the use of anotations for virtual metaproperties
052: * representing a link to a metaservice.
053: *
054: * @author Abel Muinho
055: * @since 1.0
056: */
057: public class LinkMetaPropertyAnnotationHelper {
058:
059: /** Hidden constructor. */
060: private LinkMetaPropertyAnnotationHelper() { /* empty. */
061: }
062:
063: private final static Set internalServices = new HashSet(
064: Arrays
065: .asList(new String[] {
066: ServiceConventions.DESKTOP_LAYOUT_SERVICE_IDENTIFIER,
067: ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER,
068: ServiceConventions.USER_REGISTRATION_INFORMATION_SERVICE_IDENTIFIER,
069: ServiceConventions.WORKSPACE_LAYOUT_SERVICE_IDENTIFIER }));
070:
071: /** Name of the annotation for the source property scoped name. */
072: public final static String SOURCE_PROPERTY_ANNOTATION = "sourceProperty";
073: /** Name of the annotation for the target element's identifier. */
074: public final static String TARGET_ID_ANNOTATION = "targetId";
075: /** Name of the annotation for the target metaservice service identifier. */
076: public final static String TARGET_METASERVICE_ANNOTATION = "metaservice";
077:
078: /** Obtains the source property scoped name annotation.
079: * @param mp the metaproperty whose annotation is to be returned.
080: * @return the value of the annotation, or <code>null</code> if it does
081: * not exist.
082: */
083: public static final String getSourceProperty(AnnotatedObject mp) {
084: return AnnotationHelper.getAnnotation(mp,
085: SOURCE_PROPERTY_ANNOTATION);
086: }
087:
088: /** Obtains the target element's identifier annotation.
089: * @param mp the metaproperty whose annotation is to be returned.
090: * @return the value of the annotation, or <code>null</code> if it does
091: * not exist.
092: */
093: public static final String getTargetId(AnnotatedObject mp) {
094: return AnnotationHelper.getAnnotation(mp, TARGET_ID_ANNOTATION);
095: }
096:
097: /** Obtains the target metaservice service identifier annotation.
098: * @param mp the metaproperty whose annotation is to be returned.
099: * @return the value of the annotation, or <code>null</code> if it does
100: * not exist.
101: */
102: public static final String getTargetMetaService(AnnotatedObject mp) {
103: return AnnotationHelper.getAnnotation(mp,
104: TARGET_METASERVICE_ANNOTATION);
105: }
106:
107: /**
108: * Determines if the link is to an internal service (that is, one that's
109: * managed specially by MyPersonalizer).
110: * @param ao the metaservice link virtual metaproperty.
111: * @return <code>true</code> if it is linking to an internal metaservice,
112: * <code>false</code> otherwise.
113: */
114: public static final boolean isInternalReference(AnnotatedObject ao) {
115: return internalServices.contains(getTargetMetaService(ao));
116: }
117:
118: }
|