Coverage Report - org.argouml.profile.internal.ProfileMeta
 
Classes in this File Line Coverage Branch Coverage Complexity
ProfileMeta
48%
21/43
25%
2/8
2.571
 
 1  
 /* $Id: ProfileMeta.java 18257 2010-04-13 17:58:32Z tfmorris $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2008,2010 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    maas - Initial implementation
 11  
  *    tfmorris
 12  
  *****************************************************************************
 13  
  *
 14  
  * Some portions of this file was previously release using the BSD License:
 15  
  */
 16  
 
 17  
 // Copyright (c) 2008 The Regents of the University of California. All
 18  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 19  
 // software and its documentation without fee, and without a written
 20  
 // agreement is hereby granted, provided that the above copyright notice
 21  
 // and this paragraph appear in all copies. This software program and
 22  
 // documentation are copyrighted by The Regents of the University of
 23  
 // California. The software program and documentation are supplied "AS
 24  
 // IS", without any accompanying services from The Regents. The Regents
 25  
 // does not warrant that the operation of the program will be
 26  
 // uninterrupted or error-free. The end-user understands that the program
 27  
 // was developed for research purposes and is advised not to rely
 28  
 // exclusively on the program for any reason. IN NO EVENT SHALL THE
 29  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 30  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 31  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 32  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 33  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 34  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 35  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 36  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 37  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 38  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 39  
 
 40  
 package org.argouml.profile.internal;
 41  
 
 42  
 import java.net.MalformedURLException;
 43  
 import java.util.ArrayList;
 44  
 import java.util.Collection;
 45  
 import java.util.Collections;
 46  
 import java.util.HashSet;
 47  
 import java.util.Set;
 48  
 
 49  
 import org.apache.log4j.Logger;
 50  
 import org.argouml.cognitive.Critic;
 51  
 import org.argouml.cognitive.ToDoItem;
 52  
 import org.argouml.model.Model;
 53  
 import org.argouml.profile.CoreProfileReference;
 54  
 import org.argouml.profile.Profile;
 55  
 import org.argouml.profile.ProfileException;
 56  
 import org.argouml.profile.ProfileModelLoader;
 57  
 import org.argouml.profile.ProfileReference;
 58  
 import org.argouml.profile.ResourceModelLoader;
 59  
 import org.argouml.profile.internal.ocl.CrOCL;
 60  
 import org.argouml.profile.internal.ocl.InvalidOclException;
 61  
 
 62  
 /**
 63  
  * Meta Profile which defines the TaggedValues to be used in User defined
 64  
  * Profiles
 65  
  * 
 66  
  * @author maas
 67  
  */
 68  
 public class ProfileMeta extends Profile {
 69  
 
 70  900
     private static final Logger LOG = Logger.getLogger(ProfileMeta.class);
 71  
     
 72  
     private static final String PROFILE_FILE = "metaprofile.xmi";
 73  900
     private ProfileReference profileReference = null;
 74  
     
 75  900
     private Collection model = null;
 76  
     
 77  900
     Set<Critic> critics = null;
 78  
 
 79  
     /**
 80  
      * Creates a new instance of this profile
 81  
      * 
 82  
      * @throws ProfileException if something goes wrong
 83  
      */
 84  
     @SuppressWarnings("unchecked")
 85  
     public ProfileMeta() throws ProfileException {
 86  900
         super();
 87  
         try {
 88  900
             profileReference = new CoreProfileReference(PROFILE_FILE);
 89  0
         } catch (MalformedURLException e) {
 90  0
             throw new ProfileException(
 91  
                     "Exception while creating profile reference.", e);
 92  900
         }
 93  900
     }
 94  
 
 95  
     private Collection getModel() {
 96  0
         if (model == null) {
 97  0
             ProfileModelLoader profileModelLoader = new ResourceModelLoader();
 98  
             try {
 99  0
                 model = profileModelLoader.loadModel(profileReference);
 100  0
             } catch (ProfileException e) {
 101  0
                 LOG.error("Exception loading metaprofile " + PROFILE_FILE, e);
 102  0
             }
 103  
 
 104  0
             if (model == null) {
 105  0
                 model = new ArrayList();
 106  0
                 model.add(Model.getModelManagementFactory().createModel());
 107  
             }
 108  
         }
 109  0
         return model;
 110  
     }
 111  
 
 112  
     private void loadWellFormednessRules() {
 113  900
         critics = new HashSet<Critic>();
 114  
                 
 115  
         try {
 116  900
             critics.add(new CrOCL("context ModelElement inv: "
 117  
                     + "self.taggedValue->" 
 118  
                     + "exists(x|x.type.name='Dependency') implies "
 119  
                               + "self.stereotype->exists(x|x.name = 'Profile')",
 120  
                  "The 'Dependency' tag definition should be applied"
 121  
                                 + " only to profiles.", null,
 122  
                     ToDoItem.MED_PRIORITY, null, null,
 123  
                     "http://argouml.tigris.org/"));
 124  0
         } catch (InvalidOclException e) {
 125  0
             e.printStackTrace();
 126  900
         }
 127  
 
 128  
         try {
 129  900
             critics.add(new CrOCL("context ModelElement inv: "
 130  
                     + "self.taggedValue->" 
 131  
                     + "exists(x|x.type.name='Figure') or "
 132  
                     + "exists(x|x.type.name='Description') or "
 133  
                     + "exists(x|x.type.name='i18n') or "
 134  
                     + "exists(x|x.type.name='KnowledgeType') or "
 135  
                     + "exists(x|x.type.name='MoreInfoURL') or "
 136  
                     + "exists(x|x.type.name='Priority') or "
 137  
                     + "exists(x|x.type.name='Description') or "
 138  
                     + "exists(x|x.type.name='SupportedDecision') or "
 139  
                     + "exists(x|x.type.name='Headline') "
 140  
                     + "implies "
 141  
                               + "self.stereotype->exists(x|x.name = 'Critic')",
 142  
                               
 143  
                     "Misuse of Metaprofile TaggedValues",
 144  
                     "The 'Figure', 'i18n', 'KnowledgeType', 'MoreInfoURL', " 
 145  
                     + "'Priority', 'SupportedDecision', 'Description' " 
 146  
                     + "and 'Headline' tag definitions "
 147  
                     + "should be applied only to OCL critics.",
 148  
                     
 149  
                     ToDoItem.MED_PRIORITY, null, null,
 150  
                     "http://argouml.tigris.org/"));
 151  0
         } catch (InvalidOclException e) {
 152  0
             e.printStackTrace();
 153  900
         }
 154  
         
 155  
         try {
 156  900
             critics.add(new CrOCL("context Stereotype inv: "
 157  
                     + "self.namespace.stereotype->exists(x|x.name = 'Profile')",
 158  
                             "Stereotypes should be declared inside a Profile. ",
 159  
                             "Please add the <<Profile>> stereotype to "
 160  
                                    + "the containing Namespace",
 161  
                     ToDoItem.MED_PRIORITY, null, null,
 162  
                     "http://argouml.tigris.org/"));
 163  0
         } catch (InvalidOclException e) {
 164  0
             e.printStackTrace();
 165  900
         }
 166  
 
 167  900
         setCritics(critics);
 168  900
     }
 169  
     
 170  
     @Override
 171  
     public String getDisplayName() {
 172  195
         return "MetaProfile";
 173  
     }
 174  
 
 175  
     @Override
 176  
     public Collection getProfilePackages() throws ProfileException {
 177  0
         return Collections.unmodifiableCollection(getModel());
 178  
     }
 179  
 
 180  
 
 181  
     @Override
 182  
     public Collection<Object> getLoadedPackages() {
 183  0
         if (model == null) {
 184  0
             return Collections.emptyList();
 185  
         } else {
 186  0
             return Collections.unmodifiableCollection(model);
 187  
         }
 188  
     }
 189  
     
 190  
     @Override
 191  
     public Set<Critic> getCritics() {
 192  1880
         if (critics == null) {
 193  900
             loadWellFormednessRules();
 194  
         }
 195  1880
         return super.getCritics();
 196  
     }
 197  
     
 198  
 }