alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.javacore.jmiimpl.javamodel;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.jmi.reflect.ConstraintViolationException;
import org.netbeans.jmi.javamodel.PrimitiveType;
import org.netbeans.jmi.javamodel.PrimitiveTypeClass;
import org.netbeans.jmi.javamodel.PrimitiveTypeKind;
import org.netbeans.jmi.javamodel.PrimitiveTypeKindEnum;
import org.netbeans.mdr.handlers.ClassProxyHandler;
import org.netbeans.mdr.persistence.MOFID;
import org.netbeans.mdr.persistence.StorageException;
import org.netbeans.mdr.storagemodel.StorableBaseObject;
import org.netbeans.mdr.storagemodel.StorableClass;
import org.netbeans.mdr.util.DebugException;

/**
 *
 * @author  mm109185
 */
public abstract class PrimitiveTypeClassImpl extends ClassProxyHandler implements PrimitiveTypeClass {
    private static final String MOFID_PREFIX = "primitive:"; // NOI18N
    private static Map allInstances;
    
    /** Creates a new instance of PackageClassImpl */
    public PrimitiveTypeClassImpl(StorableClass s) {
        super(s);
    }
    
    public PrimitiveType createPrimitiveType(String name, PrimitiveTypeKind kind) {
        throw new ConstraintViolationException(this, refMetaObject(), "Cannot explicitly create instances of PrimitiveType."); // NOI18N
    }
    
    public PrimitiveType createPrimitiveType() {
        throw new ConstraintViolationException(this, refMetaObject(), "Cannot explicitly create instances of PrimitiveType."); // NOI18N
    }
    
    private void initInstances() {
        if (allInstances == null) {
            try {
                StorableBaseObject s = _getDelegate();
                DeferredObject o;
                PrimitiveTypeImpl pt;
                PrimitiveTypeKind pk;
                
                allInstances=new HashMap();
                // void
                pk = PrimitiveTypeKindEnum.VOID;
                o = new DeferredObject(new MOFID(1, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // boolean
                pk = PrimitiveTypeKindEnum.BOOLEAN;
                o = new DeferredObject(new MOFID(2, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // byte
                pk = PrimitiveTypeKindEnum.BYTE;
                o = new DeferredObject(new MOFID(3, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // char
                pk = PrimitiveTypeKindEnum.CHAR;
                o = new DeferredObject(new MOFID(4, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // double
                pk = PrimitiveTypeKindEnum.DOUBLE;
                o = new DeferredObject(new MOFID(5, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // float
                pk = PrimitiveTypeKindEnum.FLOAT;
                o = new DeferredObject(new MOFID(6, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // int
                pk = PrimitiveTypeKindEnum.INT;
                o = new DeferredObject(new MOFID(7, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // long
                pk = PrimitiveTypeKindEnum.LONG;
                o = new DeferredObject(new MOFID(8, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
                
                // short
                pk = PrimitiveTypeKindEnum.SHORT;
                o = new DeferredObject(new MOFID(9, MOFID_PREFIX + pk.toString()), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
                pt = (PrimitiveTypeImpl) _getRepository().getHandler(o);
                pt.kind = pk;
                allInstances.put(pk.toString(), pt);
            } catch (StorageException e) {
                throw new DebugException();
            }
        }
    }
    
    PrimitiveType resolveType(String name) {
        initInstances();
        return (PrimitiveType) allInstances.get(name);
    }

    protected Collection _allOfClass(boolean recursive) {
        initInstances();
        return Collections.unmodifiableCollection(allInstances.values());
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.